# Loading Fixtures Earlier

**URL:** <https://www.ruby-forum.com/t/loading-fixtures-earlier/186157>\
**Category:** Rails\
**Created:** [April 1, 2010, 10:05am UTC](https://www.ruby-forum.com/t/loading-fixtures-earlier/186157 "2010-04-01T10:05:44Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![mazniak](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/8edcca/32.png) [@mazniak](https://www.ruby-forum.com/u/mazniak)\
**Post date:** [April 1, 2010, 10:05am UTC](https://www.ruby-forum.com/t/loading-fixtures-earlier/186157/1 "2010-04-01T10:05:44Z")

</div>

I have a few ActiveRecord subclasses that reassign their default scope  
upon instantiation based on some criteria (i.e. subclasses of the AR  
model Person will change their default scope according to rows found  
in the `roles` table). This works find during development, but during  
testing this fails because the fixtures (which contain the `roles`  
items) are not loaded until after the models are causing an exception  
to be raised.

Is there any way to have fixtures loaded earlier on in the testing  
process, or is there some proper Rails-provided way to seed the test  
database?

Thanks,  
—matt

---

<div class="post-metadata">

**Author:** ![mazniak](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/8edcca/32.png) [@mazniak](https://www.ruby-forum.com/u/mazniak)\
**Post date:** [April 2, 2010, 10:33am UTC](https://www.ruby-forum.com/t/loading-fixtures-earlier/186157/2 "2010-04-02T10:33:18Z")

</div>

> Is there any way to have fixtures loaded earlier on in the testing  
> process, or is there some proper Rails-provided way to seed the test  
> database?

```
 Yes. From 2.3.4 onwards there is db/seeds.rb file .You can write 

```

put data there. For more information please watch this Railscast

> **[\#179 Seed Data - RailsCasts](http://railscasts.com/episodes/179-seed-data)**
>
> Short Ruby on Rails screencasts containing tips, tricks and tutorials. Great for both novice and experienced web developers.

Sijo
