diff --git a/app/models/transfer_request.rb b/app/models/transfer_request.rb index a2a06da9d3..90e26f3734 100644 --- a/app/models/transfer_request.rb +++ b/app/models/transfer_request.rb @@ -59,6 +59,7 @@ class TransferRequest < ApplicationRecord # rubocop:todo Metrics/ClassLength state :processed_1 state :processed_2 state :processed_3 + state :processed_4 state :failed, enter: :on_failed state :passed state :qc_complete @@ -81,18 +82,22 @@ class TransferRequest < ApplicationRecord # rubocop:todo Metrics/ClassLength transitions to: :processed_3, from: [:processed_2] end + event :process_4 do + transitions to: :processed_4, from: [:processed_3] + end + event :pass do # Jumping straight to passed moves through an implied started state. transitions to: :passed, from: :pending, after: :on_started - transitions to: :passed, from: %i[started failed processed_2 processed_3] + transitions to: :passed, from: %i[started failed processed_2 processed_3 processed_4] end event :fail do - transitions to: :failed, from: %i[pending started processed_1 processed_2 processed_3 passed] + transitions to: :failed, from: %i[pending started processed_1 processed_2 processed_3 processed_4 passed] end event :cancel do - transitions to: :cancelled, from: %i[started processed_1 processed_2 processed_3 passed qc_complete] + transitions to: :cancelled, from: %i[started processed_1 processed_2 processed_3 processed_4 passed qc_complete] end event :cancel_before_started do diff --git a/features/support/capybara.rb b/features/support/capybara.rb index 9844a37be4..d94270e497 100644 --- a/features/support/capybara.rb +++ b/features/support/capybara.rb @@ -13,12 +13,7 @@ options.add_argument('--headless') options.add_argument('--window-size=1600,3200') options.add_preference('download.default_directory', DownloadHelpers::PATH.to_s) - the_driver = Capybara::Selenium::Driver.new(app, browser: :chrome, options: options) - - # the following is needed to avoid a test failure where the driver would - # forget / ignore its configured download location on every other run - the_driver.browser.download_path = DownloadHelpers::PATH.to_s - the_driver + Capybara::Selenium::Driver.new(app, browser: :chrome, options: options) end Capybara.register_driver :chrome do |app| diff --git a/spec/models/state_changer/initial_stock_tube_spec.rb b/spec/models/state_changer/initial_stock_tube_spec.rb index 82d6180ebe..4fb18fc1fc 100644 --- a/spec/models/state_changer/initial_stock_tube_spec.rb +++ b/spec/models/state_changer/initial_stock_tube_spec.rb @@ -256,6 +256,30 @@ expect(request.reload.state).to eq('started') end end + + context 'when transitioning to "processed_4" with "started" requests' do + let(:target_state) { 'processed_4' } + let(:request_state) { 'started' } + + it 'updates the tube to "processed_4" with "started" requests', :aggregate_failures do + expect(transfer_request.reload.state).to eq('processed_4') + expect(request.reload.state).to eq('started') + end + end + end + + context 'when the tube is: "processed_4"' do + let(:transfer_request_state) { 'processed_4' } + + context 'when transitioning to "passed" with "started" requests' do + let(:target_state) { 'passed' } + let(:request_state) { 'started' } + + it 'updates the tube to "passed" with "started" requests', :aggregate_failures do + expect(transfer_request.reload.state).to eq('passed') + expect(request.reload.state).to eq('started') + end + end end context 'when the tube is: "passed"' do diff --git a/spec/models/state_changer/mx_tube_spec.rb b/spec/models/state_changer/mx_tube_spec.rb index 81d1dc221b..791f1945de 100644 --- a/spec/models/state_changer/mx_tube_spec.rb +++ b/spec/models/state_changer/mx_tube_spec.rb @@ -296,6 +296,30 @@ def create_requests_and_transfers expect(request.reload.state).to eq('passed') end end + + context 'when transitioning to "processed_4" with "started" requests' do + let(:target_state) { 'processed_4' } + let(:request_state) { 'started' } + + it 'updates the tube to "processed_4" with "started" requests', :aggregate_failures do + expect(transfer_request.reload.state).to eq('processed_4') + expect(request.reload.state).to eq('started') + end + end + end + + context 'when the tube is: "processed_4"' do + let(:transfer_request_state) { 'processed_4' } + + context 'when transitioning to "passed" with "passed" requests' do + let(:target_state) { 'passed' } + let(:request_state) { 'started' } + + it 'updates the tube to "passed" with "started" requests', :aggregate_failures do + expect(transfer_request.reload.state).to eq('passed') + expect(request.reload.state).to eq('passed') + end + end end context 'when the tube is: "passed"' do diff --git a/spec/models/state_changer/stock_tube_spec.rb b/spec/models/state_changer/stock_tube_spec.rb index 8803714d1c..30708aecb7 100644 --- a/spec/models/state_changer/stock_tube_spec.rb +++ b/spec/models/state_changer/stock_tube_spec.rb @@ -297,6 +297,30 @@ expect(request.reload.state).to eq('started') end end + + context 'when transitioning to "processed_4" with "started" requests' do + let(:target_state) { 'processed_4' } + let(:request_state) { 'started' } + + it 'updates the tube to "processed_4" with "started" requests', :aggregate_failures do + expect(transfer_request.reload.state).to eq('processed_4') + expect(request.reload.state).to eq('started') + end + end + end + + context 'when the tube is: "processed_4"' do + let(:transfer_request_state) { 'processed_4' } + + context 'when transitioning to "passed" with "started" requests' do + let(:target_state) { 'passed' } + let(:request_state) { 'started' } + + it 'updates the tube to "passed" with "started" requests', :aggregate_failures do + expect(transfer_request.reload.state).to eq('passed') + expect(request.reload.state).to eq('started') + end + end end context 'when the tube is: "passed"' do diff --git a/spec/models/transfer_request_spec.rb b/spec/models/transfer_request_spec.rb index ca58fffa08..fffbe6e8aa 100644 --- a/spec/models/transfer_request_spec.rb +++ b/spec/models/transfer_request_spec.rb @@ -269,7 +269,8 @@ started: :passed, failed: :passed, processed_2: :passed, - processed_3: :passed + processed_3: :passed, + processed_4: :passed }, process_1: { pending: :processed_1 @@ -280,6 +281,9 @@ process_3: { processed_2: :processed_3 }, + process_4: { + processed_3: :processed_4 + }, qc: { passed: :qc_complete }, @@ -289,6 +293,7 @@ processed_1: :failed, processed_2: :failed, processed_3: :failed, + processed_4: :failed, passed: :failed }, cancel: { @@ -296,6 +301,7 @@ processed_1: :cancelled, processed_2: :cancelled, processed_3: :cancelled, + processed_4: :cancelled, passed: :cancelled, qc_complete: :cancelled }, diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index bdb9b6d4fe..c7373c133e 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -52,17 +52,14 @@ options.add_argument('--headless') options.add_preference('download.default_directory', DownloadHelpers::PATH.to_s) - the_driver = Capybara::Selenium::Driver.new(app, browser: :chrome, options: options) - - # copied the following over from features/support/capybara.rb because I expect it is also relevant here - the_driver.browser.download_path = DownloadHelpers::PATH.to_s if the_driver.browser.respond_to?(:download_path=) - the_driver + Capybara::Selenium::Driver.new(app, browser: :chrome, options: options) end Capybara.register_driver :selenium_chrome do |app| - driver = Capybara::Selenium::Driver.new(app, browser: :chrome) - driver.browser.download_path = DownloadHelpers::PATH.to_s - driver + options = Selenium::WebDriver::Chrome::Options.new + + options.add_preference('download.default_directory', DownloadHelpers::PATH.to_s) + Capybara::Selenium::Driver.new(app, browser: :chrome, options: options) end Capybara.javascript_driver = ENV.fetch('JS_DRIVER', 'headless_chrome').to_sym