respond_to? information of AR is not the responsibility of the spec

resolver.
This commit is contained in:
Aaron Patterson 2011-11-29 11:48:55 -08:00
parent 2169603385
commit f73f53455a
2 changed files with 10 additions and 8 deletions

View File

@ -11,9 +11,8 @@ module ActiveRecord
class Resolver # :nodoc:
attr_reader :config, :klass, :configurations
def initialize(config, klass, configurations)
def initialize(config, configurations)
@config = config
@klass = klass
@configurations = configurations
end
@ -52,9 +51,6 @@ module ActiveRecord
end
adapter_method = "#{spec[:adapter]}_connection"
unless klass.respond_to?(adapter_method)
raise AdapterNotFound, "database configuration specifies nonexistent #{spec[:adapter]} adapter"
end
ConnectionSpecification.new(spec, adapter_method)
end
@ -127,9 +123,15 @@ module ActiveRecord
# The exceptions AdapterNotSpecified, AdapterNotFound and ArgumentError
# may be returned on an error.
def self.establish_connection(spec = ENV["DATABASE_URL"])
resolver = ConnectionSpecification::Resolver.new spec, self, configurations
resolver = ConnectionSpecification::Resolver.new spec, configurations
spec = resolver.spec
unless respond_to?(spec.adapter_method)
raise AdapterNotFound, "database configuration specifies nonexistent #{spec[:adapter]} adapter"
end
remove_connection
connection_handler.establish_connection name, resolver.spec
connection_handler.establish_connection name, spec
end
class << self

View File

@ -5,7 +5,7 @@ module ActiveRecord
class ConnectionSpecification
class ResolverTest < ActiveRecord::TestCase
def resolve(spec)
Resolver.new(spec, ActiveRecord::Base, {}).spec.config
Resolver.new(spec, {}).spec.config
end
def test_url_host_no_db