Permalink
Browse files

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

resolver.
  • Loading branch information...
1 parent 2169603 commit f73f53455a01a93bd90cb8c0cee1a7c54afdb301 @tenderlove tenderlove committed Nov 29, 2011
@@ -11,9 +11,8 @@ def initialize (config, adapter_method)
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 @@ def resolve_hash_connection(spec) # :nodoc:
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 @@ def connection
# 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
@@ -5,7 +5,7 @@ class Base
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

0 comments on commit f73f534

Please sign in to comment.