Skip to content

Commit b977309

Browse files
authored
Merge pull request rails#47992 from Shopify/add-coverage-for-cpk-calculations
[Tests only] Add coverage for `.count` calculations for a CPK model
2 parents 795d524 + cce2a18 commit b977309

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

activerecord/test/cases/calculations_test.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,17 @@ def test_distinct_count_with_group_by_and_order_and_limit
392392
assert_equal({ 6 => 2 }, Account.group(:firm_id).distinct.order("1 DESC").limit(1).count)
393393
end
394394

395+
def test_count_for_a_composite_primary_key_model
396+
book = cpk_books(:cpk_great_author_first_book)
397+
assert_equal(1, Cpk::Book.where(author_id: book.author_id, number: book.number).count)
398+
end
399+
400+
def test_group_by_count_for_a_composite_primary_key_model
401+
book = cpk_books(:cpk_great_author_first_book)
402+
expected = { book.author_id => Cpk::Book.where(author_id: book.author_id).count }
403+
assert_equal(expected, Cpk::Book.where(author_id: book.author_id).group(:author_id).count)
404+
end
405+
395406
def test_should_group_by_summed_field_having_condition
396407
c = Account.group(:firm_id).having("sum(credit_limit) > 50").sum(:credit_limit)
397408
assert_nil c[1]

0 commit comments

Comments
 (0)