mongoid-pre 2.0.0.beta1 → 2.0.0.pre
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.watchr +15 -10
- data/HISTORY +342 -0
- data/README.rdoc +8 -1
- data/Rakefile +2 -3
- data/VERSION +1 -1
- data/lib/mongoid/associations/{embedded_in.rb → belongs_to.rb} +4 -4
- data/lib/mongoid/associations/belongs_to_related.rb +9 -6
- data/lib/mongoid/associations/{embeds_many.rb → has_many.rb} +20 -33
- data/lib/mongoid/associations/has_many_related.rb +4 -28
- data/lib/mongoid/associations/{embeds_one.rb → has_one.rb} +6 -6
- data/lib/mongoid/associations/options.rb +6 -1
- data/lib/mongoid/associations.rb +32 -41
- data/lib/mongoid/attributes.rb +6 -13
- data/lib/mongoid/collection.rb +1 -2
- data/lib/mongoid/commands/delete.rb +1 -1
- data/lib/mongoid/commands/delete_all.rb +1 -4
- data/lib/mongoid/commands/destroy.rb +1 -1
- data/lib/mongoid/commands/destroy_all.rb +1 -3
- data/lib/mongoid/commands/save.rb +0 -1
- data/lib/mongoid/commands.rb +13 -2
- data/lib/mongoid/components.rb +1 -6
- data/lib/mongoid/config.rb +1 -5
- data/lib/mongoid/contexts/enumerable.rb +17 -54
- data/lib/mongoid/contexts/mongo.rb +38 -101
- data/lib/mongoid/contexts/paging.rb +2 -2
- data/lib/mongoid/contexts.rb +0 -21
- data/lib/mongoid/criteria.rb +73 -15
- data/lib/mongoid/criterion/inclusion.rb +0 -2
- data/lib/mongoid/criterion/optional.rb +2 -10
- data/lib/mongoid/document.rb +30 -41
- data/lib/mongoid/extensions.rb +0 -15
- data/lib/mongoid/field.rb +7 -20
- data/lib/mongoid/fields.rb +10 -15
- data/lib/mongoid/finders.rb +98 -10
- data/lib/mongoid/identity.rb +2 -8
- data/lib/mongoid/named_scope.rb +0 -2
- data/lib/mongoid/validations/associated.rb +8 -3
- data/lib/mongoid/validations/uniqueness.rb +7 -2
- data/lib/mongoid/validations.rb +2 -2
- data/lib/mongoid/versioning.rb +1 -1
- data/lib/mongoid.rb +5 -21
- data/mongoid.gemspec +19 -59
- data/spec/integration/mongoid/associations_spec.rb +3 -42
- data/spec/integration/mongoid/attributes_spec.rb +2 -2
- data/spec/integration/mongoid/commands_spec.rb +13 -27
- data/spec/integration/mongoid/contexts/enumerable_spec.rb +0 -13
- data/spec/integration/mongoid/criteria_spec.rb +3 -50
- data/spec/integration/mongoid/document_spec.rb +5 -72
- data/spec/integration/mongoid/finders_spec.rb +28 -85
- data/spec/models/address.rb +3 -3
- data/spec/models/animal.rb +2 -2
- data/spec/models/country_code.rb +2 -2
- data/spec/models/game.rb +1 -2
- data/spec/models/inheritance.rb +5 -5
- data/spec/models/location.rb +2 -2
- data/spec/models/name.rb +3 -3
- data/spec/models/namespacing.rb +2 -2
- data/spec/models/patient.rb +0 -2
- data/spec/models/person.rb +4 -6
- data/spec/models/pet.rb +3 -3
- data/spec/models/pet_owner.rb +3 -3
- data/spec/models/phone.rb +3 -3
- data/spec/models/post.rb +1 -1
- data/spec/models/translation.rb +2 -2
- data/spec/models/vet_visit.rb +2 -2
- data/spec/spec_helper.rb +2 -2
- data/spec/unit/mongoid/associations/belongs_to_related_spec.rb +0 -4
- data/spec/unit/mongoid/associations/{embedded_in_spec.rb → belongs_to_spec.rb} +11 -11
- data/spec/unit/mongoid/associations/has_many_related_spec.rb +14 -45
- data/spec/unit/mongoid/associations/{embeds_many_spec.rb → has_many_spec.rb} +34 -79
- data/spec/unit/mongoid/associations/{embeds_one_spec.rb → has_one_spec.rb} +18 -18
- data/spec/unit/mongoid/associations/options_spec.rb +19 -20
- data/spec/unit/mongoid/associations_spec.rb +12 -74
- data/spec/unit/mongoid/attributes_spec.rb +51 -83
- data/spec/unit/mongoid/collection_spec.rb +0 -46
- data/spec/unit/mongoid/commands/delete_all_spec.rb +8 -9
- data/spec/unit/mongoid/commands/delete_spec.rb +3 -6
- data/spec/unit/mongoid/commands/destroy_all_spec.rb +2 -0
- data/spec/unit/mongoid/commands/destroy_spec.rb +3 -10
- data/spec/unit/mongoid/commands_spec.rb +11 -20
- data/spec/unit/mongoid/config_spec.rb +0 -18
- data/spec/unit/mongoid/contexts/enumerable_spec.rb +11 -198
- data/spec/unit/mongoid/contexts/mongo_spec.rb +54 -357
- data/spec/unit/mongoid/criteria_spec.rb +78 -107
- data/spec/unit/mongoid/criterion/exclusion_spec.rb +13 -3
- data/spec/unit/mongoid/criterion/inclusion_spec.rb +19 -25
- data/spec/unit/mongoid/criterion/optional_spec.rb +18 -25
- data/spec/unit/mongoid/document_spec.rb +34 -71
- data/spec/unit/mongoid/extensions/array/conversions_spec.rb +2 -2
- data/spec/unit/mongoid/extensions/datetime/conversions_spec.rb +3 -0
- data/spec/unit/mongoid/extensions/object/conversions_spec.rb +2 -16
- data/spec/unit/mongoid/extensions/proc/scoping_spec.rb +1 -1
- data/spec/unit/mongoid/field_spec.rb +0 -62
- data/spec/unit/mongoid/fields_spec.rb +0 -33
- data/spec/unit/mongoid/finders_spec.rb +1 -37
- data/spec/unit/mongoid/identity_spec.rb +6 -47
- data/spec/unit/mongoid/named_scope_spec.rb +2 -15
- data/spec/unit/mongoid/scope_spec.rb +1 -1
- data/spec/unit/mongoid/validations/uniqueness_spec.rb +3 -3
- data/spec/unit/mongoid_spec.rb +2 -11
- metadata +14 -64
- data/lib/mongoid/associations/meta_data.rb +0 -28
- data/lib/mongoid/contexts/ids.rb +0 -25
- data/lib/mongoid/deprecation.rb +0 -22
- data/lib/mongoid/dirty.rb +0 -203
- data/lib/mongoid/extensions/big_decimal/conversions.rb +0 -19
- data/lib/mongoid/extensions/binary/conversions.rb +0 -17
- data/lib/mongoid/extensions/objectid/conversions.rb +0 -15
- data/lib/mongoid/extras.rb +0 -61
- data/lib/mongoid/javascript/functions.yml +0 -37
- data/lib/mongoid/javascript.rb +0 -21
- data/lib/mongoid/observable.rb +0 -30
- data/lib/mongoid/paths.rb +0 -54
- data/lib/mongoid/persistence/command.rb +0 -20
- data/lib/mongoid/persistence/insert.rb +0 -71
- data/lib/mongoid/persistence/update.rb +0 -78
- data/lib/mongoid/persistence.rb +0 -27
- data/lib/mongoid/state.rb +0 -32
- data/spec/integration/mongoid/dirty_spec.rb +0 -70
- data/spec/integration/mongoid/persistence/update_spec.rb +0 -46
- data/spec/models/callbacks.rb +0 -18
- data/spec/unit/mongoid/associations/meta_data_spec.rb +0 -88
- data/spec/unit/mongoid/contexts_spec.rb +0 -25
- data/spec/unit/mongoid/deprecation_spec.rb +0 -24
- data/spec/unit/mongoid/dirty_spec.rb +0 -286
- data/spec/unit/mongoid/extensions/big_decimal/conversions_spec.rb +0 -22
- data/spec/unit/mongoid/extensions/binary/conversions_spec.rb +0 -22
- data/spec/unit/mongoid/extras_spec.rb +0 -102
- data/spec/unit/mongoid/javascript_spec.rb +0 -48
- data/spec/unit/mongoid/observable_spec.rb +0 -46
- data/spec/unit/mongoid/paths_spec.rb +0 -124
- data/spec/unit/mongoid/persistence/insert_spec.rb +0 -175
- data/spec/unit/mongoid/persistence/update_spec.rb +0 -148
- data/spec/unit/mongoid/persistence_spec.rb +0 -40
- data/spec/unit/mongoid/state_spec.rb +0 -83
|
@@ -121,12 +121,6 @@ describe Mongoid::Document do
|
|
|
121
121
|
lambda { Person.find(@person.id) }.should raise_error
|
|
122
122
|
end
|
|
123
123
|
|
|
124
|
-
it "marks the document as destroyed" do
|
|
125
|
-
@person.should_not be_destroyed
|
|
126
|
-
@person.destroy
|
|
127
|
-
@person.should be_destroyed
|
|
128
|
-
end
|
|
129
|
-
|
|
130
124
|
end
|
|
131
125
|
|
|
132
126
|
context "on an embedded document" do
|
|
@@ -250,7 +244,7 @@ describe Mongoid::Document do
|
|
|
250
244
|
|
|
251
245
|
before do
|
|
252
246
|
5.times do |num|
|
|
253
|
-
Person.create(:title => "Sir", :age => num
|
|
247
|
+
Person.create(:title => "Sir", :age => num)
|
|
254
248
|
end
|
|
255
249
|
end
|
|
256
250
|
|
|
@@ -291,7 +285,7 @@ describe Mongoid::Document do
|
|
|
291
285
|
end
|
|
292
286
|
|
|
293
287
|
it "returns a pretty string of class name and attributes" do
|
|
294
|
-
attrs = Person.fields.map { |name, field| "#{name}: #{@person.attributes[name]
|
|
288
|
+
attrs = Person.fields.map { |name, field| "#{name}: #{@person.attributes[name] || 'nil'}" } * ", "
|
|
295
289
|
@person.inspect.should == "#<Person _id: #{@person.id}, #{attrs}>"
|
|
296
290
|
end
|
|
297
291
|
|
|
@@ -331,10 +325,6 @@ describe Mongoid::Document do
|
|
|
331
325
|
@person.age.should == 35
|
|
332
326
|
end
|
|
333
327
|
|
|
334
|
-
it "reload should return self" do
|
|
335
|
-
@person.reload.should == @from_db
|
|
336
|
-
end
|
|
337
|
-
|
|
338
328
|
end
|
|
339
329
|
|
|
340
330
|
describe "#save" do
|
|
@@ -427,7 +417,7 @@ describe Mongoid::Document do
|
|
|
427
417
|
@person.addresses << @business
|
|
428
418
|
end
|
|
429
419
|
|
|
430
|
-
it "allows adding multiples on
|
|
420
|
+
it "allows adding multiples on a has_many in a row" do
|
|
431
421
|
@person.addresses.length.should == 2
|
|
432
422
|
end
|
|
433
423
|
|
|
@@ -444,13 +434,13 @@ describe Mongoid::Document do
|
|
|
444
434
|
|
|
445
435
|
end
|
|
446
436
|
|
|
447
|
-
context "when saving on
|
|
437
|
+
context "when saving on a has_many" do
|
|
448
438
|
|
|
449
439
|
before do
|
|
450
440
|
@home.save
|
|
451
441
|
end
|
|
452
442
|
|
|
453
|
-
it "saves the entire graph up from the
|
|
443
|
+
it "saves the entire graph up from the has_many" do
|
|
454
444
|
person = Person.first(:conditions => { :title => "Sir" })
|
|
455
445
|
person.should == @person
|
|
456
446
|
end
|
|
@@ -501,63 +491,6 @@ describe Mongoid::Document do
|
|
|
501
491
|
end
|
|
502
492
|
|
|
503
493
|
end
|
|
504
|
-
|
|
505
|
-
describe "#as_json" do
|
|
506
|
-
|
|
507
|
-
before do
|
|
508
|
-
@person = Person.new(:title => "Sir", :age => 30)
|
|
509
|
-
@address = Address.new(:street => "Nan Jing Dong Lu")
|
|
510
|
-
@person.addresses << @address
|
|
511
|
-
end
|
|
512
|
-
|
|
513
|
-
context "on a new document" do
|
|
514
|
-
|
|
515
|
-
it "returns the attributes" do
|
|
516
|
-
@person.as_json.should == @person.attributes
|
|
517
|
-
end
|
|
518
|
-
|
|
519
|
-
end
|
|
520
|
-
|
|
521
|
-
context "on a persisted document" do
|
|
522
|
-
|
|
523
|
-
it "returns the attributes" do
|
|
524
|
-
@person.save
|
|
525
|
-
from_db = Person.find(@person.id)
|
|
526
|
-
from_db.as_json.should == from_db.attributes
|
|
527
|
-
end
|
|
528
|
-
|
|
529
|
-
end
|
|
530
|
-
|
|
531
|
-
end
|
|
532
|
-
|
|
533
|
-
describe "#encode_json" do
|
|
534
|
-
|
|
535
|
-
before do
|
|
536
|
-
@person = Person.new(:title => "Sir", :age => 30)
|
|
537
|
-
@address = Address.new(:street => "Nan Jing Dong Lu")
|
|
538
|
-
@person.addresses << @address
|
|
539
|
-
@encoder = Array.new
|
|
540
|
-
end
|
|
541
|
-
|
|
542
|
-
context "on a new document" do
|
|
543
|
-
|
|
544
|
-
it "returns the attributes" do
|
|
545
|
-
@person.encode_json(@encoder).should == @person.attributes
|
|
546
|
-
end
|
|
547
|
-
|
|
548
|
-
end
|
|
549
|
-
|
|
550
|
-
context "on a persisted document" do
|
|
551
|
-
|
|
552
|
-
it "returns the attributes" do
|
|
553
|
-
@person.save
|
|
554
|
-
from_db = Person.find(@person.id)
|
|
555
|
-
from_db.encode_json(@encoder).should == from_db.attributes
|
|
556
|
-
end
|
|
557
|
-
|
|
558
|
-
end
|
|
559
|
-
|
|
560
|
-
end
|
|
561
494
|
|
|
562
495
|
context "typecasting" do
|
|
563
496
|
|
|
@@ -4,116 +4,59 @@ describe Mongoid::Finders do
|
|
|
4
4
|
|
|
5
5
|
describe "#find" do
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
@
|
|
12
|
-
3.times do |n|
|
|
13
|
-
@documents << Person.create(:title => "Mr.", :ssn => "#{n}22")
|
|
14
|
-
end
|
|
7
|
+
before do
|
|
8
|
+
@documents = []
|
|
9
|
+
@document = Person.create(:title => "Mrs.", :ssn => "another")
|
|
10
|
+
3.times do |n|
|
|
11
|
+
@documents << Person.create(:title => "Mr.", :ssn => "#{n}22")
|
|
15
12
|
end
|
|
13
|
+
end
|
|
16
14
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
context "with an id as an argument" do
|
|
22
|
-
|
|
23
|
-
context "when the document is found" do
|
|
24
|
-
|
|
25
|
-
it "returns the document" do
|
|
26
|
-
Person.find(@document.id).should == @document
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
end
|
|
15
|
+
after do
|
|
16
|
+
Person.delete_all
|
|
17
|
+
end
|
|
30
18
|
|
|
31
|
-
|
|
19
|
+
context "with an id as an argument" do
|
|
32
20
|
|
|
33
|
-
|
|
34
|
-
lambda { Person.find("5") }.should raise_error
|
|
35
|
-
end
|
|
21
|
+
context "when the document is found" do
|
|
36
22
|
|
|
23
|
+
it "returns the document" do
|
|
24
|
+
Person.find(@document.id).should == @document
|
|
37
25
|
end
|
|
38
26
|
|
|
39
27
|
end
|
|
40
28
|
|
|
41
|
-
context "
|
|
42
|
-
|
|
43
|
-
context "when the documents are found" do
|
|
44
|
-
|
|
45
|
-
it "returns an array of the documents" do
|
|
46
|
-
@people = Person.find(@documents.map(&:id))
|
|
47
|
-
@people.should == @documents
|
|
48
|
-
end
|
|
29
|
+
context "when the document is not found" do
|
|
49
30
|
|
|
31
|
+
it "raises an error" do
|
|
32
|
+
lambda { Person.find("5") }.should raise_error
|
|
50
33
|
end
|
|
51
34
|
|
|
52
|
-
context "when no documents found" do
|
|
53
|
-
|
|
54
|
-
it "raises an error" do
|
|
55
|
-
lambda { Person.find(["11", "21", "31"]) }.should raise_error
|
|
56
|
-
end
|
|
57
|
-
|
|
58
|
-
end
|
|
59
35
|
end
|
|
60
|
-
end
|
|
61
36
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
before do
|
|
65
|
-
Mongoid.use_object_ids = true
|
|
66
|
-
@documents = []
|
|
67
|
-
@document = Person.create(:title => "Mrs.", :ssn => "another")
|
|
68
|
-
3.times do |n|
|
|
69
|
-
@documents << Person.create(:title => "Mr.", :ssn => "#{n}22")
|
|
70
|
-
end
|
|
71
|
-
end
|
|
72
|
-
|
|
73
|
-
after do
|
|
74
|
-
Mongoid.use_object_ids = false
|
|
75
|
-
Person.delete_all
|
|
76
|
-
end
|
|
77
|
-
|
|
78
|
-
context "with an id as an argument" do
|
|
79
|
-
|
|
80
|
-
context "when the document is found" do
|
|
81
|
-
|
|
82
|
-
it "returns the document" do
|
|
83
|
-
Person.find(@document.id).should == @document
|
|
84
|
-
end
|
|
85
|
-
|
|
86
|
-
end
|
|
37
|
+
end
|
|
87
38
|
|
|
88
|
-
|
|
39
|
+
context "with an array of ids as args" do
|
|
89
40
|
|
|
90
|
-
|
|
91
|
-
lambda { Person.find("5") }.should raise_error
|
|
92
|
-
end
|
|
41
|
+
context "when the documents are found" do
|
|
93
42
|
|
|
43
|
+
it "returns an array of the documents" do
|
|
44
|
+
@people = Person.find(@documents.map(&:id))
|
|
45
|
+
@people.should == @documents
|
|
94
46
|
end
|
|
95
47
|
|
|
96
48
|
end
|
|
97
49
|
|
|
98
|
-
context "
|
|
99
|
-
|
|
100
|
-
context "when the documents are found" do
|
|
101
|
-
|
|
102
|
-
it "returns an array of the documents" do
|
|
103
|
-
@people = Person.find(@documents.map(&:id))
|
|
104
|
-
@people.should == @documents
|
|
105
|
-
end
|
|
50
|
+
context "when no documents found" do
|
|
106
51
|
|
|
52
|
+
it "raises an error" do
|
|
53
|
+
lambda { Person.find(["11", "21", "31"]) }.should raise_error
|
|
107
54
|
end
|
|
108
55
|
|
|
109
|
-
context "when no documents found" do
|
|
110
|
-
|
|
111
|
-
it "raises an error" do
|
|
112
|
-
lambda { Person.find(["11", "21", "31"]) }.should raise_error
|
|
113
|
-
end
|
|
114
|
-
|
|
115
|
-
end
|
|
116
56
|
end
|
|
57
|
+
|
|
117
58
|
end
|
|
59
|
+
|
|
118
60
|
end
|
|
61
|
+
|
|
119
62
|
end
|
data/spec/models/address.rb
CHANGED
|
@@ -9,9 +9,9 @@ class Address
|
|
|
9
9
|
field :parent_title
|
|
10
10
|
field :services, :type => Array
|
|
11
11
|
key :street
|
|
12
|
-
|
|
12
|
+
has_many :locations
|
|
13
13
|
|
|
14
|
-
|
|
14
|
+
belongs_to :addressable, :inverse_of => :addresses do
|
|
15
15
|
def extension
|
|
16
16
|
"Testing"
|
|
17
17
|
end
|
|
@@ -36,4 +36,4 @@ class Address
|
|
|
36
36
|
end
|
|
37
37
|
|
|
38
38
|
end
|
|
39
|
-
end
|
|
39
|
+
end
|
data/spec/models/animal.rb
CHANGED
data/spec/models/country_code.rb
CHANGED
data/spec/models/game.rb
CHANGED
data/spec/models/inheritance.rb
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
class Canvas
|
|
2
2
|
include Mongoid::Document
|
|
3
3
|
field :name
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
has_many :shapes
|
|
5
|
+
has_one :writer
|
|
6
6
|
|
|
7
7
|
def render
|
|
8
8
|
shapes.each { |shape| render }
|
|
@@ -24,7 +24,7 @@ class Shape
|
|
|
24
24
|
field :x, :type => Integer, :default => 0
|
|
25
25
|
field :y, :type => Integer, :default => 0
|
|
26
26
|
|
|
27
|
-
|
|
27
|
+
belongs_to :canvas, :inverse_of => :shapes
|
|
28
28
|
|
|
29
29
|
def render; end
|
|
30
30
|
end
|
|
@@ -42,7 +42,7 @@ class Writer
|
|
|
42
42
|
include Mongoid::Document
|
|
43
43
|
field :speed, :type => Integer, :default => 0
|
|
44
44
|
|
|
45
|
-
|
|
45
|
+
belongs_to :canvas, :inverse_of => :writer
|
|
46
46
|
|
|
47
47
|
def write; end
|
|
48
48
|
end
|
|
@@ -53,4 +53,4 @@ end
|
|
|
53
53
|
|
|
54
54
|
class PdfWriter < Writer
|
|
55
55
|
def write; end
|
|
56
|
-
end
|
|
56
|
+
end
|
data/spec/models/location.rb
CHANGED
data/spec/models/name.rb
CHANGED
|
@@ -4,10 +4,10 @@ class Name
|
|
|
4
4
|
field :last_name
|
|
5
5
|
field :parent_title
|
|
6
6
|
key :first_name, :last_name
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
has_many :translations
|
|
8
|
+
belongs_to :person, :inverse_of => :name
|
|
9
9
|
|
|
10
10
|
def set_parent=(set = false)
|
|
11
11
|
self.parent_title = person.title if set
|
|
12
12
|
end
|
|
13
|
-
end
|
|
13
|
+
end
|
data/spec/models/namespacing.rb
CHANGED
|
@@ -2,10 +2,10 @@ module Medical
|
|
|
2
2
|
class Patient
|
|
3
3
|
include Mongoid::Document
|
|
4
4
|
field :name
|
|
5
|
-
|
|
5
|
+
has_many :prescriptions, :class_name => "Medical::Prescription"
|
|
6
6
|
end
|
|
7
7
|
class Prescription
|
|
8
8
|
include Mongoid::Document
|
|
9
9
|
field :name
|
|
10
10
|
end
|
|
11
|
-
end
|
|
11
|
+
end
|
data/spec/models/patient.rb
CHANGED
data/spec/models/person.rb
CHANGED
|
@@ -4,7 +4,6 @@ class Person
|
|
|
4
4
|
|
|
5
5
|
field :title
|
|
6
6
|
field :terms, :type => Boolean
|
|
7
|
-
field :pets, :type => Boolean, :default => false
|
|
8
7
|
field :age, :type => Integer, :default => 100
|
|
9
8
|
field :dob, :type => Date
|
|
10
9
|
field :mixed_drink, :type => MixedDrink
|
|
@@ -15,7 +14,6 @@ class Person
|
|
|
15
14
|
field :score, :type => Integer
|
|
16
15
|
field :blood_alcohol_content, :type => Float, :default => lambda{ 0.0 }
|
|
17
16
|
field :ssn
|
|
18
|
-
field :owner_id, :accessible => false, :type => Integer
|
|
19
17
|
|
|
20
18
|
index :age
|
|
21
19
|
index :addresses
|
|
@@ -26,7 +24,7 @@ class Person
|
|
|
26
24
|
|
|
27
25
|
attr_reader :rescored
|
|
28
26
|
|
|
29
|
-
|
|
27
|
+
has_many :addresses do
|
|
30
28
|
def extension
|
|
31
29
|
"Testing"
|
|
32
30
|
end
|
|
@@ -35,9 +33,9 @@ class Person
|
|
|
35
33
|
end
|
|
36
34
|
end
|
|
37
35
|
|
|
38
|
-
|
|
36
|
+
has_many :phone_numbers, :class_name => "Phone"
|
|
39
37
|
|
|
40
|
-
|
|
38
|
+
has_one :name do
|
|
41
39
|
def extension
|
|
42
40
|
"Testing"
|
|
43
41
|
end
|
|
@@ -46,7 +44,7 @@ class Person
|
|
|
46
44
|
end
|
|
47
45
|
end
|
|
48
46
|
|
|
49
|
-
|
|
47
|
+
has_one :pet, :class_name => "Animal"
|
|
50
48
|
|
|
51
49
|
accepts_nested_attributes_for :addresses, :reject_if => lambda { |attrs| attrs["street"].blank? }
|
|
52
50
|
accepts_nested_attributes_for :name
|
data/spec/models/pet.rb
CHANGED
data/spec/models/pet_owner.rb
CHANGED
data/spec/models/phone.rb
CHANGED
data/spec/models/post.rb
CHANGED
data/spec/models/translation.rb
CHANGED
data/spec/models/vet_visit.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
|
@@ -8,8 +8,8 @@ require 'rubygems'
|
|
|
8
8
|
|
|
9
9
|
gem "mocha", ">= 0.9.8"
|
|
10
10
|
|
|
11
|
-
require "mongoid"
|
|
12
11
|
require "mocha"
|
|
12
|
+
require "mongoid"
|
|
13
13
|
require "spec"
|
|
14
14
|
|
|
15
15
|
Mongoid.configure do |config|
|
|
@@ -28,4 +28,4 @@ Spec::Runner.configure do |config|
|
|
|
28
28
|
config.after :suite do
|
|
29
29
|
Mongoid.master.collections.each(&:drop)
|
|
30
30
|
end
|
|
31
|
-
end
|
|
31
|
+
end
|
|
@@ -134,10 +134,6 @@ describe Mongoid::Associations::BelongsToRelated do
|
|
|
134
134
|
Mongoid::Associations::BelongsToRelated.update(nil, @child, @options).should be_nil
|
|
135
135
|
end
|
|
136
136
|
|
|
137
|
-
it "removes the association" do
|
|
138
|
-
Mongoid::Associations::BelongsToRelated.update(nil, @child, @options)
|
|
139
|
-
@child.person.should be_nil
|
|
140
|
-
end
|
|
141
137
|
end
|
|
142
138
|
|
|
143
139
|
end
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
require "spec_helper"
|
|
2
2
|
|
|
3
|
-
describe Mongoid::Associations::
|
|
3
|
+
describe Mongoid::Associations::BelongsTo do
|
|
4
4
|
|
|
5
5
|
let(:child) do
|
|
6
6
|
Name.new(:first_name => "Drexel", :last_name => "Spivey")
|
|
@@ -21,7 +21,7 @@ describe Mongoid::Associations::EmbeddedIn do
|
|
|
21
21
|
describe "#find" do
|
|
22
22
|
|
|
23
23
|
before do
|
|
24
|
-
@association = Mongoid::Associations::
|
|
24
|
+
@association = Mongoid::Associations::BelongsTo.new(target, options)
|
|
25
25
|
end
|
|
26
26
|
|
|
27
27
|
context "when finding by id" do
|
|
@@ -37,7 +37,7 @@ describe Mongoid::Associations::EmbeddedIn do
|
|
|
37
37
|
describe "#initialize" do
|
|
38
38
|
|
|
39
39
|
before do
|
|
40
|
-
@association = Mongoid::Associations::
|
|
40
|
+
@association = Mongoid::Associations::BelongsTo.new(target, options)
|
|
41
41
|
end
|
|
42
42
|
|
|
43
43
|
it "sets the target" do
|
|
@@ -62,7 +62,7 @@ describe Mongoid::Associations::EmbeddedIn do
|
|
|
62
62
|
end
|
|
63
63
|
}
|
|
64
64
|
@options = Mongoid::Associations::Options.new(:name => :person, :extend => @block)
|
|
65
|
-
@association = Mongoid::Associations::
|
|
65
|
+
@association = Mongoid::Associations::BelongsTo.new(@parent, @options)
|
|
66
66
|
end
|
|
67
67
|
|
|
68
68
|
context "when the options have an extension" do
|
|
@@ -82,7 +82,7 @@ describe Mongoid::Associations::EmbeddedIn do
|
|
|
82
82
|
before do
|
|
83
83
|
@parent = stub
|
|
84
84
|
@target = stub(:_parent => @parent)
|
|
85
|
-
@association = Mongoid::Associations::
|
|
85
|
+
@association = Mongoid::Associations::BelongsTo.instantiate(@target, options)
|
|
86
86
|
end
|
|
87
87
|
|
|
88
88
|
it "sets the parent to the target" do
|
|
@@ -98,7 +98,7 @@ describe Mongoid::Associations::EmbeddedIn do
|
|
|
98
98
|
end
|
|
99
99
|
|
|
100
100
|
it "returns nil" do
|
|
101
|
-
Mongoid::Associations::
|
|
101
|
+
Mongoid::Associations::BelongsTo.instantiate(@document, options).should be_nil
|
|
102
102
|
end
|
|
103
103
|
|
|
104
104
|
end
|
|
@@ -107,8 +107,8 @@ describe Mongoid::Associations::EmbeddedIn do
|
|
|
107
107
|
|
|
108
108
|
describe ".macro" do
|
|
109
109
|
|
|
110
|
-
it "returns :
|
|
111
|
-
Mongoid::Associations::
|
|
110
|
+
it "returns :belongs_to" do
|
|
111
|
+
Mongoid::Associations::BelongsTo.macro.should == :belongs_to
|
|
112
112
|
end
|
|
113
113
|
|
|
114
114
|
end
|
|
@@ -116,7 +116,7 @@ describe Mongoid::Associations::EmbeddedIn do
|
|
|
116
116
|
describe "#method_missing" do
|
|
117
117
|
|
|
118
118
|
before do
|
|
119
|
-
@association = Mongoid::Associations::
|
|
119
|
+
@association = Mongoid::Associations::BelongsTo.new(target, options)
|
|
120
120
|
end
|
|
121
121
|
|
|
122
122
|
context "when method is a getter" do
|
|
@@ -156,7 +156,7 @@ describe Mongoid::Associations::EmbeddedIn do
|
|
|
156
156
|
before do
|
|
157
157
|
@name = Name.new(:first_name => "Test", :last_name => "User")
|
|
158
158
|
@person = Person.new(:title => "Mrs")
|
|
159
|
-
@association = Mongoid::Associations::
|
|
159
|
+
@association = Mongoid::Associations::BelongsTo.update(@person, @name, options)
|
|
160
160
|
end
|
|
161
161
|
|
|
162
162
|
it "updates the parent document" do
|
|
@@ -179,7 +179,7 @@ describe Mongoid::Associations::EmbeddedIn do
|
|
|
179
179
|
before do
|
|
180
180
|
@address = Address.new(:street => "Broadway")
|
|
181
181
|
@person = Person.new(:title => "Mrs")
|
|
182
|
-
Mongoid::Associations::
|
|
182
|
+
Mongoid::Associations::BelongsTo.update(@person, @address, has_many_options)
|
|
183
183
|
end
|
|
184
184
|
|
|
185
185
|
it "updates the parent document" do
|