Installs database cleaner
- preparation for feature tests with capybara see: http://devblog.avdi.org/2012/08/31/configuring-database_cleaner-with-rails-rspec-capybara-and-selenium/
This commit is contained in:
parent
546977fc02
commit
8aa68fb84a
5 changed files with 33 additions and 7 deletions
1
Gemfile
1
Gemfile
|
|
@ -76,6 +76,7 @@ group :development, :test do
|
||||||
gem 'rspec', '>= 3.0.0.beta'
|
gem 'rspec', '>= 3.0.0.beta'
|
||||||
gem 'rspec-rails', '>= 3.0.0.beta'
|
gem 'rspec-rails', '>= 3.0.0.beta'
|
||||||
gem 'capybara'
|
gem 'capybara'
|
||||||
|
gem 'database_cleaner'
|
||||||
end
|
end
|
||||||
|
|
||||||
# FIXME: We should use http://weblog.rubyonrails.org/2012/3/21/strong-parameters/
|
# FIXME: We should use http://weblog.rubyonrails.org/2012/3/21/strong-parameters/
|
||||||
|
|
|
||||||
|
|
@ -81,6 +81,7 @@ GEM
|
||||||
thor
|
thor
|
||||||
d3_rails (3.4.6)
|
d3_rails (3.4.6)
|
||||||
railties (>= 3.1.0)
|
railties (>= 3.1.0)
|
||||||
|
database_cleaner (1.2.0)
|
||||||
devise (3.2.4)
|
devise (3.2.4)
|
||||||
bcrypt (~> 3.0)
|
bcrypt (~> 3.0)
|
||||||
orm_adapter (~> 0.1)
|
orm_adapter (~> 0.1)
|
||||||
|
|
@ -305,6 +306,7 @@ DEPENDENCIES
|
||||||
cocoon
|
cocoon
|
||||||
coveralls
|
coveralls
|
||||||
d3_rails
|
d3_rails
|
||||||
|
database_cleaner
|
||||||
devise
|
devise
|
||||||
factory_girl_rails
|
factory_girl_rails
|
||||||
formtastic (~> 2.3.0.rc3)
|
formtastic (~> 2.3.0.rc3)
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@ class User < ActiveRecord::Base
|
||||||
accepts_nested_attributes_for :person
|
accepts_nested_attributes_for :person
|
||||||
accepts_nested_attributes_for :roles
|
accepts_nested_attributes_for :roles
|
||||||
|
|
||||||
before_save :setup_role
|
before_create :setup_role
|
||||||
before_create :create_person
|
before_create :create_person
|
||||||
|
|
||||||
def role?(role)
|
def role?(role)
|
||||||
|
|
@ -27,12 +27,14 @@ class User < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
|
|
||||||
def setup_role
|
def setup_role
|
||||||
if self.id == 1
|
if User.count == 0
|
||||||
self.role_ids = [3]
|
admin = Role.where(name: 'Admin').first
|
||||||
|
self.role_ids = [admin.id] unless admin.nil?
|
||||||
end
|
end
|
||||||
|
|
||||||
if self.role_ids.empty?
|
if self.role_ids.empty?
|
||||||
self.role_ids = [1]
|
participant = Role.where(name: 'Participant').first
|
||||||
|
self.role_ids = [participant.id] unless participant.nil?
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,6 @@ require File.expand_path('../../config/environment', __FILE__)
|
||||||
|
|
||||||
if Rails.configuration.database_configuration['test']['database'] == ':memory:'
|
if Rails.configuration.database_configuration['test']['database'] == ':memory:'
|
||||||
load "#{Rails.root}/db/schema.rb"
|
load "#{Rails.root}/db/schema.rb"
|
||||||
load "#{Rails.root}/db/seeds.rb"
|
|
||||||
end
|
end
|
||||||
|
|
||||||
require 'rspec/rails'
|
require 'rspec/rails'
|
||||||
|
|
@ -35,7 +34,7 @@ RSpec.configure do |config|
|
||||||
# If you're not using ActiveRecord, or you'd prefer not to run each of your
|
# If you're not using ActiveRecord, or you'd prefer not to run each of your
|
||||||
# examples within a transaction, remove the following line or assign false
|
# examples within a transaction, remove the following line or assign false
|
||||||
# instead of true.
|
# instead of true.
|
||||||
config.use_transactional_fixtures = true
|
config.use_transactional_fixtures = false
|
||||||
|
|
||||||
# Run specs in random order to surface order dependencies. If you find an
|
# Run specs in random order to surface order dependencies. If you find an
|
||||||
# order dependency and want to debug it, you can fix the order by providing
|
# order dependency and want to debug it, you can fix the order by providing
|
||||||
|
|
|
||||||
22
spec/support/database_cleaner.rb
Normal file
22
spec/support/database_cleaner.rb
Normal file
|
|
@ -0,0 +1,22 @@
|
||||||
|
RSpec.configure do |config|
|
||||||
|
|
||||||
|
config.before(:suite) do
|
||||||
|
DatabaseCleaner.clean_with(:truncation)
|
||||||
|
end
|
||||||
|
|
||||||
|
config.before(:each) do
|
||||||
|
DatabaseCleaner.strategy = :transaction
|
||||||
|
end
|
||||||
|
|
||||||
|
config.before(:each, :js => true) do
|
||||||
|
DatabaseCleaner.strategy = :truncation
|
||||||
|
end
|
||||||
|
|
||||||
|
config.before(:each) do
|
||||||
|
DatabaseCleaner.start
|
||||||
|
end
|
||||||
|
|
||||||
|
config.after(:each) do
|
||||||
|
DatabaseCleaner.clean
|
||||||
|
end
|
||||||
|
end
|
||||||
Loading…
Add table
Add a link
Reference in a new issue