Browse Source

Attempt to solve race condition (#56)

pull/60/head
Daniel Baark 3 years ago committed by GitHub
parent
commit
e78e53ae4f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      app/controllers/case_logs_controller.rb
  2. 2
      app/models/case_log.rb
  3. 4
      spec/features/case_log_spec.rb

2
app/controllers/case_logs_controller.rb

@ -4,7 +4,7 @@ class CaseLogsController < ApplicationController
def index def index
@completed_case_logs = CaseLog.completed @completed_case_logs = CaseLog.completed
@in_progress_case_logs = CaseLog.in_progress @in_progress_case_logs = CaseLog.not_completed
end end
def create def create

2
app/models/case_log.rb

@ -60,7 +60,9 @@ end
class CaseLog < ApplicationRecord class CaseLog < ApplicationRecord
include Discard::Model include Discard::Model
default_scope -> { kept } default_scope -> { kept }
scope :not_started, -> { where(status: "not_started") }
scope :in_progress, -> { where(status: "in_progress") } scope :in_progress, -> { where(status: "in_progress") }
scope :not_completed, -> { where.not(status: "completed") }
scope :completed, -> { where(status: "completed") } scope :completed, -> { where(status: "completed") }
validate :instance_validations validate :instance_validations

4
spec/features/case_log_spec.rb

@ -32,6 +32,10 @@ RSpec.describe "Test Features" do
describe "Create new log" do describe "Create new log" do
it "redirects to the task list for the new log" do it "redirects to the task list for the new log" do
visit("/case_logs") 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") click_link("Create new log")
id = CaseLog.order(created_at: :desc).first.id id = CaseLog.order(created_at: :desc).first.id
expect(page).to have_content("Tasklist for log #{id}") expect(page).to have_content("Tasklist for log #{id}")

Loading…
Cancel
Save