mongo_mapper-rails3 0.7.0.1 → 0.7.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.rdoc +8 -37
- metadata +16 -284
- data/.gitignore +0 -10
- data/Gemfile +0 -15
- data/LICENSE +0 -20
- data/Rakefile +0 -58
- data/VERSION +0 -1
- data/bin/mmconsole +0 -60
- data/lib/mongo_mapper.rb +0 -131
- data/lib/mongo_mapper/document.rb +0 -439
- data/lib/mongo_mapper/embedded_document.rb +0 -68
- data/lib/mongo_mapper/plugins.rb +0 -30
- data/lib/mongo_mapper/plugins/associations.rb +0 -106
- data/lib/mongo_mapper/plugins/associations/base.rb +0 -123
- data/lib/mongo_mapper/plugins/associations/belongs_to_polymorphic_proxy.rb +0 -30
- data/lib/mongo_mapper/plugins/associations/belongs_to_proxy.rb +0 -25
- data/lib/mongo_mapper/plugins/associations/collection.rb +0 -21
- data/lib/mongo_mapper/plugins/associations/embedded_collection.rb +0 -50
- data/lib/mongo_mapper/plugins/associations/in_array_proxy.rb +0 -141
- data/lib/mongo_mapper/plugins/associations/many_documents_as_proxy.rb +0 -28
- data/lib/mongo_mapper/plugins/associations/many_documents_proxy.rb +0 -120
- data/lib/mongo_mapper/plugins/associations/many_embedded_polymorphic_proxy.rb +0 -31
- data/lib/mongo_mapper/plugins/associations/many_embedded_proxy.rb +0 -23
- data/lib/mongo_mapper/plugins/associations/many_polymorphic_proxy.rb +0 -13
- data/lib/mongo_mapper/plugins/associations/one_proxy.rb +0 -68
- data/lib/mongo_mapper/plugins/associations/proxy.rb +0 -119
- data/lib/mongo_mapper/plugins/callbacks.rb +0 -87
- data/lib/mongo_mapper/plugins/clone.rb +0 -14
- data/lib/mongo_mapper/plugins/descendants.rb +0 -17
- data/lib/mongo_mapper/plugins/dirty.rb +0 -120
- data/lib/mongo_mapper/plugins/equality.rb +0 -24
- data/lib/mongo_mapper/plugins/identity_map.rb +0 -124
- data/lib/mongo_mapper/plugins/inspect.rb +0 -15
- data/lib/mongo_mapper/plugins/keys.rb +0 -310
- data/lib/mongo_mapper/plugins/logger.rb +0 -19
- data/lib/mongo_mapper/plugins/pagination.rb +0 -26
- data/lib/mongo_mapper/plugins/pagination/proxy.rb +0 -72
- data/lib/mongo_mapper/plugins/protected.rb +0 -46
- data/lib/mongo_mapper/plugins/rails.rb +0 -46
- data/lib/mongo_mapper/plugins/serialization.rb +0 -50
- data/lib/mongo_mapper/plugins/validations.rb +0 -88
- data/lib/mongo_mapper/query.rb +0 -130
- data/lib/mongo_mapper/support.rb +0 -217
- data/lib/mongo_mapper/support/descendant_appends.rb +0 -46
- data/lib/mongo_mapper/support/find.rb +0 -77
- data/mongo_mapper-rails3.gemspec +0 -208
- data/performance/read_write.rb +0 -52
- data/specs.watchr +0 -51
- data/test/NOTE_ON_TESTING +0 -1
- data/test/functional/associations/test_belongs_to_polymorphic_proxy.rb +0 -63
- data/test/functional/associations/test_belongs_to_proxy.rb +0 -101
- data/test/functional/associations/test_in_array_proxy.rb +0 -321
- data/test/functional/associations/test_many_documents_as_proxy.rb +0 -229
- data/test/functional/associations/test_many_documents_proxy.rb +0 -453
- data/test/functional/associations/test_many_embedded_polymorphic_proxy.rb +0 -176
- data/test/functional/associations/test_many_embedded_proxy.rb +0 -256
- data/test/functional/associations/test_many_polymorphic_proxy.rb +0 -302
- data/test/functional/associations/test_one_proxy.rb +0 -161
- data/test/functional/test_associations.rb +0 -44
- data/test/functional/test_binary.rb +0 -27
- data/test/functional/test_callbacks.rb +0 -81
- data/test/functional/test_dirty.rb +0 -163
- data/test/functional/test_document.rb +0 -1244
- data/test/functional/test_embedded_document.rb +0 -125
- data/test/functional/test_identity_map.rb +0 -508
- data/test/functional/test_logger.rb +0 -20
- data/test/functional/test_modifiers.rb +0 -252
- data/test/functional/test_pagination.rb +0 -93
- data/test/functional/test_protected.rb +0 -161
- data/test/functional/test_string_id_compatibility.rb +0 -67
- data/test/functional/test_validations.rb +0 -329
- data/test/models.rb +0 -232
- data/test/support/custom_matchers.rb +0 -55
- data/test/support/timing.rb +0 -16
- data/test/test_helper.rb +0 -59
- data/test/unit/associations/test_base.rb +0 -207
- data/test/unit/associations/test_proxy.rb +0 -105
- data/test/unit/serializers/test_json_serializer.rb +0 -189
- data/test/unit/test_descendant_appends.rb +0 -71
- data/test/unit/test_document.rb +0 -231
- data/test/unit/test_dynamic_finder.rb +0 -123
- data/test/unit/test_embedded_document.rb +0 -663
- data/test/unit/test_keys.rb +0 -169
- data/test/unit/test_lint.rb +0 -8
- data/test/unit/test_mongo_mapper.rb +0 -125
- data/test/unit/test_pagination.rb +0 -160
- data/test/unit/test_plugins.rb +0 -51
- data/test/unit/test_query.rb +0 -334
- data/test/unit/test_rails.rb +0 -123
- data/test/unit/test_rails_compatibility.rb +0 -57
- data/test/unit/test_serialization.rb +0 -51
- data/test/unit/test_support.rb +0 -362
- data/test/unit/test_time_zones.rb +0 -39
- data/test/unit/test_validations.rb +0 -557
@@ -1,57 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
class TestRailsCompatibility < Test::Unit::TestCase
|
4
|
-
class BigStuff
|
5
|
-
include MongoMapper::Document
|
6
|
-
end
|
7
|
-
|
8
|
-
class Item
|
9
|
-
include MongoMapper::EmbeddedDocument
|
10
|
-
key :for_all, String
|
11
|
-
end
|
12
|
-
|
13
|
-
class FirstItem < Item
|
14
|
-
key :first_only, String
|
15
|
-
many :second_items
|
16
|
-
end
|
17
|
-
|
18
|
-
class SecondItem < Item
|
19
|
-
key :second_only, String
|
20
|
-
end
|
21
|
-
|
22
|
-
context "EmbeddedDocument" do
|
23
|
-
should "alias many to has_many" do
|
24
|
-
FirstItem.should respond_to(:has_many)
|
25
|
-
end
|
26
|
-
|
27
|
-
should "alias one to has_one" do
|
28
|
-
FirstItem.should respond_to(:has_one)
|
29
|
-
end
|
30
|
-
|
31
|
-
should "have column names" do
|
32
|
-
Item.column_names.sort.should == ['_id', 'for_all']
|
33
|
-
FirstItem.column_names.sort.should == ['_id', 'first_only', 'for_all']
|
34
|
-
SecondItem.column_names.sort.should == ['_id', 'for_all', 'second_only']
|
35
|
-
end
|
36
|
-
|
37
|
-
should "alias new to new_record?" do
|
38
|
-
instance = Item.new
|
39
|
-
instance.new_record?.should == instance.new?
|
40
|
-
end
|
41
|
-
|
42
|
-
should "implement human_name" do
|
43
|
-
Item.human.should == 'Item'
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
context "Document" do
|
48
|
-
should "implement human_name" do
|
49
|
-
BigStuff.human.should == 'Big Stuff'
|
50
|
-
end
|
51
|
-
|
52
|
-
should "respond to to_model" do
|
53
|
-
big_stuff = BigStuff.new
|
54
|
-
big_stuff.to_model.should == big_stuff
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|
@@ -1,51 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
class SerializationTest < Test::Unit::TestCase
|
4
|
-
def setup
|
5
|
-
@document = EDoc do
|
6
|
-
key :name, String
|
7
|
-
key :age, Integer
|
8
|
-
key :awesome, Boolean
|
9
|
-
key :preferences, Hash
|
10
|
-
key :created_at, Time
|
11
|
-
end
|
12
|
-
|
13
|
-
@instance = @document.new(
|
14
|
-
:name => 'John Doe',
|
15
|
-
:age => 25,
|
16
|
-
:awesome => true,
|
17
|
-
:preferences => {:language => 'Ruby'},
|
18
|
-
:created_at => Time.now.change(:usec => 0)
|
19
|
-
)
|
20
|
-
end
|
21
|
-
|
22
|
-
[:json].each do |format|
|
23
|
-
context format do
|
24
|
-
should "be reversable" do
|
25
|
-
serialized = @instance.send("to_#{format}")
|
26
|
-
unserialized = @document.new.send("from_#{format}", serialized)
|
27
|
-
|
28
|
-
assert_equal @instance, unserialized
|
29
|
-
end
|
30
|
-
|
31
|
-
should "allow attribute only filtering" do
|
32
|
-
serialized = @instance.send("to_#{format}", :only => [ :age, :name ])
|
33
|
-
unserialized = @document.new.send("from_#{format}", serialized)
|
34
|
-
|
35
|
-
assert_equal @instance.name, unserialized.name
|
36
|
-
assert_equal @instance.age, unserialized.age
|
37
|
-
assert ! unserialized.awesome
|
38
|
-
assert_nil unserialized.created_at
|
39
|
-
end
|
40
|
-
|
41
|
-
should "allow attribute except filtering" do
|
42
|
-
serialized = @instance.send("to_#{format}", :except => [ :age, :name ])
|
43
|
-
unserialized = @document.new.send("from_#{format}", serialized)
|
44
|
-
|
45
|
-
assert_nil unserialized.name
|
46
|
-
assert_nil unserialized.age
|
47
|
-
assert_equal @instance.awesome, unserialized.awesome
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
data/test/unit/test_support.rb
DELETED
@@ -1,362 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
class SupportTest < Test::Unit::TestCase
|
4
|
-
context "Array#to_mongo" do
|
5
|
-
should "convert value to_a" do
|
6
|
-
Array.to_mongo([1, 2, 3, 4]).should == [1, 2, 3, 4]
|
7
|
-
Array.to_mongo('1').should == ['1']
|
8
|
-
Array.to_mongo({'1' => '2', '3' => '4'}).should == [['1', '2'], ['3', '4']]
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
context "Array#from_mongo" do
|
13
|
-
should "be array if array" do
|
14
|
-
Array.from_mongo([1, 2]).should == [1, 2]
|
15
|
-
end
|
16
|
-
|
17
|
-
should "be empty array if nil" do
|
18
|
-
Array.from_mongo(nil).should == []
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
context "Binary#to_mongo" do
|
23
|
-
should "convert to byte buffer if not byte buffer" do
|
24
|
-
Binary.to_mongo('asdfsadasdfs').is_a?(ByteBuffer).should be_true
|
25
|
-
end
|
26
|
-
|
27
|
-
should "be byte buffer if byte buffer" do
|
28
|
-
Binary.to_mongo(ByteBuffer.new('asdfsadasdfs')).is_a?(ByteBuffer).should be_true
|
29
|
-
end
|
30
|
-
|
31
|
-
should "be nil if nil" do
|
32
|
-
Binary.to_mongo(nil).should be_nil
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
context "Binary#from_mongo" do
|
37
|
-
should "return value" do
|
38
|
-
buffer = ByteBuffer.new('asdfasdfasdf')
|
39
|
-
Binary.from_mongo(buffer).to_s.should == buffer.to_s
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
context "Boolean#to_mongo" do
|
44
|
-
should "be true for true" do
|
45
|
-
Boolean.to_mongo(true).should be_true
|
46
|
-
end
|
47
|
-
|
48
|
-
should "be false for false" do
|
49
|
-
Boolean.to_mongo(false).should be_false
|
50
|
-
end
|
51
|
-
|
52
|
-
should "handle odd assortment of other values" do
|
53
|
-
Boolean.to_mongo('true').should be_true
|
54
|
-
Boolean.to_mongo('t').should be_true
|
55
|
-
Boolean.to_mongo('1').should be_true
|
56
|
-
Boolean.to_mongo(1).should be_true
|
57
|
-
|
58
|
-
Boolean.to_mongo('false').should be_false
|
59
|
-
Boolean.to_mongo('f').should be_false
|
60
|
-
Boolean.to_mongo('0').should be_false
|
61
|
-
Boolean.to_mongo(0).should be_false
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
context "Boolean#from_mongo" do
|
66
|
-
should "be true for true" do
|
67
|
-
Boolean.from_mongo(true).should be_true
|
68
|
-
end
|
69
|
-
|
70
|
-
should "be false for false" do
|
71
|
-
Boolean.from_mongo(false).should be_false
|
72
|
-
end
|
73
|
-
|
74
|
-
should "be false for nil" do
|
75
|
-
Boolean.from_mongo(nil).should be_false
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
79
|
-
context "Date#to_mongo" do
|
80
|
-
should "be time if string" do
|
81
|
-
date = Date.to_mongo('10/1/2009')
|
82
|
-
date.should == Time.utc(2009, 10, 1)
|
83
|
-
date.should == date
|
84
|
-
date.month.should == 10
|
85
|
-
date.day.should == 1
|
86
|
-
date.year.should == 2009
|
87
|
-
end
|
88
|
-
|
89
|
-
should "be time if date" do
|
90
|
-
Date.to_mongo(Date.new(2009, 10, 1)).should == Time.utc(2009, 10, 1)
|
91
|
-
end
|
92
|
-
|
93
|
-
should "be date if time" do
|
94
|
-
Date.to_mongo(Time.parse("2009-10-1T12:30:00")).should == Time.utc(2009, 10, 1)
|
95
|
-
end
|
96
|
-
|
97
|
-
should "be nil if bogus string" do
|
98
|
-
Date.to_mongo('jdsafop874').should be_nil
|
99
|
-
end
|
100
|
-
|
101
|
-
should "be nil if empty string" do
|
102
|
-
Date.to_mongo('').should be_nil
|
103
|
-
end
|
104
|
-
end
|
105
|
-
|
106
|
-
context "Date#from_mongo" do
|
107
|
-
should "be date if date" do
|
108
|
-
date = Date.new(2009, 10, 1)
|
109
|
-
from_date = Date.from_mongo(date)
|
110
|
-
from_date.should == date
|
111
|
-
from_date.month.should == 10
|
112
|
-
from_date.day.should == 1
|
113
|
-
from_date.year.should == 2009
|
114
|
-
end
|
115
|
-
|
116
|
-
should "be date if time" do
|
117
|
-
time = Time.now
|
118
|
-
Date.from_mongo(time).should == time.to_date
|
119
|
-
end
|
120
|
-
|
121
|
-
should "be nil if nil" do
|
122
|
-
Date.from_mongo(nil).should be_nil
|
123
|
-
end
|
124
|
-
end
|
125
|
-
|
126
|
-
context "Float#to_mongo" do
|
127
|
-
should "convert value to_f" do
|
128
|
-
[21, 21.0, '21'].each do |value|
|
129
|
-
Float.to_mongo(value).should == 21.0
|
130
|
-
end
|
131
|
-
end
|
132
|
-
end
|
133
|
-
|
134
|
-
context "Hash#from_mongo" do
|
135
|
-
should "convert hash to hash with indifferent access" do
|
136
|
-
hash = Hash.from_mongo(:foo => 'bar')
|
137
|
-
hash[:foo].should == 'bar'
|
138
|
-
hash['foo'].should == 'bar'
|
139
|
-
end
|
140
|
-
|
141
|
-
should "be hash if nil" do
|
142
|
-
hash = Hash.from_mongo(nil)
|
143
|
-
hash.should == {}
|
144
|
-
hash.is_a?(HashWithIndifferentAccess).should be_true
|
145
|
-
end
|
146
|
-
end
|
147
|
-
|
148
|
-
context "Hash#to_mongo instance method" do
|
149
|
-
should "have instance method that returns self" do
|
150
|
-
hash = HashWithIndifferentAccess.new('foo' => 'bar')
|
151
|
-
hash.to_mongo.should == {'foo' => 'bar'}
|
152
|
-
end
|
153
|
-
end
|
154
|
-
|
155
|
-
context "Integer#to_mongo" do
|
156
|
-
should "convert value to integer" do
|
157
|
-
[21, 21.0, '21'].each do |value|
|
158
|
-
Integer.to_mongo(value).should == 21
|
159
|
-
end
|
160
|
-
end
|
161
|
-
|
162
|
-
should "work fine with big integers" do
|
163
|
-
[9223372036854775807, '9223372036854775807'].each do |value|
|
164
|
-
Integer.to_mongo(value).should == 9223372036854775807
|
165
|
-
end
|
166
|
-
end
|
167
|
-
end
|
168
|
-
|
169
|
-
context "ObjectId#to_mongo" do
|
170
|
-
should "return nil for nil" do
|
171
|
-
ObjectId.to_mongo(nil).should be_nil
|
172
|
-
end
|
173
|
-
|
174
|
-
should "return nil if blank string" do
|
175
|
-
ObjectId.to_mongo('').should be_nil
|
176
|
-
end
|
177
|
-
|
178
|
-
should "return value if object id" do
|
179
|
-
id = Mongo::ObjectID.new
|
180
|
-
ObjectId.to_mongo(id).should be(id)
|
181
|
-
end
|
182
|
-
|
183
|
-
should "return object id if string" do
|
184
|
-
id = Mongo::ObjectID.new
|
185
|
-
ObjectId.to_mongo(id.to_s).should be(id)
|
186
|
-
end
|
187
|
-
end
|
188
|
-
|
189
|
-
context "ObjectId#from_mongo" do
|
190
|
-
should "return value" do
|
191
|
-
id = Mongo::ObjectID.new
|
192
|
-
ObjectId.from_mongo(id).should == id
|
193
|
-
end
|
194
|
-
end
|
195
|
-
|
196
|
-
context "NilClass#to_mongo" do
|
197
|
-
should "return nil" do
|
198
|
-
nil.to_mongo(nil).should be_nil
|
199
|
-
end
|
200
|
-
end
|
201
|
-
|
202
|
-
context "NilClass#from_mongo" do
|
203
|
-
should "return nil" do
|
204
|
-
nil.from_mongo(nil).should be_nil
|
205
|
-
end
|
206
|
-
end
|
207
|
-
|
208
|
-
context "Object#to_mongo" do
|
209
|
-
should "return value" do
|
210
|
-
Object.to_mongo(21).should == 21
|
211
|
-
Object.to_mongo('21').should == '21'
|
212
|
-
Object.to_mongo(9223372036854775807).should == 9223372036854775807
|
213
|
-
end
|
214
|
-
end
|
215
|
-
|
216
|
-
context "Object#from_mongo" do
|
217
|
-
should "return value" do
|
218
|
-
Object.from_mongo(21).should == 21
|
219
|
-
Object.from_mongo('21').should == '21'
|
220
|
-
Object.from_mongo(9223372036854775807).should == 9223372036854775807
|
221
|
-
end
|
222
|
-
end
|
223
|
-
|
224
|
-
context "Set#to_mongo" do
|
225
|
-
should "convert value to_a" do
|
226
|
-
Set.to_mongo(Set.new([1,2,3])).should == [1,2,3]
|
227
|
-
end
|
228
|
-
|
229
|
-
should "convert to empty array if nil" do
|
230
|
-
Set.to_mongo(nil).should == []
|
231
|
-
end
|
232
|
-
end
|
233
|
-
|
234
|
-
context "Set#from_mongo" do
|
235
|
-
should "be a set if array" do
|
236
|
-
Set.from_mongo([1,2,3]).should == Set.new([1,2,3])
|
237
|
-
end
|
238
|
-
|
239
|
-
should "be empty set if nil" do
|
240
|
-
Set.from_mongo(nil).should == Set.new([])
|
241
|
-
end
|
242
|
-
end
|
243
|
-
|
244
|
-
context "String#to_mongo" do
|
245
|
-
should "convert value to_s" do
|
246
|
-
[21, '21'].each do |value|
|
247
|
-
String.to_mongo(value).should == '21'
|
248
|
-
end
|
249
|
-
end
|
250
|
-
|
251
|
-
should "be nil if nil" do
|
252
|
-
String.to_mongo(nil).should be_nil
|
253
|
-
end
|
254
|
-
end
|
255
|
-
|
256
|
-
context "String#from_mongo" do
|
257
|
-
should "be string if value present" do
|
258
|
-
String.from_mongo('Scotch! Scotch! Scotch!').should == 'Scotch! Scotch! Scotch!'
|
259
|
-
end
|
260
|
-
|
261
|
-
should "return nil if nil" do
|
262
|
-
String.from_mongo(nil).should be_nil
|
263
|
-
end
|
264
|
-
|
265
|
-
should "return empty string if blank" do
|
266
|
-
String.from_mongo('').should == ''
|
267
|
-
end
|
268
|
-
end
|
269
|
-
|
270
|
-
context "Symbol" do
|
271
|
-
%w(gt lt gte lte ne in nin mod all size where exists asc desc).each do |operator|
|
272
|
-
should "have $#{operator} operator" do
|
273
|
-
:foo.respond_to?(operator)
|
274
|
-
end
|
275
|
-
end
|
276
|
-
end
|
277
|
-
|
278
|
-
context "Time#to_mongo without Time.zone" do
|
279
|
-
should "be time to milliseconds if string" do
|
280
|
-
Time.to_mongo('2000-01-01 01:01:01.123456').should == Time.local(2000, 1, 1, 1, 1, 1, 123000).utc
|
281
|
-
end
|
282
|
-
|
283
|
-
should "be time in utc if time" do
|
284
|
-
Time.to_mongo(Time.local(2009, 8, 15, 0, 0, 0)).zone.should == 'UTC'
|
285
|
-
end
|
286
|
-
|
287
|
-
should "be nil if blank string" do
|
288
|
-
Time.to_mongo('').should be_nil
|
289
|
-
end
|
290
|
-
|
291
|
-
should "not be nil if nil" do
|
292
|
-
Time.to_mongo(nil).should be_nil
|
293
|
-
end
|
294
|
-
end
|
295
|
-
|
296
|
-
context "Time#to_mongo with Time.zone" do
|
297
|
-
should "be time to milliseconds if time" do
|
298
|
-
Time.zone = 'Hawaii'
|
299
|
-
Time.to_mongo(Time.zone.local(2009, 8, 15, 14, 0, 0, 123456)).should == Time.utc(2009, 8, 16, 0, 0, 0, 123000)
|
300
|
-
Time.zone = nil
|
301
|
-
end
|
302
|
-
|
303
|
-
should "be time to milliseconds if string" do
|
304
|
-
Time.zone = 'Hawaii'
|
305
|
-
Time.to_mongo('2009-08-15 14:00:00.123456').should == Time.utc(2009, 8, 16, 0, 0, 0, 123000)
|
306
|
-
Time.zone = nil
|
307
|
-
end
|
308
|
-
|
309
|
-
should "be nil if blank string" do
|
310
|
-
Time.zone = 'Hawaii'
|
311
|
-
Time.to_mongo('').should be_nil
|
312
|
-
Time.zone = nil
|
313
|
-
end
|
314
|
-
|
315
|
-
should "be nil if nil" do
|
316
|
-
Time.zone = 'Hawaii'
|
317
|
-
Time.to_mongo(nil).should be_nil
|
318
|
-
Time.zone = nil
|
319
|
-
end
|
320
|
-
end
|
321
|
-
|
322
|
-
context "Time#from_mongo without Time.zone" do
|
323
|
-
should "be time" do
|
324
|
-
time = Time.now
|
325
|
-
Time.from_mongo(time).should == time
|
326
|
-
end
|
327
|
-
|
328
|
-
should "be nil if nil" do
|
329
|
-
Time.from_mongo(nil).should be_nil
|
330
|
-
end
|
331
|
-
end
|
332
|
-
|
333
|
-
context "Time#from_mongo with Time.zone" do
|
334
|
-
should "be time in Time.zone" do
|
335
|
-
Time.zone = 'Hawaii'
|
336
|
-
|
337
|
-
time = Time.from_mongo(Time.utc(2009, 10, 1))
|
338
|
-
time.should == Time.zone.local(2009, 9, 30, 14)
|
339
|
-
time.is_a?(ActiveSupport::TimeWithZone).should be_true
|
340
|
-
|
341
|
-
Time.zone = nil
|
342
|
-
end
|
343
|
-
|
344
|
-
should "be nil if nil" do
|
345
|
-
Time.zone = 'Hawaii'
|
346
|
-
Time.from_mongo(nil).should be_nil
|
347
|
-
Time.zone = nil
|
348
|
-
end
|
349
|
-
end
|
350
|
-
|
351
|
-
context "Mongo::ObjectID.to_json" do
|
352
|
-
should "convert object id to string" do
|
353
|
-
id = Mongo::ObjectID.new
|
354
|
-
id.to_json.should == %Q("#{id}")
|
355
|
-
end
|
356
|
-
|
357
|
-
should "support ruby driver syntax also" do
|
358
|
-
id = Mongo::ObjectID.new
|
359
|
-
id.original_to_json.should == %Q({"$oid": "#{id}"})
|
360
|
-
end
|
361
|
-
end
|
362
|
-
end
|