1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Merge pull request #28989 from matthewd/quoted_id-deprecation

Clarify deprecation message for #quoted_id
This commit is contained in:
Matthew Draper 2017-05-06 20:35:14 +09:30 committed by GitHub
commit e5434b0389
2 changed files with 22 additions and 2 deletions

View file

@ -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

View file

@ -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