Skip to content

Commit e893af3

Browse files
committed
Add academic year preparation date
This adds support for adding academic years to the service before their official start date through the introduce of a preparation period. For now this has no impact on the service, but in the future this will change which programme years are displayed on the programmes page and which year groups patients are assigned to when importing records. Jira-Issue: MAV-1505
1 parent 242f6d0 commit e893af3

2 files changed

Lines changed: 73 additions & 10 deletions

File tree

app/lib/academic_year.rb

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,17 @@ def current = Date.current.academic_year
1111
# when changing the date in tests).
1212
def first = [2024, current].min
1313

14-
def last = current
14+
def last = preparation? ? current + 1 : current
15+
16+
def preparation? = Date.current >= preparation_start_date
17+
18+
private
19+
20+
def preparation_start_date
21+
start_date = (current + 1).to_academic_year_date_range.first
22+
days_of_preparation =
23+
Settings.number_of_preparation_days_before_academic_year_starts.to_i
24+
start_date - days_of_preparation.days
25+
end
1526
end
1627
end

spec/lib/academic_year_spec.rb

Lines changed: 61 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,25 @@
44
describe "#all" do
55
subject { travel_to(today) { described_class.all } }
66

7-
context "in 2024" do
7+
context "first day of 2024" do
88
let(:today) { Date.new(2024, 9, 1) }
99

1010
it { should eq([2024]) }
1111
end
1212

13-
context "in 2025" do
13+
context "last day of only 2024" do
14+
let(:today) { Date.new(2025, 7, 31) }
15+
16+
it { should eq([2024]) }
17+
end
18+
19+
context "preparing for 2025" do
20+
let(:today) { Date.new(2025, 8, 1) }
21+
22+
it { should eq([2024, 2025]) }
23+
end
24+
25+
context "first day of 2025" do
1426
let(:today) { Date.new(2025, 9, 1) }
1527

1628
it { should eq([2024, 2025]) }
@@ -20,13 +32,13 @@
2032
describe "#current" do
2133
subject { travel_to(today) { described_class.current } }
2234

23-
context "in 2024" do
35+
context "first day of 2024" do
2436
let(:today) { Date.new(2024, 9, 1) }
2537

2638
it { should eq(2024) }
2739
end
2840

29-
context "in 2025" do
41+
context "first day of 2025" do
3042
let(:today) { Date.new(2025, 9, 1) }
3143

3244
it { should eq(2025) }
@@ -36,19 +48,19 @@
3648
describe "#first" do
3749
subject { travel_to(today) { described_class.first } }
3850

39-
context "in 2023" do
51+
context "first day of 2023" do
4052
let(:today) { Date.new(2023, 9, 1) }
4153

4254
it { should eq(2023) }
4355
end
4456

45-
context "in 2024" do
57+
context "first day of 2024" do
4658
let(:today) { Date.new(2024, 9, 1) }
4759

4860
it { should eq(2024) }
4961
end
5062

51-
context "in 2025" do
63+
context "first day of 2025" do
5264
let(:today) { Date.new(2025, 9, 1) }
5365

5466
it { should eq(2024) }
@@ -58,16 +70,56 @@
5870
describe "#last" do
5971
subject { travel_to(today) { described_class.last } }
6072

61-
context "in 2024" do
73+
context "first day of 2024" do
6274
let(:today) { Date.new(2024, 9, 1) }
6375

6476
it { should eq(2024) }
6577
end
6678

67-
context "in 2025" do
79+
context "last day of only 2024" do
80+
let(:today) { Date.new(2025, 7, 31) }
81+
82+
it { should eq(2024) }
83+
end
84+
85+
context "preparing for 2025" do
86+
let(:today) { Date.new(2025, 8, 1) }
87+
88+
it { should eq(2025) }
89+
end
90+
91+
context "first day of 2025" do
6892
let(:today) { Date.new(2025, 9, 1) }
6993

7094
it { should eq(2025) }
7195
end
7296
end
97+
98+
describe "#preparation?" do
99+
subject { travel_to(today) { described_class.preparation? } }
100+
101+
context "first day of 2024" do
102+
let(:today) { Date.new(2024, 9, 1) }
103+
104+
it { should be(false) }
105+
end
106+
107+
context "last day of only 2024" do
108+
let(:today) { Date.new(2025, 7, 31) }
109+
110+
it { should be(false) }
111+
end
112+
113+
context "preparing for 2025" do
114+
let(:today) { Date.new(2025, 8, 1) }
115+
116+
it { should be(true) }
117+
end
118+
119+
context "first day of 2025" do
120+
let(:today) { Date.new(2025, 9, 1) }
121+
122+
it { should be(false) }
123+
end
124+
end
73125
end

0 commit comments

Comments
 (0)