test/unit/test_support.rb in mongo_mapper-0.6.10 vs test/unit/test_support.rb in mongo_mapper-0.7.0
- old
+ new
@@ -88,10 +88,14 @@
should "be time if date" do
Date.to_mongo(Date.new(2009, 10, 1)).should == Time.utc(2009, 10, 1)
end
+ should "be date if time" do
+ Date.to_mongo(Time.parse("2009-10-1T12:30:00")).should == Time.utc(2009, 10, 1)
+ end
+
should "be nil if bogus string" do
Date.to_mongo('jdsafop874').should be_nil
end
should "be nil if empty string" do
@@ -261,13 +265,21 @@
should "return empty string if blank" do
String.from_mongo('').should == ''
end
end
+ context "Symbol" do
+ %w(gt lt gte lte ne in nin mod all size where exists asc desc).each do |operator|
+ should "have $#{operator} operator" do
+ :foo.respond_to?(operator)
+ end
+ end
+ end
+
context "Time#to_mongo without Time.zone" do
- should "be time if string" do
- Time.to_mongo('2000-01-01 01:01:01.123456').should == Time.local(2000, 1, 1, 1, 1, 1, 123456).utc
+ should "be time to milliseconds if string" do
+ Time.to_mongo('2000-01-01 01:01:01.123456').should == Time.local(2000, 1, 1, 1, 1, 1, 123000).utc
end
should "be time in utc if time" do
Time.to_mongo(Time.local(2009, 8, 15, 0, 0, 0)).zone.should == 'UTC'
end
@@ -280,19 +292,19 @@
Time.to_mongo(nil).should be_nil
end
end
context "Time#to_mongo with Time.zone" do
- should "be time if time" do
+ should "be time to milliseconds if time" do
Time.zone = 'Hawaii'
- Time.to_mongo(Time.zone.local(2009, 8, 15, 14, 0, 0)).should == Time.utc(2009, 8, 16, 0, 0, 0)
+ Time.to_mongo(Time.zone.local(2009, 8, 15, 14, 0, 0, 123456)).should == Time.utc(2009, 8, 16, 0, 0, 0, 123000)
Time.zone = nil
end
- should "be time if string" do
+ should "be time to milliseconds if string" do
Time.zone = 'Hawaii'
- Time.to_mongo('2009-08-15 14:00:00').should == Time.utc(2009, 8, 16, 0, 0, 0)
+ Time.to_mongo('2009-08-15 14:00:00.123456').should == Time.utc(2009, 8, 16, 0, 0, 0, 123000)
Time.zone = nil
end
should "be nil if blank string" do
Time.zone = 'Hawaii'
@@ -339,8 +351,12 @@
context "Mongo::ObjectID.to_json" do
should "convert object id to string" do
id = Mongo::ObjectID.new
id.to_json.should == %Q("#{id}")
end
+
+ should "support ruby driver syntax also" do
+ id = Mongo::ObjectID.new
+ id.original_to_json.should == %Q({"$oid": "#{id}"})
+ end
end
-
end
\ No newline at end of file