diff options
-rw-r--r-- | activeresource/lib/active_resource/base.rb | 7 | ||||
-rw-r--r-- | activeresource/test/base/custom_methods_test.rb | 2 |
2 files changed, 6 insertions, 3 deletions
diff --git a/activeresource/lib/active_resource/base.rb b/activeresource/lib/active_resource/base.rb index 6fa301d740..be0560879d 100644 --- a/activeresource/lib/active_resource/base.rb +++ b/activeresource/lib/active_resource/base.rb @@ -122,7 +122,7 @@ module ActiveResource case scope when :all then find_every(options) when :first then find_every(options).first - when Symbol then get(scope, options) + when Symbol then instantiate_collection(get(scope, options)) else find_single(scope, options) end end @@ -142,7 +142,10 @@ module ActiveResource # Find every resource. def find_every(options) prefix_options, query_options = split_options(options) - collection = connection.get(collection_path(prefix_options, query_options)) || [] + instantiate_collection(connection.get(collection_path(prefix_options, query_options)) || []) + end + + def instantiate_collection(collection, prefix_options = {}) collection.collect! do |element| returning new(element) do |resource| resource.prefix_options = prefix_options diff --git a/activeresource/test/base/custom_methods_test.rb b/activeresource/test/base/custom_methods_test.rb index b937fe8f9e..3648e0484d 100644 --- a/activeresource/test/base/custom_methods_test.rb +++ b/activeresource/test/base/custom_methods_test.rb @@ -82,6 +82,6 @@ class CustomMethodsTest < Test::Unit::TestCase end def test_find_custom_resources - assert_equal [{ "id" => 1, "name" => 'Matz' }], Person.find(:managers) + assert_equal 'Matz', Person.find(:managers).first.name end end
\ No newline at end of file |