aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases
diff options
context:
space:
mode:
authorCarlos Antonio da Silva <carlosantoniodasilva@gmail.com>2012-11-17 19:08:07 -0200
committerCarlos Antonio da Silva <carlosantoniodasilva@gmail.com>2012-11-21 22:21:01 -0200
commitad9983f625ea414c5b7bbc0fd12be17ec04fc590 (patch)
tree352c4e140b1d689ad37ce6e4099eff9d7f061c56 /activerecord/test/cases
parent76a6bfd6c8dc9e3c27779a39b3e04402e20f0eaa (diff)
downloadrails-ad9983f625ea414c5b7bbc0fd12be17ec04fc590.tar.gz
rails-ad9983f625ea414c5b7bbc0fd12be17ec04fc590.tar.bz2
rails-ad9983f625ea414c5b7bbc0fd12be17ec04fc590.zip
Deprecate Relation#sum with a block.
To perform a sum calculation over the array of elements, use to_a.sum(&block). Please check the discussion in f9cb645dfcb5cc89f59d2f8b58a019486c828c73 for more context.
Diffstat (limited to 'activerecord/test/cases')
-rw-r--r--activerecord/test/cases/associations/has_many_associations_test.rb6
-rw-r--r--activerecord/test/cases/calculations_test.rb6
2 files changed, 10 insertions, 2 deletions
diff --git a/activerecord/test/cases/associations/has_many_associations_test.rb b/activerecord/test/cases/associations/has_many_associations_test.rb
index 01afa087be..6cdc166533 100644
--- a/activerecord/test/cases/associations/has_many_associations_test.rb
+++ b/activerecord/test/cases/associations/has_many_associations_test.rb
@@ -1658,6 +1658,12 @@ class HasManyAssociationsTest < ActiveRecord::TestCase
assert_deprecated { klass.has_many :foo, :counter_sql => 'lol' }
end
+ test "sum calculation with block for array compatibility is deprecated" do
+ assert_deprecated do
+ posts(:welcome).comments.sum { |c| c.id }
+ end
+ end
+
test "has many associations on new records use null relations" do
post = Post.new
diff --git a/activerecord/test/cases/calculations_test.rb b/activerecord/test/cases/calculations_test.rb
index bf8c0f1e70..5cb7eabf0e 100644
--- a/activerecord/test/cases/calculations_test.rb
+++ b/activerecord/test/cases/calculations_test.rb
@@ -389,8 +389,10 @@ class CalculationsTest < ActiveRecord::TestCase
Account.where("credit_limit > 50").from('accounts').sum(:credit_limit)
end
- def test_sum_array_compatibility
- assert_equal Account.sum(:credit_limit), Account.sum(&:credit_limit)
+ def test_sum_array_compatibility_deprecation
+ assert_deprecated do
+ assert_equal Account.sum(:credit_limit), Account.sum(&:credit_limit)
+ end
end
def test_average_with_from_option