Browse Source

reuse existing method to determine whether we are in a collection period

pull/1396/head
Arthur Campbell 3 years ago
parent
commit
6a50bf73bc
  1. 12
      app/helpers/collection_time_helper.rb
  2. 2
      app/views/schemes/toggle_active.html.erb
  3. 60
      spec/helpers/collection_time_helper_spec.rb

12
app/helpers/collection_time_helper.rb

@ -44,16 +44,4 @@ module CollectionTimeHelper
def previous_collection_start_date
current_collection_start_date - 1.year
end
def currently_crossover_period?
# generally the crossover period ends on the first Friday in June, but there may be arbitrary exceptions such as in 2023
today = Time.zone.today
if today.year == 2023
today.between?(Time.zone.local(2023, 4, 1).to_date, Time.zone.local(2023, 6, 9).to_date)
else
crossover_end_date = Time.zone.local(today.year, 6, 1).to_date
crossover_end_date += 1 until crossover_end_date.friday?
today.between?(Time.zone.local(today.year, 4, 1).to_date, crossover_end_date)
end
end
end

2
app/views/schemes/toggle_active.html.erb

@ -11,7 +11,7 @@
<%= form_with model: @scheme_deactivation_period, url: toggle_scheme_form_path(action, @scheme), method: "patch", local: true do |f| %>
<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds">
<% collection_start_date = currently_crossover_period? ? previous_collection_start_date : current_collection_start_date %>
<% collection_start_date = FormHandler.instance.in_crossover_period? ? previous_collection_start_date : current_collection_start_date %>
<%= f.govuk_error_summary %>
<%= f.govuk_radio_buttons_fieldset date_type_question(action),
legend: { text: I18n.t("questions.scheme.toggle_active.apply_from") },

60
spec/helpers/collection_time_helper_spec.rb

@ -109,64 +109,4 @@ RSpec.describe CollectionTimeHelper do
end
end
end
describe "#currently_crossover_period?" do
subject(:result) { currently_crossover_period? }
around do |example|
Timecop.freeze(now) do
example.run
end
end
context "when it is January" do
let(:now) { Time.utc(2022, 1, 3) }
it "returns false" do
expect(result).to be false
end
end
context "when it is December" do
let(:now) { Time.utc(2020, 12, 3) }
it "returns false" do
expect(result).to be false
end
end
context "when it is April" do
let(:now) { Time.utc(2023, 4, 3) }
it "returns true" do
expect(result).to be true
end
end
context "when it is June" do
context "and it is the first Friday" do
let(:now) { Time.utc(2024, 6, 7) }
it "returns true" do
expect(result).to be true
end
end
context "and it is after the first Friday" do
let(:now) { Time.utc(2024, 6, 8) }
it "returns false" do
expect(result).to be false
end
end
context "and it is 2023, after the first Friday, but before the arbitrary crossover period end" do
let(:now) { Time.utc(2023, 6, 7) }
it "returns true" do
expect(result).to be true
end
end
end
end
end

Loading…
Cancel
Save