aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorRyuta Kamizono <kamipo@gmail.com>2019-01-02 04:15:32 +0900
committerRyuta Kamizono <kamipo@gmail.com>2019-01-02 04:15:32 +0900
commit600a66f60c76cb2d32fbf7abe4e37d509fdade47 (patch)
tree85f4a5b299a9c626f5cebf7b5f7e515485545685 /activerecord
parenta426615fb178bd7c90dba875dba53eaadd7393db (diff)
downloadrails-600a66f60c76cb2d32fbf7abe4e37d509fdade47.tar.gz
rails-600a66f60c76cb2d32fbf7abe4e37d509fdade47.tar.bz2
rails-600a66f60c76cb2d32fbf7abe4e37d509fdade47.zip
Fix TypeError: no implicit conversion of Arel::Attributes::Attribute into String properly
This reverts 27c6c07 since `arel_attr.to_s` is not right way to avoid the type error. That to_s returns `"#<struct Arel::Attributes::Attribute ...>"`, there is no reason to match the regex to the inspect form. And also, the regex path is not covered by our test cases. I've tweaked the regex for redundant part and added assertions for the regex path.
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/lib/active_record/relation/calculations.rb2
-rw-r--r--activerecord/test/cases/calculations_test.rb2
2 files changed, 3 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/relation/calculations.rb b/activerecord/lib/active_record/relation/calculations.rb
index 0fa5ba2e50..3ef6e7928f 100644
--- a/activerecord/lib/active_record/relation/calculations.rb
+++ b/activerecord/lib/active_record/relation/calculations.rb
@@ -245,7 +245,7 @@ module ActiveRecord
if distinct && (group_values.any? || select_values.empty? && order_values.empty?)
column_name = primary_key
end
- elsif /\s*DISTINCT[\s(]+/i.match?(column_name.to_s)
+ elsif column_name.is_a?(::String) && /\bDISTINCT[\s(]/i.match?(column_name)
distinct = nil
end
end
diff --git a/activerecord/test/cases/calculations_test.rb b/activerecord/test/cases/calculations_test.rb
index 4d3db912c5..5b5202d167 100644
--- a/activerecord/test/cases/calculations_test.rb
+++ b/activerecord/test/cases/calculations_test.rb
@@ -432,6 +432,8 @@ class CalculationsTest < ActiveRecord::TestCase
def test_should_count_selected_field_with_include
assert_equal 6, Account.includes(:firm).distinct.count
assert_equal 4, Account.includes(:firm).distinct.select(:credit_limit).count
+ assert_equal 4, Account.includes(:firm).distinct.count("DISTINCT credit_limit")
+ assert_equal 4, Account.includes(:firm).distinct.count("DISTINCT(credit_limit)")
end
def test_should_not_perform_joined_include_by_default