djsun-mongo_mapper 0.5.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (71) hide show
  1. data/.gitignore +8 -0
  2. data/LICENSE +20 -0
  3. data/README.rdoc +39 -0
  4. data/Rakefile +87 -0
  5. data/VERSION +1 -0
  6. data/bin/mmconsole +55 -0
  7. data/lib/mongo_mapper/associations/base.rb +83 -0
  8. data/lib/mongo_mapper/associations/belongs_to_polymorphic_proxy.rb +34 -0
  9. data/lib/mongo_mapper/associations/belongs_to_proxy.rb +22 -0
  10. data/lib/mongo_mapper/associations/many_documents_as_proxy.rb +27 -0
  11. data/lib/mongo_mapper/associations/many_documents_proxy.rb +116 -0
  12. data/lib/mongo_mapper/associations/many_embedded_polymorphic_proxy.rb +33 -0
  13. data/lib/mongo_mapper/associations/many_embedded_proxy.rb +67 -0
  14. data/lib/mongo_mapper/associations/many_polymorphic_proxy.rb +11 -0
  15. data/lib/mongo_mapper/associations/many_proxy.rb +6 -0
  16. data/lib/mongo_mapper/associations/proxy.rb +74 -0
  17. data/lib/mongo_mapper/associations.rb +86 -0
  18. data/lib/mongo_mapper/callbacks.rb +106 -0
  19. data/lib/mongo_mapper/document.rb +308 -0
  20. data/lib/mongo_mapper/dynamic_finder.rb +35 -0
  21. data/lib/mongo_mapper/embedded_document.rb +354 -0
  22. data/lib/mongo_mapper/finder_options.rb +94 -0
  23. data/lib/mongo_mapper/key.rb +32 -0
  24. data/lib/mongo_mapper/observing.rb +50 -0
  25. data/lib/mongo_mapper/pagination.rb +51 -0
  26. data/lib/mongo_mapper/rails_compatibility/document.rb +15 -0
  27. data/lib/mongo_mapper/rails_compatibility/embedded_document.rb +27 -0
  28. data/lib/mongo_mapper/save_with_validation.rb +19 -0
  29. data/lib/mongo_mapper/serialization.rb +55 -0
  30. data/lib/mongo_mapper/serializers/json_serializer.rb +92 -0
  31. data/lib/mongo_mapper/support.rb +171 -0
  32. data/lib/mongo_mapper/validations.rb +69 -0
  33. data/lib/mongo_mapper.rb +95 -0
  34. data/mongo_mapper.gemspec +156 -0
  35. data/specs.watchr +32 -0
  36. data/test/NOTE_ON_TESTING +1 -0
  37. data/test/custom_matchers.rb +48 -0
  38. data/test/functional/associations/test_belongs_to_polymorphic_proxy.rb +55 -0
  39. data/test/functional/associations/test_belongs_to_proxy.rb +49 -0
  40. data/test/functional/associations/test_many_documents_as_proxy.rb +244 -0
  41. data/test/functional/associations/test_many_embedded_polymorphic_proxy.rb +132 -0
  42. data/test/functional/associations/test_many_embedded_proxy.rb +174 -0
  43. data/test/functional/associations/test_many_polymorphic_proxy.rb +297 -0
  44. data/test/functional/associations/test_many_proxy.rb +331 -0
  45. data/test/functional/test_associations.rb +44 -0
  46. data/test/functional/test_binary.rb +18 -0
  47. data/test/functional/test_callbacks.rb +85 -0
  48. data/test/functional/test_document.rb +964 -0
  49. data/test/functional/test_embedded_document.rb +97 -0
  50. data/test/functional/test_logger.rb +20 -0
  51. data/test/functional/test_pagination.rb +87 -0
  52. data/test/functional/test_rails_compatibility.rb +30 -0
  53. data/test/functional/test_validations.rb +279 -0
  54. data/test/models.rb +169 -0
  55. data/test/test_helper.rb +30 -0
  56. data/test/unit/serializers/test_json_serializer.rb +193 -0
  57. data/test/unit/test_association_base.rb +144 -0
  58. data/test/unit/test_document.rb +165 -0
  59. data/test/unit/test_dynamic_finder.rb +125 -0
  60. data/test/unit/test_embedded_document.rb +643 -0
  61. data/test/unit/test_finder_options.rb +193 -0
  62. data/test/unit/test_key.rb +175 -0
  63. data/test/unit/test_mongomapper.rb +28 -0
  64. data/test/unit/test_observing.rb +101 -0
  65. data/test/unit/test_pagination.rb +109 -0
  66. data/test/unit/test_rails_compatibility.rb +39 -0
  67. data/test/unit/test_serializations.rb +52 -0
  68. data/test/unit/test_support.rb +272 -0
  69. data/test/unit/test_time_zones.rb +40 -0
  70. data/test/unit/test_validations.rb +503 -0
  71. metadata +207 -0
@@ -0,0 +1,643 @@
1
+ require 'test_helper'
2
+
3
+ class Grandparent
4
+ include MongoMapper::EmbeddedDocument
5
+ key :grandparent, String
6
+ end
7
+
8
+ class Parent < Grandparent
9
+ include MongoMapper::EmbeddedDocument
10
+ key :parent, String
11
+ end
12
+
13
+ class Child < Parent
14
+ include MongoMapper::EmbeddedDocument
15
+ key :child, String
16
+ end
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
+
28
+ class OtherChild < Parent
29
+ include MongoMapper::EmbeddedDocument
30
+ include KeyOverride
31
+
32
+ key :other_child, String
33
+ end
34
+
35
+ class EmbeddedDocumentTest < Test::Unit::TestCase
36
+ context "Including MongoMapper::EmbeddedDocument in a class" do
37
+ setup do
38
+ @klass = Class.new do
39
+ include MongoMapper::EmbeddedDocument
40
+ end
41
+ end
42
+
43
+ should "add _id key" do
44
+ @klass.keys['_id'].should_not be_nil
45
+ end
46
+
47
+ context "#to_mongo" do
48
+ should "be nil if nil" do
49
+ @klass.to_mongo(nil).should be_nil
50
+ end
51
+
52
+ should "convert to_mongo for other values" do
53
+ doc = @klass.new(:foo => 'bar')
54
+ to_mongo = @klass.to_mongo(doc)
55
+ to_mongo.is_a?(Hash).should be_true
56
+ to_mongo['foo'].should == 'bar'
57
+ end
58
+ end
59
+
60
+ context "#from_mongo" do
61
+ should "be nil if nil" do
62
+ @klass.from_mongo(nil).should be_nil
63
+ end
64
+
65
+ should "be instance if instance of class" do
66
+ doc = @klass.new
67
+ @klass.from_mongo(doc).should == doc
68
+ end
69
+
70
+ should "be instance if hash of attributes" do
71
+ doc = @klass.from_mongo({:foo => 'bar'})
72
+ doc.instance_of?(@klass).should be_true
73
+ doc.foo.should == 'bar'
74
+ end
75
+ end
76
+ end
77
+
78
+ context "parent_model" do
79
+ should "be nil if none of parents ancestors include EmbeddedDocument" do
80
+ parent = Class.new
81
+ document = Class.new(parent) do
82
+ include MongoMapper::EmbeddedDocument
83
+ end
84
+ document.parent_model.should be_nil
85
+ end
86
+
87
+ should "work when other modules have been included" do
88
+ grandparent = Class.new
89
+ parent = Class.new grandparent do
90
+ include MongoMapper::EmbeddedDocument
91
+ end
92
+
93
+ example_module = Module.new
94
+ document = Class.new(parent) do
95
+ include MongoMapper::EmbeddedDocument
96
+ include example_module
97
+ end
98
+
99
+ document.parent_model.should == parent
100
+ end
101
+
102
+ should "find parent" do
103
+ Parent.parent_model.should == Grandparent
104
+ Child.parent_model.should == Parent
105
+ end
106
+ end
107
+
108
+ context "defining a key" do
109
+ setup do
110
+ @document = Class.new do
111
+ include MongoMapper::EmbeddedDocument
112
+ end
113
+ end
114
+
115
+ should "work with name" do
116
+ key = @document.key(:name)
117
+ key.name.should == 'name'
118
+ end
119
+
120
+ should "work with name and type" do
121
+ key = @document.key(:name, String)
122
+ key.name.should == 'name'
123
+ key.type.should == String
124
+ end
125
+
126
+ should "work with name, type and options" do
127
+ key = @document.key(:name, String, :required => true)
128
+ key.name.should == 'name'
129
+ key.type.should == String
130
+ key.options[:required].should be_true
131
+ end
132
+
133
+ should "work with name and options" do
134
+ key = @document.key(:name, :required => true)
135
+ key.name.should == 'name'
136
+ key.options[:required].should be_true
137
+ end
138
+
139
+ should "be tracked per document" do
140
+ @document.key(:name, String)
141
+ @document.key(:age, Integer)
142
+ @document.keys['name'].name.should == 'name'
143
+ @document.keys['name'].type.should == String
144
+ @document.keys['age'].name.should == 'age'
145
+ @document.keys['age'].type.should == Integer
146
+ end
147
+
148
+ should "not be redefinable" do
149
+ @document.key(:foo, String)
150
+ @document.keys['foo'].type.should == String
151
+ @document.key(:foo, Integer)
152
+ @document.keys['foo'].type.should == String
153
+ end
154
+
155
+ should "create reader method" do
156
+ @document.new.should_not respond_to(:foo)
157
+ @document.key(:foo, String)
158
+ @document.new.should respond_to(:foo)
159
+ end
160
+
161
+ should "create reader before typecast method" do
162
+ @document.new.should_not respond_to(:foo_before_typecast)
163
+ @document.key(:foo, String)
164
+ @document.new.should respond_to(:foo_before_typecast)
165
+ end
166
+
167
+ should "create writer method" do
168
+ @document.new.should_not respond_to(:foo=)
169
+ @document.key(:foo, String)
170
+ @document.new.should respond_to(:foo=)
171
+ end
172
+
173
+ should "create boolean method" do
174
+ @document.new.should_not respond_to(:foo?)
175
+ @document.key(:foo, String)
176
+ @document.new.should respond_to(:foo?)
177
+ end
178
+ end
179
+
180
+ context "keys" do
181
+ should "be inherited" do
182
+ Grandparent.keys.keys.sort.should == ['_id', 'grandparent']
183
+ Parent.keys.keys.sort.should == ['_id', 'grandparent', 'parent']
184
+ Child.keys.keys.sort.should == ['_id', 'child', 'grandparent', 'parent']
185
+ end
186
+
187
+ should "propogate to subclasses if key added after class definition" do
188
+ Grandparent.key :_type, String
189
+
190
+ Grandparent.keys.keys.sort.should == ['_id', '_type', 'grandparent']
191
+ Parent.keys.keys.sort.should == ['_id', '_type', 'grandparent', 'parent']
192
+ Child.keys.keys.sort.should == ['_id', '_type', 'child', 'grandparent', 'parent']
193
+ end
194
+
195
+ should "not add anonymous objects to the ancestor tree" do
196
+ OtherChild.ancestors.any? { |a| a.name.blank? }.should be_false
197
+ end
198
+
199
+ should "not include descendant keys" do
200
+ lambda { Parent.new.other_child }.should raise_error
201
+ end
202
+ end
203
+
204
+ context "#inspect" do
205
+ setup do
206
+ @document = Class.new do
207
+ include MongoMapper::Document
208
+ key :animals
209
+ end
210
+ end
211
+
212
+ should "call inspect on the document's attributes instead of to_s" do
213
+ doc = @document.new
214
+ doc.animals = %w(dog cat)
215
+ doc.inspect.should include(%(animals: ["dog", "cat"]))
216
+ end
217
+ end
218
+
219
+ context "subclasses" do
220
+ should "default to nil" do
221
+ Child.subclasses.should be_nil
222
+ end
223
+
224
+ should "be recorded" do
225
+ Grandparent.subclasses.should == [Parent]
226
+ Parent.subclasses.should == [Child, OtherChild]
227
+ end
228
+ end
229
+
230
+ context "Applying default values for keys" do
231
+ setup do
232
+ @document = Class.new do
233
+ include MongoMapper::EmbeddedDocument
234
+
235
+ key :name, String, :default => 'foo'
236
+ key :age, Integer, :default => 20
237
+ key :net_worth, Float, :default => 100.00
238
+ key :active, Boolean, :default => true
239
+ key :smart, Boolean, :default => false
240
+ key :skills, Array, :default => [1]
241
+ key :options, Hash, :default => {'foo' => 'bar'}
242
+ end
243
+
244
+ @doc = @document.new
245
+ end
246
+
247
+ should "work for strings" do
248
+ @doc.name.should == 'foo'
249
+ end
250
+
251
+ should "work for integers" do
252
+ @doc.age.should == 20
253
+ end
254
+
255
+ should "work for floats" do
256
+ @doc.net_worth.should == 100.00
257
+ end
258
+
259
+ should "work for booleans" do
260
+ @doc.active.should == true
261
+ @doc.smart.should == false
262
+ end
263
+
264
+ should "work for arrays" do
265
+ @doc.skills.should == [1]
266
+ @doc.skills << 2
267
+ @doc.skills.should == [1, 2]
268
+ end
269
+
270
+ should "work for hashes" do
271
+ @doc.options['foo'].should == 'bar'
272
+ @doc.options['baz'] = 'wick'
273
+ @doc.options['baz'].should == 'wick'
274
+ end
275
+ end
276
+
277
+ context "An instance of an embedded document" do
278
+ setup do
279
+ @document = Class.new do
280
+ include MongoMapper::EmbeddedDocument
281
+
282
+ key :name, String
283
+ key :age, Integer
284
+ end
285
+ end
286
+
287
+ should "automatically have an _id key" do
288
+ @document.keys.keys.should include('_id')
289
+ end
290
+
291
+ should "have id method that sets _id" do
292
+ doc = @document.new
293
+ doc.id.should == doc._id.to_s
294
+ end
295
+
296
+ should "have a nil _root_document" do
297
+ @document.new._root_document.should be_nil
298
+ end
299
+
300
+ context "setting custom id" do
301
+ should "set _id" do
302
+ doc = @document.new(:id => '1234')
303
+ doc._id.should == '1234'
304
+ end
305
+
306
+ should "know that custom id is set" do
307
+ doc = @document.new
308
+ doc.using_custom_id?.should be_false
309
+ doc.id = '1234'
310
+ doc.using_custom_id?.should be_true
311
+ end
312
+ end
313
+
314
+ context "being initialized" do
315
+ should "accept a hash that sets keys and values" do
316
+ doc = @document.new(:name => 'John', :age => 23)
317
+ doc.attributes.keys.sort.should == ['_id', 'age', 'name']
318
+ doc.attributes['name'].should == 'John'
319
+ doc.attributes['age'].should == 23
320
+ end
321
+
322
+ should "be able to assign keys dynamically" do
323
+ doc = @document.new(:name => 'John', :skills => ['ruby', 'rails'])
324
+ doc.name.should == 'John'
325
+ doc.skills.should == ['ruby', 'rails']
326
+ end
327
+
328
+ should "set the root on embedded documents" do
329
+ document = Class.new(@document) do
330
+ many :children
331
+ end
332
+
333
+ doc = document.new :_root_document => 'document', 'children' => [{}]
334
+ doc.children.first._root_document.should == 'document'
335
+ end
336
+
337
+ should "not throw error if initialized with nil" do
338
+ lambda {
339
+ @document.new(nil)
340
+ }.should_not raise_error
341
+ end
342
+ end
343
+
344
+ context "initialized when _type key present" do
345
+ setup do
346
+ ::FooBar = Class.new do
347
+ include MongoMapper::EmbeddedDocument
348
+ key :_type, String
349
+ end
350
+ end
351
+
352
+ teardown do
353
+ Object.send(:remove_const, :FooBar)
354
+ end
355
+
356
+ should "set _type to class name" do
357
+ FooBar.new._type.should == 'FooBar'
358
+ end
359
+
360
+ should "not change _type if already set" do
361
+ FooBar.new(:_type => 'Foo')._type.should == 'Foo'
362
+ end
363
+ end
364
+
365
+ context "mass assigning keys" do
366
+ should "update values for keys provided" do
367
+ doc = @document.new(:name => 'foobar', :age => 10)
368
+ doc.attributes = {:name => 'new value', :age => 5}
369
+ doc.attributes[:name].should == 'new value'
370
+ doc.attributes[:age].should == 5
371
+ end
372
+
373
+ should "not update values for keys that were not provided" do
374
+ doc = @document.new(:name => 'foobar', :age => 10)
375
+ doc.attributes = {:name => 'new value'}
376
+ doc.attributes[:name].should == 'new value'
377
+ doc.attributes[:age].should == 10
378
+ end
379
+
380
+ should "not ignore keys that have methods defined" do
381
+ @document.class_eval do
382
+ attr_writer :password
383
+
384
+ def passwd
385
+ @password
386
+ end
387
+ end
388
+
389
+ doc = @document.new(:name => 'foobar', :password => 'secret')
390
+ doc.passwd.should == 'secret'
391
+ end
392
+
393
+ should "typecast key values" do
394
+ doc = @document.new(:name => 1234, :age => '21')
395
+ doc.name.should == '1234'
396
+ doc.age.should == 21
397
+ end
398
+ end
399
+
400
+ context "attributes" do
401
+ should "default to hash with all keys" do
402
+ doc = @document.new
403
+ doc.attributes.keys.sort.should == ['_id', 'age', 'name']
404
+ end
405
+
406
+ should "return all keys with values" do
407
+ doc = @document.new(:name => 'string', :age => nil)
408
+ doc.attributes.keys.sort.should == ['_id', 'age', 'name']
409
+ doc.attributes.values.should include('string')
410
+ doc.attributes.values.should include(nil)
411
+ end
412
+ end
413
+
414
+ context "to_mongo" do
415
+ should "default to hash with _id key" do
416
+ doc = @document.new
417
+ doc.to_mongo.keys.sort.should == %w(_id age name)
418
+ end
419
+
420
+ should "return all keys" do
421
+ doc = @document.new(:name => 'string', :age => nil)
422
+ doc.to_mongo.keys.sort.should == %w(_id age name)
423
+ end
424
+ end
425
+
426
+ should "convert dates into times" do
427
+ document = Class.new(@document) do
428
+ key :start_date, Date
429
+ end
430
+ doc = document.new :start_date => "12/05/2009"
431
+ doc.start_date.should == Date.new(2009, 12, 05)
432
+ end
433
+
434
+ context "clone" do
435
+ should "regenerate the id" do
436
+ doc = @document.new(:name => "foo", :age => 27)
437
+ doc_id = doc.id
438
+ clone = doc.clone
439
+ clone_id = clone.id
440
+ clone_id.should_not == doc_id
441
+ end
442
+
443
+ should "copy the attributes" do
444
+ doc = @document.new(:name => "foo", :age => 27)
445
+ clone = doc.clone
446
+ clone.name.should == "foo"
447
+ clone.age.should == 27
448
+ end
449
+ end
450
+
451
+ context "key shorcut access" do
452
+ should "be able to read key with []" do
453
+ doc = @document.new(:name => 'string')
454
+ doc[:name].should == 'string'
455
+ end
456
+
457
+ context "[]=" do
458
+ should "write key value for existing key" do
459
+ doc = @document.new
460
+ doc[:name] = 'string'
461
+ doc[:name].should == 'string'
462
+ end
463
+
464
+ should "create key and write value for missing key" do
465
+ doc = @document.new
466
+ doc[:foo] = 'string'
467
+ @document.keys.keys.include?('foo').should be_true
468
+ doc[:foo].should == 'string'
469
+ end
470
+ end
471
+ end
472
+
473
+ context "indifferent access" do
474
+ should "be enabled for keys" do
475
+ doc = @document.new(:name => 'string')
476
+ doc.attributes[:name].should == 'string'
477
+ doc.attributes['name'].should == 'string'
478
+ end
479
+ end
480
+
481
+ context "reading an attribute" do
482
+ should "work for defined keys" do
483
+ doc = @document.new(:name => 'string')
484
+ doc.name.should == 'string'
485
+ end
486
+
487
+ should "raise no method error for undefined keys" do
488
+ doc = @document.new
489
+ lambda { doc.fart }.should raise_error(NoMethodError)
490
+ end
491
+
492
+ should "be accessible for use in the model" do
493
+ @document.class_eval do
494
+ def name_and_age
495
+ "#{read_attribute(:name)} (#{read_attribute(:age)})"
496
+ end
497
+ end
498
+
499
+ doc = @document.new(:name => 'John', :age => 27)
500
+ doc.name_and_age.should == 'John (27)'
501
+ end
502
+
503
+ should "set instance variable" do
504
+ @document.key :foo, Array
505
+ doc = @document.new
506
+ doc.instance_variable_get("@foo").should be_nil
507
+ doc.foo
508
+ doc.instance_variable_get("@foo").should == []
509
+ end
510
+
511
+ should "not set instance variable if frozen" do
512
+ @document.key :foo, Array
513
+ doc = @document.new
514
+ doc.instance_variable_get("@foo").should be_nil
515
+ doc.freeze
516
+ doc.foo
517
+ doc.instance_variable_get("@foo").should be_nil
518
+ end
519
+
520
+ should "be overrideable by modules" do
521
+ @document = Class.new do
522
+ include MongoMapper::Document
523
+ key :other_child, String
524
+ end
525
+
526
+ child = @document.new
527
+ child.other_child.should be_nil
528
+
529
+ @document.send :include, KeyOverride
530
+
531
+ overriden_child = @document.new
532
+ overriden_child.other_child.should == 'special result'
533
+ end
534
+ end
535
+
536
+ context "reading an attribute before typcasting" do
537
+ should "work for defined keys" do
538
+ doc = @document.new(:name => 12)
539
+ doc.name_before_typecast.should == 12
540
+ end
541
+
542
+ should "raise no method error for undefined keys" do
543
+ doc = @document.new
544
+ lambda { doc.foo_before_typecast }.should raise_error(NoMethodError)
545
+ end
546
+
547
+ should "be accessible for use in a document" do
548
+ @document.class_eval do
549
+ def untypcasted_name
550
+ read_attribute_before_typecast(:name)
551
+ end
552
+ end
553
+
554
+ doc = @document.new(:name => 12)
555
+ doc.name.should == '12'
556
+ doc.untypcasted_name.should == 12
557
+ end
558
+ end
559
+
560
+ context "writing an attribute" do
561
+ should "work for defined keys" do
562
+ doc = @document.new
563
+ doc.name = 'John'
564
+ doc.name.should == 'John'
565
+ end
566
+
567
+ should "raise no method error for undefined keys" do
568
+ doc = @document.new
569
+ lambda { doc.fart = 'poof!' }.should raise_error(NoMethodError)
570
+ end
571
+
572
+ should "typecast value" do
573
+ doc = @document.new
574
+ doc.name = 1234
575
+ doc.name.should == '1234'
576
+ doc.age = '21'
577
+ doc.age.should == 21
578
+ end
579
+
580
+ should "be accessible for use in the model" do
581
+ @document.class_eval do
582
+ def name_and_age=(new_value)
583
+ new_value.match(/([^\(\s]+) \((.*)\)/)
584
+ write_attribute :name, $1
585
+ write_attribute :age, $2
586
+ end
587
+ end
588
+
589
+ doc = @document.new
590
+ doc.name_and_age = 'Frank (62)'
591
+ doc.name.should == 'Frank'
592
+ doc.age.should == 62
593
+ end
594
+
595
+ should "be overrideable by modules" do
596
+ @document = Class.new do
597
+ include MongoMapper::Document
598
+ key :other_child, String
599
+ end
600
+
601
+ child = @document.new(:other_child => 'foo')
602
+ child.other_child.should == 'foo'
603
+
604
+ @document.send :include, KeyOverride
605
+
606
+ overriden_child = @document.new(:other_child => 'foo')
607
+ overriden_child.other_child.should == 'foo modified'
608
+ end
609
+ end # writing an attribute
610
+
611
+ context "checking if an attributes value is present" do
612
+ should "work for defined keys" do
613
+ doc = @document.new
614
+ doc.name?.should be_false
615
+ doc.name = 'John'
616
+ doc.name?.should be_true
617
+ end
618
+
619
+ should "raise no method error for undefined keys" do
620
+ doc = @document.new
621
+ lambda { doc.fart? }.should raise_error(NoMethodError)
622
+ end
623
+ end
624
+
625
+ context "equality" do
626
+ should "be equal if id and class are the same" do
627
+ (@document.new('_id' => 1) == @document.new('_id' => 1)).should be(true)
628
+ end
629
+
630
+ should "not be equal if class same but id different" do
631
+ (@document.new('_id' => 1) == @document.new('_id' => 2)).should be(false)
632
+ end
633
+
634
+ should "not be equal if id same but class different" do
635
+ @another_document = Class.new do
636
+ include MongoMapper::Document
637
+ end
638
+
639
+ (@document.new('_id' => 1) == @another_document.new('_id' => 1)).should be(false)
640
+ end
641
+ end
642
+ end # instance of a embedded document
643
+ end