Skip to content

Commit

Permalink
Fix Lineup creation
Browse files Browse the repository at this point in the history
  • Loading branch information
jonallured committed Nov 5, 2024
1 parent c839b95 commit 4fd0889
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
4 changes: 3 additions & 1 deletion app/jobs/create_lineup_job.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
class CreateLineupJob < ApplicationJob
def perform
Lineup.create_next
while Lineup.current.nil?
Lineup.create_next
end
end
end
29 changes: 29 additions & 0 deletions spec/jobs/create_lineup_job_spec.rb
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 4fd0889

Please sign in to comment.