Permalink
Browse files

log which config format AR uses to connect with

  • Loading branch information...
1 parent 93f25ac commit d46ad3460a5c8bffae1a907a11ba6ce3fec4de87 @hone hone committed Apr 4, 2012
@@ -72,9 +72,13 @@ class Railtie < Rails::Railtie
# and then establishes the connection.
initializer "active_record.initialize_database" do |app|
ActiveSupport.on_load(:active_record) do
+ db_connection_type = "DATABASE_URL"
unless ENV['DATABASE_URL']
+ db_connection_type = "database.yml"
self.configurations = app.config.database_configuration
end
+ Rails.logger.info "Connecting to database specified by #{db_connection_type}"
+
establish_connection
end
end
@@ -39,5 +39,24 @@ def teardown
# clean up
FileUtils.rm("#{app_path}/#{database_path}")
end
+
+ test "DATABASE_URL env var takes precedence over config/database.yml" do
+ database_path = "/db/foo.sqlite3"
+ ENV['DATABASE_URL'] = "sqlite3://#{database_path}"
+ simple_controller
+
+ get '/foo'
+ assert File.read("#{app_path}/log/production.log").include?("DATABASE_URL")
+
+ # clean up
+ FileUtils.rm("#{app_path}/#{database_path}")
+ end
+
+ test "logs the use of config/database.yml" do
+ simple_controller
+
+ get '/foo'
+ assert File.read("#{app_path}/log/production.log").include?("database.yml")
+ end
end
end

0 comments on commit d46ad34

Please sign in to comment.