diff --git a/app/jobs/create_lineup_job.rb b/app/jobs/create_lineup_job.rb index cb38921..0dd30a8 100644 --- a/app/jobs/create_lineup_job.rb +++ b/app/jobs/create_lineup_job.rb @@ -1,7 +1,6 @@ class CreateLineupJob < ApplicationJob def perform - while Lineup.current.nil? - Lineup.create_next - end + Lineup.create_next while Lineup.current.nil? + Lineup.create_next end end diff --git a/spec/jobs/create_lineup_job_spec.rb b/spec/jobs/create_lineup_job_spec.rb index 3ab7c15..e6dac6c 100644 --- a/spec/jobs/create_lineup_job_spec.rb +++ b/spec/jobs/create_lineup_job_spec.rb @@ -1,15 +1,27 @@ require "rails_helper" describe CreateLineupJob do + context "when there is a current Lineup" do + let(:current_on) { Date.today } + + it "creates a Lineup for tomorrow" do + FactoryBot.create(:lineup, current_on: current_on) + expect(Lineup.current).to_not be_nil + expect do + CreateLineupJob.new.perform + end.to change(Lineup, :count).from(1).to(2) + end + end + context "when there is a Lineup from yesterday" do let(:current_on) { Date.yesterday } - it "creates a Lineup for today" do + it "creates a Lineup for today and tomorrow" 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) + end.to change(Lineup, :count).from(1).to(3) expect(Lineup.current).to_not be_nil end end @@ -22,7 +34,7 @@ expect(Lineup.current).to be_nil expect do CreateLineupJob.new.perform - end.to change(Lineup, :count).from(1).to(8) + end.to change(Lineup, :count).from(1).to(9) expect(Lineup.current).to_not be_nil end end