diff --git a/app/controllers/locations_controller.rb b/app/controllers/locations_controller.rb index 0eaef3445..127c0ec61 100644 --- a/app/controllers/locations_controller.rb +++ b/app/controllers/locations_controller.rb @@ -123,6 +123,8 @@ class LocationsController < ApplicationController year = location_params["startdate(1i)"] if [day, month, year].none?(&:blank?) && Date.valid_date?(year.to_i, month.to_i, day.to_i) @location.startdate = Time.zone.local(year.to_i, month.to_i, day.to_i) + else + @location.startdate = nil end if @location.save(context: :startdate) redirect_to scheme_location_check_answers_path(@scheme, @location, route: params[:route]) diff --git a/spec/features/schemes_helpers.rb b/spec/features/schemes_helpers.rb index 23ccffc84..68c5d9dee 100644 --- a/spec/features/schemes_helpers.rb +++ b/spec/features/schemes_helpers.rb @@ -69,7 +69,7 @@ module SchemesHelpers choose "location-mobility-type-none-field" click_button "Save and continue" fill_in "Day", with: 2 - fill_in "Month", with: 2 + fill_in "Month", with: 5 fill_in "Year", with: 2022 click_button "Save and continue" end @@ -89,7 +89,7 @@ module SchemesHelpers choose "location-mobility-type-none-field" click_button "Save and continue" fill_in "Day", with: 2 - fill_in "Month", with: 2 + fill_in "Month", with: 5 fill_in "Year", with: 2022 click_button "Save and continue" end diff --git a/spec/requests/locations_controller_spec.rb b/spec/requests/locations_controller_spec.rb index 07958b46f..3faa4ebf7 100644 --- a/spec/requests/locations_controller_spec.rb +++ b/spec/requests/locations_controller_spec.rb @@ -1089,14 +1089,14 @@ RSpec.describe LocationsController, type: :request do end context "when startdate is submitted" do - let(:params) { { location: { "startdate(1i)": "2000", "startdate(2i)": "1", "startdate(3i)": "2" } } } + let(:params) { { location: { "startdate(1i)": "2022", "startdate(2i)": "1", "startdate(3i)": "2" } } } before do patch "/schemes/#{scheme.id}/locations/#{location.id}/availability", params: end it "adds startdate to location" do - expect(Location.last.startdate).to eq(Time.zone.local(2000, 1, 2)) + expect(Location.last.startdate).to eq(Time.zone.local(2022, 1, 2)) end it "redirects correctly" do @@ -1106,14 +1106,14 @@ RSpec.describe LocationsController, type: :request do end context "when startdate is submitted with leading zeroes" do - let(:params) { { location: { "startdate(1i)": "2000", "startdate(2i)": "01", "startdate(3i)": "02" } } } + let(:params) { { location: { "startdate(1i)": "2022", "startdate(2i)": "01", "startdate(3i)": "02" } } } before do patch "/schemes/#{scheme.id}/locations/#{location.id}/availability", params: end it "adds startdate correctly " do - expect(Location.last.startdate).to eq(Time.zone.local(2000, 1, 2)) + expect(Location.last.startdate).to eq(Time.zone.local(2022, 1, 2)) end it "redirects correctly" do @@ -1131,7 +1131,7 @@ RSpec.describe LocationsController, type: :request do it "displays the new page with an error message" do expect(response).to have_http_status(:unprocessable_entity) - expect(page).to have_content(I18n.t("validations.location.startdate_blank")) + expect(page).to have_content(I18n.t("validations.location.startdate_invalid")) end end @@ -1163,14 +1163,14 @@ RSpec.describe LocationsController, type: :request do end context "when startdate is submitted" do - let(:params) { { location: { "startdate(1i)": "2000", "startdate(2i)": "1", "startdate(3i)": "2" } } } + let(:params) { { location: { "startdate(1i)": "2022", "startdate(2i)": "1", "startdate(3i)": "2" } } } before do patch "/schemes/#{scheme.id}/locations/#{location.id}/availability", params: end it "adds startdate to location" do - expect(Location.last.startdate).to eq(Time.zone.local(2000, 1, 2)) + expect(Location.last.startdate).to eq(Time.zone.local(2022, 1, 2)) end it "redirects correctly" do @@ -1180,14 +1180,14 @@ RSpec.describe LocationsController, type: :request do end context "when startdate is submitted with leading zeroes" do - let(:params) { { location: { "startdate(1i)": "2000", "startdate(2i)": "01", "startdate(3i)": "02" } } } + let(:params) { { location: { "startdate(1i)": "2022", "startdate(2i)": "01", "startdate(3i)": "02" } } } before do patch "/schemes/#{scheme.id}/locations/#{location.id}/availability", params: end it "adds startdate correctly " do - expect(Location.last.startdate).to eq(Time.zone.local(2000, 1, 2)) + expect(Location.last.startdate).to eq(Time.zone.local(2022, 1, 2)) end it "redirects correctly" do @@ -1205,7 +1205,7 @@ RSpec.describe LocationsController, type: :request do it "displays the new page with an error message" do expect(response).to have_http_status(:unprocessable_entity) - expect(page).to have_content(I18n.t("validations.location.startdate_blank")) + expect(page).to have_content(I18n.t("validations.location.startdate_invalid")) end end