Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add database_cleaner support/setup file

  • Loading branch information...
commit 2bb5d08d1ad3beda4923314d7339daaa5990131f 1 parent 11d50f0
@gylaz gylaz authored
View
11 lib/suspenders/app_builder.rb
@@ -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'
@@ -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
View
1  lib/suspenders/generators/app_generator.rb
@@ -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
View
21 templates/database_cleaner_rspec.rb
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.