mongoid 0.6.10 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/mongoid/associations/accessor.rb +1 -1
- data/lib/mongoid/associations/belongs_to.rb +2 -1
- data/lib/mongoid/associations/has_many.rb +2 -1
- data/lib/mongoid/associations/has_one.rb +1 -1
- data/lib/mongoid/document.rb +3 -1
- data/lib/mongoid/extensions/boolean/conversions.rb +2 -1
- data/mongoid.gemspec +1 -1
- data/spec/unit/mongoid/associations/accessor_spec.rb +3 -3
- data/spec/unit/mongoid/attributes_spec.rb +25 -8
- data/spec/unit/mongoid/document_spec.rb +12 -0
- data/spec/unit/mongoid/extensions/boolean/conversions_spec.rb +16 -0
- metadata +1 -1
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.7.0
|
@@ -21,7 +21,7 @@ module Mongoid #:nodoc:
|
|
21
21
|
# object: The object that was passed in to the setter method.
|
22
22
|
# options: optional options.
|
23
23
|
def set(type, name, document, object, options ={})
|
24
|
-
type.update(object, document, name)
|
24
|
+
type.update(object, document, name, options)
|
25
25
|
end
|
26
26
|
end
|
27
27
|
end
|
@@ -25,12 +25,13 @@ module Mongoid #:nodoc:
|
|
25
25
|
# Perform an update of the relationship of the parent and child. This
|
26
26
|
# is initialized by setting a parent object as the association on the
|
27
27
|
# +Document+. Will properly set a has_one or a has_many.
|
28
|
-
def update(parent, child, name)
|
28
|
+
def update(parent, child, name, options = {})
|
29
29
|
name = child.class.name.demodulize.downcase
|
30
30
|
has_one = parent.associations[name]
|
31
31
|
child.parentize(parent, name) if has_one
|
32
32
|
child.parentize(parent, name.tableize) unless has_one
|
33
33
|
child.notify
|
34
|
+
parent
|
34
35
|
end
|
35
36
|
end
|
36
37
|
end
|
@@ -77,12 +77,13 @@ module Mongoid #:nodoc:
|
|
77
77
|
# Perform an update of the relationship of the parent and child. This
|
78
78
|
# is initialized by setting the has_many to the supplied +Enumerable+
|
79
79
|
# and setting up the parentization.
|
80
|
-
def update(children, parent, name)
|
80
|
+
def update(children, parent, name, options = {})
|
81
81
|
parent.attributes.delete(name)
|
82
82
|
children.each do |child|
|
83
83
|
child.parentize(parent, name)
|
84
84
|
child.notify
|
85
85
|
end
|
86
|
+
new(name, parent, options)
|
86
87
|
end
|
87
88
|
end
|
88
89
|
|
@@ -23,7 +23,7 @@ module Mongoid #:nodoc:
|
|
23
23
|
class << self
|
24
24
|
# Perform an update of the relationship of the parent and child. This
|
25
25
|
# is initialized by setting the has_one to the supplied child.
|
26
|
-
def update(child, parent, name)
|
26
|
+
def update(child, parent, name, options = {})
|
27
27
|
child.parentize(parent, name)
|
28
28
|
child.notify
|
29
29
|
child
|
data/lib/mongoid/document.rb
CHANGED
@@ -201,12 +201,14 @@ module Mongoid #:nodoc:
|
|
201
201
|
self.class.fields
|
202
202
|
end
|
203
203
|
|
204
|
-
# Get the
|
204
|
+
# Get the id associated with this object.
|
205
205
|
# This is in essence the primary key.
|
206
206
|
def id
|
207
207
|
@attributes[:_id]
|
208
208
|
end
|
209
209
|
|
210
|
+
alias :_id :id
|
211
|
+
|
210
212
|
# Instantiate a new Document, setting the Document's attributes if given.
|
211
213
|
# If no attributes are provided, they will be initialized with an empty Hash.
|
212
214
|
def initialize(attrs = {})
|
data/mongoid.gemspec
CHANGED
@@ -56,7 +56,7 @@ describe Mongoid::Associations::Accessor do
|
|
56
56
|
context "when type is has_many" do
|
57
57
|
|
58
58
|
it "returns a HasMany" do
|
59
|
-
Mongoid::Associations::HasMany.expects(:update).with(@document, @object, :addresses)
|
59
|
+
Mongoid::Associations::HasMany.expects(:update).with(@document, @object, :addresses, {})
|
60
60
|
Mongoid::Associations::Accessor.set(Mongoid::Associations::HasMany, :addresses, @document, @object)
|
61
61
|
end
|
62
62
|
|
@@ -65,7 +65,7 @@ describe Mongoid::Associations::Accessor do
|
|
65
65
|
context "when type is has_one" do
|
66
66
|
|
67
67
|
it "returns a HasOne" do
|
68
|
-
Mongoid::Associations::HasOne.expects(:update).with(@document, @object, :name)
|
68
|
+
Mongoid::Associations::HasOne.expects(:update).with(@document, @object, :name, {})
|
69
69
|
Mongoid::Associations::Accessor.set(Mongoid::Associations::HasOne, :name, @document, @object)
|
70
70
|
end
|
71
71
|
|
@@ -74,7 +74,7 @@ describe Mongoid::Associations::Accessor do
|
|
74
74
|
context "when type is belongs_to" do
|
75
75
|
|
76
76
|
it "returns a BelongsTo" do
|
77
|
-
Mongoid::Associations::BelongsTo.expects(:update).with(@object, @document, :person)
|
77
|
+
Mongoid::Associations::BelongsTo.expects(:update).with(@object, @document, :person, {})
|
78
78
|
Mongoid::Associations::Accessor.set(Mongoid::Associations::BelongsTo, :person, @document, @object)
|
79
79
|
end
|
80
80
|
|
@@ -33,16 +33,33 @@ describe Mongoid::Attributes do
|
|
33
33
|
|
34
34
|
context "when associations provided in the attributes" do
|
35
35
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
36
|
+
context "when association is a has_one" do
|
37
|
+
|
38
|
+
before do
|
39
|
+
@name = Name.new(:first_name => "Testy")
|
40
|
+
@attributes = {
|
41
|
+
:name => @name
|
42
|
+
}
|
43
|
+
@person = Person.new(@attributes)
|
44
|
+
end
|
45
|
+
|
46
|
+
it "sets the associations" do
|
47
|
+
@person.name.should == @name
|
48
|
+
end
|
49
|
+
|
42
50
|
end
|
43
51
|
|
44
|
-
|
45
|
-
|
52
|
+
context "when association is a belongs_to" do
|
53
|
+
|
54
|
+
before do
|
55
|
+
@person = Person.new
|
56
|
+
@name = Name.new(:first_name => "Tyler", :person => @person)
|
57
|
+
end
|
58
|
+
|
59
|
+
it "sets the association" do
|
60
|
+
@name.person.should == @person
|
61
|
+
end
|
62
|
+
|
46
63
|
end
|
47
64
|
|
48
65
|
end
|
@@ -315,6 +315,18 @@ describe Mongoid::Document do
|
|
315
315
|
|
316
316
|
end
|
317
317
|
|
318
|
+
describe "#_id" do
|
319
|
+
|
320
|
+
before do
|
321
|
+
@person = Person.new
|
322
|
+
end
|
323
|
+
|
324
|
+
it "delegates to #id" do
|
325
|
+
@person._id.should == @person.id
|
326
|
+
end
|
327
|
+
|
328
|
+
end
|
329
|
+
|
318
330
|
describe "#index" do
|
319
331
|
|
320
332
|
context "when unique options are not provided" do
|
@@ -20,6 +20,22 @@ describe Mongoid::Extensions::Boolean::Conversions do
|
|
20
20
|
|
21
21
|
end
|
22
22
|
|
23
|
+
context "when 0" do
|
24
|
+
|
25
|
+
it "returns false" do
|
26
|
+
Boolean.set("0").should be_false
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
|
31
|
+
context "when 1" do
|
32
|
+
|
33
|
+
it "returns true" do
|
34
|
+
Boolean.set("1").should be_true
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
|
23
39
|
end
|
24
40
|
|
25
41
|
describe "#get" do
|