diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2007-04-26 02:03:40 +0000 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2007-04-26 02:03:40 +0000 |
commit | 46b58d80b95232bff0435d9e5ab0a3281872005f (patch) | |
tree | d830a55006d19ddbef80922e4a253a181c4dd0ff | |
parent | 9b8399fb7f97c0b7f7f80ffc8bc2e74565fec642 (diff) | |
download | rails-46b58d80b95232bff0435d9e5ab0a3281872005f.tar.gz rails-46b58d80b95232bff0435d9e5ab0a3281872005f.tar.bz2 rails-46b58d80b95232bff0435d9e5ab0a3281872005f.zip |
The find should instantiate real objects, not return hashes
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@6585 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
-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 |