Commit 48007c6444e66810c2d8a0acd89c24ae33f19f90

Authored by ikeqiao
1 parent 39a1b495
Exists in master

use database_cleaner to reset test database

Showing 1 changed file with 14 additions and 1 deletions   Show diff stats
spec/spec_helper.rb
1 1  
2 2 require 'debugger'
3   -
  3 +require 'database_cleaner'
4 4 require 'rubygems'
5 5 require "active_record"
6 6 require 'active_support'
... ... @@ -19,8 +19,10 @@ module Rails
19 19 end
20 20  
21 21  
  22 +
22 23 ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :database => ":memory:")
23 24 # ActiveRecord::Base.configurations = true
  25 +ActiveRecord::Base.logger = Logger.new(STDOUT)
24 26  
25 27 ActiveRecord::Schema.verbose = false
26 28  
... ... @@ -81,5 +83,16 @@ RSpec.configure do |config|
81 83  
82 84 config.after(:all) do
83 85 end
  86 +
  87 + config.before(:suite) do
  88 + DatabaseCleaner.strategy = :transaction
  89 + DatabaseCleaner.clean_with(:truncation)
  90 + end
  91 +
  92 + config.around(:each) do |example|
  93 + DatabaseCleaner.cleaning do
  94 + example.run
  95 + end
  96 + end
84 97 end
85 98  
... ...