S
Stephen Richards
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
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