Skip to content

Commit

Permalink
adding code and spec to fix blindness to callbacks that return false …
Browse files Browse the repository at this point in the history
…during updates
  • Loading branch information
Chase Martyn authored and KieranP committed Apr 25, 2011
1 parent 2ea6a75 commit fe564b3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/mongoid/persistence/update.rb
Expand Up @@ -50,11 +50,12 @@ def persist
child.move_changes
child.new_record = false if child.new_record?
end
true
else
return false
end
end
end; true
end
end

protected
Expand Down
10 changes: 10 additions & 0 deletions spec/unit/mongoid/persistence/update_spec.rb
Expand Up @@ -133,6 +133,16 @@ def tree_set_expectation
update.persist.should == true
end
end

context "when before_save callback returns false" do
before do
Patient.set_callback :save, :before, lambda { |r| return false }
end

it "returns false" do
document.save.should == false
end
end

context "when the document is embedded" do

Expand Down

0 comments on commit fe564b3

Please sign in to comment.