diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2010-09-07 10:48:14 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2010-09-07 10:48:14 -0700 |
commit | 604281221ce0eb71d7b922be2cd012018cca1fbf (patch) | |
tree | 3c1d79a707fc94bd0f5605c6eb07b9bf54ca91ba | |
parent | d00f1c18eb2d113095e2d21d6876010a748037b0 (diff) | |
download | rails-604281221ce0eb71d7b922be2cd012018cca1fbf.tar.gz rails-604281221ce0eb71d7b922be2cd012018cca1fbf.tar.bz2 rails-604281221ce0eb71d7b922be2cd012018cca1fbf.zip |
select should raise error when no block or no parameter is passed
-rw-r--r-- | activerecord/lib/active_record/relation/query_methods.rb | 6 | ||||
-rw-r--r-- | activerecord/test/cases/relations_test.rb | 4 |
2 files changed, 7 insertions, 3 deletions
diff --git a/activerecord/lib/active_record/relation/query_methods.rb b/activerecord/lib/active_record/relation/query_methods.rb index 22c605e9d0..6860da80d3 100644 --- a/activerecord/lib/active_record/relation/query_methods.rb +++ b/activerecord/lib/active_record/relation/query_methods.rb @@ -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 diff --git a/activerecord/test/cases/relations_test.rb b/activerecord/test/cases/relations_test.rb index e21e1cb635..b7112d0e37 100644 --- a/activerecord/test/cases/relations_test.rb +++ b/activerecord/test/cases/relations_test.rb @@ -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 |