From bf1494a1018a0bdc50dac4e87fdbf4b6b03083fa Mon Sep 17 00:00:00 2001 From: Ryuta Kamizono Date: Mon, 8 Apr 2019 17:43:56 +0900 Subject: Fix GROUP BY with calculate longer name field to respect `table_alias_length` Follow up of c9e4c848eeeb8999b778fa1ae52185ca5537fffe. --- activerecord/test/cases/calculations_test.rb | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'activerecord/test/cases') diff --git a/activerecord/test/cases/calculations_test.rb b/activerecord/test/cases/calculations_test.rb index c4070fc341..16c2a3661d 100644 --- a/activerecord/test/cases/calculations_test.rb +++ b/activerecord/test/cases/calculations_test.rb @@ -363,6 +363,17 @@ class CalculationsTest < ActiveRecord::TestCase assert_equal 60, c[2] end + def test_should_calculate_grouped_with_longer_field + field = "a" * Account.connection.max_identifier_length + + Account.update_all("#{field} = credit_limit") + + c = Account.group(:firm_id).sum(field) + assert_equal 50, c[1] + assert_equal 105, c[6] + assert_equal 60, c[2] + end + def test_should_calculate_with_invalid_field assert_equal 6, Account.calculate(:count, "*") assert_equal 6, Account.calculate(:count, :all) -- cgit v1.2.3