mongoid 0.6.7 → 0.6.8

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.6.7
1
+ 0.6.8
@@ -2,13 +2,24 @@ 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(fields, params)
6
- attributes = HashWithIndifferentAccess.new(params)
5
+ def process(params)
6
+ @attributes = HashWithIndifferentAccess.new(params)
7
+ process_fields
8
+ process_associations
9
+ end
10
+
11
+ protected
12
+ def process_fields
7
13
  fields.values.each do |field|
8
- value = field.set(attributes[field.name])
9
- attributes[field.name] = value if value
14
+ value = field.set(@attributes[field.name])
15
+ @attributes[field.name] = value if value
16
+ end
17
+ end
18
+
19
+ def process_associations
20
+ @attributes.each_pair do |key, value|
21
+ @attributes[key] = send("#{key}=", value) if value.is_a?(Document)
10
22
  end
11
- attributes
12
23
  end
13
24
 
14
25
  end
@@ -209,8 +209,8 @@ module Mongoid #:nodoc:
209
209
 
210
210
  # Instantiate a new Document, setting the Document's attributes if given.
211
211
  # If no attributes are provided, they will be initialized with an empty Hash.
212
- def initialize(attributes = {})
213
- @attributes = process(fields, attributes)
212
+ def initialize(attrs = {})
213
+ process(attrs)
214
214
  @new_record = true if id.nil?
215
215
  generate_key
216
216
  end
@@ -275,7 +275,7 @@ module Mongoid #:nodoc:
275
275
  # Writes all the attributes of this Document, and delegate up to
276
276
  # the parent.
277
277
  def write_attributes(attrs)
278
- @attributes = process(fields, attrs)
278
+ process(attrs)
279
279
  notify
280
280
  end
281
281
 
data/mongoid.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{mongoid}
8
- s.version = "0.6.7"
8
+ s.version = "0.6.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"]
@@ -26,6 +26,23 @@ describe Mongoid::Attributes do
26
26
  attrs = Person.new(@attributes).attributes
27
27
  attrs[:age].should == 30
28
28
  attrs[:terms].should == true
29
+ attrs[:_id].should == "1"
30
+ end
31
+
32
+ end
33
+
34
+ context "when associations provided in the attributes" do
35
+
36
+ before do
37
+ @name = Name.new(:first_name => "Testy")
38
+ @attributes = {
39
+ :name => @name
40
+ }
41
+ @person = Person.new(@attributes)
42
+ end
43
+
44
+ it "sets the associations" do
45
+ @person.name.should == @name
29
46
  end
30
47
 
31
48
  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.6.7
4
+ version: 0.6.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Durran Jordan