Skip to content
This repository has been archived by the owner on Apr 17, 2018. It is now read-only.

Commit

Permalink
update_attributes should save model
Browse files Browse the repository at this point in the history
  • Loading branch information
Abdul-Rahman Advany authored and somebee committed May 19, 2008
1 parent 78d46d1 commit 72db385
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
12 changes: 11 additions & 1 deletion lib/data_mapper/resource.rb
Expand Up @@ -231,12 +231,22 @@ def attributes=(values_hash)
end
end

# Updates attributes and saves model
#
# ==== Parameters
# <Hash>:: Attributes to be updates
# <Symbol, String, Array>:: Keys of Hash to update (others won't be updated)
#
# ==== Returns
# <TrueClass, FalseClass>:: returns if model got saved or not
#-
# @public
def update_attributes(hash, *update_only)
raise 'Update takes a hash as first parameter' unless hash.is_a?(Hash)
loop_thru = update_only.empty? ? hash.keys : update_only
loop_thru.each {|attr| send("#{attr}=", hash[attr])}
save
end


##
# Produce a new Transaction for the class of this Resource
Expand Down
2 changes: 1 addition & 1 deletion spec/unit/resource_spec.rb
Expand Up @@ -108,7 +108,7 @@ def self.default_storage_name
jupiter.send(:private_attributes=, attributes.merge({ :core => 'Magma' }))
jupiter.attributes.should == attributes.merge({ :core => 'Magma' })

jupiter.update_attributes({ :core => "Toast", :type => "Bob" }, :core)
jupiter.update_attributes({ :core => "Toast", :type => "Bob" }, :core).should be_true
jupiter.core.should == "Toast"
jupiter.type.should_not == "Bob"
end
Expand Down

0 comments on commit 72db385

Please sign in to comment.