diff --git a/app/controllers/locations_controller.rb b/app/controllers/locations_controller.rb index d01f5fb20..a37a0a7cd 100644 --- a/app/controllers/locations_controller.rb +++ b/app/controllers/locations_controller.rb @@ -164,11 +164,10 @@ private def deactivation_date return if params[:location].blank? - - return @location.errors.add(:deactivation_date_type, message: I18n.t("validations.location.deactivation_date.not_selected")) if params[:location][:deactivation_date].blank? && params[:location][:deactivation_date_type].blank? collection_start_date = FormHandler.instance.current_collection_start_date + return collection_start_date if params[:location][:deactivation_date_type] == "default" - return collection_start_date if params[:location][:deactivation_date_type].to_i == 1 + return @location.errors.add(:deactivation_date_type, message: I18n.t("validations.location.deactivation_date.not_selected")) if params[:location][:deactivation_date].blank? && params[:location][:deactivation_date_type].blank? return params[:location][:deactivation_date] if params[:location][:deactivation_date_type].blank? day = params[:location]["deactivation_date(3i)"] diff --git a/app/views/locations/toggle_active.html.erb b/app/views/locations/toggle_active.html.erb index c1e5ce84e..fe5b665a5 100644 --- a/app/views/locations/toggle_active.html.erb +++ b/app/views/locations/toggle_active.html.erb @@ -19,11 +19,11 @@ hint: { text: I18n.t("hints.location.deactivation", date: collection_start_date.to_formatted_s(:govuk_date)) } do %> <%= govuk_warning_text text: I18n.t("warnings.location.deactivation.existing_logs") %> <%= f.govuk_radio_button :deactivation_date_type, - 1, + "default", label: { text: "From the start of the current collection period (#{collection_start_date.to_formatted_s(:govuk_date)})" } %> <%= f.govuk_radio_button :deactivation_date_type, - 2, + "other", label: { text: "For tenancies starting after a certain date" }, **basic_conditional_html_attributes({ "deactivation_date" => %w[other] }, "location") do %> <%= f.govuk_date_field :deactivation_date, diff --git a/spec/requests/locations_controller_spec.rb b/spec/requests/locations_controller_spec.rb index 3cf0dd895..fc624cbd0 100644 --- a/spec/requests/locations_controller_spec.rb +++ b/spec/requests/locations_controller_spec.rb @@ -1249,7 +1249,7 @@ RSpec.describe LocationsController, type: :request do end context "with default date" do - let(:params) { { location: { deactivation_date_type: 1 } } } + let(:params) { { location: { deactivation_date_type: "default" } } } it "renders the confirmation page" do expect(response).to have_http_status(:ok) @@ -1288,7 +1288,7 @@ RSpec.describe LocationsController, type: :request do end context "when invalid date is entered" do - let(:params) { { location: { deactivation_date_type: 2, "deactivation_date(3i)": "10", "deactivation_date(2i)": "44", "deactivation_date(1i)": "2022" } } } + let(:params) { { location: { deactivation_date_type: "other", "deactivation_date(3i)": "10", "deactivation_date(2i)": "44", "deactivation_date(1i)": "2022" } } } it "displays the new page with an error message" do expect(response).to have_http_status(:unprocessable_entity) @@ -1297,7 +1297,7 @@ RSpec.describe LocationsController, type: :request do end context "when the date is entered is before the beginning of current collection window" do - let(:params) { { location: { deactivation_date_type: 2, "deactivation_date(3i)": "10", "deactivation_date(2i)": "4", "deactivation_date(1i)": "2020" } } } + let(:params) { { location: { deactivation_date_type: "other", "deactivation_date(3i)": "10", "deactivation_date(2i)": "4", "deactivation_date(1i)": "2020" } } } it "displays the new page with an error message" do expect(response).to have_http_status(:unprocessable_entity) @@ -1306,7 +1306,7 @@ RSpec.describe LocationsController, type: :request do end context "when the day is not entered" do - let(:params) { { location: { deactivation_date_type: 2, "deactivation_date(3i)": "", "deactivation_date(2i)": "2", "deactivation_date(1i)": "2022" } } } + let(:params) { { location: { deactivation_date_type: "other", "deactivation_date(3i)": "", "deactivation_date(2i)": "2", "deactivation_date(1i)": "2022" } } } it "displays page with an error message" do expect(response).to have_http_status(:unprocessable_entity) @@ -1315,7 +1315,7 @@ RSpec.describe LocationsController, type: :request do end context "when the month is not entered" do - let(:params) { { location: { deactivation_date_type: 2, "deactivation_date(3i)": "2", "deactivation_date(2i)": "", "deactivation_date(1i)": "2022" } } } + let(:params) { { location: { deactivation_date_type: "other", "deactivation_date(3i)": "2", "deactivation_date(2i)": "", "deactivation_date(1i)": "2022" } } } it "displays page with an error message" do expect(response).to have_http_status(:unprocessable_entity) @@ -1324,7 +1324,7 @@ RSpec.describe LocationsController, type: :request do end context "when the year is not entered" do - let(:params) { { location: { deactivation_date_type: 2, "deactivation_date(3i)": "2", "deactivation_date(2i)": "2", "deactivation_date(1i)": "" } } } + let(:params) { { location: { deactivation_date_type: "other", "deactivation_date(3i)": "2", "deactivation_date(2i)": "2", "deactivation_date(1i)": "" } } } it "displays page with an error message" do expect(response).to have_http_status(:unprocessable_entity)