From 370c6f0e287677117a9b89faa45420a587375463 Mon Sep 17 00:00:00 2001 From: Sebastian Korfmann Date: Tue, 21 Apr 2015 15:17:59 +0200 Subject: [PATCH] Failing test case for "after_commit" on destroy --- test/paranoia_test.rb | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) 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