Skip to content

Instantly share code, notes, and snippets.

@baroquebobcat
Created January 6, 2012 18:30
Show Gist options
  • Select an option

  • Save baroquebobcat/1571808 to your computer and use it in GitHub Desktop.

Select an option

Save baroquebobcat/1571808 to your computer and use it in GitHub Desktop.
# Snippet to wrap tests with ActiveRecord db transactions outside Rails.
#
# references:
# https://github.com/rails/rails/blob/master/railties/lib/rails/test_help.rb#L27
# https://github.com/rails/rails/blob/master/activerecord/lib/active_record/fixtures.rb#L704
#
# TestFixtures checks whether configurations is blank
# to determine whether to use transactions/fixtures or not.
# which is why we need to set it to something.
ActiveRecord::Base.configurations= {test: {
database: 'something_test',
adapter: 'mysql',
# ...
}}
ActiveRecord::Base.establish_connection ActiveRecord::Base.configurations[:test]
class ActiveSupport::TestCase < ::Test::Unit::TestCase
include ActiveRecord::TestFixtures
setup do
ActiveRecord::IdentityMap.clear
end
# if you want to use fixtures you can set the fixture path, and it'll load them like rails does.
# self.fixture_path = "my_fixtures"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment