mirror of
https://github.com/openSUSE/osem.git
synced 2026-08-13 19:54:02 +00:00
Use Rails transactional tests
As of Rails 5.1:
- Rails has built-in support for running tests within database
transactions, so Database Cleaner is no longer needed for this.
- Rails automatically shares the database connection across threads,
so transactional_capybara is no longer needed.
Changes:
- Enable `use_transactional_tests`.
- Remove transactional_capybara.
- Remove the Database Cleaner test wrapper.
This resolves:
- transactional_capybara mismanages the shared database connection,
causing the connection to falsely report as idle after the first
test. At 6 minutes (idle_timeout + reaping_frequency) into testing,
the connection is closed, causing e.g. `PG::ConnectionBad` errors.
This commit is contained in:
parent
310fc8dc68
commit
c3e02c20b9
7 changed files with 3 additions and 24 deletions
1
Gemfile
1
Gemfile
|
|
@ -242,7 +242,6 @@ group :test do
|
||||||
gem 'database_cleaner'
|
gem 'database_cleaner'
|
||||||
gem 'geckodriver-helper'
|
gem 'geckodriver-helper'
|
||||||
gem 'rspec-rails'
|
gem 'rspec-rails'
|
||||||
gem 'transactional_capybara'
|
|
||||||
gem 'webdrivers'
|
gem 'webdrivers'
|
||||||
# for measuring test coverage
|
# for measuring test coverage
|
||||||
gem 'simplecov-cobertura'
|
gem 'simplecov-cobertura'
|
||||||
|
|
|
||||||
|
|
@ -568,8 +568,6 @@ GEM
|
||||||
thread_safe (0.3.6)
|
thread_safe (0.3.6)
|
||||||
tilt (2.0.9)
|
tilt (2.0.9)
|
||||||
timecop (0.9.1)
|
timecop (0.9.1)
|
||||||
transactional_capybara (0.2.0)
|
|
||||||
capybara
|
|
||||||
transitions (1.2.1)
|
transitions (1.2.1)
|
||||||
ttfunk (1.7.0)
|
ttfunk (1.7.0)
|
||||||
turbolinks (5.2.1)
|
turbolinks (5.2.1)
|
||||||
|
|
@ -714,7 +712,6 @@ DEPENDENCIES
|
||||||
stripe
|
stripe
|
||||||
stripe-ruby-mock
|
stripe-ruby-mock
|
||||||
timecop
|
timecop
|
||||||
transactional_capybara
|
|
||||||
transitions
|
transitions
|
||||||
turbolinks
|
turbolinks
|
||||||
uglifier (>= 1.3.0)
|
uglifier (>= 1.3.0)
|
||||||
|
|
|
||||||
|
|
@ -85,7 +85,6 @@ feature Commercial do
|
||||||
click_button 'Update'
|
click_button 'Update'
|
||||||
page.find('#flash')
|
page.find('#flash')
|
||||||
expect(flash).to eq('Commercial was successfully updated.')
|
expect(flash).to eq('Commercial was successfully updated.')
|
||||||
TransactionalCapybara::AjaxHelpers.wait_for_ajax(page)
|
|
||||||
expect(event.commercials.count).to eq(1)
|
expect(event.commercials.count).to eq(1)
|
||||||
commercial.reload
|
commercial.reload
|
||||||
expect(commercial.url).to eq('https://www.youtube.com/watch?v=M9bq_alk-sw')
|
expect(commercial.url).to eq('https://www.youtube.com/watch?v=M9bq_alk-sw')
|
||||||
|
|
@ -118,7 +117,6 @@ feature Commercial do
|
||||||
end
|
end
|
||||||
page.find('#flash')
|
page.find('#flash')
|
||||||
expect(flash).to eq('Commercial was successfully destroyed.')
|
expect(flash).to eq('Commercial was successfully destroyed.')
|
||||||
TransactionalCapybara::AjaxHelpers.wait_for_ajax(page)
|
|
||||||
expect(event.commercials.count).to eq(0)
|
expect(event.commercials.count).to eq(0)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -138,7 +138,6 @@ feature Event do
|
||||||
|
|
||||||
page.find('#flash')
|
page.find('#flash')
|
||||||
expect(page).to have_content 'Proposal was successfully submitted.'
|
expect(page).to have_content 'Proposal was successfully submitted.'
|
||||||
TransactionalCapybara::AjaxHelpers.wait_for_ajax(page)
|
|
||||||
expect(current_path).to eq(conference_program_proposals_path(conference.short_title))
|
expect(current_path).to eq(conference_program_proposals_path(conference.short_title))
|
||||||
expect(Event.count).to eq(expected_count)
|
expect(Event.count).to eq(expected_count)
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -392,7 +392,7 @@ feature 'Version' do
|
||||||
click_link 'Comments (0)'
|
click_link 'Comments (0)'
|
||||||
fill_in 'comment_body', with: 'Sample comment'
|
fill_in 'comment_body', with: 'Sample comment'
|
||||||
click_button 'Add Comment'
|
click_button 'Add Comment'
|
||||||
TransactionalCapybara::AjaxHelpers.wait_for_ajax(page)
|
expect(page).to have_text('Comments (1)')
|
||||||
Comment.last.destroy
|
Comment.last.destroy
|
||||||
PaperTrail::Version.last.reify.save
|
PaperTrail::Version.last.reify.save
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -20,9 +20,6 @@ require 'webdrivers'
|
||||||
# all migrations applied
|
# all migrations applied
|
||||||
ActiveRecord::Migration.maintain_test_schema!
|
ActiveRecord::Migration.maintain_test_schema!
|
||||||
|
|
||||||
# Keep capybara and the database on the same page
|
|
||||||
require 'transactional_capybara/rspec'
|
|
||||||
|
|
||||||
# Adds rspec helper provided by paper_trail
|
# Adds rspec helper provided by paper_trail
|
||||||
# makes it easier to control when PaperTrail is enabled during testing.
|
# makes it easier to control when PaperTrail is enabled during testing.
|
||||||
require 'paper_trail/frameworks/rspec'
|
require 'paper_trail/frameworks/rspec'
|
||||||
|
|
@ -49,10 +46,8 @@ RSpec.configure do |config|
|
||||||
# config.mock_with :flexmock
|
# config.mock_with :flexmock
|
||||||
# config.mock_with :rr
|
# config.mock_with :rr
|
||||||
|
|
||||||
# If you're not using ActiveRecord, or you'd prefer not to run each of your
|
# Test within database transactions
|
||||||
# examples within a transaction, remove the following line or assign false
|
config.use_transactional_examples = true
|
||||||
# instead of 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
|
||||||
|
|
|
||||||
|
|
@ -5,13 +5,4 @@ RSpec.configure do |config|
|
||||||
DatabaseCleaner.clean_with(:truncation)
|
DatabaseCleaner.clean_with(:truncation)
|
||||||
Rails.application.load_seed
|
Rails.application.load_seed
|
||||||
end
|
end
|
||||||
|
|
||||||
config.before(:each) do
|
|
||||||
DatabaseCleaner.start
|
|
||||||
end
|
|
||||||
|
|
||||||
config.after(:each) do |example|
|
|
||||||
TransactionalCapybara::AjaxHelpers.wait_for_ajax(page) if example.metadata[:js]
|
|
||||||
DatabaseCleaner.clean
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue