diff options
author | Erik Michaels-Ober <sferik@gmail.com> | 2016-03-14 21:57:52 -0700 |
---|---|---|
committer | Erik Michaels-Ober <sferik@gmail.com> | 2016-03-19 15:29:07 -0700 |
commit | 58772397e9b790e80bcd4d8e51937dc82ecb719e (patch) | |
tree | 7edc2ef7e149e25b3d784de1164a61c4d616c11c /activerecord/test | |
parent | dda31d59a03adb7e5aa372e72bb66a3886632f2f (diff) | |
download | rails-58772397e9b790e80bcd4d8e51937dc82ecb719e.tar.gz rails-58772397e9b790e80bcd4d8e51937dc82ecb719e.tar.bz2 rails-58772397e9b790e80bcd4d8e51937dc82ecb719e.zip |
Forward ActiveRecord::Relation#count to Enumerable#count if block given
Diffstat (limited to 'activerecord/test')
-rw-r--r-- | activerecord/test/cases/calculations_test.rb | 4 | ||||
-rw-r--r-- | activerecord/test/cases/relations_test.rb | 5 |
2 files changed, 9 insertions, 0 deletions
diff --git a/activerecord/test/cases/calculations_test.rb b/activerecord/test/cases/calculations_test.rb index 8f2682c781..cfae700159 100644 --- a/activerecord/test/cases/calculations_test.rb +++ b/activerecord/test/cases/calculations_test.rb @@ -482,6 +482,10 @@ class CalculationsTest < ActiveRecord::TestCase assert_equal 1, Account.where(firm_name: '37signals').order(:firm_name).reverse_order.count end + def test_count_with_block + assert_equal 4, Account.count { |account| account.credit_limit.modulo(10).zero? } + end + def test_should_sum_expression # Oracle adapter returns floating point value 636.0 after SUM if current_adapter?(:OracleAdapter) diff --git a/activerecord/test/cases/relations_test.rb b/activerecord/test/cases/relations_test.rb index 95e4230a58..aa5766534f 100644 --- a/activerecord/test/cases/relations_test.rb +++ b/activerecord/test/cases/relations_test.rb @@ -1086,6 +1086,11 @@ class RelationTest < ActiveRecord::TestCase assert_equal 9, posts.where(:comments_count => 0).count end + def test_count_with_block + posts = Post.all + assert_equal 10, posts.count { |p| p.comments_count.even? } + end + def test_count_on_association_relation author = Author.last another_author = Author.first |