I’m writing a test case in Minitest that creates a database entry. After the test is run, all changes that the test did should be rolled back. What is a good way to achieve this?
require 'minitest/autorun'
require 'rubygems'
require 'sequel'
require 'factory_girl'
class TestPostgresqlFunctions < MiniTest::Unit::TestCase
def test_simple_function
Factory.find_definitions
user = FactoryGirl.create(:user)
end
end
With this code, the created entry will stay in the database. I’m not using Rails or any other framework. The database I’m using is PostgreSQL 9.1.
This should work (requires Sequel 3.29.0 or greater):