From 777fa257aaa962bf67f6e5522efaa420ea7dc88b Mon Sep 17 00:00:00 2001 From: Kevin Deisz Date: Fri, 29 May 2015 09:41:03 -0400 Subject: Allow Enumerable#pluck to take a splat. This allows easier integration with ActiveRecord, such that AR#pluck will now use Enumerable#pluck if the relation is loaded, without needing to hit the database. --- activesupport/test/core_ext/enumerable_test.rb | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'activesupport/test/core_ext') diff --git a/activesupport/test/core_ext/enumerable_test.rb b/activesupport/test/core_ext/enumerable_test.rb index 21743cdea5..f09b7d8850 100644 --- a/activesupport/test/core_ext/enumerable_test.rb +++ b/activesupport/test/core_ext/enumerable_test.rb @@ -3,6 +3,8 @@ require 'active_support/core_ext/array' require 'active_support/core_ext/enumerable' Payment = Struct.new(:price) +ExpandedPayment = Struct.new(:dollars, :cents) + class SummablePayment < Payment def +(p) self.class.new(price + p.price) end end @@ -114,5 +116,12 @@ class EnumerableTests < ActiveSupport::TestCase def test_pluck payments = GenericEnumerable.new([ Payment.new(5), Payment.new(15), Payment.new(10) ]) assert_equal [5, 15, 10], payments.pluck(:price) + + payments = GenericEnumerable.new([ + ExpandedPayment.new(5, 99), + ExpandedPayment.new(15, 0), + ExpandedPayment.new(10, 50) + ]) + assert_equal [[5, 99], [15, 0], [10, 50]], payments.pluck(:dollars, :cents) end end -- cgit v1.2.3