Permalink
Browse files

Remove deprecated support to `quoted_id` when typecasting an Active R…

…ecord object
  • Loading branch information...
rafaelfranca committed Jul 17, 2017
1 parent 48766e3 commit 82472b3922bda2f337a79cef961b4760d04f9689
@@ -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 Quoting
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 @@ def quote(value)
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 @@ def raise_if_bind_arity_mismatch(statement, expected, provided)
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 @@ def test_quoted_datetime_local
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 @@ def test_type_cast_unknown_should_raise_error
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 @@ def test_bind_chars
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)

0 comments on commit 82472b3

Please sign in to comment.