Skip to content

Commit

Permalink
Removed assign_attributes. Don't like the api for that. Trying to thi…
Browse files Browse the repository at this point in the history
…nk things through more. Also refactored attributes to be more clear and simple instead of using returning.
  • Loading branch information
jnunemaker committed Aug 16, 2009
1 parent ae31734 commit 204d28b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 36 deletions.
18 changes: 5 additions & 13 deletions lib/mongomapper/embedded_document.rb
Original file line number Diff line number Diff line change
Expand Up @@ -166,20 +166,12 @@ def attributes=(attrs)
end

def attributes
returning HashWithIndifferentAccess.new do |attributes|
self.class.keys.each_pair do |name, key|
value = value_for_key(key)
attributes[name] = value unless value.nil?
end

attributes.merge!(embedded_association_attributes)
end
end

def assign_attributes(white_list, values)
white_list.each do |key|
send("#{key}=", values[key]) if values.has_key?(key)
attrs = HashWithIndifferentAccess.new
self.class.keys.each_pair do |name, key|
value = value_for_key(key)
attrs[name] = value unless value.nil?
end
attrs.merge!(embedded_association_attributes)
end

def [](name)
Expand Down
23 changes: 0 additions & 23 deletions test/functional/test_document.rb
Original file line number Diff line number Diff line change
Expand Up @@ -873,29 +873,6 @@ class ::Thing
end
end

context "Updating an existing document using assign attributes" do
setup do
@doc = @document.create(:first_name => 'John', :age => '27')
@doc.assign_attributes([:first_name], {:first_name => 'David', :age => '26'})
@doc.save
end

should "not insert document into collection" do
@document.count.should == 1
end

should "update attributes" do
@doc.first_name.should == 'David'
@doc.age.should_not == 26
end

should "only update the first name in the database" do
from_db = @document.find(@doc.id)
from_db.first_name.should == 'David'
from_db.age.should == 27
end
end

context "Destroying a document that exists" do
setup do
@doc = @document.create(:first_name => 'John', :age => '27')
Expand Down

0 comments on commit 204d28b

Please sign in to comment.