diff --git a/test/paranoia_test.rb b/test/paranoia_test.rb index 1a5e4267..10e48488 100644 --- a/test/paranoia_test.rb +++ b/test/paranoia_test.rb @@ -111,6 +111,14 @@ def test_destroy_behavior_for_plain_models_callbacks assert model.instance_variable_get(:@after_commit_callback_called) end + def test_destroy_behavior_for_conditional_models_callbacks + model = ConditionalCallbackModel.new + model.save + model.remove_called_variables # clear called callback flags + model.destroy + + assert model.instance_variable_get(:@after_commit_callback_called) + end def test_delete_behavior_for_plain_models_callbacks model = CallbackModel.new @@ -858,6 +866,18 @@ def remove_called_variables end end +class ConditionalCallbackModel < ActiveRecord::Base + self.table_name = 'callback_models' + + acts_as_paranoid + + after_commit -> { instance_variable_set :@after_commit_callback_called, true }, on: :destroy + + def remove_called_variables + instance_variables.each {|name| (name.to_s.end_with?('_called')) ? remove_instance_variable(name) : nil} + end +end + class ParentModel < ActiveRecord::Base acts_as_paranoid has_many :paranoid_models