From 1e2be8321424a0aa6bba5401ffe91045e110ccf1 Mon Sep 17 00:00:00 2001 From: eddieleeper Date: Wed, 20 Dec 2023 15:07:48 +0000 Subject: [PATCH] Update contract start date rules; amendments following review (#265) --- README.md | 4 ++-- app/models/form/eligibility_check.rb | 9 ++------- config/application.rb | 1 + spec/models/form/eligibility_check_spec.rb | 4 ++-- 4 files changed, 7 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index fa4daf17..8d40c63c 100644 --- a/README.md +++ b/README.md @@ -105,10 +105,10 @@ available environments. Run the following command `make edit-app-secrets` #### Contract Start Date -The environment variable `CONTRACT_START_MONTHS_LIMIT` can be set to `5` to override +The custom configuration entry `config.x.form_eligibility.contract_start_months_limit` can be set to `5` to override the default of six months prior to the current service start date. `AppSettings.current.service_start_date`. -This can be set to either `5` or `6` anything else will default to `6`. +This should be set to either `5` or `6` anything else will default to `6`. ### SSH access diff --git a/app/models/form/eligibility_check.rb b/app/models/form/eligibility_check.rb index 3cf7fc69..9137b797 100644 --- a/app/models/form/eligibility_check.rb +++ b/app/models/form/eligibility_check.rb @@ -54,16 +54,11 @@ def contract_start_date_eligible?(start_date) # default to 6 and only allow 5 or 6. anything else results in 6. def months_limit - limit = ENV.fetch("CONTRACT_START_MONTHS_LIMIT", 6).to_i + limit = Rails.configuration.x.form_eligibility.contract_start_months_limit.to_i [5, 6].include?(limit) ? limit : 6 end def months_limit_in_words - case months_limit - when 5 - "five" - else - "six" - end + months_limit == 5 ? "five" : "six" end end diff --git a/config/application.rb b/config/application.rb index 2948f757..1122ac69 100644 --- a/config/application.rb +++ b/config/application.rb @@ -49,5 +49,6 @@ class Application < Rails::Application config.x.govuk_notify.generic_email_template_id = ENV.fetch("GOVUK_NOTIFY_GENERIC_EMAIL_TEMPLATE_ID") config.x.events.filtered_attributes = YAML.load_file(Rails.root.join("config/events/filtered_attributes.yml")) + config.x.form_eligibility.contract_start_months_limit = 6 end end diff --git a/spec/models/form/eligibility_check_spec.rb b/spec/models/form/eligibility_check_spec.rb index 4d7654ee..bfea7001 100644 --- a/spec/models/form/eligibility_check_spec.rb +++ b/spec/models/form/eligibility_check_spec.rb @@ -74,11 +74,11 @@ service_end_date: 1.month.from_now.end_of_month, ) travel_to Time.zone.local(2024, 5, 31) - ENV["CONTRACT_START_MONTHS_LIMIT"] = "5" + Rails.configuration.x.form_eligibility.contract_start_months_limit = 5 end after do - ENV.delete("CONTRACT_START_MONTHS_LIMIT") + Rails.configuration.x.form_eligibility.contract_start_months_limit = 6 end let(:form) { build(:form, :eligible) }