spec/unit/mongoid/commands_spec.rb in mongoid-pre-2.0.0.beta1 vs spec/unit/mongoid/commands_spec.rb in mongoid-pre-2.0.0.pre

- old
+ new

@@ -35,26 +35,10 @@ before do @person = Person.new end - context "when validation fails" do - - it "it raises an error" do - Mongoid::Commands::Save.expects(:execute).with(@person, true).returns(false) - @person.save.should be_false - end - - it "should run callback before_create and no after_create" do - @person.expects(:run_callbacks).with(:create).yields.returns(false) - Mongoid::Commands::Save.expects(:execute).with(@person, true).returns(false) - @person.expects(:run_callbacks).with(:after_create).never - @person.save.should be_false - end - - end - it "delegates to the save command" do Mongoid::Commands::Save.expects(:execute).with(@person, true).returns(true) @person.save end @@ -83,13 +67,14 @@ before do @person = Person.new end - it "lets the error bubble up" do + it "returns false" do Mongoid::Commands::Save.expects(:execute).raises(Mongo::OperationFailure.new("Operation Failed")) - lambda { @person.save }.should raise_error + @person.save + @person.errors[:mongoid].should == [ "Operation Failed" ] end end end @@ -198,11 +183,17 @@ before do @person = Person.new Mongoid::Commands::Save.expects(:execute).raises(Mongo::OperationFailure.new("Operation Failed")) end - it "lets the error bubble up" do - lambda { Person.create }.should raise_error + it "returns the document with errors" do + person = Person.create + person.errors[:mongoid].should == [ "Operation Failed" ] + end + + it "keeps the document's new record flag" do + person = Person.create + person.should be_a_new_record end end end