Skip to content

Commit

Permalink
Add Session#today_or_future_dates
Browse files Browse the repository at this point in the history
This can be used to figure out the dates for the session that are
upcoming.
  • Loading branch information
thomasleese committed Oct 1, 2024
1 parent 26bd246 commit 2eb84aa
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
4 changes: 4 additions & 0 deletions app/models/session.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ def year_groups
programmes.flat_map(&:year_groups).uniq.sort
end

def today_or_future_dates
dates.select(&:today_or_future?).map(&:value)
end

def create_patient_sessions!
return if location.nil?

Expand Down
38 changes: 38 additions & 0 deletions spec/models/session_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,44 @@
it { should contain_exactly(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11) }
end

describe "#today_or_future_dates" do
subject(:today_or_future_dates) do
travel_to(today) { session.today_or_future_dates }
end

let(:dates) do
[Date.new(2024, 1, 1), Date.new(2024, 1, 2), Date.new(2024, 1, 3)]
end

let(:session) { create(:session, academic_year: 2023, date: nil) }

before { dates.each { |value| create(:session_date, session:, value:) } }

context "on the first day" do
let(:today) { dates.first }

it { should match_array(dates) }
end

context "on the second day" do
let(:today) { dates.second }

it { should match_array(dates.drop(1)) }
end

context "on the third day" do
let(:today) { dates.third }

it { should match_array(dates.drop(2)) }
end

context "after the session" do
let(:today) { dates.third + 1.day }

it { should be_empty }
end
end

describe "#create_patient_sessions!" do
subject(:create_patient_sessions!) { session.create_patient_sessions! }

Expand Down

0 comments on commit 2eb84aa

Please sign in to comment.