From 19537ecd0fcc888842a49007187c371fcb454d11 Mon Sep 17 00:00:00 2001 From: Sean Griffin Date: Thu, 1 Jan 2015 10:00:08 -0700 Subject: Stop relying on columns in sqlite quoting tests The string encoding test wasn't using the types for anything. The boolean casting test included logic that should be in the tests for the types, and the string test was legitimately not testing anything useful. --- .../test/cases/adapters/sqlite3/quoting_test.rb | 23 +--------------------- activerecord/test/cases/type/integer_test.rb | 6 ++++++ 2 files changed, 7 insertions(+), 22 deletions(-) (limited to 'activerecord/test') diff --git a/activerecord/test/cases/adapters/sqlite3/quoting_test.rb b/activerecord/test/cases/adapters/sqlite3/quoting_test.rb index ac8332e2fa..dd10995a1d 100644 --- a/activerecord/test/cases/adapters/sqlite3/quoting_test.rb +++ b/activerecord/test/cases/adapters/sqlite3/quoting_test.rb @@ -15,10 +15,9 @@ module ActiveRecord def test_type_cast_binary_encoding_without_logger @conn.extend(Module.new { def logger; end }) - column = Column.new(nil, nil, Type::String.new) binary = SecureRandom.hex expected = binary.dup.encode!(Encoding::UTF_8) - assert_equal expected, @conn.type_cast(binary, column) + assert_equal expected, @conn.type_cast(binary) end def test_type_cast_symbol @@ -47,31 +46,11 @@ module ActiveRecord end def test_type_cast_true - c = Column.new(nil, 1, Type::Integer.new) assert_equal 't', @conn.type_cast(true, nil) - assert_equal 1, @conn.type_cast(true, c) end def test_type_cast_false - c = Column.new(nil, 1, Type::Integer.new) assert_equal 'f', @conn.type_cast(false, nil) - assert_equal 0, @conn.type_cast(false, c) - end - - def test_type_cast_string - assert_equal '10', @conn.type_cast('10', nil) - - c = Column.new(nil, 1, Type::Integer.new) - assert_equal 10, @conn.type_cast('10', c) - - c = Column.new(nil, 1, Type::Float.new) - assert_equal 10.1, @conn.type_cast('10.1', c) - - c = Column.new(nil, 1, Type::Binary.new) - assert_equal '10.1', @conn.type_cast('10.1', c) - - c = Column.new(nil, 1, Type::Date.new) - assert_equal '10.1', @conn.type_cast('10.1', c) end def test_type_cast_bigdecimal diff --git a/activerecord/test/cases/type/integer_test.rb b/activerecord/test/cases/type/integer_test.rb index af4d0b4642..ff956b7680 100644 --- a/activerecord/test/cases/type/integer_test.rb +++ b/activerecord/test/cases/type/integer_test.rb @@ -41,6 +41,12 @@ module ActiveRecord assert_nil type.type_cast_from_user(1.0/0.0) end + test "casting booleans for database" do + type = Type::Integer.new + assert_equal 1, type.type_cast_for_database(true) + assert_equal 0, type.type_cast_for_database(false) + end + test "changed?" do type = Type::Integer.new -- cgit v1.2.3