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 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
1 change: 0 additions & 1 deletion lib/ripple/document/persistence.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ def destroy!

def destroy
destroy!
true
rescue Riak::FailedRequest
false
end
Expand Down
14 changes: 13 additions & 1 deletion spec/ripple/callbacks_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,19 @@
end

subject { doc.new }


it "destroy should return false and not destroy the document when a callback returns false" do
# Make double sure, test without before_destroy first
u = User.create!(:email => 'nobody@domain.com')
u.destroy.should_not be false
User.find(u.key).should be nil
# Now real test
User.before_destroy { false }
u = User.create!(:email => 'nobody@domain.com')
u.destroy.should be false
User.find(u.key).should be_an_instance_of(User)
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