Created
August 15, 2013 06:27
-
-
Save aaronjensen/6238709 to your computer and use it in GitHub Desktop.
check for leaking transactions in rspec tests
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
| def check_for_leftovers | |
| tables = ActiveRecord::Base.connection.select_values("show tables") | |
| leftovers = {} | |
| tables.each do |table| | |
| next if %w(schema_migrations vanity_experiments).include? table | |
| count = ActiveRecord::Base.connection.select_value("select count(*) from #{table}") | |
| leftovers[table] = count if count > 0 | |
| end | |
| if leftovers.any? | |
| DatabaseCleaner.clean_with :truncation | |
| raise "LEFTOVERS in\n#{leftovers.map {|k,v| "#{k}: #{v}"}.join("\n")}" | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment