load nil is noop. use new? instead of new_resource?

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@5006 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
Jeremy Kemper 2006-09-04 23:36:13 +00:00
parent 1d4d037b0d
commit 97487c4e11
2 changed files with 9 additions and 2 deletions

View File

@ -102,7 +102,7 @@ module ActiveResource
@prefix_options = prefix_options
end
def new_resource?
def new?
id.nil?
end
@ -115,7 +115,7 @@ module ActiveResource
end
def save
new_resource? ? create : update
new? ? create : update
end
def destroy
@ -134,6 +134,7 @@ module ActiveResource
# Manually load attributes from a hash. Recursively loads collections of
# resources.
def load(attributes)
return self if attributes.nil?
attributes.each do |key, value|
@attributes[key.to_s] =
case value

View File

@ -14,6 +14,12 @@ class BaseLoadTest < Test::Unit::TestCase
@person = Person.new
end
def test_load_nil
assert_nothing_raised do
assert_equal @person, @person.load(nil)
end
end
def test_load_simple_hash
assert_equal Hash.new, @person.attributes
assert_equal @matz.stringify_keys, @person.load(@matz).attributes