From e78e53ae4ff390705414bd6dcf317c7711d21fe0 Mon Sep 17 00:00:00 2001 From: Daniel Baark <5101747+baarkerlounger@users.noreply.github.com> Date: Thu, 21 Oct 2021 14:44:38 +0100 Subject: [PATCH] Attempt to solve race condition (#56) --- app/controllers/case_logs_controller.rb | 2 +- app/models/case_log.rb | 2 ++ spec/features/case_log_spec.rb | 4 ++++ 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/app/controllers/case_logs_controller.rb b/app/controllers/case_logs_controller.rb index 85f1ae1b1..2eeba44cf 100644 --- a/app/controllers/case_logs_controller.rb +++ b/app/controllers/case_logs_controller.rb @@ -4,7 +4,7 @@ class CaseLogsController < ApplicationController def index @completed_case_logs = CaseLog.completed - @in_progress_case_logs = CaseLog.in_progress + @in_progress_case_logs = CaseLog.not_completed end def create diff --git a/app/models/case_log.rb b/app/models/case_log.rb index fd63535d5..5ad7e515e 100644 --- a/app/models/case_log.rb +++ b/app/models/case_log.rb @@ -60,7 +60,9 @@ end class CaseLog < ApplicationRecord include Discard::Model default_scope -> { kept } + scope :not_started, -> { where(status: "not_started") } scope :in_progress, -> { where(status: "in_progress") } + scope :not_completed, -> { where.not(status: "completed") } scope :completed, -> { where(status: "completed") } validate :instance_validations diff --git a/spec/features/case_log_spec.rb b/spec/features/case_log_spec.rb index fed45d5d1..5d9fa1fdb 100644 --- a/spec/features/case_log_spec.rb +++ b/spec/features/case_log_spec.rb @@ -32,6 +32,10 @@ RSpec.describe "Test Features" do describe "Create new log" do it "redirects to the task list for the new log" do visit("/case_logs") + # Ensure that we've finished creating both case logs before running the + # Capybara click part to ensure we don't get creation race conditions + expect(page).to have_link(nil, href: "/case_logs/#{case_log.id}") + expect(page).to have_link(nil, href: "/case_logs/#{empty_case_log.id}") click_link("Create new log") id = CaseLog.order(created_at: :desc).first.id expect(page).to have_content("Tasklist for log #{id}")