mirror of
https://github.com/github/rails.git
synced 2026-04-26 03:00:59 -04:00
select should raise error when no block or no parameter is passed
This commit is contained in:
@@ -29,12 +29,12 @@ module ActiveRecord
|
||||
relation
|
||||
end
|
||||
|
||||
def select(value = nil)
|
||||
def select(value = Proc.new)
|
||||
if block_given?
|
||||
to_a.select {|*block_args| yield(*block_args) }
|
||||
to_a.select {|*block_args| value.call(*block_args) }
|
||||
else
|
||||
relation = clone
|
||||
relation.select_values += [value] if value
|
||||
relation.select_values += [value]
|
||||
relation
|
||||
end
|
||||
end
|
||||
|
||||
@@ -465,6 +465,10 @@ class RelationTest < ActiveRecord::TestCase
|
||||
assert davids.loaded?
|
||||
end
|
||||
|
||||
def test_select_argument_error
|
||||
assert_raises(ArgumentError) { Developer.select }
|
||||
end
|
||||
|
||||
def test_relation_merging
|
||||
devs = Developer.where("salary >= 80000") & Developer.limit(2) & Developer.order('id ASC').where("id < 3")
|
||||
assert_equal [developers(:david), developers(:jamis)], devs.to_a
|
||||
|
||||
Reference in New Issue
Block a user