Ticket #7543: load_nils.diff
| File load_nils.diff, 1.6 kB (added by sneakin, 2 years ago) |
|---|
-
test/base/load_test.rb
old new 21 21 end 22 22 23 23 def test_load_expects_hash 24 assert_ raise(ArgumentError) { @person.load nil }24 assert_nothing_raised(ArgumentError) { @person.load nil } 25 25 assert_raise(ArgumentError) { @person.load '<person id="1"/>' } 26 26 end 27 27 -
lib/active_resource/base.rb
old new 228 228 # Manually load attributes from a hash. Recursively loads collections of 229 229 # resources. 230 230 def load(attributes) 231 raise ArgumentError, "expected an attributes Hash, got #{attributes.inspect}" unless attributes.is_a?(Hash) 232 attributes.each do |key, value| 233 @attributes[key.to_s] = 234 case value 231 if attributes 232 raise ArgumentError, "expected an attributes Hash, got #{attributes.inspect}" unless attributes.is_a?(Hash) 233 attributes.each do |key, value| 234 @attributes[key.to_s] = 235 case value 235 236 when Array 236 237 resource = find_or_create_resource_for_collection(key) 237 238 value.map { |attrs| resource.new(attrs) } … … 242 243 value.class.new(value.attributes, value.prefix_options) 243 244 else 244 245 value.dup rescue value 245 end 246 end 247 end 246 248 end 249 247 250 self 248 251 end 249 252