djsun-mongomapper 0.3.1.1 → 0.3.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (34) hide show
  1. data/History +20 -1
  2. data/Rakefile +5 -3
  3. data/VERSION +1 -1
  4. data/lib/mongomapper/associations/base.rb +3 -5
  5. data/lib/mongomapper/associations/belongs_to_polymorphic_proxy.rb +5 -3
  6. data/lib/mongomapper/associations/belongs_to_proxy.rb +4 -4
  7. data/lib/mongomapper/associations/many_documents_proxy.rb +32 -14
  8. data/lib/mongomapper/associations/proxy.rb +2 -6
  9. data/lib/mongomapper/associations.rb +38 -15
  10. data/lib/mongomapper/document.rb +165 -95
  11. data/lib/mongomapper/dynamic_finder.rb +38 -0
  12. data/lib/mongomapper/embedded_document.rb +116 -88
  13. data/lib/mongomapper/finder_options.rb +3 -14
  14. data/lib/mongomapper/key.rb +12 -16
  15. data/lib/mongomapper/serializers/json_serializer.rb +15 -12
  16. data/lib/mongomapper/support.rb +30 -0
  17. data/lib/mongomapper.rb +7 -33
  18. data/mongomapper.gemspec +10 -7
  19. data/test/functional/associations/test_belongs_to_polymorphic_proxy.rb +14 -0
  20. data/test/functional/associations/test_belongs_to_proxy.rb +10 -0
  21. data/test/functional/associations/test_many_polymorphic_proxy.rb +46 -52
  22. data/test/functional/associations/test_many_proxy.rb +71 -12
  23. data/test/functional/test_associations.rb +9 -2
  24. data/test/functional/test_document.rb +281 -20
  25. data/test/functional/test_rails_compatibility.rb +2 -3
  26. data/test/models.rb +39 -8
  27. data/test/unit/serializers/test_json_serializer.rb +46 -12
  28. data/test/unit/test_association_base.rb +10 -2
  29. data/test/unit/test_document.rb +7 -9
  30. data/test/unit/test_embedded_document.rb +180 -24
  31. data/test/unit/test_finder_options.rb +7 -38
  32. data/test/unit/test_key.rb +54 -24
  33. metadata +5 -5
  34. data/test/unit/test_mongo_id.rb +0 -35
@@ -83,14 +83,6 @@ class DocumentTest < Test::Unit::TestCase
83
83
  doc.collection.should == @document.collection
84
84
  end
85
85
 
86
- should "automatically have a created_at key" do
87
- @document.keys.keys.should include('created_at')
88
- end
89
-
90
- should "automatically have an updated_at key" do
91
- @document.keys.keys.should include('updated_at')
92
- end
93
-
94
86
  should "use default values if defined for keys" do
95
87
  @document.key :active, Boolean, :default => true
96
88
 
@@ -100,7 +92,13 @@ class DocumentTest < Test::Unit::TestCase
100
92
 
101
93
  context "new?" do
102
94
  should "be true if no id" do
103
- @document.new.new?.should be(true)
95
+ @document.new.new?.should be_true
96
+ end
97
+
98
+ should "be true if id but using custom id and not saved yet" do
99
+ doc = @document.new
100
+ doc.id = '1234'
101
+ doc.new?.should be_true
104
102
  end
105
103
  end
106
104
 
@@ -15,8 +15,20 @@ class Child < Parent
15
15
  key :child, String
16
16
  end
17
17
 
18
+ module KeyOverride
19
+ def other_child
20
+ read_attribute(:other_child) || "special result"
21
+ end
22
+
23
+ def other_child=(value)
24
+ super(value + " modified")
25
+ end
26
+ end
27
+
18
28
  class OtherChild < Parent
19
29
  include MongoMapper::EmbeddedDocument
30
+ include KeyOverride
31
+
20
32
  key :other_child, String
21
33
  end
22
34
 
@@ -41,6 +53,21 @@ class EmbeddedDocumentTest < Test::Unit::TestCase
41
53
  end
42
54
  document.parent_model.should be_nil
43
55
  end
56
+
57
+ should "work when other modules have been included" do
58
+ grandparent = Class.new
59
+ parent = Class.new grandparent do
60
+ include MongoMapper::EmbeddedDocument
61
+ end
62
+
63
+ example_module = Module.new
64
+ document = Class.new(parent) do
65
+ include MongoMapper::EmbeddedDocument
66
+ include example_module
67
+ end
68
+
69
+ document.parent_model.should == parent
70
+ end
44
71
 
45
72
  should "find parent" do
46
73
  Parent.parent_model.should == Grandparent
@@ -55,16 +82,28 @@ class EmbeddedDocumentTest < Test::Unit::TestCase
55
82
  end
56
83
  end
57
84
 
58
- should "work" do
85
+ should "work with name" do
86
+ key = @document.key(:name)
87
+ key.name.should == 'name'
88
+ end
89
+
90
+ should "work with name and type" do
59
91
  key = @document.key(:name, String)
60
92
  key.name.should == 'name'
61
93
  key.type.should == String
62
- key.should be_instance_of(MongoMapper::Key)
63
94
  end
64
95
 
65
- should "work with options" do
96
+ should "work with name, type and options" do
66
97
  key = @document.key(:name, String, :required => true)
67
- key.options[:required].should be(true)
98
+ key.name.should == 'name'
99
+ key.type.should == String
100
+ key.options[:required].should be_true
101
+ end
102
+
103
+ should "work with name and options" do
104
+ key = @document.key(:name, :required => true)
105
+ key.name.should == 'name'
106
+ key.options[:required].should be_true
68
107
  end
69
108
 
70
109
  should "be tracked per document" do
@@ -76,11 +115,11 @@ class EmbeddedDocumentTest < Test::Unit::TestCase
76
115
  @document.keys['age'].type.should == Integer
77
116
  end
78
117
 
79
- should "be redefinable" do
118
+ should "not be redefinable" do
80
119
  @document.key(:foo, String)
81
120
  @document.keys['foo'].type.should == String
82
121
  @document.key(:foo, Integer)
83
- @document.keys['foo'].type.should == Integer
122
+ @document.keys['foo'].type.should == String
84
123
  end
85
124
 
86
125
  should "create reader method" do
@@ -122,6 +161,14 @@ class EmbeddedDocumentTest < Test::Unit::TestCase
122
161
  Parent.keys.keys.sort.should == ['_id', '_type', 'grandparent', 'parent']
123
162
  Child.keys.keys.sort.should == ['_id', '_type', 'child', 'grandparent', 'parent']
124
163
  end
164
+
165
+ should "not add anonymous objects to the ancestor tree" do
166
+ OtherChild.ancestors.any? { |a| a.name.blank? }.should be_false
167
+ end
168
+
169
+ should "not include descendant keys" do
170
+ lambda { Parent.new.other_child }.should raise_error
171
+ end
125
172
  end
126
173
 
127
174
  context "subclasses" do
@@ -134,6 +181,53 @@ class EmbeddedDocumentTest < Test::Unit::TestCase
134
181
  Parent.subclasses.should == [Child, OtherChild]
135
182
  end
136
183
  end
184
+
185
+ context "Applying default values for keys" do
186
+ setup do
187
+ @document = Class.new do
188
+ include MongoMapper::EmbeddedDocument
189
+
190
+ key :name, String, :default => 'foo'
191
+ key :age, Integer, :default => 20
192
+ key :net_worth, Float, :default => 100.00
193
+ key :active, Boolean, :default => true
194
+ key :smart, Boolean, :default => false
195
+ key :skills, Array, :default => [1]
196
+ key :options, Hash, :default => {'foo' => 'bar'}
197
+ end
198
+
199
+ @doc = @document.new
200
+ end
201
+
202
+ should "work for strings" do
203
+ @doc.name.should == 'foo'
204
+ end
205
+
206
+ should "work for integers" do
207
+ @doc.age.should == 20
208
+ end
209
+
210
+ should "work for floats" do
211
+ @doc.net_worth.should == 100.00
212
+ end
213
+
214
+ should "work for booleans" do
215
+ @doc.active.should == true
216
+ @doc.smart.should == false
217
+ end
218
+
219
+ should "work for arrays" do
220
+ @doc.skills.should == [1]
221
+ @doc.skills << 2
222
+ @doc.skills.should == [1, 2]
223
+ end
224
+
225
+ should "work for hashes" do
226
+ @doc.options['foo'].should == 'bar'
227
+ @doc.options['baz'] = 'wick'
228
+ @doc.options['baz'].should == 'wick'
229
+ end
230
+ end
137
231
 
138
232
  context "An instance of an embedded document" do
139
233
  setup do
@@ -149,16 +243,23 @@ class EmbeddedDocumentTest < Test::Unit::TestCase
149
243
  @document.keys.keys.should include('_id')
150
244
  end
151
245
 
152
- should "have id method that is string representation of _id" do
246
+ should "have id method that sets _id" do
153
247
  doc = @document.new
154
248
  doc.id.should == doc._id.to_s
155
249
  end
156
250
 
157
- should "be able to set _id using id=" do
158
- id = MongoID.new
159
- doc = @document.new(:id => id.to_s)
160
- doc._id.should == id
161
- doc.id.should == id.to_s
251
+ context "setting custom id" do
252
+ should "set _id" do
253
+ doc = @document.new(:id => '1234')
254
+ doc._id.should == '1234'
255
+ end
256
+
257
+ should "know that custom id is set" do
258
+ doc = @document.new
259
+ doc.using_custom_id?.should be_false
260
+ doc.id = '1234'
261
+ doc.using_custom_id?.should be_true
262
+ end
162
263
  end
163
264
 
164
265
  context "being initialized" do
@@ -168,6 +269,12 @@ class EmbeddedDocumentTest < Test::Unit::TestCase
168
269
  doc.attributes['name'].should == 'John'
169
270
  doc.attributes['age'].should == 23
170
271
  end
272
+
273
+ should "be able to assign keys dynamically" do
274
+ doc = @document.new(:name => 'John', :skills => ['ruby', 'rails'])
275
+ doc.name.should == 'John'
276
+ doc.skills.should == ['ruby', 'rails']
277
+ end
171
278
 
172
279
  should "not throw error if initialized with nil" do
173
280
  lambda {
@@ -191,13 +298,6 @@ class EmbeddedDocumentTest < Test::Unit::TestCase
191
298
  doc.attributes[:age].should == 10
192
299
  end
193
300
 
194
- should "raise undefined method if no key exists" do
195
- doc = @document.new(:name => 'foobar', :age => 10)
196
- lambda {
197
- doc.attributes = {:name => 'new value', :foobar => 'baz'}
198
- }.should raise_error(NoMethodError)
199
- end
200
-
201
301
  should "not ignore keys that have methods defined" do
202
302
  @document.class_eval do
203
303
  attr_writer :password
@@ -237,10 +337,19 @@ class EmbeddedDocumentTest < Test::Unit::TestCase
237
337
  doc[:name].should == 'string'
238
338
  end
239
339
 
240
- should "be able to write key value with []=" do
241
- doc = @document.new
242
- doc[:name] = 'string'
243
- doc[:name].should == 'string'
340
+ context "[]=" do
341
+ should "write key value for existing key" do
342
+ doc = @document.new
343
+ doc[:name] = 'string'
344
+ doc[:name].should == 'string'
345
+ end
346
+
347
+ should "create key and write value for missing key" do
348
+ doc = @document.new
349
+ doc[:foo] = 'string'
350
+ @document.keys.keys.include?('foo').should be_true
351
+ doc[:foo].should == 'string'
352
+ end
244
353
  end
245
354
  end
246
355
 
@@ -273,6 +382,38 @@ class EmbeddedDocumentTest < Test::Unit::TestCase
273
382
  doc = @document.new(:name => 'John', :age => 27)
274
383
  doc.name_and_age.should == 'John (27)'
275
384
  end
385
+
386
+ should "set instance variable" do
387
+ @document.key :foo, Array
388
+ doc = @document.new
389
+ doc.instance_variable_get("@foo").should be_nil
390
+ doc.foo
391
+ doc.instance_variable_get("@foo").should == []
392
+ end
393
+
394
+ should "not set instance variable if frozen" do
395
+ @document.key :foo, Array
396
+ doc = @document.new
397
+ doc.instance_variable_get("@foo").should be_nil
398
+ doc.freeze
399
+ doc.foo
400
+ doc.instance_variable_get("@foo").should be_nil
401
+ end
402
+
403
+ should "be overrideable by modules" do
404
+ @document = Class.new do
405
+ include MongoMapper::Document
406
+ key :other_child, String
407
+ end
408
+
409
+ child = @document.new
410
+ child.other_child.should be_nil
411
+
412
+ @document.send :include, KeyOverride
413
+
414
+ overriden_child = @document.new
415
+ overriden_child.other_child.should == 'special result'
416
+ end
276
417
  end
277
418
 
278
419
  context "reading an attribute before typcasting" do
@@ -333,6 +474,21 @@ class EmbeddedDocumentTest < Test::Unit::TestCase
333
474
  doc.name.should == 'Frank'
334
475
  doc.age.should == 62
335
476
  end
477
+
478
+ should "be overrideable by modules" do
479
+ @document = Class.new do
480
+ include MongoMapper::Document
481
+ key :other_child, String
482
+ end
483
+
484
+ child = @document.new(:other_child => 'foo')
485
+ child.other_child.should == 'foo'
486
+
487
+ @document.send :include, KeyOverride
488
+
489
+ overriden_child = @document.new(:other_child => 'foo')
490
+ overriden_child.other_child.should == 'foo modified'
491
+ end
336
492
  end # writing an attribute
337
493
 
338
494
  context "checking if an attributes value is present" do
@@ -367,4 +523,4 @@ class EmbeddedDocumentTest < Test::Unit::TestCase
367
523
  end
368
524
  end
369
525
  end # instance of a embedded document
370
- end
526
+ end
@@ -28,7 +28,6 @@ class FinderOptionsTest < Test::Unit::TestCase
28
28
  end
29
29
  end
30
30
 
31
-
32
31
  context "Converting conditions to criteria" do
33
32
  should "work with simple criteria" do
34
33
  FinderOptions.to_mongo_criteria(:foo => 'bar').should == {
@@ -47,53 +46,23 @@ class FinderOptionsTest < Test::Unit::TestCase
47
46
  }
48
47
  end
49
48
 
50
- should "not use $in for arrays if already using array modifier" do
49
+ should "not use $in for arrays if already using array operator" do
51
50
  FinderOptions.to_mongo_criteria(:foo => {'$all' => [1,2,3]}).should == {
52
51
  :foo => {'$all' => [1,2,3]}
53
52
  }
53
+
54
+ FinderOptions.to_mongo_criteria(:foo => {'$any' => [1,2,3]}).should == {
55
+ :foo => {'$any' => [1,2,3]}
56
+ }
54
57
  end
55
58
 
56
59
  should "work arbitrarily deep" do
57
60
  FinderOptions.to_mongo_criteria(:foo => {:bar => [1,2,3]}).should == {
58
61
  :foo => {:bar => {'$in' => [1,2,3]}}
59
62
  }
60
- end
61
-
62
- should "convert string _ids to objectid automatically" do
63
- id = XGen::Mongo::Driver::ObjectID.new
64
-
65
- FinderOptions.to_mongo_criteria(:_id => id.to_s).should == {
66
- :_id => id
67
- }
68
- end
69
-
70
- should "leave objectid _ids alone" do
71
- id = XGen::Mongo::Driver::ObjectID.new
72
-
73
- FinderOptions.to_mongo_criteria(:_id => id).should == {
74
- :_id => id
75
- }
76
- end
77
-
78
- should "convert array of string _ids to object ids" do
79
- id1 = XGen::Mongo::Driver::ObjectID.new
80
- id2 = XGen::Mongo::Driver::ObjectID.new
81
-
82
- FinderOptions.to_mongo_criteria(:_id => [id1.to_s, id2.to_s]).should == {
83
- :_id => {'$in' => [id1, id2]}
84
- }
85
- end
86
-
87
- should "convert array of string _ids when using mongo array stuff" do
88
- id1 = XGen::Mongo::Driver::ObjectID.new
89
- id2 = XGen::Mongo::Driver::ObjectID.new
90
-
91
- FinderOptions.to_mongo_criteria(:_id => {'$all' => [id1.to_s, id2.to_s]}).should == {
92
- :_id => {'$all' => [id1, id2]}
93
- }
94
63
 
95
- FinderOptions.to_mongo_criteria(:_id => {'$any' => [id1.to_s, id2.to_s]}).should == {
96
- :_id => {'$any' => [id1, id2]}
64
+ FinderOptions.to_mongo_criteria(:foo => {:bar => {'$any' => [1,2,3]}}).should == {
65
+ :foo => {:bar => {'$any' => [1,2,3]}}
97
66
  }
98
67
  end
99
68
  end
@@ -14,7 +14,7 @@ class KeyTest < Test::Unit::TestCase
14
14
 
15
15
  context "The Key Class" do
16
16
  should "have the native types defined" do
17
- Key::NativeTypes.should == [String, Float, Time, Integer, Boolean, Array, Hash, MongoID]
17
+ Key::NativeTypes.should == [String, Float, Time, Integer, Boolean, Array, Hash]
18
18
  end
19
19
  end
20
20
 
@@ -30,7 +30,7 @@ class KeyTest < Test::Unit::TestCase
30
30
  should "allow setting options" do
31
31
  Key.new(:foo, Integer, :required => true).options[:required].should be(true)
32
32
  end
33
-
33
+
34
34
  should "default options to {}" do
35
35
  Key.new(:foo, Integer, nil).options.should == {}
36
36
  end
@@ -38,6 +38,30 @@ class KeyTest < Test::Unit::TestCase
38
38
  should "symbolize option keys" do
39
39
  Key.new(:foo, Integer, 'required' => true).options[:required].should be(true)
40
40
  end
41
+
42
+ should "work with just name" do
43
+ key = Key.new(:foo)
44
+ key.name.should == 'foo'
45
+ end
46
+
47
+ should "work with name and type" do
48
+ key = Key.new(:foo, String)
49
+ key.name.should == 'foo'
50
+ key.type.should == String
51
+ end
52
+
53
+ should "work with name, type, and options" do
54
+ key = Key.new(:foo, String, :required => true)
55
+ key.name.should == 'foo'
56
+ key.type.should == String
57
+ key.options[:required].should be_true
58
+ end
59
+
60
+ should "work with name and options" do
61
+ key = Key.new(:foo, :required => true)
62
+ key.name.should == 'foo'
63
+ key.options[:required].should be_true
64
+ end
41
65
  end
42
66
 
43
67
  context "A key" do
@@ -52,14 +76,19 @@ class KeyTest < Test::Unit::TestCase
52
76
  should "not be equal to another key with different type" do
53
77
  Key.new(:name, String).should_not == Key.new(:name, Integer)
54
78
  end
55
-
56
- should "know if it is native" do
57
- Key.new(:name, String).native?.should be_true
58
- end
59
-
60
- should "know if it is not native" do
61
- klass = Class.new
62
- Key.new(:name, klass).native?.should be_false
79
+
80
+ context "native?" do
81
+ should "be true if native type" do
82
+ Key.new(:name, String).native?.should be_true
83
+ end
84
+
85
+ should "be true if no type" do
86
+ Key.new(:name).native?.should be_true
87
+ end
88
+
89
+ should "be false if not native" do
90
+ Key.new(:name, Class.new).native?.should be_false
91
+ end
63
92
  end
64
93
 
65
94
  should "know if it is a embedded_document" do
@@ -75,14 +104,6 @@ class KeyTest < Test::Unit::TestCase
75
104
  end
76
105
 
77
106
  context "setting a value" do
78
- should "correctly typecast MongoIDs" do
79
- key = Key.new(:_id, MongoID)
80
- id = MongoID.new
81
- [id, id.to_s].each do |a|
82
- key.set(a).should == id
83
- end
84
- end
85
-
86
107
  should "correctly typecast Strings" do
87
108
  key = Key.new(:foo, String)
88
109
  [21, '21'].each do |a|
@@ -96,6 +117,13 @@ class KeyTest < Test::Unit::TestCase
96
117
  key.set(a).should == 21
97
118
  end
98
119
  end
120
+
121
+ should "work fine with long integers" do
122
+ key = Key.new(:foo, Integer)
123
+ [9223372036854775807, '9223372036854775807'].each do |value|
124
+ key.set(value).should == 9223372036854775807
125
+ end
126
+ end
99
127
 
100
128
  should "correctly typecast Floats" do
101
129
  key = Key.new(:foo, Float)
@@ -109,16 +137,11 @@ class KeyTest < Test::Unit::TestCase
109
137
  key.set('2000-01-01 01:01:01.123456').should == Time.local(2000, 1, 1, 1, 1, 1, 123456)
110
138
  end
111
139
 
112
- should_eventually "correctly typecast Times into UTC time zone" do
140
+ should "correctly typecast Times into UTC time zone" do
113
141
  key = Key.new(:foo, Time)
114
142
  key.set('2000-01-01 01:01:01.123456').zone.should == "UTC"
115
143
  end
116
144
 
117
- should_eventually "correctly typecast Dates" do
118
- key = Key.new(:foo, Date)
119
- key.set('2000-01-01').should == Date.new(2000, 1, 1)
120
- end
121
-
122
145
  should "correctly typecast Boolean" do
123
146
  key = Key.new(:foo, Boolean)
124
147
  ['false', false, 'f', '0', 0].each do |b|
@@ -151,6 +174,13 @@ class KeyTest < Test::Unit::TestCase
151
174
  key = Key.new(:foo, String)
152
175
  key.get('bar').should == 'bar'
153
176
  end
177
+
178
+ should "work without type" do
179
+ key = Key.new(:foo)
180
+ key.get([1,"2"]).should == [1, "2"]
181
+ key.get(false).should == false
182
+ key.get({}).should == {}
183
+ end
154
184
 
155
185
  context "for a key with a default value set" do
156
186
  setup do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: djsun-mongomapper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1.1
4
+ version: 0.3.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Nunemaker
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-08-06 00:00:00 -07:00
12
+ date: 2009-08-16 00:00:00 -07:00
13
13
  default_executable: mmconsole
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -30,7 +30,7 @@ dependencies:
30
30
  requirements:
31
31
  - - "="
32
32
  - !ruby/object:Gem::Version
33
- version: 0.10.1
33
+ version: 0.11.1
34
34
  version:
35
35
  - !ruby/object:Gem::Dependency
36
36
  name: jnunemaker-validatable
@@ -92,6 +92,7 @@ files:
92
92
  - lib/mongomapper/associations/proxy.rb
93
93
  - lib/mongomapper/callbacks.rb
94
94
  - lib/mongomapper/document.rb
95
+ - lib/mongomapper/dynamic_finder.rb
95
96
  - lib/mongomapper/embedded_document.rb
96
97
  - lib/mongomapper/finder_options.rb
97
98
  - lib/mongomapper/key.rb
@@ -102,6 +103,7 @@ files:
102
103
  - lib/mongomapper/save_with_validation.rb
103
104
  - lib/mongomapper/serialization.rb
104
105
  - lib/mongomapper/serializers/json_serializer.rb
106
+ - lib/mongomapper/support.rb
105
107
  - lib/mongomapper/validations.rb
106
108
  - mongomapper.gemspec
107
109
  - test/NOTE_ON_TESTING
@@ -125,7 +127,6 @@ files:
125
127
  - test/unit/test_embedded_document.rb
126
128
  - test/unit/test_finder_options.rb
127
129
  - test/unit/test_key.rb
128
- - test/unit/test_mongo_id.rb
129
130
  - test/unit/test_mongomapper.rb
130
131
  - test/unit/test_observing.rb
131
132
  - test/unit/test_pagination.rb
@@ -180,7 +181,6 @@ test_files:
180
181
  - test/unit/test_embedded_document.rb
181
182
  - test/unit/test_finder_options.rb
182
183
  - test/unit/test_key.rb
183
- - test/unit/test_mongo_id.rb
184
184
  - test/unit/test_mongomapper.rb
185
185
  - test/unit/test_observing.rb
186
186
  - test/unit/test_pagination.rb
@@ -1,35 +0,0 @@
1
- require 'test_helper'
2
-
3
- class MongoIDTest < Test::Unit::TestCase
4
- PhonyError = Class.new(StandardError)
5
-
6
- class Phony
7
- def to_s
8
- raise PhonyError
9
- end
10
- end
11
-
12
- context "mm_typecast" do
13
- should "return value if object id" do
14
- id = XGen::Mongo::Driver::ObjectID.new
15
- MongoID.mm_typecast(id).should == id
16
- end
17
-
18
- should "return object id if string" do
19
- id = XGen::Mongo::Driver::ObjectID.new
20
- MongoID.mm_typecast(id.to_s).should == id
21
- end
22
-
23
- should_eventually "raise MongoMapper::IllegalID if invalid id" do
24
- lambda {
25
- MongoID.mm_typecast(1234)
26
- }.should raise_error(MongoMapper::IllegalID)
27
- end
28
-
29
- should "raise exception if message does not match illegal object id" do
30
- lambda {
31
- MongoID.mm_typecast(Phony.new)
32
- }.should raise_error(PhonyError)
33
- end
34
- end
35
- end