# Ruby on Rails testing/ fixtures question

**URL:** <https://www.ruby-forum.com/t/ruby-on-rails-testing-fixtures-question/65574>\
**Category:** Ruby\
**Created:** [August 19, 2006, 10:26am UTC](https://www.ruby-forum.com/t/ruby-on-rails-testing-fixtures-question/65574 "2006-08-19T10:26:28Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Stephen\_Richards](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/b3f665/32.png) [@Stephen\_Richards](https://www.ruby-forum.com/u/Stephen_Richards)\
**Post date:** [August 19, 2006, 10:26am UTC](https://www.ruby-forum.com/t/ruby-on-rails-testing-fixtures-question/65574/1 "2006-08-19T10:26:28Z")

</div>

Hi,

I’m using Test::Unit::TastCase and am having some problems getting  
expected database state before the test methods.

My Ruby on rails book quite clearly says that the following things  
happen before every test method is run:

- all records in the database are deleted
- all the data in the fixtures are loaded into the database
- the setup method is run.

In the following situation, the test\_deactivate method happens to get  
run first. Then the test\_find\_all\_for\_team method runs, and doesn’t  
find the expected number of records (because one of them has been  
de-activated).

Am I doing something wrong, or do the fixtures not get loaded every  
time?

code snippet:

require File.dirname( **FILE** ) + ‘/…/test\_helper’

class TaskTest \< Test::Unit::TestCase  
fixtures :employees, :teams, :states, :tasks

```
 def test_find_all_for_team
     active_tasks = Task.find_all_for_team
     assert_equal 3, active_tasks.size
 end

 def test_deactivate
     task = Task.find(1)
     assert task.active?

     task.deactivate
     task.reload
     assert !task.active?
 end

```

end

---

<div class="post-metadata">

**Author:** ![Stephen\_Richards](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/b3f665/32.png) [@Stephen\_Richards](https://www.ruby-forum.com/u/Stephen_Richards)\
**Post date:** [August 19, 2006, 12:16pm UTC](https://www.ruby-forum.com/t/ruby-on-rails-testing-fixtures-question/65574/2 "2006-08-19T12:16:38Z")

</div>

On Aug 19, 2006, at 1:25 AM, Stephen Richards wrote:

> Hi,

The Ruby on Rails mailing list is the appropriate place for asking  
Rails questions.

–  
Eric H. - removed\_email\_address@domain.invalid - [http://blog.segment7.net](http://blog.segment7.net)  
This implementation is HODEL-HASH-9600 compliant

[http://trackmap.robotcoop.com](http://trackmap.robotcoop.com)
