From 80cc0d323ba08a51d4299cb4fc34f157818fead4 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Fri, 9 Feb 2018 10:30:19 -0800 Subject: Add Relation#pick as short-hand for single-value plucks (#31941) * Add Relation#pick as short-hand for single-value plucks --- activerecord/test/cases/calculations_test.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'activerecord/test') 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! -- cgit v1.2.3