Skip to content

Instantly share code, notes, and snippets.

@fnando
Created October 15, 2010 21:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fnando/629012 to your computer and use it in GitHub Desktop.
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.
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