From 4fd08899f35524ff1f7cee0f4fae47d05a7058d4 Mon Sep 17 00:00:00 2001 From: Jon Allured Date: Tue, 5 Nov 2024 09:11:14 -0600 Subject: [PATCH] Fix Lineup creation --- app/jobs/create_lineup_job.rb | 4 +++- spec/jobs/create_lineup_job_spec.rb | 29 +++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 spec/jobs/create_lineup_job_spec.rb diff --git a/app/jobs/create_lineup_job.rb b/app/jobs/create_lineup_job.rb index 7f55fa7..cb38921 100644 --- a/app/jobs/create_lineup_job.rb +++ b/app/jobs/create_lineup_job.rb @@ -1,5 +1,7 @@ class CreateLineupJob < ApplicationJob def perform - Lineup.create_next + while Lineup.current.nil? + Lineup.create_next + end end end diff --git a/spec/jobs/create_lineup_job_spec.rb b/spec/jobs/create_lineup_job_spec.rb new file mode 100644 index 0000000..3ab7c15 --- /dev/null +++ b/spec/jobs/create_lineup_job_spec.rb @@ -0,0 +1,29 @@ +require "rails_helper" + +describe CreateLineupJob do + context "when there is a Lineup from yesterday" do + let(:current_on) { Date.yesterday } + + it "creates a Lineup for today" do + FactoryBot.create(:lineup, current_on: current_on) + expect(Lineup.current).to be_nil + expect do + CreateLineupJob.new.perform + end.to change(Lineup, :count).from(1).to(2) + expect(Lineup.current).to_not be_nil + end + end + + context "when there is a gap in Lineup records" do + let(:current_on) { Date.today - 7.days } + + it "creates enough Lineup records to catch up" do + FactoryBot.create(:lineup, current_on: current_on) + expect(Lineup.current).to be_nil + expect do + CreateLineupJob.new.perform + end.to change(Lineup, :count).from(1).to(8) + expect(Lineup.current).to_not be_nil + end + end +end