fix url connections for sqlite3

This commit is contained in:
Aaron Patterson 2013-12-20 16:13:34 -08:00
parent d0ffa7f853
commit fbb79b517f
2 changed files with 34 additions and 1 deletions

@ -69,11 +69,22 @@ def connection_url_to_hash(url) # :nodoc:
config = URI.parse url
adapter = config.scheme
adapter = "postgresql" if adapter == "postgres"
database = if adapter == 'sqlite3'
if '/:memory:' == config.path
':memory:'
else
config.path
end
else
config.path.sub(%r{^/},"")
end
spec = { :adapter => adapter,
:username => config.user,
:password => config.password,
:port => config.port,
:database => config.path.sub(%r{^/},""),
:database => database,
:host => config.host }
spec.reject!{ |_,value| value.blank? }

@ -1,6 +1,7 @@
# encoding: utf-8
require "cases/helper"
require 'models/owner'
require 'tempfile'
module ActiveRecord
module ConnectionAdapters
@ -25,6 +26,27 @@ def setup
ActiveSupport::Notifications.subscribe('sql.active_record', @subscriber)
end
def test_connect_with_url
original_connection = ActiveRecord::Base.remove_connection
tf = Tempfile.open 'whatever'
url = "sqlite3://#{tf.path}"
ActiveRecord::Base.establish_connection(url)
assert ActiveRecord::Base.connection
ensure
tf.close
tf.unlink
ActiveRecord::Base.establish_connection(original_connection)
end
def test_connect_memory_with_url
original_connection = ActiveRecord::Base.remove_connection
url = "sqlite3:///:memory:"
ActiveRecord::Base.establish_connection(url)
assert ActiveRecord::Base.connection
ensure
ActiveRecord::Base.establish_connection(original_connection)
end
def test_valid_column
column = @conn.columns('items').find { |col| col.name == 'id' }
assert @conn.valid_type?(column.type)