Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ActiveRecord delete_everything! is used in tests. All tests do not us…
…e transactions now
- Loading branch information
Showing
3 changed files
with
26 additions
and
3 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#config/initializers/active_record_delete_everything.rb | ||
|
||
module ActiveRecord | ||
class Base | ||
class << self | ||
def delete_everything! | ||
begin | ||
ActiveRecord::Base.connection.rollback_db_transaction | ||
rescue | ||
#Intentionally suppress exception when no trasactions | ||
end | ||
klasses = ActiveRecord::Base.connection.tables.reject { |t| t == 'schema_migrations' }.collect { |t| t.classify.constantize } | ||
klasses.each { | k | k.delete_all } | ||
end | ||
end | ||
end | ||
end |
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
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