diff options
Diffstat (limited to 'activeresource')
-rw-r--r-- | activeresource/lib/active_resource/base.rb | 5 | ||||
-rw-r--r-- | activeresource/test/base/load_test.rb | 6 |
2 files changed, 9 insertions, 2 deletions
diff --git a/activeresource/lib/active_resource/base.rb b/activeresource/lib/active_resource/base.rb index ec6cee19fa..40a50201a7 100644 --- a/activeresource/lib/active_resource/base.rb +++ b/activeresource/lib/active_resource/base.rb @@ -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 diff --git a/activeresource/test/base/load_test.rb b/activeresource/test/base/load_test.rb index 674f8456f0..726e7100b7 100644 --- a/activeresource/test/base/load_test.rb +++ b/activeresource/test/base/load_test.rb @@ -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 |