spec/integration/mongoid/commands_spec.rb in mongoid-1.0.6 vs spec/integration/mongoid/commands_spec.rb in mongoid-1.1.0

- old
+ new

@@ -8,10 +8,41 @@ after do @person.delete end + describe ".create" do + + it "saves and returns the document" do + person = Person.create(:title => "Sensei") + person.should be_a_kind_of(Person) + person.should_not be_a_new_record + end + + end + + describe ".create!" do + + context "inserting with a field that is not unique" do + + context "when a unique index exists" do + + after do + Person.delete_all + end + + it "raises an error" do + Person.create!(:ssn => "555-55-9999") + lambda { Person.create!(:ssn => "555-55-9999") }.should raise_error + end + + end + + end + + end + describe "#delete" do before do @person.save end @@ -54,33 +85,41 @@ end end + describe "save!" do + + context "inserting with a field that is not unique" do + + context "when a unique index exists" do + + it "raises an error" do + Person.create!(:ssn => "555-55-9999") + person = Person.new(:ssn => "555-55-9999") + lambda { person.save!(:ssn => "555-55-9999") }.should raise_error + end + + end + + end + + end + describe "#update_attributes" do context "when validation passes" do it "returns true" do - @person.update_attributes(:title => "Blah").should be_true + @person.update_attributes(:ssn => "555-55-1234").should be_true end it "saves the attributes" do - @person.update_attributes(:title => "Blah") + @person.update_attributes(:ssn => "555-55-1235", :title => "Blah") @from_db = Person.find(@person.id) @from_db.title.should == "Blah" end - end - - end - - describe ".create" do - - it "saves and returns the document" do - person = Person.create(:title => "Sensei") - person.should be_a_kind_of(Person) - person.should_not be_a_new_record end end describe ".delete_all" do