spec/unit/base_spec.rb in couchrest_model-1.1.2 vs spec/unit/base_spec.rb in couchrest_model-1.2.0.beta
- old
+ new
@@ -79,10 +79,57 @@
end
@doc = klass.new
@doc.name.should eql("foobar")
end
end
+ describe "multipart attributes" do
+ context "with valid params" do
+ it "should parse a legal date" do
+ valid_date_params = { "exec_date(1i)"=>"2011",
+ "exec_date(2i)"=>"10",
+ "exec_date(3i)"=>"18"}
+ @obj = WithDateAndTime.new valid_date_params
+ @obj.exec_date.should_not be_nil
+ @obj.exec_date.should be_kind_of(Date)
+ @obj.exec_date.should == Date.new(2011, 10 ,18)
+ end
+
+ it "should parse a legal time" do
+ valid_time_params = { "exec_time(1i)"=>"2011",
+ "exec_time(2i)"=>"10",
+ "exec_time(3i)"=>"18",
+ "exec_time(4i)"=>"15",
+ "exec_time(5i)"=>"15",
+ "exec_time(6i)"=>"15",}
+ @obj = WithDateAndTime.new valid_time_params
+ @obj.exec_time.should_not be_nil
+ @obj.exec_time.should be_kind_of(Time)
+ @obj.exec_time.should == Time.utc(2011, 10 ,18, 15, 15, 15)
+ end
+ end
+
+ context "with invalid params" do
+ before(:each) do
+ @invalid_date_params = { "exec_date(1i)"=>"2011",
+ "exec_date(2i)"=>"foo",
+ "exec_date(3i)"=>"18"}
+ end
+ it "should still create a model if there are invalid attributes" do
+ @obj = WithDateAndTime.new @invalid_date_params
+ @obj.should_not be_nil
+ @obj.should be_kind_of(WithDateAndTime)
+ end
+ it "should not crash because of an empty value" do
+ @invalid_date_params["exec_date(2i)"] = ""
+ @obj = WithDateAndTime.new @invalid_date_params
+ @obj.should_not be_nil
+ @obj.exec_date.should_not be_kind_of(Date)
+ @obj.should be_kind_of(WithDateAndTime)
+ end
+ end
+ end
+
describe "ActiveModel compatability Basic" do
before(:each) do
@obj = Basic.new(nil)
@@ -353,28 +400,27 @@
end
end
describe "counting all instances of a model" do
before(:each) do
- @db = reset_test_db!
+ reset_test_db!
end
-
+
it ".count should return 0 if there are no docuemtns" do
WithTemplateAndUniqueID.count.should == 0
end
-
+
it ".count should return the number of documents" do
WithTemplateAndUniqueID.new('slug' => '1').save
WithTemplateAndUniqueID.new('slug' => '2').save
WithTemplateAndUniqueID.new('slug' => '3').save
-
WithTemplateAndUniqueID.count.should == 3
end
end
describe "finding the first instance of a model" do
before(:each) do
- @db = reset_test_db!
+ reset_test_db!
WithTemplateAndUniqueID.new('slug' => '1').save
WithTemplateAndUniqueID.new('slug' => '2').save
WithTemplateAndUniqueID.new('slug' => '3').save
WithTemplateAndUniqueID.new('slug' => '4').save
end