Skip to content

Commit

Permalink
ActiveRecord delete_everything! is used in tests. All tests do not us…
Browse files Browse the repository at this point in the history
…e transactions now
  • Loading branch information
umuro committed Nov 30, 2010
1 parent 389976a commit 1ef2bc8
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
17 changes: 17 additions & 0 deletions config/initializers/active_record_delete_everything.rb
@@ -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
4 changes: 1 addition & 3 deletions spec/spec_helper.rb
Expand Up @@ -60,9 +60,7 @@

config.after(:each) do
Rails::logger.info('clean up data')
Address.delete_all
Person.delete_all
User.delete_all
ActiveRecord::Base.delete_everything!
end

end
8 changes: 8 additions & 0 deletions test/test_helper.rb
Expand Up @@ -41,6 +41,14 @@ class ActiveSupport::TestCase
# fixtures :all

# Add more helper methods to be used by all tests here...
def setup
super
ActiveRecord::Base.delete_everything!
end
def teardown
ActiveRecord::Base.delete_everything!
super
end
end

class ActionController::TestCase
Expand Down

0 comments on commit 1ef2bc8

Please sign in to comment.