mongoid-pre 2.0.0.beta1 → 2.0.0.pre

Sign up to get free protection for your applications and to get access to all the features.
Files changed (135) hide show
  1. data/.watchr +15 -10
  2. data/HISTORY +342 -0
  3. data/README.rdoc +8 -1
  4. data/Rakefile +2 -3
  5. data/VERSION +1 -1
  6. data/lib/mongoid/associations/{embedded_in.rb → belongs_to.rb} +4 -4
  7. data/lib/mongoid/associations/belongs_to_related.rb +9 -6
  8. data/lib/mongoid/associations/{embeds_many.rb → has_many.rb} +20 -33
  9. data/lib/mongoid/associations/has_many_related.rb +4 -28
  10. data/lib/mongoid/associations/{embeds_one.rb → has_one.rb} +6 -6
  11. data/lib/mongoid/associations/options.rb +6 -1
  12. data/lib/mongoid/associations.rb +32 -41
  13. data/lib/mongoid/attributes.rb +6 -13
  14. data/lib/mongoid/collection.rb +1 -2
  15. data/lib/mongoid/commands/delete.rb +1 -1
  16. data/lib/mongoid/commands/delete_all.rb +1 -4
  17. data/lib/mongoid/commands/destroy.rb +1 -1
  18. data/lib/mongoid/commands/destroy_all.rb +1 -3
  19. data/lib/mongoid/commands/save.rb +0 -1
  20. data/lib/mongoid/commands.rb +13 -2
  21. data/lib/mongoid/components.rb +1 -6
  22. data/lib/mongoid/config.rb +1 -5
  23. data/lib/mongoid/contexts/enumerable.rb +17 -54
  24. data/lib/mongoid/contexts/mongo.rb +38 -101
  25. data/lib/mongoid/contexts/paging.rb +2 -2
  26. data/lib/mongoid/contexts.rb +0 -21
  27. data/lib/mongoid/criteria.rb +73 -15
  28. data/lib/mongoid/criterion/inclusion.rb +0 -2
  29. data/lib/mongoid/criterion/optional.rb +2 -10
  30. data/lib/mongoid/document.rb +30 -41
  31. data/lib/mongoid/extensions.rb +0 -15
  32. data/lib/mongoid/field.rb +7 -20
  33. data/lib/mongoid/fields.rb +10 -15
  34. data/lib/mongoid/finders.rb +98 -10
  35. data/lib/mongoid/identity.rb +2 -8
  36. data/lib/mongoid/named_scope.rb +0 -2
  37. data/lib/mongoid/validations/associated.rb +8 -3
  38. data/lib/mongoid/validations/uniqueness.rb +7 -2
  39. data/lib/mongoid/validations.rb +2 -2
  40. data/lib/mongoid/versioning.rb +1 -1
  41. data/lib/mongoid.rb +5 -21
  42. data/mongoid.gemspec +19 -59
  43. data/spec/integration/mongoid/associations_spec.rb +3 -42
  44. data/spec/integration/mongoid/attributes_spec.rb +2 -2
  45. data/spec/integration/mongoid/commands_spec.rb +13 -27
  46. data/spec/integration/mongoid/contexts/enumerable_spec.rb +0 -13
  47. data/spec/integration/mongoid/criteria_spec.rb +3 -50
  48. data/spec/integration/mongoid/document_spec.rb +5 -72
  49. data/spec/integration/mongoid/finders_spec.rb +28 -85
  50. data/spec/models/address.rb +3 -3
  51. data/spec/models/animal.rb +2 -2
  52. data/spec/models/country_code.rb +2 -2
  53. data/spec/models/game.rb +1 -2
  54. data/spec/models/inheritance.rb +5 -5
  55. data/spec/models/location.rb +2 -2
  56. data/spec/models/name.rb +3 -3
  57. data/spec/models/namespacing.rb +2 -2
  58. data/spec/models/patient.rb +0 -2
  59. data/spec/models/person.rb +4 -6
  60. data/spec/models/pet.rb +3 -3
  61. data/spec/models/pet_owner.rb +3 -3
  62. data/spec/models/phone.rb +3 -3
  63. data/spec/models/post.rb +1 -1
  64. data/spec/models/translation.rb +2 -2
  65. data/spec/models/vet_visit.rb +2 -2
  66. data/spec/spec_helper.rb +2 -2
  67. data/spec/unit/mongoid/associations/belongs_to_related_spec.rb +0 -4
  68. data/spec/unit/mongoid/associations/{embedded_in_spec.rb → belongs_to_spec.rb} +11 -11
  69. data/spec/unit/mongoid/associations/has_many_related_spec.rb +14 -45
  70. data/spec/unit/mongoid/associations/{embeds_many_spec.rb → has_many_spec.rb} +34 -79
  71. data/spec/unit/mongoid/associations/{embeds_one_spec.rb → has_one_spec.rb} +18 -18
  72. data/spec/unit/mongoid/associations/options_spec.rb +19 -20
  73. data/spec/unit/mongoid/associations_spec.rb +12 -74
  74. data/spec/unit/mongoid/attributes_spec.rb +51 -83
  75. data/spec/unit/mongoid/collection_spec.rb +0 -46
  76. data/spec/unit/mongoid/commands/delete_all_spec.rb +8 -9
  77. data/spec/unit/mongoid/commands/delete_spec.rb +3 -6
  78. data/spec/unit/mongoid/commands/destroy_all_spec.rb +2 -0
  79. data/spec/unit/mongoid/commands/destroy_spec.rb +3 -10
  80. data/spec/unit/mongoid/commands_spec.rb +11 -20
  81. data/spec/unit/mongoid/config_spec.rb +0 -18
  82. data/spec/unit/mongoid/contexts/enumerable_spec.rb +11 -198
  83. data/spec/unit/mongoid/contexts/mongo_spec.rb +54 -357
  84. data/spec/unit/mongoid/criteria_spec.rb +78 -107
  85. data/spec/unit/mongoid/criterion/exclusion_spec.rb +13 -3
  86. data/spec/unit/mongoid/criterion/inclusion_spec.rb +19 -25
  87. data/spec/unit/mongoid/criterion/optional_spec.rb +18 -25
  88. data/spec/unit/mongoid/document_spec.rb +34 -71
  89. data/spec/unit/mongoid/extensions/array/conversions_spec.rb +2 -2
  90. data/spec/unit/mongoid/extensions/datetime/conversions_spec.rb +3 -0
  91. data/spec/unit/mongoid/extensions/object/conversions_spec.rb +2 -16
  92. data/spec/unit/mongoid/extensions/proc/scoping_spec.rb +1 -1
  93. data/spec/unit/mongoid/field_spec.rb +0 -62
  94. data/spec/unit/mongoid/fields_spec.rb +0 -33
  95. data/spec/unit/mongoid/finders_spec.rb +1 -37
  96. data/spec/unit/mongoid/identity_spec.rb +6 -47
  97. data/spec/unit/mongoid/named_scope_spec.rb +2 -15
  98. data/spec/unit/mongoid/scope_spec.rb +1 -1
  99. data/spec/unit/mongoid/validations/uniqueness_spec.rb +3 -3
  100. data/spec/unit/mongoid_spec.rb +2 -11
  101. metadata +14 -64
  102. data/lib/mongoid/associations/meta_data.rb +0 -28
  103. data/lib/mongoid/contexts/ids.rb +0 -25
  104. data/lib/mongoid/deprecation.rb +0 -22
  105. data/lib/mongoid/dirty.rb +0 -203
  106. data/lib/mongoid/extensions/big_decimal/conversions.rb +0 -19
  107. data/lib/mongoid/extensions/binary/conversions.rb +0 -17
  108. data/lib/mongoid/extensions/objectid/conversions.rb +0 -15
  109. data/lib/mongoid/extras.rb +0 -61
  110. data/lib/mongoid/javascript/functions.yml +0 -37
  111. data/lib/mongoid/javascript.rb +0 -21
  112. data/lib/mongoid/observable.rb +0 -30
  113. data/lib/mongoid/paths.rb +0 -54
  114. data/lib/mongoid/persistence/command.rb +0 -20
  115. data/lib/mongoid/persistence/insert.rb +0 -71
  116. data/lib/mongoid/persistence/update.rb +0 -78
  117. data/lib/mongoid/persistence.rb +0 -27
  118. data/lib/mongoid/state.rb +0 -32
  119. data/spec/integration/mongoid/dirty_spec.rb +0 -70
  120. data/spec/integration/mongoid/persistence/update_spec.rb +0 -46
  121. data/spec/models/callbacks.rb +0 -18
  122. data/spec/unit/mongoid/associations/meta_data_spec.rb +0 -88
  123. data/spec/unit/mongoid/contexts_spec.rb +0 -25
  124. data/spec/unit/mongoid/deprecation_spec.rb +0 -24
  125. data/spec/unit/mongoid/dirty_spec.rb +0 -286
  126. data/spec/unit/mongoid/extensions/big_decimal/conversions_spec.rb +0 -22
  127. data/spec/unit/mongoid/extensions/binary/conversions_spec.rb +0 -22
  128. data/spec/unit/mongoid/extras_spec.rb +0 -102
  129. data/spec/unit/mongoid/javascript_spec.rb +0 -48
  130. data/spec/unit/mongoid/observable_spec.rb +0 -46
  131. data/spec/unit/mongoid/paths_spec.rb +0 -124
  132. data/spec/unit/mongoid/persistence/insert_spec.rb +0 -175
  133. data/spec/unit/mongoid/persistence/update_spec.rb +0 -148
  134. data/spec/unit/mongoid/persistence_spec.rb +0 -40
  135. data/spec/unit/mongoid/state_spec.rb +0 -83
@@ -94,18 +94,7 @@ describe Mongoid::Associations do
94
94
 
95
95
  end
96
96
 
97
- describe "#associations" do
98
-
99
- before do
100
- @person = Person.new
101
- end
102
-
103
- it "is a hash with name keys and meta data values" do
104
- @person.associations["addresses"].should be_a_kind_of(Mongoid::Associations::MetaData)
105
- end
106
- end
107
-
108
- describe ".embedded_in" do
97
+ describe ".belongs_to" do
109
98
 
110
99
  it "creates a reader for the association" do
111
100
  address = Address.new
@@ -141,7 +130,7 @@ describe Mongoid::Associations do
141
130
  context "when inverse_of not supplied" do
142
131
 
143
132
  it "raises an error" do
144
- lambda { Person.class_eval { embedded_in :nothing } }.should raise_error
133
+ lambda { Person.class_eval { belongs_to :nothing } }.should raise_error
145
134
  end
146
135
 
147
136
  end
@@ -210,18 +199,6 @@ describe Mongoid::Associations do
210
199
 
211
200
  end
212
201
 
213
- context "when attributes are nil" do
214
-
215
- before do
216
- @writer = @canvas.build_writer(nil)
217
- end
218
-
219
- it "defaults them to empty" do
220
- @writer.should be_a_kind_of(Writer)
221
- end
222
-
223
- end
224
-
225
202
  end
226
203
 
227
204
  describe "#create_*" do
@@ -274,7 +251,7 @@ describe Mongoid::Associations do
274
251
 
275
252
  end
276
253
 
277
- describe ".embeds_many" do
254
+ describe ".has_many" do
278
255
 
279
256
  it "adds a new Association to the collection" do
280
257
  person = Person.new
@@ -350,7 +327,7 @@ describe Mongoid::Associations do
350
327
 
351
328
  end
352
329
 
353
- describe ".embeds_one" do
330
+ describe ".has_one" do
354
331
 
355
332
  before do
356
333
  @person = Person.new
@@ -421,7 +398,7 @@ describe Mongoid::Associations do
421
398
  describe ".reflect_on_association" do
422
399
 
423
400
  it "returns the association class for the name" do
424
- Person.reflect_on_association(:addresses).should == :embeds_many
401
+ Person.reflect_on_association(:addresses).should == :has_many
425
402
  end
426
403
 
427
404
  end
@@ -440,10 +417,6 @@ describe Mongoid::Associations do
440
417
  @game.should respond_to(:person)
441
418
  end
442
419
 
443
- it "defaults the foreign_key option to the name_id" do
444
- @game.associations["person"].foreign_key.should == "person_id"
445
- end
446
-
447
420
  context "when document is root level" do
448
421
 
449
422
  it "puts an index on the foreign key" do
@@ -453,22 +426,6 @@ describe Mongoid::Associations do
453
426
 
454
427
  end
455
428
 
456
- context "when using object ids" do
457
-
458
- before do
459
- Mongoid.use_object_ids = true
460
- end
461
-
462
- after do
463
- Mongoid.use_object_ids = false
464
- end
465
-
466
- it "sets the foreign key as an object id" do
467
- Game.expects(:field).with("person_id", :type => Mongo::ObjectID)
468
- Game.belongs_to_related :person
469
- end
470
- end
471
-
472
429
  end
473
430
 
474
431
  describe ".has_one_related" do
@@ -525,34 +482,15 @@ describe Mongoid::Associations do
525
482
 
526
483
  context "when associations exist" do
527
484
 
528
- context "when the document is a new record" do
529
-
530
- before do
531
- @related = stub(:id => "100", :person= => true)
532
- @person = Person.new
533
- @person.posts = [@related]
534
- end
535
-
536
- it "saves each association" do
537
- @related.expects(:save).returns(@related)
538
- @person.update_associations(:posts)
539
- end
540
-
485
+ before do
486
+ @related = stub(:id => "100", :person= => true)
487
+ @person = Person.new
488
+ @person.posts = [@related]
541
489
  end
542
490
 
543
- context "when the document is not new" do
544
-
545
- before do
546
- @related = stub(:id => "100", :person= => true)
547
- @person = Person.new
548
- @person.instance_variable_set(:@new_record, false)
549
- @person.posts = [@related]
550
- end
551
-
552
- it "does not save each association" do
553
- @person.update_associations(:posts)
554
- end
555
-
491
+ it "saves each association" do
492
+ @related.expects(:save).returns(@related)
493
+ @person.update_associations(:posts)
556
494
  end
557
495
 
558
496
  end
@@ -142,17 +142,6 @@ describe Mongoid::Attributes do
142
142
 
143
143
  describe "#process" do
144
144
 
145
- context "when passing non accessible fields" do
146
-
147
- before do
148
- @person = Person.new(:owner_id => 6)
149
- end
150
-
151
- it "does not set the value" do
152
- @person.owner_id.should be_nil
153
- end
154
- end
155
-
156
145
  context "when attributes dont have fields defined" do
157
146
 
158
147
  before do
@@ -342,23 +331,10 @@ describe Mongoid::Attributes do
342
331
 
343
332
  it "returns the default value" do
344
333
  @person.age.should == 100
345
- @person.pets.should == false
346
334
  end
347
335
 
348
336
  end
349
337
 
350
- context "when attribute is not accessible" do
351
-
352
- before do
353
- @person = Person.new
354
- @person.owner_id = 5
355
- end
356
-
357
- it "returns the value" do
358
- @person.read_attribute(:owner_id).should == 5
359
- end
360
- end
361
-
362
338
  end
363
339
 
364
340
  describe "#remove_attribute" do
@@ -415,91 +391,83 @@ describe Mongoid::Attributes do
415
391
 
416
392
  end
417
393
 
418
- describe "#attributes=" do
419
- it 'should be a alias of write_attributes' do
420
-
421
- end
422
- end
423
-
424
- [:attributes=, :write_attributes].each do |method|
425
- describe "##{method}" do
394
+ describe "#write_attributes" do
426
395
 
427
- context "typecasting" do
396
+ context "typecasting" do
428
397
 
429
- before do
430
- @person = Person.new
431
- @attributes = { :age => "50" }
432
- end
433
-
434
- it "properly casts values" do
435
- @person.send(method, @attributes)
436
- @person.age.should == 50
437
- end
398
+ before do
399
+ @person = Person.new
400
+ @attributes = { :age => "50" }
401
+ end
438
402
 
439
- it "allows passing of nil" do
440
- @person.send(method, nil)
441
- @person.age.should == 100
442
- end
403
+ it "properly casts values" do
404
+ @person.write_attributes(@attributes)
405
+ @person.age.should == 50
406
+ end
443
407
 
408
+ it "allows passing of nil" do
409
+ @person.write_attributes(nil)
410
+ @person.age.should == 100
444
411
  end
445
412
 
446
- context "on a parent document" do
413
+ end
447
414
 
448
- context "when the parent has a has many through a has one" do
415
+ context "on a parent document" do
449
416
 
450
- before do
451
- @owner = PetOwner.new(:title => "Mr")
452
- @pet = Pet.new(:name => "Fido")
453
- @owner.pet = @pet
454
- @vet_visit = VetVisit.new(:date => Date.today)
455
- @pet.vet_visits = [@vet_visit]
456
- end
417
+ context "when the parent has a has many through a has one" do
457
418
 
458
- it "does not overwrite child attributes if not in the hash" do
459
- @owner.send(method, { :pet => { :name => "Bingo" } })
460
- @owner.pet.name.should == "Bingo"
461
- @owner.pet.vet_visits.size.should == 1
462
- end
419
+ before do
420
+ @owner = PetOwner.new(:title => "Mr")
421
+ @pet = Pet.new(:name => "Fido")
422
+ @owner.pet = @pet
423
+ @vet_visit = VetVisit.new(:date => Date.today)
424
+ @pet.vet_visits = [@vet_visit]
425
+ end
463
426
 
427
+ it "does not overwrite child attributes if not in the hash" do
428
+ @owner.write_attributes({ :pet => { :name => "Bingo" } })
429
+ @owner.pet.name.should == "Bingo"
430
+ @owner.pet.vet_visits.size.should == 1
464
431
  end
465
432
 
466
433
  end
467
434
 
468
- context "on a child document" do
435
+ end
469
436
 
470
- context "when child is part of a has one" do
437
+ context "on a child document" do
471
438
 
472
- before do
473
- @person = Person.new(:title => "Sir", :age => 30)
474
- @name = Name.new(:first_name => "Test", :last_name => "User")
475
- @person.name = @name
476
- end
439
+ context "when child is part of a has one" do
477
440
 
478
- it "sets the child attributes on the parent" do
479
- @name.send(method, :first_name => "Test2", :last_name => "User2")
480
- @person.attributes[:name].should ==
481
- { "_id" => "test-user", "first_name" => "Test2", "last_name" => "User2", "_type" => "Name" }
482
- end
441
+ before do
442
+ @person = Person.new(:title => "Sir", :age => 30)
443
+ @name = Name.new(:first_name => "Test", :last_name => "User")
444
+ @person.name = @name
445
+ end
483
446
 
447
+ it "sets the child attributes on the parent" do
448
+ @name.write_attributes(:first_name => "Test2", :last_name => "User2")
449
+ @person.attributes[:name].should ==
450
+ { "_id" => "test-user", "first_name" => "Test2", "last_name" => "User2", "_type" => "Name" }
484
451
  end
485
452
 
486
- context "when child is part of a has many" do
453
+ end
487
454
 
488
- before do
489
- @person = Person.new(:title => "Sir")
490
- @address = Address.new(:street => "Test")
491
- @person.addresses << @address
492
- end
455
+ context "when child is part of a has many" do
493
456
 
494
- it "updates the child attributes on the parent" do
495
- @address.send(method, "street" => "Test2")
496
- @person.attributes[:addresses].should ==
497
- [ { "_id" => "test", "street" => "Test2", "_type" => "Address" } ]
498
- end
457
+ before do
458
+ @person = Person.new(:title => "Sir")
459
+ @address = Address.new(:street => "Test")
460
+ @person.addresses << @address
461
+ end
499
462
 
463
+ it "updates the child attributes on the parent" do
464
+ @address.write_attributes("street" => "Test2")
465
+ @person.attributes[:addresses].should ==
466
+ [ { "_id" => "test", "street" => "Test2", "_type" => "Address" } ]
500
467
  end
501
468
 
502
469
  end
470
+
503
471
  end
504
472
 
505
473
  end
@@ -40,52 +40,6 @@ describe Mongoid::Collection do
40
40
  end
41
41
  end
42
42
 
43
- describe "#directed" do
44
-
45
- context "when an enslave option is not passed" do
46
-
47
- before do
48
- slaves.expects(:empty?).returns(false)
49
- end
50
-
51
- before do
52
- Person.enslave
53
- end
54
-
55
- after do
56
- Person.enslaved = false
57
- end
58
-
59
- it "uses the default" do
60
- collection.directed.should == slaves
61
- end
62
- end
63
-
64
- context "when an enslave option is passed" do
65
-
66
- before do
67
- slaves.expects(:empty?).returns(false)
68
- end
69
-
70
- it "overwrites the default" do
71
- collection.directed(:enslave => true).should == slaves
72
- end
73
- end
74
-
75
- context "when cached option is passed" do
76
-
77
- let(:options) do
78
- { :cache => true }
79
- end
80
-
81
- it "removed the cache option" do
82
- collection.directed(options).should == master
83
- options[:cache].should be_nil
84
- end
85
- end
86
-
87
- end
88
-
89
43
  describe "#find" do
90
44
 
91
45
  before do
@@ -15,45 +15,44 @@ describe Mongoid::Commands::DeleteAll do
15
15
  before do
16
16
  @collection = mock
17
17
  @conditions = { :conditions => { :title => "Sir" } }
18
- @cursor = stub(:count => 30)
19
18
  end
20
19
 
21
20
  it "deletes each document that the criteria finds" do
22
21
  @klass.expects(:collection).returns(@collection)
23
- @collection.expects(:find).with(@conditions[:conditions].merge(:_type => "Person")).returns(@cursor)
24
- @collection.expects(:remove).with(@conditions[:conditions].merge(:_type => "Person"), :safe => true)
22
+ @collection.expects(:remove).with(@conditions[:conditions].merge(:_type => "Person"))
25
23
  Mongoid::Commands::DeleteAll.execute(@klass, @conditions)
26
24
  end
25
+
27
26
  end
28
27
 
29
28
  context "when no conditions supplied" do
30
29
 
31
30
  before do
32
31
  @collection = mock
33
- @cursor = stub(:count => 30)
34
32
  end
35
33
 
36
34
  it "drops the collection" do
37
35
  @klass.expects(:collection).returns(@collection)
38
- @collection.expects(:find).with({ :_type => "Person" }).returns(@cursor)
39
- @collection.expects(:remove).with({ :_type => "Person" }, { :safe => true })
36
+ @collection.expects(:remove).with(:_type => "Person")
40
37
  Mongoid::Commands::DeleteAll.execute(@klass)
41
38
  end
39
+
42
40
  end
43
41
 
44
42
  context "when empty conditions supplied" do
45
43
 
46
44
  before do
47
45
  @collection = mock
48
- @cursor = stub(:count => 30)
49
46
  end
50
47
 
51
48
  it "drops the collection" do
52
49
  @klass.expects(:collection).returns(@collection)
53
- @collection.expects(:find).with({ :_type => "Person" }).returns(@cursor)
54
- @collection.expects(:remove).with({ :_type => "Person" }, { :safe => true })
50
+ @collection.expects(:remove).with(:_type => "Person")
55
51
  Mongoid::Commands::DeleteAll.execute(@klass, {})
56
52
  end
53
+
57
54
  end
55
+
58
56
  end
57
+
59
58
  end
@@ -14,12 +14,6 @@ describe Mongoid::Commands::Delete do
14
14
  Mongoid::Commands::Delete.execute(@document)
15
15
  end
16
16
 
17
- it "sets the destroyed flag to true" do
18
- @collection.expects(:remove).with({ :_id => @document.id }).returns(true)
19
- @document.expects(:destroyed=).with(true)
20
- Mongoid::Commands::Delete.execute(@document)
21
- end
22
-
23
17
  context "when the document is embedded" do
24
18
 
25
19
  before do
@@ -33,6 +27,9 @@ describe Mongoid::Commands::Delete do
33
27
  Mongoid::Commands::Delete.execute(@address)
34
28
  @parent.addresses.should be_empty
35
29
  end
30
+
36
31
  end
32
+
37
33
  end
34
+
38
35
  end
@@ -17,5 +17,7 @@ describe Mongoid::Commands::DestroyAll do
17
17
  Mongoid::Commands::Destroy.expects(:execute).with(@doc)
18
18
  Mongoid::Commands::DestroyAll.execute(@klass, @conditions)
19
19
  end
20
+
20
21
  end
22
+
21
23
  end
@@ -23,29 +23,22 @@ describe Mongoid::Commands::Destroy do
23
23
  Mongoid::Commands::Destroy.execute(@document)
24
24
  end
25
25
 
26
- it "sets the destroy flag on the document" do
27
- @document.expects(:run_callbacks).with(:destroy).yields
28
- @collection.expects(:remove).with({ :_id => @document.id }).returns(true)
29
- @document.expects(:destroyed=).with(true)
30
- Mongoid::Commands::Destroy.execute(@document)
31
- end
32
-
33
26
  context "when the document is embedded" do
34
27
 
35
28
  before do
36
29
  @parent = Person.new
37
30
  @address = Address.new(:street => "Genoa Pl")
38
31
  @parent.addresses << @address
39
- @collection = mock
40
- Person.expects(:collection).returns(@collection)
41
32
  end
42
33
 
43
34
  it "removes the document from the parent attributes" do
44
35
  @parent.addresses.should == [@address]
45
- @collection.expects(:save).returns(true)
46
36
  Mongoid::Commands::Destroy.execute(@address)
47
37
  @parent.addresses.should be_empty
48
38
  end
39
+
49
40
  end
41
+
50
42
  end
43
+
51
44
  end
@@ -37,22 +37,6 @@ describe Mongoid::Commands do
37
37
  @person = Person.new
38
38
  end
39
39
 
40
- context "when validation fails" do
41
-
42
- it "it raises an error" do
43
- Mongoid::Commands::Save.expects(:execute).with(@person, true).returns(false)
44
- @person.save.should be_false
45
- end
46
-
47
- it "should run callback before_create and no after_create" do
48
- @person.expects(:run_callbacks).with(:create).yields.returns(false)
49
- Mongoid::Commands::Save.expects(:execute).with(@person, true).returns(false)
50
- @person.expects(:run_callbacks).with(:after_create).never
51
- @person.save.should be_false
52
- end
53
-
54
- end
55
-
56
40
  it "delegates to the save command" do
57
41
  Mongoid::Commands::Save.expects(:execute).with(@person, true).returns(true)
58
42
  @person.save
@@ -85,9 +69,10 @@ describe Mongoid::Commands do
85
69
  @person = Person.new
86
70
  end
87
71
 
88
- it "lets the error bubble up" do
72
+ it "returns false" do
89
73
  Mongoid::Commands::Save.expects(:execute).raises(Mongo::OperationFailure.new("Operation Failed"))
90
- lambda { @person.save }.should raise_error
74
+ @person.save
75
+ @person.errors[:mongoid].should == [ "Operation Failed" ]
91
76
  end
92
77
 
93
78
  end
@@ -200,8 +185,14 @@ describe Mongoid::Commands do
200
185
  Mongoid::Commands::Save.expects(:execute).raises(Mongo::OperationFailure.new("Operation Failed"))
201
186
  end
202
187
 
203
- it "lets the error bubble up" do
204
- lambda { Person.create }.should raise_error
188
+ it "returns the document with errors" do
189
+ person = Person.create
190
+ person.errors[:mongoid].should == [ "Operation Failed" ]
191
+ end
192
+
193
+ it "keeps the document's new record flag" do
194
+ person = Person.create
195
+ person.should be_a_new_record
205
196
  end
206
197
 
207
198
  end
@@ -39,13 +39,6 @@ describe Mongoid::Config do
39
39
  end
40
40
  end
41
41
 
42
- describe "#persist_types" do
43
-
44
- it "defaults to true" do
45
- config.persist_types.should == true
46
- end
47
- end
48
-
49
42
  describe "#persist_in_safe_mode=" do
50
43
 
51
44
  context "when setting to true" do
@@ -66,10 +59,6 @@ describe Mongoid::Config do
66
59
  config.persist_in_safe_mode = false
67
60
  end
68
61
 
69
- after do
70
- config.persist_in_safe_mode = true
71
- end
72
-
73
62
  it "sets the value" do
74
63
  config.persist_in_safe_mode.should == false
75
64
  end
@@ -166,11 +155,4 @@ describe Mongoid::Config do
166
155
 
167
156
  end
168
157
 
169
- describe "#use_object_ids" do
170
-
171
- it "defaults to false" do
172
- config.use_object_ids.should == false
173
- end
174
- end
175
-
176
158
  end