basecamp/marginalia — pull request #42 by dylanahsmith (2014-11-21 00:20:56+00:00)
Title: Avoid connecting to the database to instrument active record.

cc @arthurnn

## Problem

It looks like there were two fixes for issue #2.
1. commit 0110a04a192f7474de9c667a9a373a540b58facd tried to fix it, but the check wasn't done right, so needed to get fixed by pull #21.
2. Another fix was pull #6

I dislike the solution in pull #6 since it connects to the database to make the check. This makes it hard to change the configuration (e.g. with mysql2 the configuration can't be changed after it connects), and it can make processes that don't need to use the database dependant on it being available.

## Solution

I removed the redundant fix which unnecessarily connected to the database.

## Testing

I used to following script to make sure this works as intended

```ruby
require 'active_record'
require 'action_controller'
require 'marginalia'
RAILS_ROOT = File.expand_path(File.dirname(__FILE__))

ActiveRecord::Base.establish_connection({
:adapter => ENV["DRIVER"] || "mysql",
:host => "localhost",
:username => ENV["DB_USERNAME"] || "root",
:database => "marginalia_test"
})

# notice that establish_connection doesn't actually connect to the database
fail if ActiveRecord::Base.connection_pool.active_connection?

# make sure issue #2 is still fixed
class ActiveRecord::ConnectionAdapters::SQLiteAdapter
end
fail if ActiveRecord::ConnectionAdapters::SQLiteAdapter.method_defined?(:execute)

Marginalia::Railtie.insert

# will fail if a connection was made to the database
fail if ActiveRecord::Base.connection_pool.active_connection?
```