diff options
author | Rafael França <rafaelmfranca@gmail.com> | 2017-07-24 14:50:14 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-07-24 14:50:14 -0400 |
commit | 06dff4d7da6bfec842e94e1585cd1af9d048e6a4 (patch) | |
tree | 8e24fef4737eb2c95dc2c94020cdf3fa93983727 /activerecord/test/cases | |
parent | 3a4a775732a0512d5ef0c97c2bbeb03110766715 (diff) | |
parent | 3293ca6d38b42582c95ae7f6eaf6c0bd8eef2d65 (diff) | |
download | rails-06dff4d7da6bfec842e94e1585cd1af9d048e6a4.tar.gz rails-06dff4d7da6bfec842e94e1585cd1af9d048e6a4.tar.bz2 rails-06dff4d7da6bfec842e94e1585cd1af9d048e6a4.zip |
Merge pull request #29848 from kamipo/fix_distinct_count_with_order_and_limit
Fix `COUNT(DISTINCT ...)` with `ORDER BY` and `LIMIT`
Diffstat (limited to 'activerecord/test/cases')
-rw-r--r-- | activerecord/test/cases/calculations_test.rb | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/activerecord/test/cases/calculations_test.rb b/activerecord/test/cases/calculations_test.rb index dd6815b149..92d071187d 100644 --- a/activerecord/test/cases/calculations_test.rb +++ b/activerecord/test/cases/calculations_test.rb @@ -236,6 +236,30 @@ class CalculationsTest < ActiveRecord::TestCase end end + def test_distinct_count_with_order_and_limit + assert_equal 4, Account.distinct.order(:firm_id).limit(4).count + end + + def test_distinct_count_with_order_and_offset + assert_equal 4, Account.distinct.order(:firm_id).offset(2).count + end + + def test_distinct_count_with_order_and_limit_and_offset + assert_equal 4, Account.distinct.order(:firm_id).limit(4).offset(2).count + end + + def test_distinct_joins_count_with_order_and_limit + assert_equal 3, Account.joins(:firm).distinct.order(:firm_id).limit(3).count + end + + def test_distinct_joins_count_with_order_and_offset + assert_equal 3, Account.joins(:firm).distinct.order(:firm_id).offset(2).count + end + + def test_distinct_joins_count_with_order_and_limit_and_offset + assert_equal 3, Account.joins(:firm).distinct.order(:firm_id).limit(3).offset(2).count + end + def test_should_group_by_summed_field_having_condition c = Account.group(:firm_id).having("sum(credit_limit) > 50").sum(:credit_limit) assert_nil c[1] |