Browse Source

Use database ID assignment everywhere we need ID to reduce flakiness

pull/109/head
baarkerlounger 4 years ago
parent
commit
953c618085
  1. 1
      Gemfile
  2. 1
      spec/factories/case_log.rb
  3. 4
      spec/helpers/tasklist_helper_spec.rb
  4. 45
      spec/rails_helper.rb
  5. 4
      spec/views/case_log_index_view_spec.rb

1
Gemfile

@ -61,7 +61,6 @@ end
group :test do
gem "capybara", require: false
gem "database_cleaner-active_record", require: false
gem "factory_bot_rails"
gem "selenium-webdriver", require: false
gem "simplecov", require: false

1
spec/factories/case_log.rb

@ -1,6 +1,5 @@
FactoryBot.define do
factory :case_log do
sequence(:id) { |i| i }
trait :in_progress do
status { 1 }
tenant_code { "TH356" }

4
spec/helpers/tasklist_helper_spec.rb

@ -1,8 +1,8 @@
require "rails_helper"
RSpec.describe TasklistHelper do
let(:empty_case_log) { FactoryBot.build(:case_log) }
let(:case_log) { FactoryBot.build(:case_log, :in_progress) }
let(:empty_case_log) { FactoryBot.create(:case_log) }
let(:case_log) { FactoryBot.create(:case_log, :in_progress) }
form_handler = FormHandler.instance
let(:form) { form_handler.get_form("test_form") }

45
spec/rails_helper.rb

@ -6,7 +6,6 @@ require File.expand_path("../config/environment", __dir__)
abort("The Rails environment is running in production mode!") if Rails.env.production?
require "rspec/rails"
require "capybara/rspec"
require "database_cleaner/active_record"
# Comment to run `js: true specs` with visible browser interaction
Capybara.javascript_driver = :selenium_headless
@ -43,49 +42,7 @@ RSpec.configure do |config|
# 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
# instead of true.
# config.use_transactional_fixtures = true
config.before(:suite) do
if config.use_transactional_fixtures?
raise(<<-MSG)
Delete line `config.use_transactional_fixtures = true` from rails_helper.rb
(or set it to false) to prevent uncommitted transactions being used in
JavaScript-dependent specs.
During testing, the app-under-test that the browser driver connects to
uses a different database connection to the database connection used by
the spec. The app's database connection would not be able to access
uncommitted transaction data setup over the spec's database connection.
MSG
end
DatabaseCleaner.clean_with(:truncation)
end
config.before(:each) do
DatabaseCleaner.strategy = :transaction
end
config.before(:each, type: :feature) do
# :rack_test driver's Rack app under test shares database connection
# with the specs, so continue to use transaction strategy for speed.
driver_shares_db_connection_with_specs = Capybara.current_driver == :rack_test
unless driver_shares_db_connection_with_specs
# Driver is probably for an external browser with an app
# under test that does *not* share a database connection with the
# specs, so use truncation strategy.
DatabaseCleaner.strategy = :truncation
end
end
config.before(:each) do
DatabaseCleaner.start
end
config.append_after(:each) do
DatabaseCleaner.clean
end
config.use_transactional_fixtures = true
# You can uncomment this line to turn off ActiveRecord support entirely.
# config.use_active_record = false

4
spec/views/case_log_index_view_spec.rb

@ -1,7 +1,7 @@
require "rails_helper"
RSpec.describe "case_logs/index" do
let(:in_progress_log) { FactoryBot.build(:case_log, :in_progress) }
let(:completed_log) { FactoryBot.build(:case_log, :completed) }
let(:in_progress_log) { FactoryBot.create(:case_log, :in_progress) }
let(:completed_log) { FactoryBot.create(:case_log, :completed) }
context "given an in progress log list" do
it "renders a table for in progress logs only" do

Loading…
Cancel
Save