Skip to content

Commit

Permalink
The find should instantiate real objects, not return hashes
Browse files Browse the repository at this point in the history
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@6585 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information
dhh committed Apr 26, 2007
1 parent 9b8399f commit 46b58d8
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
7 changes: 5 additions & 2 deletions activeresource/lib/active_resource/base.rb
Expand Up @@ -122,7 +122,7 @@ def find(*arguments)
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
Expand All @@ -142,7 +142,10 @@ def exists?(id, options = {})
# 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
Expand Down
2 changes: 1 addition & 1 deletion activeresource/test/base/custom_methods_test.rb
Expand Up @@ -82,6 +82,6 @@ def test_custom_new_element_method
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

0 comments on commit 46b58d8

Please sign in to comment.