开发者

Rails testing with factories. Transactional uniqueness problem

I keep getting validation errors when running factories due to uniqueness constraints on fields. I am using shoulda with factory_girl. I h开发者_JS百科ave 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?


(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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜