Skip to content

Commit

Permalink
Add database_cleaner support/setup file
Browse files Browse the repository at this point in the history
  • Loading branch information
Greg Lazarev committed Jan 2, 2013
1 parent 11d50f0 commit 2bb5d08
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
11 changes: 10 additions & 1 deletion lib/suspenders/app_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,19 @@ def add_capybara_webkit_gem
:after => /gem 'capybara'/
end

def enable_database_cleaner
replace_in_file 'spec/spec_helper.rb',
'config.use_transactional_fixtures = true',
'config.use_transactional_fixtures = false'

copy_file 'database_cleaner_rspec.rb', 'spec/support/database_cleaner.rb'
end

def configure_rspec
remove_file '.rspec'
copy_file 'rspec', '.rspec'
prepend_file 'spec/spec_helper.rb', simplecov_init

replace_in_file 'spec/spec_helper.rb',
'# config.mock_with :mocha',
'config.mock_with :mocha'
Expand Down Expand Up @@ -136,7 +145,7 @@ def configure_rspec

def configure_time_zone
time_zone_config = <<-RUBY
config.active_record.default_timezone = :utc
config.active_record.default_timezone = :utc
RUBY
inject_into_class "config/application.rb", "Application", time_zone_config
end
Expand Down
1 change: 1 addition & 0 deletions lib/suspenders/generators/app_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ def setup_test_environment
build :test_factories_first
build :generate_rspec
build :configure_rspec
build :enable_database_cleaner

if options[:webkit]
build :configure_capybara_webkit
Expand Down
21 changes: 21 additions & 0 deletions templates/database_cleaner_rspec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
RSpec.configure do |config|
config.before(:suite) do
DatabaseCleaner.clean_with(:deletion)
end

config.before(:each) do
DatabaseCleaner.strategy = :transaction
end

config.before(:each, :js => true) do
DatabaseCleaner.strategy = :deletion
end

config.before(:each) do
DatabaseCleaner.start
end

config.after(:each) do
DatabaseCleaner.clean
end
end

0 comments on commit 2bb5d08

Please sign in to comment.