Permalink
Browse files

Merge pull request #41 from packagethief/master

Fix nested attribute loading from anonymous classes under Ruby 1.9
  • Loading branch information...
2 parents 720f9e5 + d98d012 commit 6639bb40f716339688784cecfc4a5d2cfef8a772 @jeremy jeremy committed Sep 18, 2012
Showing with 7 additions and 1 deletion.
  1. +1 −1 lib/active_resource/base.rb
  2. +6 −0 test/cases/base/load_test.rb
@@ -1490,7 +1490,7 @@ def find_or_create_resource_for(name)
if self.class.const_defined?(*const_args)
self.class.const_get(*const_args)
else
- ancestors = self.class.name.split("::")
+ ancestors = self.class.name.to_s.split("::")
if ancestors.size > 1
find_or_create_resource_in_modules(resource_name, ancestors)
else
@@ -108,6 +108,12 @@ def test_load_one_with_unknown_resource
assert_equal @first_address.values.first.stringify_keys, address.attributes
end
+ def test_load_one_with_unknown_resource_from_anonymous_subclass
+ subclass = Class.new(Person).tap { |c| c.element_name = 'person' }
+ address = silence_warnings { subclass.new.load(@first_address).address }
+ assert_kind_of subclass::Address, address
+ end
+
def test_load_collection_with_existing_resource
addresses = @person.load(@addresses_from_json).street_addresses
assert_kind_of Array, addresses

0 comments on commit 6639bb4

Please sign in to comment.