diff options
author | Jon Leighton <j@jonathanleighton.com> | 2011-11-30 01:41:09 -0800 |
---|---|---|
committer | Jon Leighton <j@jonathanleighton.com> | 2011-11-30 01:41:09 -0800 |
commit | 271308cb9617b86cd4de20b629be504b48aea537 (patch) | |
tree | d713dd695abdcb09f1c191f1844166a27bf8ba38 /activerecord/test/cases/calculations_test.rb | |
parent | 38ab982cfff98570b5f12933cff489364845789c (diff) | |
parent | a382d60f6abc94b6a965525872f858e48abc00de (diff) | |
download | rails-271308cb9617b86cd4de20b629be504b48aea537.tar.gz rails-271308cb9617b86cd4de20b629be504b48aea537.tar.bz2 rails-271308cb9617b86cd4de20b629be504b48aea537.zip |
Merge pull request #1915 from bogdan/active_record_map
ActiveRecord::Base.map method for direct select by single column
Diffstat (limited to 'activerecord/test/cases/calculations_test.rb')
-rw-r--r-- | activerecord/test/cases/calculations_test.rb | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/activerecord/test/cases/calculations_test.rb b/activerecord/test/cases/calculations_test.rb index c38814713a..5abf3d1af4 100644 --- a/activerecord/test/cases/calculations_test.rb +++ b/activerecord/test/cases/calculations_test.rb @@ -1,5 +1,6 @@ require "cases/helper" require 'models/company' +require "models/contract" require 'models/topic' require 'models/edge' require 'models/club' @@ -446,4 +447,28 @@ class CalculationsTest < ActiveRecord::TestCase distinct_authors_for_approved_count = Topic.group(:approved).count(:author_name, :distinct => true)[true] assert_equal distinct_authors_for_approved_count, 2 end + + def test_pluck + assert_equal [1,2,3,4], Topic.order(:id).pluck(:id) + end + + def test_pluck_type_cast + topic = topics(:first) + relation = Topic.where(:id => topic.id) + assert_equal [ topic.approved ], relation.pluck(:approved) + assert_equal [ topic.last_read ], relation.pluck(:last_read) + assert_equal [ topic.written_on ], relation.pluck(:written_on) + + end + + def test_pluck_and_uniq + assert_equal [50, 53, 55, 60], Account.order(:credit_limit).uniq.pluck(:credit_limit) + end + + def test_pluck_in_relation + company = Company.first + contract = company.contracts.create! + assert_equal [contract.id], company.contracts.pluck(:id) + end + end |