Skip to content

Commit

Permalink
Ensure lineup for tomorrow
Browse files Browse the repository at this point in the history
  • Loading branch information
jonallured committed Nov 9, 2024
1 parent 756953f commit 4559903
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
5 changes: 2 additions & 3 deletions app/jobs/create_lineup_job.rb
Original file line number Diff line number Diff line change
@@ -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
18 changes: 15 additions & 3 deletions spec/jobs/create_lineup_job_spec.rb
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down

0 comments on commit 4559903

Please sign in to comment.