diff options
author | Bogdan Gusiev <agresso@gmail.com> | 2011-11-30 11:03:00 +0200 |
---|---|---|
committer | Bogdan Gusiev <agresso@gmail.com> | 2011-11-30 11:03:00 +0200 |
commit | a382d60f6abc94b6a965525872f858e48abc00de (patch) | |
tree | 969d8b7d6321f7868e2f613f6f44987f3f471911 /activerecord/test/cases/calculations_test.rb | |
parent | d9c288207731e61c40ce6276fd91f0b800d3fabb (diff) | |
download | rails-a382d60f6abc94b6a965525872f858e48abc00de.tar.gz rails-a382d60f6abc94b6a965525872f858e48abc00de.tar.bz2 rails-a382d60f6abc94b6a965525872f858e48abc00de.zip |
ActiveRecord::Relation#pluck method
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 |