spec/mongomodel/attributes/store_spec.rb in mongomodel-0.4.9 vs spec/mongomodel/attributes/store_spec.rb in mongomodel-0.5.0

- old
+ new

@@ -25,11 +25,11 @@ properties[:custom_default] = MongoModel::Properties::Property.new(:custom_default, CustomClassWithDefault) properties[:default] = MongoModel::Properties::Property.new(:default, String, :default => 'Default') properties[:as] = MongoModel::Properties::Property.new(:as, String, :as => '_custom_as') properties end - let(:instance) { mock('instance', :properties => properties) } + let(:instance) { double('instance', :properties => properties) } subject { Attributes::Store.new(instance) } it "sets default property values" do subject.keys.should == properties.keys @@ -141,13 +141,13 @@ { :date => "2005-11-04", :time => "4:55pm" } => Time.zone.local(2005, 11, 4, 16, 55, 0), nil => nil }, :datetime => { - Time.local(2008, 5, 14, 1, 2, 3, 123456) => Time.local(2008, 5, 14, 1, 2, 3, 0).to_datetime, + Time.local(2008, 5, 14, 1, 2, 3, 123456) => Time.local(2008, 5, 14, 1, 2, 3, 123000).to_datetime, Date.civil(2009, 11, 15) => DateTime.civil(2009, 11, 15, 0, 0, 0, 0), - "Sat Jan 01 20:15:01.123456 UTC 2000" => DateTime.civil(2000, 1, 1, 20, 15, 1, 0), + "Sat Jan 01 20:15:01.123456 UTC 2000" => DateTime.civil(2000, 1, 1, 20, 15, Rational(1123, 1000), 0), "2009/3/4" => DateTime.civil(2009, 3, 4, 0, 0, 0, 0), "09:34" => lambda { |t| t.hour == 9 && t.min == 34 }, "5:21pm" => lambda { |t| t.hour == 17 && t.min == 21 }, { :date => "2005-11-04", :time => "4:55pm" } => DateTime.civil(2005, 11, 4, 16, 55, 0), nil => nil @@ -289,27 +289,29 @@ subject[:symbol] = :symbol subject[:hash] = { :foo => 'bar', :custom => CustomClass.new('custom in hash') } subject[:array] = [ 123, 'abc', 45.67, true, :bar, CustomClass.new('custom in array') ] subject[:date] = Date.civil(2009, 11, 15) subject[:time] = Time.local(2008, 5, 14, 1, 2, 3, 4, 0.5) + subject[:datetime] = DateTime.civil(2000, 1, 1, 20, 15, Rational(1123456, 1000000), 0) subject[:rational] = Rational(2, 3) subject[:openstruct] = OpenStruct.new(:abc => 123) subject[:custom] = CustomClass.new('custom') subject[:as] = "As property" subject[:non_property] = "Hello World" subject[:custom_non_property] = CustomClass.new('custom non property') - + subject.to_mongo.should include({ 'string' => 'string', 'integer' => 42, 'float' => 123.45, 'boolean' => false, 'symbol' => :symbol, 'hash' => { :foo => 'bar', :custom => { :name => 'custom in hash' } }, 'array' => [ 123, 'abc', 45.67, true, :bar, { :name => 'custom in array' } ], 'date' => "2009/11/15", - 'time' => Time.local(2008, 5, 14, 1, 2, 3, 4, 0), + 'time' => Time.local(2008, 5, 14, 1, 2, 3, 4, 0).utc, + 'datetime' => Time.utc(2000, 1, 1, 20, 15, 1, 123000), 'rational' => "2/3", 'openstruct' => { :abc => 123 }, 'custom' => { :name => 'custom' }, '_custom_as' => "As property", 'non_property' => "Hello World", @@ -326,10 +328,11 @@ 'symbol' => :symbol, 'hash' => { :foo => 'bar' }, 'array' => [ 123, 'abc', 45.67, true, :bar ], 'date' => Time.utc(2009, 11, 15), 'time' => Time.local(2008, 5, 14, 1, 2, 3, 4, 0.5), + 'datetime' => Time.utc(2000, 1, 1, 20, 15, 1, 123000), 'rational' => "2/3", 'openstruct' => { "foo" => "bar" }, 'custom' => { :name => 'custom' }, '_custom_as' => "As property", 'custom_non_property' => { :name => 'custom non property' } @@ -342,9 +345,10 @@ subject[:symbol].should == :symbol subject[:hash].should == { :foo => 'bar' }.with_indifferent_access subject[:array].should == [ 123, 'abc', 45.67, true, :bar ] subject[:date].should == Date.civil(2009, 11, 15) subject[:time].should == Time.local(2008, 5, 14, 1, 2, 3, 4, 0) + subject[:datetime].should == DateTime.civil(2000, 1, 1, 20, 15, Rational(1123, 1000), 0) subject[:rational].should == Rational(2, 3) subject[:openstruct].should == OpenStruct.new(:foo => "bar") subject[:custom].should == CustomClass.new('custom') subject[:as].should == "As property" subject[:custom_non_property].should == { :name => 'custom non property' }