Permalink
Browse files

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
  • Loading branch information...
1 parent 1d4d037 commit 97487c4e1154696fb0b30ea8727ba5459f575719 @jeremy jeremy committed Sep 4, 2006
Showing with 9 additions and 2 deletions.
  1. +3 −2 activeresource/lib/active_resource/base.rb
  2. +6 −0 activeresource/test/base/load_test.rb
@@ -102,7 +102,7 @@ def initialize(attributes = {}, prefix_options = {})
@prefix_options = prefix_options
end
- def new_resource?
+ def new?
id.nil?
end
@@ -115,7 +115,7 @@ def id=(id)
end
def save
- new_resource? ? create : update
+ new? ? create : update
end
def destroy
@@ -134,6 +134,7 @@ def reload
# 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
@@ -14,6 +14,12 @@ def setup
@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

0 comments on commit 97487c4

Please sign in to comment.