diff options
author | Sławosz Sławiński <slawosz@gmail.com> | 2011-07-23 21:35:16 +0200 |
---|---|---|
committer | Sławosz Sławiński <slawosz@cubiware.com> | 2011-07-26 14:57:47 +0200 |
commit | 04cc446d178653d362510e79a22db5300d463161 (patch) | |
tree | 72e82bb0dd388a7a962a1887e60a67394732bea9 | |
parent | 8e0061128e8946d6e6fab68c078517db668ef050 (diff) | |
download | rails-04cc446d178653d362510e79a22db5300d463161.tar.gz rails-04cc446d178653d362510e79a22db5300d463161.tar.bz2 rails-04cc446d178653d362510e79a22db5300d463161.zip |
allow select to have multiple arguments
-rw-r--r-- | activerecord/lib/active_record/relation/query_methods.rb | 9 | ||||
-rw-r--r-- | activerecord/test/cases/base_test.rb | 5 |
2 files changed, 11 insertions, 3 deletions
diff --git a/activerecord/lib/active_record/relation/query_methods.rb b/activerecord/lib/active_record/relation/query_methods.rb index 1654ae1eac..792ffe1c5d 100644 --- a/activerecord/lib/active_record/relation/query_methods.rb +++ b/activerecord/lib/active_record/relation/query_methods.rb @@ -37,12 +37,15 @@ module ActiveRecord relation end - def select(value = Proc.new) + def select(*args, &blk) + if !block_given? && args.blank? + raise ArgumentError + end if block_given? - to_a.select {|*block_args| value.call(*block_args) } + to_a.select {|*block_args| blk.call(*block_args) } else relation = clone - relation.select_values += Array.wrap(value) + relation.select_values += args relation end end diff --git a/activerecord/test/cases/base_test.rb b/activerecord/test/cases/base_test.rb index f2f5b73626..84b66fdf49 100644 --- a/activerecord/test/cases/base_test.rb +++ b/activerecord/test/cases/base_test.rb @@ -123,6 +123,11 @@ class BasicsTest < ActiveRecord::TestCase assert_equal Topic.all.map(&:id).sort, topic_ids end + def test_select_symbol_for_many_arguments + topics = Topic.select(:id, :author_name).map{|topic| [topic.id, topic.author_name]}.sort + assert_equal Topic.all.map{|topic| [topic.id,topic.author_name]}.sort, topics + end + def test_table_exists assert !NonExistentTable.table_exists? assert Topic.table_exists? |