mongoid 0.7.6 → 0.7.7
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/mongoid/attributes.rb +2 -9
- data/lib/mongoid/document.rb +1 -0
- data/mongoid.gemspec +2 -2
- data/spec/unit/mongoid/attributes_spec.rb +14 -0
- data/spec/unit/mongoid/document_spec.rb +2 -3
- metadata +2 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.7.
|
1
|
+
0.7.7
|
data/lib/mongoid/attributes.rb
CHANGED
@@ -2,17 +2,10 @@ module Mongoid #:nodoc:
|
|
2
2
|
module Attributes #:nodoc:
|
3
3
|
# Process the provided attributes casting them to their proper values if a
|
4
4
|
# field exists for them on the +Document+.
|
5
|
-
def process(
|
6
|
-
|
7
|
-
process_attributes
|
8
|
-
end
|
9
|
-
|
10
|
-
protected
|
11
|
-
def process_attributes
|
12
|
-
@attributes.each_pair do |key, value|
|
5
|
+
def process(attrs = {})
|
6
|
+
attrs.each_pair do |key, value|
|
13
7
|
send("#{key}=", value)
|
14
8
|
end
|
15
9
|
end
|
16
|
-
|
17
10
|
end
|
18
11
|
end
|
data/lib/mongoid/document.rb
CHANGED
@@ -242,6 +242,7 @@ module Mongoid #:nodoc:
|
|
242
242
|
# Instantiate a new Document, setting the Document's attributes if given.
|
243
243
|
# If no attributes are provided, they will be initialized with an empty Hash.
|
244
244
|
def initialize(attrs = {})
|
245
|
+
@attributes = {}.with_indifferent_access
|
245
246
|
process(defaults.merge(attrs))
|
246
247
|
@new_record = true if id.nil?
|
247
248
|
generate_key
|
data/mongoid.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{mongoid}
|
8
|
-
s.version = "0.7.
|
8
|
+
s.version = "0.7.7"
|
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"]
|
12
|
-
s.date = %q{2009-11-
|
12
|
+
s.date = %q{2009-11-16}
|
13
13
|
s.email = %q{durran@gmail.com}
|
14
14
|
s.extra_rdoc_files = [
|
15
15
|
"README.textile"
|
@@ -80,4 +80,18 @@ describe Mongoid::Attributes do
|
|
80
80
|
|
81
81
|
end
|
82
82
|
|
83
|
+
context "updating when attributes already exist" do
|
84
|
+
|
85
|
+
before do
|
86
|
+
@person = Person.new(:title => "Sir")
|
87
|
+
@attributes = { :dob => "2000-01-01" }
|
88
|
+
end
|
89
|
+
|
90
|
+
it "only overwrites supplied attributes" do
|
91
|
+
@person.process(@attributes)
|
92
|
+
@person.title.should == "Sir"
|
93
|
+
end
|
94
|
+
|
95
|
+
end
|
96
|
+
|
83
97
|
end
|
@@ -755,7 +755,7 @@ describe Mongoid::Document do
|
|
755
755
|
it "sets the child attributes on the parent" do
|
756
756
|
@name.write_attributes(:first_name => "Test2", :last_name => "User2")
|
757
757
|
@person.attributes[:name].should ==
|
758
|
-
{ "first_name" => "Test2", "last_name" => "User2" }
|
758
|
+
{ "_id" => "test-user", "first_name" => "Test2", "last_name" => "User2" }
|
759
759
|
end
|
760
760
|
|
761
761
|
end
|
@@ -771,8 +771,7 @@ describe Mongoid::Document do
|
|
771
771
|
it "updates the child attributes on the parent" do
|
772
772
|
@address.write_attributes("street" => "Test2")
|
773
773
|
@person.attributes[:addresses].should ==
|
774
|
-
[ { "_id" => "test", "street" => "
|
775
|
-
{ "street" => "Test2" } ]
|
774
|
+
[ { "_id" => "test", "street" => "Test2" } ]
|
776
775
|
end
|
777
776
|
|
778
777
|
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.7.
|
4
|
+
version: 0.7.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Durran Jordan
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-11-
|
12
|
+
date: 2009-11-16 00:00:00 -05:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|