aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Draper <matthew@trebex.net>2017-05-05 18:07:12 +0930
committerMatthew Draper <matthew@trebex.net>2017-05-05 18:22:16 +0930
commitae73637e35db20d0c4e14959d8c1274e5399278e (patch)
tree3a6103304320d0cd9cfc7f2dbf56eb1f97c181ee
parent3d890b66c1bfbdcabb7ef66e0774e0f01e2ed5d6 (diff)
downloadrails-ae73637e35db20d0c4e14959d8c1274e5399278e.tar.gz
rails-ae73637e35db20d0c4e14959d8c1274e5399278e.tar.bz2
rails-ae73637e35db20d0c4e14959d8c1274e5399278e.zip
Clarify deprecation message for #quoted_id
In this case, it's the method definition that's more at fault, rather than the current caller.
-rw-r--r--activerecord/lib/active_record/connection_adapters/abstract/quoting.rb9
-rw-r--r--activerecord/test/cases/quoting_test.rb15
2 files changed, 22 insertions, 2 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/abstract/quoting.rb b/activerecord/lib/active_record/connection_adapters/abstract/quoting.rb
index f0c0fbab6c..61233dcc51 100644
--- a/activerecord/lib/active_record/connection_adapters/abstract/quoting.rb
+++ b/activerecord/lib/active_record/connection_adapters/abstract/quoting.rb
@@ -10,8 +10,15 @@ module ActiveRecord
value = id_value_for_database(value) if value.is_a?(Base)
if value.respond_to?(:quoted_id)
+ at = value.method(:quoted_id).source_location
+ at &&= " at %s:%d" % at
+
+ owner = value.method(:quoted_id).owner.to_s
+ klass = value.class.to_s
+ klass += "(#{owner})" unless owner == klass
+
ActiveSupport::Deprecation.warn \
- "Using #quoted_id is deprecated and will be removed in Rails 5.2."
+ "Defining #quoted_id is deprecated and will be ignored in Rails 5.2. (defined on #{klass}#{at})"
return value.quoted_id
end
diff --git a/activerecord/test/cases/quoting_test.rb b/activerecord/test/cases/quoting_test.rb
index f260d043e4..f647526fbc 100644
--- a/activerecord/test/cases/quoting_test.rb
+++ b/activerecord/test/cases/quoting_test.rb
@@ -81,8 +81,21 @@ module ActiveRecord
end
end
+ class QuotedOne
+ def quoted_id
+ 1
+ end
+ end
+ class SubQuotedOne < QuotedOne
+ end
def test_quote_with_quoted_id
- assert_deprecated { assert_equal 1, @quoter.quote(Struct.new(:quoted_id).new(1)) }
+ assert_deprecated /defined on \S+::QuotedOne at .*quoting_test\.rb:[0-9]/ do
+ assert_equal 1, @quoter.quote(QuotedOne.new)
+ end
+
+ assert_deprecated /defined on \S+::SubQuotedOne\(\S+::QuotedOne\) at .*quoting_test\.rb:[0-9]/ do
+ assert_equal 1, @quoter.quote(SubQuotedOne.new)
+ end
end
def test_quote_nil