We have a number of rspec tests that started failing with uniqueness
validation failures once we added uniqueness constraints to our models
despite their being no uniqueness violations at the DB level - we have
unique constraints in the db and the same tests without the
model-level validations work well - even negative tests that cause
mysql to issue uuniqueness exceptions.
We use factory girl for creating models for tests (with create not build).
A teammate of mine determined this had to do with transactions within
rspec, so for now we can work around the failing specs by turning
transactions off before the tests and then on again afterwards, but
this obviously has the disadvantage that if these non-transactional
tests fail we have a database with test data artifacts left over in
We have tried moving tests set up and tear down code from before all
to before each and even within each it block itself - no change.
The behavior in the tests is unique to the tests, we see no unique
constraint issues in our integration nor production environments.
Anyone else here encouter this behavior and have a resolution that
does not involve turning off transactions for rspec or risk losing the
idempotency of tests?
If your response adds value to the thread I don't care if you top
post or not