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
@@ -11,11 +11,7 @@ describe Mongoid::Associations::HasManyRelated do
11
11
  end
12
12
 
13
13
  let(:options) do
14
- Mongoid::Associations::Options.new(
15
- :name => :posts,
16
- :foreign_key => "person_id",
17
- :extend => block
18
- )
14
+ Mongoid::Associations::Options.new(:name => :posts, :extend => block)
19
15
  end
20
16
 
21
17
  describe "#<<" do
@@ -45,36 +41,16 @@ describe Mongoid::Associations::HasManyRelated do
45
41
 
46
42
  context "when parent document has not been saved" do
47
43
 
48
- context "when appending a non mongoid object" do
49
-
50
- before do
51
- @parent = stub(:id => "1", :new_record? => true, :class => Person)
52
- Post.expects(:all).returns([])
53
- @association = Mongoid::Associations::HasManyRelated.new(@parent, options)
54
- end
55
-
56
- it "appends the child document" do
57
- @child.expects(:person_id=).with(@parent.id)
58
- @association << @child
59
- @association.size.should == 1
60
- end
44
+ before do
45
+ @parent = stub(:id => "1", :new_record? => true, :class => Person)
46
+ Post.expects(:all).returns([])
47
+ @association = Mongoid::Associations::HasManyRelated.new(@parent, options)
61
48
  end
62
49
 
63
- context "when appending a mongoid document" do
64
-
65
- before do
66
- @criteria = mock
67
- @parent = stub(:id => "1", :new_record? => true, :class => Person)
68
- Post.expects(:all).returns(@criteria)
69
- @association = Mongoid::Associations::HasManyRelated.new(@parent, options)
70
- end
71
-
72
- it "appends the child document" do
73
- @criteria.expects(:entries).returns([])
74
- @child.expects(:person_id=).with(@parent.id)
75
- @association << @child
76
- @association.size.should == 1
77
- end
50
+ it "appends the child document" do
51
+ @child.expects(:person_id=).with(@parent.id)
52
+ @association << @child
53
+ @association.size.should == 1
78
54
  end
79
55
 
80
56
  end
@@ -101,10 +77,8 @@ describe Mongoid::Associations::HasManyRelated do
101
77
  describe "#build" do
102
78
 
103
79
  before do
104
- @criteria = mock
105
- @criteria.expects(:entries).returns([])
106
- @parent = stub(:id => "5", :class => Person, :new_record? => true)
107
- Post.expects(:all).returns(@criteria)
80
+ @parent = stub(:id => "5", :class => Person)
81
+ Post.expects(:all).returns([])
108
82
  @association = Mongoid::Associations::HasManyRelated.new(@parent, options)
109
83
  end
110
84
 
@@ -191,23 +165,18 @@ describe Mongoid::Associations::HasManyRelated do
191
165
  describe "#create" do
192
166
 
193
167
  before do
194
- @post = mock
195
- @parent = stub(:id => "5", :class => Person, :new_record? => true)
168
+ @parent = stub(:id => "5", :class => Person)
196
169
  Post.expects(:all).returns([])
170
+ Mongoid::Commands::Save.expects(:execute)
197
171
  @association = Mongoid::Associations::HasManyRelated.new(@parent, options)
198
- Post.expects(:instantiate).returns(@post)
199
172
  end
200
173
 
201
174
  it "builds and saves the new object" do
202
- @post.expects(:run_callbacks).with(:create).yields
203
- @post.expects(:save).returns(true)
204
175
  @association.create(:title => "Sassy")
205
176
  end
206
177
 
207
178
  it "returns the new object" do
208
- @post.expects(:run_callbacks).with(:create).yields
209
- @post.expects(:save).returns(true)
210
- @association.create(:title => "Sassy").should == @post
179
+ @association.create(:title => "Sassy").should be_a_kind_of(Post)
211
180
  end
212
181
 
213
182
  end
@@ -1,18 +1,18 @@
1
1
  require "spec_helper"
2
2
 
3
- describe Mongoid::Associations::EmbedsMany do
3
+ describe Mongoid::Associations::HasMany do
4
4
 
5
5
  before do
6
6
  @attributes = { "addresses" => [
7
7
  { "_id" => "street-1", "street" => "Street 1", "state" => "CA" },
8
8
  { "_id" => "street-2", "street" => "Street 2" } ] }
9
- @document = stub(:raw_attributes => @attributes, :add_observer => true, :observe => true)
9
+ @document = stub(:raw_attributes => @attributes, :add_observer => true, :update => true)
10
10
  end
11
11
 
12
12
  describe "#[]" do
13
13
 
14
14
  before do
15
- @association = Mongoid::Associations::EmbedsMany.new(
15
+ @association = Mongoid::Associations::HasMany.new(
16
16
  @document,
17
17
  Mongoid::Associations::Options.new(:name => :addresses)
18
18
  )
@@ -40,7 +40,7 @@ describe Mongoid::Associations::EmbedsMany do
40
40
  describe "#<<" do
41
41
 
42
42
  before do
43
- @association = Mongoid::Associations::EmbedsMany.new(
43
+ @association = Mongoid::Associations::HasMany.new(
44
44
  @document,
45
45
  Mongoid::Associations::Options.new(:name => :addresses)
46
46
  )
@@ -80,7 +80,7 @@ describe Mongoid::Associations::EmbedsMany do
80
80
  context "when a type is not provided" do
81
81
 
82
82
  before do
83
- @association = Mongoid::Associations::EmbedsMany.new(
83
+ @association = Mongoid::Associations::HasMany.new(
84
84
  @document,
85
85
  Mongoid::Associations::Options.new(:name => :addresses)
86
86
  )
@@ -104,7 +104,7 @@ describe Mongoid::Associations::EmbedsMany do
104
104
  context "when a type is provided" do
105
105
 
106
106
  before do
107
- @association = Mongoid::Associations::EmbedsMany.new(
107
+ @association = Mongoid::Associations::HasMany.new(
108
108
  @document,
109
109
  Mongoid::Associations::Options.new(:name => :shapes)
110
110
  )
@@ -125,19 +125,18 @@ describe Mongoid::Associations::EmbedsMany do
125
125
  context "when a type is not provided" do
126
126
 
127
127
  before do
128
- @association = Mongoid::Associations::EmbedsMany.new(
128
+ @association = Mongoid::Associations::HasMany.new(
129
129
  @document,
130
130
  Mongoid::Associations::Options.new(:name => :addresses)
131
131
  )
132
- @address = mock(:parentize => true, :write_attributes => true)
133
- Address.expects(:instantiate).returns(@address)
134
- @address.expects(:run_callbacks).with(:create).yields
132
+ @address = Address.new(:street => "Yet Another")
135
133
  end
136
134
 
137
135
  it "builds and saves a new object" do
138
- @address.expects(:save).returns(true)
136
+ Mongoid::Commands::Save.expects(:execute).returns(true)
139
137
  address = @association.create({ :street => "Yet Another" })
140
- address.should == @address
138
+ address.should be_a_kind_of(Address)
139
+ address.street.should == "Yet Another"
141
140
  end
142
141
 
143
142
  end
@@ -145,71 +144,27 @@ describe Mongoid::Associations::EmbedsMany do
145
144
  context "when a type is provided" do
146
145
 
147
146
  before do
148
- @association = Mongoid::Associations::EmbedsMany.new(
147
+ @association = Mongoid::Associations::HasMany.new(
149
148
  @document,
150
149
  Mongoid::Associations::Options.new(:name => :shapes)
151
150
  )
152
- @circle = mock(:parentize => true, :write_attributes => true)
153
- Circle.expects(:instantiate).returns(@circle)
154
- @circle.expects(:run_callbacks).with(:create).yields
155
151
  end
156
152
 
157
153
  it "instantiates a class of that type" do
158
- @circle.expects(:save).returns(true)
154
+ Mongoid::Commands::Save.expects(:execute).returns(true)
159
155
  circle = @association.create({ :radius => 100 }, Circle)
160
- circle.should == @circle
161
- end
162
-
163
- end
164
-
165
- end
166
-
167
- describe "#create!" do
168
-
169
- context "when validations pass" do
170
-
171
- before do
172
- @association = Mongoid::Associations::EmbedsMany.new(
173
- @document,
174
- Mongoid::Associations::Options.new(:name => :addresses)
175
- )
176
- @address = mock(:parentize => true, :write_attributes => true, :errors => [])
177
- Address.expects(:instantiate).returns(@address)
178
- @address.expects(:run_callbacks).with(:create).yields
156
+ circle.should be_a_kind_of(Circle)
157
+ circle.radius.should == 100
179
158
  end
180
159
 
181
- it "builds and saves a new object" do
182
- @address.expects(:save).returns(true)
183
- address = @association.create!({ :street => "Yet Another" })
184
- address.should == @address
185
- end
186
160
  end
187
161
 
188
- context "when validations fail" do
189
-
190
- before do
191
- @association = Mongoid::Associations::EmbedsMany.new(
192
- @document,
193
- Mongoid::Associations::Options.new(:name => :addresses)
194
- )
195
- @address = mock(:parentize => true, :write_attributes => true, :errors => [ "test" ])
196
- Address.expects(:instantiate).returns(@address)
197
- @address.expects(:run_callbacks).with(:create).yields
198
- end
199
-
200
- it "builds and saves a new object" do
201
- @address.expects(:save).returns(false)
202
- lambda {
203
- @association.create!({ :street => "Yet Another" })
204
- }.should raise_error(Mongoid::Errors::Validations)
205
- end
206
- end
207
162
  end
208
163
 
209
164
  describe "#concat" do
210
165
 
211
166
  before do
212
- @association = Mongoid::Associations::EmbedsMany.new(
167
+ @association = Mongoid::Associations::HasMany.new(
213
168
  @document,
214
169
  Mongoid::Associations::Options.new(:name => :addresses)
215
170
  )
@@ -227,7 +182,7 @@ describe Mongoid::Associations::EmbedsMany do
227
182
  describe "#clear" do
228
183
 
229
184
  before do
230
- @association = Mongoid::Associations::EmbedsMany.new(
185
+ @association = Mongoid::Associations::HasMany.new(
231
186
  @document,
232
187
  Mongoid::Associations::Options.new(:name => :addresses)
233
188
  )
@@ -245,7 +200,7 @@ describe Mongoid::Associations::EmbedsMany do
245
200
  describe "#find" do
246
201
 
247
202
  before do
248
- @association = Mongoid::Associations::EmbedsMany.new(
203
+ @association = Mongoid::Associations::HasMany.new(
249
204
  @document,
250
205
  Mongoid::Associations::Options.new(:name => :addresses)
251
206
  )
@@ -275,7 +230,7 @@ describe Mongoid::Associations::EmbedsMany do
275
230
  context "when there are elements in the array" do
276
231
 
277
232
  before do
278
- @association = Mongoid::Associations::EmbedsMany.new(
233
+ @association = Mongoid::Associations::HasMany.new(
279
234
  @document,
280
235
  Mongoid::Associations::Options.new(:name => :addresses)
281
236
  )
@@ -291,7 +246,7 @@ describe Mongoid::Associations::EmbedsMany do
291
246
  context "when the array is empty" do
292
247
 
293
248
  before do
294
- @association = Mongoid::Associations::EmbedsMany.new(
249
+ @association = Mongoid::Associations::HasMany.new(
295
250
  Person.new,
296
251
  Mongoid::Associations::Options.new(:name => :addresses)
297
252
  )
@@ -310,8 +265,8 @@ describe Mongoid::Associations::EmbedsMany do
310
265
  context "when no extension exists" do
311
266
 
312
267
  before do
313
- @canvas = stub(:raw_attributes => { "shapes" => [{ "_type" => "Circle", "radius" => 5 }] }, :observe => true)
314
- @association = Mongoid::Associations::EmbedsMany.new(
268
+ @canvas = stub(:raw_attributes => { "shapes" => [{ "_type" => "Circle", "radius" => 5 }] }, :update => true)
269
+ @association = Mongoid::Associations::HasMany.new(
315
270
  @canvas,
316
271
  Mongoid::Associations::Options.new(:name => :shapes)
317
272
  )
@@ -334,7 +289,7 @@ describe Mongoid::Associations::EmbedsMany do
334
289
  "Testing"
335
290
  end
336
291
  end
337
- @association = Mongoid::Associations::EmbedsMany.new(
292
+ @association = Mongoid::Associations::HasMany.new(
338
293
  @person,
339
294
  Mongoid::Associations::Options.new(:name => :addresses, :extend => @block)
340
295
  )
@@ -351,8 +306,8 @@ describe Mongoid::Associations::EmbedsMany do
351
306
  describe ".instantiate" do
352
307
 
353
308
  it "delegates to new" do
354
- Mongoid::Associations::EmbedsMany.expects(:new).with(@document, @options)
355
- Mongoid::Associations::EmbedsMany.instantiate(@document, @options)
309
+ Mongoid::Associations::HasMany.expects(:new).with(@document, @options)
310
+ Mongoid::Associations::HasMany.instantiate(@document, @options)
356
311
  end
357
312
 
358
313
  end
@@ -362,7 +317,7 @@ describe Mongoid::Associations::EmbedsMany do
362
317
  context "#length" do
363
318
 
364
319
  it "returns the length of the delegated array" do
365
- @association = Mongoid::Associations::EmbedsMany.new(
320
+ @association = Mongoid::Associations::HasMany.new(
366
321
  @document,
367
322
  Mongoid::Associations::Options.new(:name => :addresses)
368
323
  )
@@ -375,8 +330,8 @@ describe Mongoid::Associations::EmbedsMany do
375
330
 
376
331
  describe ".macro" do
377
332
 
378
- it "returns :embeds_many" do
379
- Mongoid::Associations::EmbedsMany.macro.should == :embeds_many
333
+ it "returns :has_many" do
334
+ Mongoid::Associations::HasMany.macro.should == :has_many
380
335
  end
381
336
 
382
337
  end
@@ -384,7 +339,7 @@ describe Mongoid::Associations::EmbedsMany do
384
339
  describe "#nested_build" do
385
340
 
386
341
  before do
387
- @association = Mongoid::Associations::EmbedsMany.new(
342
+ @association = Mongoid::Associations::HasMany.new(
388
343
  @document,
389
344
  Mongoid::Associations::Options.new(:name => :addresses)
390
345
  )
@@ -403,7 +358,7 @@ describe Mongoid::Associations::EmbedsMany do
403
358
  context "when the association class has a criteria class method" do
404
359
 
405
360
  before do
406
- @association = Mongoid::Associations::EmbedsMany.new(
361
+ @association = Mongoid::Associations::HasMany.new(
407
362
  @document,
408
363
  Mongoid::Associations::Options.new(:name => :addresses)
409
364
  )
@@ -430,7 +385,7 @@ describe Mongoid::Associations::EmbedsMany do
430
385
  context "when no class method exists" do
431
386
 
432
387
  before do
433
- @association = Mongoid::Associations::EmbedsMany.new(
388
+ @association = Mongoid::Associations::HasMany.new(
434
389
  @document,
435
390
  Mongoid::Associations::Options.new(:name => :addresses)
436
391
  )
@@ -447,7 +402,7 @@ describe Mongoid::Associations::EmbedsMany do
447
402
  describe "#paginate" do
448
403
 
449
404
  before do
450
- @association = Mongoid::Associations::EmbedsMany.new(
405
+ @association = Mongoid::Associations::HasMany.new(
451
406
  @document,
452
407
  Mongoid::Associations::Options.new(:name => :addresses)
453
408
  )
@@ -466,7 +421,7 @@ describe Mongoid::Associations::EmbedsMany do
466
421
  describe "#push" do
467
422
 
468
423
  before do
469
- @association = Mongoid::Associations::EmbedsMany.new(
424
+ @association = Mongoid::Associations::HasMany.new(
470
425
  @document,
471
426
  Mongoid::Associations::Options.new(:name => :addresses)
472
427
  )
@@ -491,7 +446,7 @@ describe Mongoid::Associations::EmbedsMany do
491
446
  before do
492
447
  @address = Address.new(:street => "Madison Ave")
493
448
  @person = Person.new(:title => "Sir")
494
- @association = Mongoid::Associations::EmbedsMany.update(
449
+ @association = Mongoid::Associations::HasMany.update(
495
450
  [@address],
496
451
  @person,
497
452
  Mongoid::Associations::Options.new(:name => :addresses)
@@ -1,13 +1,13 @@
1
1
  require "spec_helper"
2
2
 
3
- describe Mongoid::Associations::EmbedsOne do
3
+ describe Mongoid::Associations::HasOne do
4
4
 
5
5
  before do
6
6
  @attributes = { "mixed_drink" => {
7
7
  "name" => "Jack and Coke", "_type" => "MixedDrink" },
8
8
  "writer" => { "speed" => 50, "_type" => "HtmlWriter" }
9
9
  }
10
- @document = stub(:raw_attributes => @attributes, :observe => true)
10
+ @document = stub(:raw_attributes => @attributes, :update => true)
11
11
  end
12
12
 
13
13
  describe "#build_*" do
@@ -15,7 +15,7 @@ describe Mongoid::Associations::EmbedsOne do
15
15
  context "when attributes provided" do
16
16
 
17
17
  before do
18
- @association = Mongoid::Associations::EmbedsOne.new(
18
+ @association = Mongoid::Associations::HasOne.new(
19
19
  @document,
20
20
  @attributes["mixed_drink"],
21
21
  Mongoid::Associations::Options.new(:name => :mixed_drink)
@@ -32,7 +32,7 @@ describe Mongoid::Associations::EmbedsOne do
32
32
  context "when a type is supplied" do
33
33
 
34
34
  before do
35
- @association = Mongoid::Associations::EmbedsOne.new(
35
+ @association = Mongoid::Associations::HasOne.new(
36
36
  @document,
37
37
  @attributes["writer"],
38
38
  Mongoid::Associations::Options.new(:name => :writer)
@@ -75,7 +75,7 @@ describe Mongoid::Associations::EmbedsOne do
75
75
  end
76
76
  }
77
77
  @options = Mongoid::Associations::Options.new(:name => :name, :extend => @block)
78
- @association = Mongoid::Associations::EmbedsOne.new(@parent, {}, @options)
78
+ @association = Mongoid::Associations::HasOne.new(@parent, {}, @options)
79
79
  end
80
80
 
81
81
  context "when the options have an extension" do
@@ -94,7 +94,7 @@ describe Mongoid::Associations::EmbedsOne do
94
94
 
95
95
  before do
96
96
  @document = Person.new
97
- @association = Mongoid::Associations::EmbedsOne.instantiate(
97
+ @association = Mongoid::Associations::HasOne.instantiate(
98
98
  @document,
99
99
  Mongoid::Associations::Options.new(:name => :name)
100
100
  )
@@ -110,7 +110,7 @@ describe Mongoid::Associations::EmbedsOne do
110
110
 
111
111
  before do
112
112
  @document = stub(:raw_attributes => { "name" => {} })
113
- @association = Mongoid::Associations::EmbedsOne.instantiate(
113
+ @association = Mongoid::Associations::HasOne.instantiate(
114
114
  @document,
115
115
  Mongoid::Associations::Options.new(:name => :name)
116
116
  )
@@ -130,8 +130,8 @@ describe Mongoid::Associations::EmbedsOne do
130
130
  end
131
131
 
132
132
  it "delegates to new" do
133
- Mongoid::Associations::EmbedsOne.expects(:new).with(@document, { "first_name" => "Test" }, @options)
134
- Mongoid::Associations::EmbedsOne.instantiate(@document, @options)
133
+ Mongoid::Associations::HasOne.expects(:new).with(@document, { "first_name" => "Test" }, @options)
134
+ Mongoid::Associations::HasOne.instantiate(@document, @options)
135
135
  end
136
136
 
137
137
  end
@@ -141,7 +141,7 @@ describe Mongoid::Associations::EmbedsOne do
141
141
  describe "#method_missing" do
142
142
 
143
143
  before do
144
- @association = Mongoid::Associations::EmbedsOne.new(
144
+ @association = Mongoid::Associations::HasOne.new(
145
145
  @document,
146
146
  @attributes["mixed_drink"],
147
147
  Mongoid::Associations::Options.new(:name => :mixed_drink)
@@ -172,7 +172,7 @@ describe Mongoid::Associations::EmbedsOne do
172
172
  context "when attributes provided" do
173
173
 
174
174
  before do
175
- @association = Mongoid::Associations::EmbedsOne.new(
175
+ @association = Mongoid::Associations::HasOne.new(
176
176
  @document,
177
177
  @attributes["mixed_drink"],
178
178
  Mongoid::Associations::Options.new(:name => :mixed_drink)
@@ -190,8 +190,8 @@ describe Mongoid::Associations::EmbedsOne do
190
190
 
191
191
  describe ".macro" do
192
192
 
193
- it "returns :embeds_one" do
194
- Mongoid::Associations::EmbedsOne.macro.should == :embeds_one
193
+ it "returns :has_one" do
194
+ Mongoid::Associations::HasOne.macro.should == :has_one
195
195
  end
196
196
 
197
197
  end
@@ -203,7 +203,7 @@ describe Mongoid::Associations::EmbedsOne do
203
203
  before do
204
204
  @name = Name.new(:first_name => "Donald")
205
205
  @person = Person.new(:title => "Sir")
206
- @association = Mongoid::Associations::EmbedsOne.update(
206
+ @association = Mongoid::Associations::HasOne.update(
207
207
  @name,
208
208
  @person,
209
209
  Mongoid::Associations::Options.new(:name => :name)
@@ -230,7 +230,7 @@ describe Mongoid::Associations::EmbedsOne do
230
230
  before do
231
231
  @name = Name.new(:first_name => "Donald")
232
232
  @person = Person.new(:title => "Sir")
233
- Mongoid::Associations::EmbedsOne.update(
233
+ Mongoid::Associations::HasOne.update(
234
234
  nil,
235
235
  @person,
236
236
  Mongoid::Associations::Options.new(:name => :name)
@@ -248,7 +248,7 @@ describe Mongoid::Associations::EmbedsOne do
248
248
  describe "#to_a" do
249
249
 
250
250
  before do
251
- @association = Mongoid::Associations::EmbedsOne.new(
251
+ @association = Mongoid::Associations::HasOne.new(
252
252
  @document,
253
253
  @attributes["mixed_drink"],
254
254
  Mongoid::Associations::Options.new(:name => :mixed_drink)
@@ -266,9 +266,9 @@ describe Mongoid::Associations::EmbedsOne do
266
266
  context "when the document is not nil" do
267
267
 
268
268
  before do
269
- @document = stub(:raw_attributes => { "name" => { "first_name" => "Test" } }, :observe => true)
269
+ @document = stub(:raw_attributes => { "name" => { "first_name" => "Test" } }, :update => true)
270
270
  @options = Mongoid::Associations::Options.new(:name => :name)
271
- @association = Mongoid::Associations::EmbedsOne.instantiate(@document, @options)
271
+ @association = Mongoid::Associations::HasOne.instantiate(@document, @options)
272
272
  end
273
273
 
274
274
  it "validates the document" do
@@ -75,29 +75,15 @@ describe Mongoid::Associations::Options do
75
75
 
76
76
  describe "#foreign_key" do
77
77
 
78
- context "when no custom key defined" do
79
-
80
- before do
81
- @attributes = { :name => :posts }
82
- @options = Mongoid::Associations::Options.new(@attributes)
83
- end
84
-
85
- it "returns the association foreign_key" do
86
- @options.foreign_key.should == "post_id"
87
- end
78
+ before do
79
+ @attributes = { :name => :game }
80
+ @options = Mongoid::Associations::Options.new(@attributes)
88
81
  end
89
82
 
90
- context "when a custom key is defined" do
91
-
92
- before do
93
- @attributes = { :name => :posts, :foreign_key => "blog_post_id" }
94
- @options = Mongoid::Associations::Options.new(@attributes)
95
- end
96
-
97
- it "returns the custom foreign_key" do
98
- @options.foreign_key.should == "blog_post_id"
99
- end
83
+ it "returns the association foreign_key" do
84
+ @options.foreign_key.should == "game_id"
100
85
  end
86
+
101
87
  end
102
88
 
103
89
  describe "#inverse_of" do
@@ -160,6 +146,19 @@ describe Mongoid::Associations::Options do
160
146
 
161
147
  end
162
148
 
149
+ describe "#parent_key" do
150
+
151
+ before do
152
+ @attributes = { :parent_key => :person_id }
153
+ @options = Mongoid::Associations::Options.new(@attributes)
154
+ end
155
+
156
+ it "returns the parent's foreign key value" do
157
+ @options.parent_key.should == :person_id
158
+ end
159
+
160
+ end
161
+
163
162
  describe "#polymorphic" do
164
163
 
165
164
  context "when attribute provided" do