提交 19537ecd 编写于 作者: S Sean Griffin

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.
上级 03f6e235
......@@ -15,10 +15,9 @@ def setup
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 @@ def test_type_cast_nil
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
......
......@@ -41,6 +41,12 @@ class IntegerTest < ActiveRecord::TestCase
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
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册