diff options
author | Jeremy Kemper <jeremy@bitsweat.net> | 2006-07-09 20:48:31 +0000 |
---|---|---|
committer | Jeremy Kemper <jeremy@bitsweat.net> | 2006-07-09 20:48:31 +0000 |
commit | 5241b97709c693f272d457abc9165e7d750330b3 (patch) | |
tree | aceed61edcbc803208046a74ccd5a5d19683ae5f /activesupport/test | |
parent | 1dc4cc030ffecb57ceffecac81215ed1d7924f3f (diff) | |
download | rails-5241b97709c693f272d457abc9165e7d750330b3.tar.gz rails-5241b97709c693f272d457abc9165e7d750330b3.tar.bz2 rails-5241b97709c693f272d457abc9165e7d750330b3.zip |
Optional identity for Enumerable#sum defaults to zero. Closes #5657.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@4599 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activesupport/test')
-rw-r--r-- | activesupport/test/core_ext/enumerable_test.rb | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/activesupport/test/core_ext/enumerable_test.rb b/activesupport/test/core_ext/enumerable_test.rb index 3180755e5f..0590846b7b 100644 --- a/activesupport/test/core_ext/enumerable_test.rb +++ b/activesupport/test/core_ext/enumerable_test.rb @@ -44,7 +44,13 @@ class EnumerableTests < Test::Unit::TestCase assert_raise(TypeError) { payments.sum(&:price) } assert_equal 60, payments.sum { |p| p.price.to_i * 2 } end - + + def test_empty_sums + assert_equal 0, [].sum + assert_equal 0, [].sum { |i| i } + assert_equal Payment.new(0), [].sum(Payment.new(0)) + end + def test_index_by payments = [ Payment.new(5), Payment.new(15), Payment.new(10) ] assert_equal( |