# Why does Rails do this?

**URL:** <https://www.ruby-forum.com/t/why-does-rails-do-this/117087>\
**Category:** Rails\
**Created:** [October 12, 2007, 8:28pm UTC](https://www.ruby-forum.com/t/why-does-rails-do-this/117087 "2007-10-12T20:28:33Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![curi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/e68b1a/32.png) [@curi](https://www.ruby-forum.com/u/curi)\
**Post date:** [October 12, 2007, 8:28pm UTC](https://www.ruby-forum.com/t/why-does-rails-do-this/117087/1 "2007-10-12T20:28:33Z")

</div>

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?

- Elliot T.  
[www.curi.us](http://www.curi.us)

---

<div class="post-metadata">

**Author:** ![curi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/e68b1a/32.png) [@curi](https://www.ruby-forum.com/u/curi)\
**Post date:** [October 12, 2007, 8:39pm UTC](https://www.ruby-forum.com/t/why-does-rails-do-this/117087/2 "2007-10-12T20:39:55Z")

</div>

On Oct 12, 1:28 pm, Elliot T. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
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

> **[Hey Daddio!](http://softiesonrails.com)**
>
> Home of Hey Daddio Software

[essentialrails.com](http://essentialrails.com)

---

<div class="post-metadata">

**Author:** ![curi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/e68b1a/32.png) [@curi](https://www.ruby-forum.com/u/curi)\
**Post date:** [October 12, 2007, 8:55pm UTC](https://www.ruby-forum.com/t/why-does-rails-do-this/117087/3 "2007-10-12T20:55:33Z")

</div>

Jeff C. wrote:

> On Oct 12, 1:28 pm, Elliot T. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> 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’])

- Elliot  
[www.curi.us](http://www.curi.us)
