May 26, 2016
This blog is part of our Rails 5 series.
In Rails 4.x we have transactional fixtures that wrap each test in a database transaction. This transaction rollbacks all the changes at the end of the test. It means the state of the database, before the test is same as after the test is done.
By default this functionality is enabled. We can choose to disable it in a test
case class by setting the class attribute use_transactional_fixtures
to
false
class FooTest < ActiveSupport::TestCase
self.use_transactional_fixtures = false
end
Rails also comes with fixtures for tests. So it may seem that
use_transactional_fixtures
has something to do with the Rails fixtures. A lot
of people don't use fixtures and they think that they should disable
use_transactional_fixtures
because they do not use fixtures.
To overcome this confusion, Rails 5 has renamed transactional fixtures to transactional tests making it clear that it has nothing to do with the fixtures used in tests.
In Rails 5, the above example will be written as follows.
class FooTest < ActiveSupport::TestCase
self.use_transactional_tests = false
end
If this blog was helpful, check out our full blog archive.