Skip to content
This repository
Browse code

Merge pull request #41 from packagethief/master

Fix nested attribute loading from anonymous classes under Ruby 1.9
  • Loading branch information...
commit 6639bb40f716339688784cecfc4a5d2cfef8a772 2 parents 720f9e5 + d98d012
Jeremy Kemper jeremy authored
2  lib/active_resource/base.rb
@@ -1490,7 +1490,7 @@ def find_or_create_resource_for(name)
1490 1490 if self.class.const_defined?(*const_args)
1491 1491 self.class.const_get(*const_args)
1492 1492 else
1493   - ancestors = self.class.name.split("::")
  1493 + ancestors = self.class.name.to_s.split("::")
1494 1494 if ancestors.size > 1
1495 1495 find_or_create_resource_in_modules(resource_name, ancestors)
1496 1496 else
6 test/cases/base/load_test.rb
@@ -108,6 +108,12 @@ def test_load_one_with_unknown_resource
108 108 assert_equal @first_address.values.first.stringify_keys, address.attributes
109 109 end
110 110
  111 + def test_load_one_with_unknown_resource_from_anonymous_subclass
  112 + subclass = Class.new(Person).tap { |c| c.element_name = 'person' }
  113 + address = silence_warnings { subclass.new.load(@first_address).address }
  114 + assert_kind_of subclass::Address, address
  115 + end
  116 +
111 117 def test_load_collection_with_existing_resource
112 118 addresses = @person.load(@addresses_from_json).street_addresses
113 119 assert_kind_of Array, addresses

0 comments on commit 6639bb4

Please sign in to comment.
Something went wrong with that request. Please try again.