views:

30

answers:

1

I keep getting validation errors when running factories due to uniqueness constraints on fields. I am using shoulda with factory_girl. I have a both a unit test and a functional test creating 2 products in the database. I can run 'rake test:units' and 'rake test:functionals' over and over in any order and everything is will be green but when I run 'rake test' which runs the units followed by the functionals I get errors due to uniqueness.

I also tried creating models to break uniqueness in 2 different unit tests and I get the error then as well.

I have been playing with these settings in test_helper.rb but can't get anything to work

class ActiveSupport::TestCase
  self.use_transactional_fixtures = true
  self.use_instantiated_fixtures  = false
end

Does the transactional_fixtures setting take any effect of factories. Whats the best way to handle cleaning the database between tests?

+1  A: 

(sigh..)

So the problem was that I was copying code from the shoulda docs and ended up declaring my test classes like so:

class UserTest < Test::Unit::TestCase

However for the transactional fixtures setting to have any effect you need to inherit from ActiveSupport::TestCase by declaring your classes

class UserTest < ActiveSupport::TestCase

Hopefully this can help save someone else some time.

crayment