mongoid 0.5.7 → 0.5.8
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/mongoid/extensions/hash/accessors.rb +3 -3
- data/mongoid.gemspec +1 -1
- data/spec/integration/mongoid/document_spec.rb +9 -3
- data/spec/unit/mongoid/associations/has_many_association_spec.rb +6 -0
- data/spec/unit/mongoid/document_spec.rb +5 -3
- data/spec/unit/mongoid/extensions/hash/accessors_spec.rb +2 -2
- metadata +1 -1
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.5.
|
1
|
+
0.5.8
|
@@ -3,12 +3,12 @@ module Mongoid #:nodoc:
|
|
3
3
|
module Hash #:nodoc:
|
4
4
|
module Accessors #:nodoc:
|
5
5
|
def insert(key, attrs)
|
6
|
-
|
6
|
+
self[key] = attrs if key.singular?
|
7
7
|
if key.plural?
|
8
|
-
if elements =
|
8
|
+
if elements = self[key]
|
9
9
|
elements.delete_if { |e| (e[:_id] == attrs[:_id]) } << attrs
|
10
10
|
else
|
11
|
-
|
11
|
+
self[key] = [attrs]
|
12
12
|
end
|
13
13
|
end
|
14
14
|
end
|
data/mongoid.gemspec
CHANGED
@@ -117,9 +117,15 @@ describe Mongoid::Document do
|
|
117
117
|
before do
|
118
118
|
@person = Person.new(:title => "Sir")
|
119
119
|
@name = Name.new(:first_name => "Syd", :last_name => "Vicious")
|
120
|
-
@
|
120
|
+
@home = Address.new(:street => "Oxford Street")
|
121
|
+
@business = Address.new(:street => "Upper Street")
|
121
122
|
@person.name = @name
|
122
|
-
@person.addresses << @
|
123
|
+
@person.addresses << @home
|
124
|
+
@person.addresses << @business
|
125
|
+
end
|
126
|
+
|
127
|
+
it "allows adding multiples on a has_many in a row" do
|
128
|
+
@person.addresses.length.should == 2
|
123
129
|
end
|
124
130
|
|
125
131
|
context "when saving on a has_one" do
|
@@ -138,7 +144,7 @@ describe Mongoid::Document do
|
|
138
144
|
context "when saving on a has_many" do
|
139
145
|
|
140
146
|
before do
|
141
|
-
@
|
147
|
+
@home.save
|
142
148
|
end
|
143
149
|
|
144
150
|
it "saves the entire graph up from the has_many" do
|
@@ -47,6 +47,12 @@ describe Mongoid::Associations::HasManyAssociation do
|
|
47
47
|
@address.parent.should == @document
|
48
48
|
end
|
49
49
|
|
50
|
+
it "allows multiple additions" do
|
51
|
+
@association << @address
|
52
|
+
@association << @address
|
53
|
+
@association.length.should == 4
|
54
|
+
end
|
55
|
+
|
50
56
|
end
|
51
57
|
|
52
58
|
describe "#concat" do
|
@@ -508,7 +508,7 @@ describe Mongoid::Document do
|
|
508
508
|
it "sets the child attributes on the parent" do
|
509
509
|
@name.write_attributes(:first_name => "Test2", :last_name => "User2")
|
510
510
|
@person.attributes[:name].should ==
|
511
|
-
{
|
511
|
+
{ "first_name" => "Test2", "last_name" => "User2" }
|
512
512
|
end
|
513
513
|
|
514
514
|
end
|
@@ -522,8 +522,10 @@ describe Mongoid::Document do
|
|
522
522
|
end
|
523
523
|
|
524
524
|
it "updates the child attributes on the parent" do
|
525
|
-
@address.write_attributes(
|
526
|
-
@person.attributes[:addresses].should ==
|
525
|
+
@address.write_attributes("street" => "Test2")
|
526
|
+
@person.attributes[:addresses].should ==
|
527
|
+
[ { "_id" => "test", "street" => "Test" },
|
528
|
+
{ "street" => "Test2" } ]
|
527
529
|
end
|
528
530
|
|
529
531
|
end
|
@@ -67,7 +67,7 @@ describe Mongoid::Extensions::Hash::Accessors do
|
|
67
67
|
context "when matching attribute does not exist" do
|
68
68
|
|
69
69
|
before do
|
70
|
-
@new = { :street => "New Street" }
|
70
|
+
@new = { :_id => 10, :street => "New Street" }
|
71
71
|
end
|
72
72
|
|
73
73
|
it "updates the matching attributes" do
|
@@ -75,7 +75,7 @@ describe Mongoid::Extensions::Hash::Accessors do
|
|
75
75
|
@hash[:addresses].should == [
|
76
76
|
{ :_id => 3, :street => "First Street" },
|
77
77
|
{ :_id => 4, :street => "Second Street" },
|
78
|
-
{ :street => "New Street" }
|
78
|
+
{ :_id => 10, :street => "New Street" }
|
79
79
|
]
|
80
80
|
end
|
81
81
|
end
|