diff --git a/activerecord/test/cases/calculations_test.rb b/activerecord/test/cases/calculations_test.rb index 0fb21dce85..10d6bbfdf5 100644 --- a/activerecord/test/cases/calculations_test.rb +++ b/activerecord/test/cases/calculations_test.rb @@ -392,6 +392,17 @@ def test_distinct_count_with_group_by_and_order_and_limit assert_equal({ 6 => 2 }, Account.group(:firm_id).distinct.order("1 DESC").limit(1).count) end + def test_count_for_a_composite_primary_key_model + book = cpk_books(:cpk_great_author_first_book) + assert_equal(1, Cpk::Book.where(author_id: book.author_id, number: book.number).count) + end + + def test_group_by_count_for_a_composite_primary_key_model + book = cpk_books(:cpk_great_author_first_book) + expected = { book.author_id => Cpk::Book.where(author_id: book.author_id).count } + assert_equal(expected, Cpk::Book.where(author_id: book.author_id).group(:author_id).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]