From 4979857a2bd518f00d0b64b085b0fda51c193053 Mon Sep 17 00:00:00 2001 From: Aidan Haran Date: Wed, 1 Jan 2025 20:47:16 +0000 Subject: [PATCH] Coerce test (#1283) --- test/cases/coerced_tests.rb | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/test/cases/coerced_tests.rb b/test/cases/coerced_tests.rb index 21d419c9b..f3b16083c 100644 --- a/test/cases/coerced_tests.rb +++ b/test/cases/coerced_tests.rb @@ -376,6 +376,18 @@ def test_payload_row_count_on_raw_sql_coerced end class CalculationsTest < ActiveRecord::TestCase + # SELECT columns must be in the GROUP clause. + coerce_tests! :test_should_count_with_group_by_qualified_name_on_loaded + def test_should_count_with_group_by_qualified_name_on_loaded_coerced + accounts = Account.group("accounts.id").select("accounts.id") + expected = { 1 => 1, 2 => 1, 3 => 1, 4 => 1, 5 => 1, 6 => 1 } + assert_not_predicate accounts, :loaded? + assert_equal expected, accounts.count + accounts.load + assert_predicate accounts, :loaded? + assert_equal expected, accounts.count(:id) + end + # Fix randomly failing test. The loading of the model's schema was affecting the test. coerce_tests! :test_offset_is_kept def test_offset_is_kept_coerced