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

document.destroy now returns false if before_destroy callback returns fa... #290

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
3 changes: 1 addition & 2 deletions lib/ripple/document/persistence.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,7 @@ def destroy!
end

def destroy
destroy!
true
(destroy!)==false ? false : true
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If destroy! returns false, this line seems unnecessary. Just return the value of destroy! or !!destroy!.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree. It's an unnecessary check - although it makes sure it only ever returns true or false and not somethings else (like a Ripple::Document).

rescue Riak::FailedRequest
false
end
Expand Down
6 changes: 6 additions & 0 deletions spec/ripple/callbacks_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@

subject { doc.new }

#TG:
it "destory should return false when a callback returns false" do
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo s/destory/destroy/

doc.before_destroy { false }
subject.destroy.should be false
end

it "should add create, update, save, and destroy callback declarations" do
[:save, :create, :update, :destroy].each do |event|
doc.private_instance_methods.map(&:to_s).should include("_run_#{event}_callbacks")
Expand Down