Created
October 15, 2010 21:46
-
-
Save fnando/629012 to your computer and use it in GitHub Desktop.
A simple DatabaseCleaner replacement that only support TRUNCATE and ActiveRecord. Had a hard time using original DatabaseCleaner with Rails 3.
This file contains 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
module DatabaseCleaner | |
def self.clean | |
Array.new.tap do |cache| | |
ActiveRecord::Base.descendants.each do |model| | |
next if cache.include?(model.table_name) | |
cache << model.table_name | |
table_name = ActiveRecord::Base.connection.quote_table_name(model.table_name) | |
ActiveRecord::Base.connection.execute "TRUNCATE TABLE #{table_name}" | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment