aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/calculations_test.rb
diff options
context:
space:
mode:
authorRyuta Kamizono <kamipo@gmail.com>2019-04-08 17:43:56 +0900
committerRyuta Kamizono <kamipo@gmail.com>2019-04-08 17:46:46 +0900
commitbf1494a1018a0bdc50dac4e87fdbf4b6b03083fa (patch)
tree7a84a832f964f4ace8944d6f094b5e52864d4df0 /activerecord/test/cases/calculations_test.rb
parent57c7cbb1623c0e8befc58988a34bbb9896fd226a (diff)
downloadrails-bf1494a1018a0bdc50dac4e87fdbf4b6b03083fa.tar.gz
rails-bf1494a1018a0bdc50dac4e87fdbf4b6b03083fa.tar.bz2
rails-bf1494a1018a0bdc50dac4e87fdbf4b6b03083fa.zip
Fix GROUP BY with calculate longer name field to respect `table_alias_length`
Follow up of c9e4c848eeeb8999b778fa1ae52185ca5537fffe.
Diffstat (limited to 'activerecord/test/cases/calculations_test.rb')
-rw-r--r--activerecord/test/cases/calculations_test.rb11
1 files changed, 11 insertions, 0 deletions
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)