mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Remove deprecated support to quoted_id
when typecasting an Active Record object
This commit is contained in:
parent
48766e32d3
commit
82472b3922
5 changed files with 4 additions and 71 deletions
|
@ -1,3 +1,7 @@
|
|||
* Remove deprecated support to `quoted_id` when typecasting an Active Record object.
|
||||
|
||||
*Rafael Mendonça França*
|
||||
|
||||
* Fix `bin/rails db:setup` and `bin/rails db:test:prepare` create wrong
|
||||
ar_internal_metadata's data for a test database.
|
||||
|
||||
|
|
|
@ -11,19 +11,6 @@ module ActiveRecord
|
|||
def quote(value)
|
||||
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 \
|
||||
"Defining #quoted_id is deprecated and will be ignored in Rails 5.2. (defined on #{klass}#{at})"
|
||||
return value.quoted_id
|
||||
end
|
||||
|
||||
if value.respond_to?(:value_for_database)
|
||||
value = value.value_for_database
|
||||
end
|
||||
|
@ -37,10 +24,6 @@ module ActiveRecord
|
|||
def type_cast(value, column = nil)
|
||||
value = id_value_for_database(value) if value.is_a?(Base)
|
||||
|
||||
if value.respond_to?(:quoted_id) && value.respond_to?(:id)
|
||||
return value.id
|
||||
end
|
||||
|
||||
if column
|
||||
value = type_cast_from_column(column, value)
|
||||
end
|
||||
|
|
|
@ -207,10 +207,5 @@ module ActiveRecord
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
def quoted_id # :nodoc:
|
||||
self.class.connection.quote(@attributes[self.class.primary_key].value_for_database)
|
||||
end
|
||||
deprecate :quoted_id
|
||||
end
|
||||
end
|
||||
|
|
|
@ -83,23 +83,6 @@ module ActiveRecord
|
|||
end
|
||||
end
|
||||
|
||||
class QuotedOne
|
||||
def quoted_id
|
||||
1
|
||||
end
|
||||
end
|
||||
class SubQuotedOne < QuotedOne
|
||||
end
|
||||
def test_quote_with_quoted_id
|
||||
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
|
||||
assert_equal "NULL", @quoter.quote(nil)
|
||||
end
|
||||
|
@ -207,26 +190,6 @@ module ActiveRecord
|
|||
obj = Class.new.new
|
||||
assert_raise(TypeError) { @conn.type_cast(obj) }
|
||||
end
|
||||
|
||||
def test_type_cast_object_which_responds_to_quoted_id
|
||||
quoted_id_obj = Class.new {
|
||||
def quoted_id
|
||||
"'zomg'"
|
||||
end
|
||||
|
||||
def id
|
||||
10
|
||||
end
|
||||
}.new
|
||||
assert_equal 10, @conn.type_cast(quoted_id_obj)
|
||||
|
||||
quoted_id_obj = Class.new {
|
||||
def quoted_id
|
||||
"'zomg'"
|
||||
end
|
||||
}.new
|
||||
assert_raise(TypeError) { @conn.type_cast(quoted_id_obj) }
|
||||
end
|
||||
end
|
||||
|
||||
class QuoteBooleanTest < ActiveRecord::TestCase
|
||||
|
|
|
@ -153,18 +153,6 @@ class SanitizeTest < ActiveRecord::TestCase
|
|||
assert_equal "name=#{quoted_bambi_and_thumper}", bind("name=?", "Bambi\nand\nThumper".mb_chars)
|
||||
end
|
||||
|
||||
def test_bind_record
|
||||
o = Class.new {
|
||||
def quoted_id
|
||||
1
|
||||
end
|
||||
}.new
|
||||
assert_deprecated { assert_equal "1", bind("?", o) }
|
||||
|
||||
os = [o] * 3
|
||||
assert_deprecated { assert_equal "1,1,1", bind("?", os) }
|
||||
end
|
||||
|
||||
def test_named_bind_with_postgresql_type_casts
|
||||
l = Proc.new { bind(":a::integer '2009-01-01'::date", a: "10") }
|
||||
assert_nothing_raised(&l)
|
||||
|
|
Loading…
Reference in a new issue