diff options
author | Gabriel Mazetto <brodock@gmail.com> | 2018-01-15 21:25:22 +0100 |
---|---|---|
committer | Gabriel Mazetto <brodock@gmail.com> | 2018-01-15 23:44:29 +0100 |
commit | fcd0044ca5ad9d78fa8f3478a9021504d9da5bb4 (patch) | |
tree | 6139d06d6a413cce3049213c92a375542cf21a7c | |
parent | 9e70ff345fa68d700b77b5939d34870ee61cb131 (diff) | |
download | gitlab-ce-rspec-transactions.tar.gz |
test capybara with transactions sharing connnectionrspec-transactions
-rw-r--r-- | Gemfile | 1 | ||||
-rw-r--r-- | Gemfile.lock | 3 | ||||
-rw-r--r-- | spec/spec_helper.rb | 10 | ||||
-rw-r--r-- | spec/support/db_cleaner.rb | 22 |
4 files changed, 18 insertions, 18 deletions
@@ -371,6 +371,7 @@ group :test do gem 'timecop', '~> 0.8.0' gem 'concurrent-ruby', '~> 1.0.5' gem 'test-prof', '~> 0.2.5' + gem 'transactional_capybara' end gem 'octokit', '~> 4.6.2' diff --git a/Gemfile.lock b/Gemfile.lock index b83a3f0f7a4..102fb8df96c 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -924,6 +924,8 @@ GEM parslet (~> 1.5.0) toml-rb (0.3.15) citrus (~> 3.0, > 3.0) + transactional_capybara (0.2.0) + capybara truncato (0.7.10) htmlentities (~> 4.3.1) nokogiri (~> 1.8.0, >= 1.7.0) @@ -1197,6 +1199,7 @@ DEPENDENCIES thin (~> 1.7.0) timecop (~> 0.8.0) toml-rb (~> 0.3.15) + transactional_capybara truncato (~> 0.7.9) u2f (~> 0.2.1) uglifier (~> 2.7.2) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 6186fb92bad..56d839b7a26 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -184,6 +184,16 @@ FactoryBot::SyntaxRunner.class_eval do end ActiveRecord::Migration.maintain_test_schema! +require "transactional_capybara/rspec" + +class ActiveRecord::Base + mattr_accessor :shared_connection + @@shared_connection = nil + + def self.connection + @@shared_connection || ConnectionPool::Wrapper.new(:size => 1) { retrieve_connection } + end +end Shoulda::Matchers.configure do |config| config.integrate do |with| diff --git a/spec/support/db_cleaner.rb b/spec/support/db_cleaner.rb index edaee03ea6c..d4b40feebee 100644 --- a/spec/support/db_cleaner.rb +++ b/spec/support/db_cleaner.rb @@ -3,31 +3,17 @@ RSpec.configure do |config| DatabaseCleaner.clean_with(:truncation) end - config.append_after(:context) do - DatabaseCleaner.clean_with(:truncation, cache_tables: false) - end - config.before(:each) do DatabaseCleaner.strategy = :transaction end - config.before(:each, :js) do - DatabaseCleaner.strategy = :truncation - end - - config.before(:each, :truncate) do - DatabaseCleaner.strategy = :truncation - end - config.before(:each, :migration) do DatabaseCleaner.strategy = :truncation, { cache_tables: false } end - config.before(:each) do - DatabaseCleaner.start - end - - config.append_after(:each) do - DatabaseCleaner.clean + config.around(:each) do |example| + DatabaseCleaner.cleaning do + example.run + end end end |