Permalink
Browse files

Changed ActiveRecord::Associations::CollectionProxy#select to take mu…

…ltiple arguments.

This makes the arguments the same as ActiveRecord::QueryMethods::select.
  • Loading branch information...
1 parent a92814b commit a8ede3664055f33c102b3f229cf280b0bf69c540 @derikson derikson committed Apr 8, 2013
@@ -67,11 +67,11 @@ def reset
@target = []
end
- def select(select = nil)
+ def select(*fields)
if block_given?
load_target.select.each { |e| yield e }
else
- scope.select(select)
+ scope.select(*fields)
end
end
@@ -76,7 +76,7 @@ def loaded?
# # #<Pet id: nil, name: "Choo-Choo">
# # ]
#
- # person.pets.select([:id, :name])
+ # person.pets.select(:id, :name )
# # => [
# # #<Pet id: 1, name: "Fancy-Fancy">,
# # #<Pet id: 2, name: "Spook">,
@@ -107,8 +107,8 @@ def loaded?
# # #<Pet id: 2, name: "Spook">,
# # #<Pet id: 3, name: "Choo-Choo">
# # ]
- def select(select = nil, &block)
- @association.select(select, &block)
+ def select(*fields, &block)
+ @association.select(*fields, &block)
end
# Finds an object in the collection responding to the +id+. Uses the same
@@ -523,7 +523,11 @@ def test_default_select
end
def test_select_query_method
- assert_equal ['id'], posts(:welcome).comments.select(:id).first.attributes.keys
+ assert_equal ['id', 'body'], posts(:welcome).comments.select(:id, :body).first.attributes.keys
+ end
+
+ def test_select_with_block
+ assert_equal [1], posts(:welcome).comments.select { |c| c.id == 1 }.map(&:id)
end
def test_adding

0 comments on commit a8ede36

Please sign in to comment.