spec/couchrest/persistence_spec.rb in couchrest_model-1.0.0 vs spec/couchrest/persistence_spec.rb in couchrest_model-1.1.0.beta

- old
+ new

@@ -13,21 +13,21 @@ end describe "creating a new document from database" do it "should instantialize" do - doc = Article.create_from_database({'_id' => 'testitem1', '_rev' => 123, 'couchrest-type' => 'Article', 'name' => 'my test'}) + doc = Article.build_from_database({'_id' => 'testitem1', '_rev' => 123, 'couchrest-type' => 'Article', 'name' => 'my test'}) doc.class.should eql(Article) end it "should instantialize of same class if no couchrest-type included from DB" do - doc = Article.create_from_database({'_id' => 'testitem1', '_rev' => 123, 'name' => 'my test'}) + doc = Article.build_from_database({'_id' => 'testitem1', '_rev' => 123, 'name' => 'my test'}) doc.class.should eql(Article) end it "should instantialize document of different type" do - doc = Article.create_from_database({'_id' => 'testitem2', '_rev' => 123, Article.model_type_key => 'WithTemplateAndUniqueID', 'name' => 'my test'}) + doc = Article.build_from_database({'_id' => 'testitem2', '_rev' => 123, Article.model_type_key => 'WithTemplateAndUniqueID', 'name' => 'my test'}) doc.class.should eql(WithTemplateAndUniqueID) end end @@ -327,18 +327,18 @@ @doc = WithCallBacks.new end describe "validation" do it "should run before_validation before validating" do - @doc.run_before_validate.should be_nil + @doc.run_before_validation.should be_nil @doc.should be_valid - @doc.run_before_validate.should be_true + @doc.run_before_validation.should be_true end it "should run after_validation after validating" do - @doc.run_after_validate.should be_nil + @doc.run_after_validation.should be_nil @doc.should be_valid - @doc.run_after_validate.should be_true + @doc.run_after_validation.should be_true end end describe "save" do it "should run the after filter after saving" do @@ -409,7 +409,36 @@ end end end + + describe "#reload" do + it "reloads defined attributes" do + i = Article.create!(:title => "Reload when changed") + i.title.should == "Reload when changed" + + i.title = "..." + i.title.should == "..." + + i.reload + i.title.should == "Reload when changed" + end + + it "reloads defined attributes set to nil" do + i = Article.create!(:title => "Reload when nil") + i.title.should == "Reload when nil" + + i.title = nil + i.title.should be_nil + + i.reload + i.title.should == "Reload when nil" + end + + it "returns self" do + i = Article.create!(:title => "Reload return self") + i.reload.should be(i) + end + end end