Skip to content

Commit

Permalink
Remove deprecated support to quoted_id when typecasting an Active R…
Browse files Browse the repository at this point in the history
…ecord object
  • Loading branch information
rafaelfranca committed Oct 23, 2017
1 parent 48766e3 commit 82472b3
Show file tree
Hide file tree
Showing 5 changed files with 4 additions and 71 deletions.
4 changes: 4 additions & 0 deletions activerecord/CHANGELOG.md
@@ -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 * Fix `bin/rails db:setup` and `bin/rails db:test:prepare` create wrong
ar_internal_metadata's data for a test database. ar_internal_metadata's data for a test database.


Expand Down
Expand Up @@ -11,19 +11,6 @@ module Quoting
def quote(value) def quote(value)
value = id_value_for_database(value) if value.is_a?(Base) 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) if value.respond_to?(:value_for_database)
value = value.value_for_database value = value.value_for_database
end end
Expand All @@ -37,10 +24,6 @@ def quote(value)
def type_cast(value, column = nil) def type_cast(value, column = nil)
value = id_value_for_database(value) if value.is_a?(Base) 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 if column
value = type_cast_from_column(column, value) value = type_cast_from_column(column, value)
end end
Expand Down
5 changes: 0 additions & 5 deletions activerecord/lib/active_record/sanitization.rb
Expand Up @@ -207,10 +207,5 @@ def raise_if_bind_arity_mismatch(statement, expected, provided)
end end
end 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
end end
37 changes: 0 additions & 37 deletions activerecord/test/cases/quoting_test.rb
Expand Up @@ -83,23 +83,6 @@ def test_quoted_datetime_local
end end
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 def test_quote_nil
assert_equal "NULL", @quoter.quote(nil) assert_equal "NULL", @quoter.quote(nil)
end end
Expand Down Expand Up @@ -207,26 +190,6 @@ def test_type_cast_unknown_should_raise_error
obj = Class.new.new obj = Class.new.new
assert_raise(TypeError) { @conn.type_cast(obj) } assert_raise(TypeError) { @conn.type_cast(obj) }
end 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 end


class QuoteBooleanTest < ActiveRecord::TestCase class QuoteBooleanTest < ActiveRecord::TestCase
Expand Down
12 changes: 0 additions & 12 deletions activerecord/test/cases/sanitize_test.rb
Expand Up @@ -153,18 +153,6 @@ def test_bind_chars
assert_equal "name=#{quoted_bambi_and_thumper}", bind("name=?", "Bambi\nand\nThumper".mb_chars) assert_equal "name=#{quoted_bambi_and_thumper}", bind("name=?", "Bambi\nand\nThumper".mb_chars)
end 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 def test_named_bind_with_postgresql_type_casts
l = Proc.new { bind(":a::integer '2009-01-01'::date", a: "10") } l = Proc.new { bind(":a::integer '2009-01-01'::date", a: "10") }
assert_nothing_raised(&l) assert_nothing_raised(&l)
Expand Down

0 comments on commit 82472b3

Please sign in to comment.