mongoid 0.5.7 → 0.5.8

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/VERSION CHANGED
@@ -1 +1 @@
1
- 0.5.7
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
- store(key, attrs) if key.singular?
6
+ self[key] = attrs if key.singular?
7
7
  if key.plural?
8
- if elements = fetch(key, nil)
8
+ if elements = self[key]
9
9
  elements.delete_if { |e| (e[:_id] == attrs[:_id]) } << attrs
10
10
  else
11
- store(key, [attrs])
11
+ self[key] = [attrs]
12
12
  end
13
13
  end
14
14
  end
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{mongoid}
8
- s.version = "0.5.7"
8
+ s.version = "0.5.8"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Durran Jordan"]
@@ -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
- @address = Address.new(:street => "Oxford Street")
120
+ @home = Address.new(:street => "Oxford Street")
121
+ @business = Address.new(:street => "Upper Street")
121
122
  @person.name = @name
122
- @person.addresses << @address
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
- @address.save
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
- { :first_name => "Test2", :last_name => "User2" }
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(:street => "Test2")
526
- @person.attributes[:addresses].should == [{ :street => "Test2" }]
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongoid
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.7
4
+ version: 0.5.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Durran Jordan