mirror of
https://github.com/github/rails.git
synced 2026-04-26 03:00:59 -04:00
adding adapter tests, avoiding private apis, fixing code in 1.9 [#4986 state:resolved]
Signed-off-by: José Valim <jose.valim@gmail.com>
This commit is contained in:
committed by
José Valim
parent
5b91c97763
commit
100d2282e3
@@ -6,6 +6,10 @@ module ActiveRecord
|
||||
def self.sqlite3_connection(config) # :nodoc:
|
||||
parse_sqlite_config!(config)
|
||||
|
||||
unless 'sqlite3' == config[:adapter]
|
||||
raise ArgumentError, 'adapter name should be "sqlite3"'
|
||||
end
|
||||
|
||||
unless self.class.const_defined?(:SQLite3)
|
||||
require_library_or_gem(config[:adapter])
|
||||
end
|
||||
@@ -24,13 +28,13 @@ module ActiveRecord
|
||||
|
||||
module ConnectionAdapters #:nodoc:
|
||||
class SQLite3Adapter < SQLiteAdapter # :nodoc:
|
||||
|
||||
|
||||
# Returns the current database encoding format as a string, eg: 'UTF-8'
|
||||
def encoding
|
||||
if @connection.respond_to?(:encoding)
|
||||
@connection.encoding[0]['encoding']
|
||||
@connection.encoding.to_s
|
||||
else
|
||||
encoding = @connection.send(:get_query_pragma, 'encoding')
|
||||
encoding = @connection.execute('PRAGMA encoding')
|
||||
encoding[0]['encoding']
|
||||
end
|
||||
end
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
require "cases/helper"
|
||||
|
||||
module ActiveRecord
|
||||
module ConnectionAdapters
|
||||
class SQLite3AdapterTest < ActiveRecord::TestCase
|
||||
def test_connection_no_db
|
||||
assert_raises(ArgumentError) do
|
||||
Base.sqlite3_connection {}
|
||||
end
|
||||
end
|
||||
|
||||
def test_connection_no_adapter
|
||||
assert_raises(ArgumentError) do
|
||||
Base.sqlite3_connection :database => ':memory:'
|
||||
end
|
||||
end
|
||||
|
||||
def test_connection_wrong_adapter
|
||||
assert_raises(ArgumentError) do
|
||||
Base.sqlite3_connection :database => ':memory:',:adapter => 'vuvuzela'
|
||||
end
|
||||
end
|
||||
|
||||
def test_bad_timeout
|
||||
assert_raises(TypeError) do
|
||||
Base.sqlite3_connection :database => ':memory:',
|
||||
:adapter => 'sqlite3',
|
||||
:timeout => 'usa'
|
||||
end
|
||||
end
|
||||
|
||||
# connection is OK with a nil timeout
|
||||
def test_nil_timeout
|
||||
conn = Base.sqlite3_connection :database => ':memory:',
|
||||
:adapter => 'sqlite3',
|
||||
:timeout => nil
|
||||
assert conn, 'made a connection'
|
||||
end
|
||||
|
||||
def test_connect
|
||||
conn = Base.sqlite3_connection :database => ':memory:',
|
||||
:adapter => 'sqlite3',
|
||||
:timeout => 100
|
||||
assert conn, 'should have connection'
|
||||
end
|
||||
|
||||
# sqlite3 defaults to UTF-8 encoding
|
||||
def test_encoding
|
||||
conn = Base.sqlite3_connection :database => ':memory:',
|
||||
:adapter => 'sqlite3',
|
||||
:timeout => 100
|
||||
assert_equal 'UTF-8', conn.encoding
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user