diff --git a/lib/ripple/document/persistence.rb b/lib/ripple/document/persistence.rb index a6a3dd89..85d984df 100644 --- a/lib/ripple/document/persistence.rb +++ b/lib/ripple/document/persistence.rb @@ -91,7 +91,6 @@ def destroy! def destroy destroy! - true rescue Riak::FailedRequest false end diff --git a/spec/ripple/callbacks_spec.rb b/spec/ripple/callbacks_spec.rb index 0c9ced81..dea6f212 100644 --- a/spec/ripple/callbacks_spec.rb +++ b/spec/ripple/callbacks_spec.rb @@ -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")