mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Dont re-define class SQLite3Adapter on test
We were declaring in a few tests, which depending of
the order load will cause an error, as the super class could change.
see ac1c4e141b (commitcomment-17731383)
This commit is contained in:
parent
755f6bf3d3
commit
66ebbc4952
2 changed files with 87 additions and 97 deletions
|
@ -3,98 +3,92 @@ require 'bigdecimal'
|
||||||
require 'yaml'
|
require 'yaml'
|
||||||
require 'securerandom'
|
require 'securerandom'
|
||||||
|
|
||||||
module ActiveRecord
|
class SQLite3QuotingTest < ActiveRecord::SQLite3TestCase
|
||||||
module ConnectionAdapters
|
def setup
|
||||||
class SQLite3Adapter
|
@conn = ActiveRecord::Base.connection
|
||||||
class QuotingTest < ActiveRecord::SQLite3TestCase
|
end
|
||||||
def setup
|
|
||||||
@conn = ActiveRecord::Base.connection
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_type_cast_binary_encoding_without_logger
|
def test_type_cast_binary_encoding_without_logger
|
||||||
@conn.extend(Module.new { def logger; end })
|
@conn.extend(Module.new { def logger; end })
|
||||||
binary = SecureRandom.hex
|
binary = SecureRandom.hex
|
||||||
expected = binary.dup.encode!(Encoding::UTF_8)
|
expected = binary.dup.encode!(Encoding::UTF_8)
|
||||||
assert_equal expected, @conn.type_cast(binary)
|
assert_equal expected, @conn.type_cast(binary)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_type_cast_symbol
|
def test_type_cast_symbol
|
||||||
assert_equal 'foo', @conn.type_cast(:foo)
|
assert_equal 'foo', @conn.type_cast(:foo)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_type_cast_date
|
def test_type_cast_date
|
||||||
date = Date.today
|
date = Date.today
|
||||||
expected = @conn.quoted_date(date)
|
expected = @conn.quoted_date(date)
|
||||||
assert_equal expected, @conn.type_cast(date)
|
assert_equal expected, @conn.type_cast(date)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_type_cast_time
|
def test_type_cast_time
|
||||||
time = Time.now
|
time = Time.now
|
||||||
expected = @conn.quoted_date(time)
|
expected = @conn.quoted_date(time)
|
||||||
assert_equal expected, @conn.type_cast(time)
|
assert_equal expected, @conn.type_cast(time)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_type_cast_numeric
|
def test_type_cast_numeric
|
||||||
assert_equal 10, @conn.type_cast(10)
|
assert_equal 10, @conn.type_cast(10)
|
||||||
assert_equal 2.2, @conn.type_cast(2.2)
|
assert_equal 2.2, @conn.type_cast(2.2)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_type_cast_nil
|
def test_type_cast_nil
|
||||||
assert_equal nil, @conn.type_cast(nil)
|
assert_equal nil, @conn.type_cast(nil)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_type_cast_true
|
def test_type_cast_true
|
||||||
assert_equal 't', @conn.type_cast(true)
|
assert_equal 't', @conn.type_cast(true)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_type_cast_false
|
def test_type_cast_false
|
||||||
assert_equal 'f', @conn.type_cast(false)
|
assert_equal 'f', @conn.type_cast(false)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_type_cast_bigdecimal
|
def test_type_cast_bigdecimal
|
||||||
bd = BigDecimal.new '10.0'
|
bd = BigDecimal.new '10.0'
|
||||||
assert_equal bd.to_f, @conn.type_cast(bd)
|
assert_equal bd.to_f, @conn.type_cast(bd)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_type_cast_unknown_should_raise_error
|
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
|
def test_type_cast_object_which_responds_to_quoted_id
|
||||||
quoted_id_obj = Class.new {
|
quoted_id_obj = Class.new {
|
||||||
def quoted_id
|
def quoted_id
|
||||||
"'zomg'"
|
"'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
|
|
||||||
|
|
||||||
def test_quoting_binary_strings
|
|
||||||
value = "hello".encode('ascii-8bit')
|
|
||||||
type = Type::String.new
|
|
||||||
|
|
||||||
assert_equal "'hello'", @conn.quote(type.serialize(value))
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_quoted_time_returns_date_qualified_time
|
|
||||||
value = ::Time.utc(2000, 1, 1, 12, 30, 0, 999999)
|
|
||||||
type = Type::Time.new
|
|
||||||
|
|
||||||
assert_equal "'2000-01-01 12:30:00.999999'", @conn.quote(type.serialize(value))
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
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
|
||||||
|
|
||||||
|
def test_quoting_binary_strings
|
||||||
|
value = "hello".encode('ascii-8bit')
|
||||||
|
type = Type::String.new
|
||||||
|
|
||||||
|
assert_equal "'hello'", @conn.quote(type.serialize(value))
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_quoted_time_returns_date_qualified_time
|
||||||
|
value = ::Time.utc(2000, 1, 1, 12, 30, 0, 999999)
|
||||||
|
type = Type::Time.new
|
||||||
|
|
||||||
|
assert_equal "'2000-01-01 12:30:00.999999'", @conn.quote(type.serialize(value))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,24 +1,20 @@
|
||||||
require 'cases/helper'
|
require 'cases/helper'
|
||||||
|
|
||||||
module ActiveRecord::ConnectionAdapters
|
class SQLite3StatementPoolTest < ActiveRecord::SQLite3TestCase
|
||||||
class SQLite3Adapter
|
if Process.respond_to?(:fork)
|
||||||
class StatementPoolTest < ActiveRecord::SQLite3TestCase
|
def test_cache_is_per_pid
|
||||||
if Process.respond_to?(:fork)
|
|
||||||
def test_cache_is_per_pid
|
|
||||||
|
|
||||||
cache = StatementPool.new(10)
|
cache = StatementPool.new(10)
|
||||||
cache['foo'] = 'bar'
|
cache['foo'] = 'bar'
|
||||||
assert_equal 'bar', cache['foo']
|
assert_equal 'bar', cache['foo']
|
||||||
|
|
||||||
pid = fork {
|
pid = fork {
|
||||||
lookup = cache['foo'];
|
lookup = cache['foo'];
|
||||||
exit!(!lookup)
|
exit!(!lookup)
|
||||||
}
|
}
|
||||||
|
|
||||||
Process.waitpid pid
|
Process.waitpid pid
|
||||||
assert $?.success?, 'process should exit successfully'
|
assert $?.success?, 'process should exit successfully'
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue