aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@loudthinking.com>2018-02-09 10:30:19 -0800
committerGitHub <noreply@github.com>2018-02-09 10:30:19 -0800
commit80cc0d323ba08a51d4299cb4fc34f157818fead4 (patch)
tree78b41781f1d67b810dc781084a5971ea469424bf /activerecord/test
parentb6ee4e4b989bfc2fe50b2b830fdcb90ef9e23d9a (diff)
downloadrails-80cc0d323ba08a51d4299cb4fc34f157818fead4.tar.gz
rails-80cc0d323ba08a51d4299cb4fc34f157818fead4.tar.bz2
rails-80cc0d323ba08a51d4299cb4fc34f157818fead4.zip
Add Relation#pick as short-hand for single-value plucks (#31941)
* Add Relation#pick as short-hand for single-value plucks
Diffstat (limited to 'activerecord/test')
-rw-r--r--activerecord/test/cases/calculations_test.rb10
1 files changed, 10 insertions, 0 deletions
diff --git a/activerecord/test/cases/calculations_test.rb b/activerecord/test/cases/calculations_test.rb
index 82b15e565b..ec8bc913a1 100644
--- a/activerecord/test/cases/calculations_test.rb
+++ b/activerecord/test/cases/calculations_test.rb
@@ -793,6 +793,16 @@ class CalculationsTest < ActiveRecord::TestCase
end
end
+ def test_pick_one
+ assert_equal "The First Topic", Topic.order(:id).pick(:heading)
+ assert_nil Topic.where("1=0").pick(:heading)
+ end
+
+ def test_pick_two
+ assert_equal ["David", "david@loudthinking.com"], Topic.order(:id).pick(:author_name, :author_email_address)
+ assert_nil Topic.where("1=0").pick(:author_name, :author_email_address)
+ end
+
def test_grouped_calculation_with_polymorphic_relation
part = ShipPart.create!(name: "has trinket")
part.trinkets.create!