aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/calculations_test.rb
diff options
context:
space:
mode:
authorSean Griffin <sean@seantheprogrammer.com>2016-07-11 10:43:02 -0400
committerSean Griffin <sean@seantheprogrammer.com>2016-07-11 10:57:37 -0400
commita45363a2fb53e0a016f33dd211c00b5d81764379 (patch)
treea6000f5b52353c689b6e9867ab0b73a13df3143a /activerecord/test/cases/calculations_test.rb
parent79bc06647ccb77840877f2d8e3dcf620460d7306 (diff)
downloadrails-a45363a2fb53e0a016f33dd211c00b5d81764379.tar.gz
rails-a45363a2fb53e0a016f33dd211c00b5d81764379.tar.bz2
rails-a45363a2fb53e0a016f33dd211c00b5d81764379.zip
Always prefer class types to query types when casting `group`
When `group` is used in combination with any calculation method, the resulting hash uses the grouping expression as the key. Currently we're incorrectly always favoring the type reported by the query, instead of the type known by the class. This causes differing behavior depending on whether the adaptor actually gives proper types with the query or not. After this change, the behavior will be the same on all adaptors -- we see if we know the type from the class, fall back to the type from the query, and finally fall back to the identity type. Fixes #25595
Diffstat (limited to 'activerecord/test/cases/calculations_test.rb')
-rw-r--r--activerecord/test/cases/calculations_test.rb6
1 files changed, 6 insertions, 0 deletions
diff --git a/activerecord/test/cases/calculations_test.rb b/activerecord/test/cases/calculations_test.rb
index cfae700159..06c2f10dc6 100644
--- a/activerecord/test/cases/calculations_test.rb
+++ b/activerecord/test/cases/calculations_test.rb
@@ -1,4 +1,5 @@
require "cases/helper"
+require "models/book"
require 'models/club'
require 'models/company'
require "models/contract"
@@ -793,4 +794,9 @@ class CalculationsTest < ActiveRecord::TestCase
assert_equal 50, result[1].credit_limit
assert_equal 50, result[2].credit_limit
end
+
+ def test_group_by_attribute_with_custom_type
+ Book.create!(status: :published)
+ assert_equal({ "published" => 1 }, Book.group(:status).count)
+ end
end