Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Failing test case for "after_commit" on destroy #228

Open
wants to merge 1 commit into
base: rails4
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions test/paranoia_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down