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

Don't use column object for type casting in quoting

We're never going to be able to use the attribute object here, however,
so let's just accept the ugly demeter violation here for now.

Remove test cases which were either redundant with other tests in the
file, or were actually testing the type objects (which are tested
elsewhere)
This commit is contained in:
Sean Griffin 2014-06-18 05:55:36 -06:00
parent dccf6da66b
commit 0336efaae8
3 changed files with 6 additions and 31 deletions

View file

@ -14,8 +14,8 @@ module ActiveRecord
# value. Is this really the only case? Are we missing tests for other types? # value. Is this really the only case? Are we missing tests for other types?
# We should have a real column object passed (or nil) here, and check for that # We should have a real column object passed (or nil) here, and check for that
# instead # instead
if column.respond_to?(:type_cast_for_database) if column.respond_to?(:cast_type)
value = column.type_cast_for_database(value) value = column.cast_type.type_cast_for_database(value)
end end
_quote(value) _quote(value)
@ -34,8 +34,8 @@ module ActiveRecord
# value. Is this really the only case? Are we missing tests for other types? # value. Is this really the only case? Are we missing tests for other types?
# We should have a real column object passed (or nil) here, and check for that # We should have a real column object passed (or nil) here, and check for that
# instead # instead
if column.respond_to?(:type_cast_for_database) if column.respond_to?(:cast_type)
value = column.type_cast_for_database(value) value = column.cast_type.type_cast_for_database(value)
end end
_type_cast(value) _type_cast(value)

View file

@ -179,8 +179,8 @@ module ActiveRecord
end end
def array_column(column) def array_column(column)
if column.array && !column.respond_to?(:type_cast_for_database) if column.array && !column.respond_to?(:cast_type)
OID::Array.new(AdapterProxyType.new(column, self)) Column.new('', nil, OID::Array.new(AdapterProxyType.new(column, self)))
else else
column column
end end

View file

@ -93,12 +93,10 @@ module ActiveRecord
def test_quote_true def test_quote_true
assert_equal @quoter.quoted_true, @quoter.quote(true, nil) assert_equal @quoter.quoted_true, @quoter.quote(true, nil)
assert_equal '1', @quoter.quote(true, Type::Integer.new)
end end
def test_quote_false def test_quote_false
assert_equal @quoter.quoted_false, @quoter.quote(false, nil) assert_equal @quoter.quoted_false, @quoter.quote(false, nil)
assert_equal '0', @quoter.quote(false, Type::Integer.new)
end end
def test_quote_float def test_quote_float
@ -157,25 +155,6 @@ module ActiveRecord
assert_equal "'lo\\\\l'", @quoter.quote(string, nil) assert_equal "'lo\\\\l'", @quoter.quote(string, nil)
end end
def test_quote_string_int_column
assert_equal "1", @quoter.quote('1', Type::Integer.new)
assert_equal "1", @quoter.quote('1.2', Type::Integer.new)
end
def test_quote_string_float_column
assert_equal "1.0", @quoter.quote('1', Type::Float.new)
assert_equal "1.2", @quoter.quote('1.2', Type::Float.new)
end
def test_quote_as_mb_chars_binary_column
string = ActiveSupport::Multibyte::Chars.new('lo\l')
assert_equal "'lo\\\\l'", @quoter.quote(string, Type::Binary.new)
end
def test_quote_binary_without_string_to_binary
assert_equal "'lo\\\\l'", @quoter.quote('lo\l', Type::Binary.new)
end
def test_string_with_crazy_column def test_string_with_crazy_column
assert_equal "'lo\\\\l'", @quoter.quote('lo\l') assert_equal "'lo\\\\l'", @quoter.quote('lo\l')
end end
@ -183,10 +162,6 @@ module ActiveRecord
def test_quote_duration def test_quote_duration
assert_equal "1800", @quoter.quote(30.minutes) assert_equal "1800", @quoter.quote(30.minutes)
end end
def test_quote_duration_int_column
assert_equal "7200", @quoter.quote(2.hours, Type::Integer.new)
end
end end
end end
end end