Created
January 6, 2012 18:30
-
-
Save baroquebobcat/1571808 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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