Why does Rails do this?

i was trying to run tests for the sentry plugin and they failed when
using fixtures

activerecord’s fixtures.rb reads:

  def setup_with_fixtures
    return unless defined?(ActiveRecord::Base) &&

!ActiveRecord::Base.configurations.blank?

This quietly fails to setup fixtures, causing errors later and elsewhere
when you try to use a fixture. Not fun to track down. i got sentry’s
tests to run by adding:

ActiveRecord::Base.configurations[:nothing] = true

if that works, why check for blank config? apparently none is necessary.
alternatively, if blank config is an error, shouldn’t Rails raise
something instead of ignore it?

On Oct 12, 1:28 pm, Elliot T. [email protected]
wrote:

when you try to use a fixture. Not fun to track down. i got sentry’s
tests to run by adding:

Fixtures are for loading test data into your test database. The code
here is doing a basic sanity check: first, that ActiveRecord is
defined in your project (should be) and that the database
configurations have been loaded (from database.yml).

ActiveRecord::Base.configurations[:nothing] = true

if that works, why check for blank config? apparently none is necessary.
alternatively, if blank config is an error, shouldn’t Rails raise
something instead of ignore it?

You’ve put something in there to make the sanity check “think” you’ve
configured the database, but you really haven’t.

Sounds like your plugin is being loaded before the Rails has had a
chance to initialize - that’s the real problem here.

Hope this helps
Jeff

essentialrails.com

Jeff C. wrote:

On Oct 12, 1:28 pm, Elliot T. [email protected]
wrote:

when you try to use a fixture. Not fun to track down. i got sentry’s
tests to run by adding:

Fixtures are for loading test data into your test database. The code
here is doing a basic sanity check: first, that ActiveRecord is
defined in your project (should be) and that the database
configurations have been loaded (from database.yml).

I understand having a sanity check, but I don’t understand failing
quietly, so you get an error later and elsewhere b/c a variable wasn’t
initialized b/c the setup just returned.

You’ve put something in there to make the sanity check “think” you’ve
configured the database, but you really haven’t.

Sounds like your plugin is being loaded before the Rails has had a
chance to initialize - that’s the real problem here.

The thing is: it works when I trick it. It is loading active record and
connecting to the database, and the fixtures are loading data into the
database and the tests pass – all with the configurations blank. Here’s
some relevant code. Maybe the establish_connection call is improper?
cause it’s using the db config but without activerecord getting fully
clued in.

require ‘active_record’
require ‘active_record/fixtures’
config_location = File.dirname(FILE) + ‘/database.yml’
config = YAML::load(IO.read(config_location))
ActiveRecord::Base.establish_connection(config[ENV[‘DB’] || ‘mysql’])