Skip to content

Commit

Permalink
respond_to? information of AR is not the responsibility of the spec
Browse files Browse the repository at this point in the history
resolver.
  • Loading branch information
tenderlove committed Nov 29, 2011
1 parent 2169603 commit f73f534
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit f73f534

Please sign in to comment.