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

_denormalize_destroy_to_* callback fixed to trigger before the destroy op #43

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
6 changes: 5 additions & 1 deletion lib/mongoid/alize/to_callback.rb
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,11 @@ def set_callback

def set_destroy_callback
unless callback_attached?("destroy", aliased_destroy_callback_name)
klass.set_callback(:destroy, :after, aliased_destroy_callback_name)
if self.metadata.dependent == :restrict
klass.set_callback(:destroy, :after, aliased_destroy_callback_name)
else
klass.set_callback(:destroy, :before, aliased_destroy_callback_name)
end
end
end

Expand Down
2 changes: 1 addition & 1 deletion spec/mongoid/alize/to_callback_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def define_and_create(callback_name=:define_callback)

describe "#set_destroy_callback" do
it "should set a destroy callback on the klass" do
mock(@callback.klass).set_callback(:destroy, :after, "denormalize_destroy_to_head")
mock(@callback.klass).set_callback(:destroy, :before, "denormalize_destroy_to_head")
@callback.send(:set_destroy_callback)
end

Expand Down