diff --git a/app/controllers/locations_controller.rb b/app/controllers/locations_controller.rb index b482b81f0..a2624a790 100644 --- a/app/controllers/locations_controller.rb +++ b/app/controllers/locations_controller.rb @@ -69,7 +69,7 @@ private end def location_params - required_params = params.require(:location).permit(:postcode, :name, :units, :type_of_unit, :wheelchair_adaptation, :add_another_location).merge(scheme_id: @scheme.id) + required_params = params.require(:location).permit(:postcode, :name, :units, :type_of_unit, :wheelchair_adaptation, :add_another_location, :startdate).merge(scheme_id: @scheme.id) required_params[:postcode] = PostcodeService.clean(required_params[:postcode]) if required_params[:postcode] required_params end diff --git a/app/views/locations/edit.html.erb b/app/views/locations/edit.html.erb index 9227b3efb..45cb3bba5 100644 --- a/app/views/locations/edit.html.erb +++ b/app/views/locations/edit.html.erb @@ -44,6 +44,10 @@ hint: { text: "This includes stairlifts, ramps, level-access showers or grab rails" }, legend: { text: "Are the majority of units in this location built or adapted to wheelchair-user standards?", size: "m" } %> + <%= f.govuk_date_field :startdate, + legend: { text: "When did the first property in this location become available?", size: "m" }, + width: 20 %> + <%= govuk_section_break(visible: true, size: "m") %> <% another_location_selection = %w[Yes no].map { |key, _| OpenStruct.new(id: key, name: key.to_s.humanize) } %> diff --git a/app/views/locations/new.html.erb b/app/views/locations/new.html.erb index 8d964d07c..94c34ed8b 100644 --- a/app/views/locations/new.html.erb +++ b/app/views/locations/new.html.erb @@ -45,6 +45,10 @@ :name, hint: { text: "This includes stairlifts, ramps, level-access showers or grab rails" }, legend: { text: "Are the majority of units in this location built or adapted to wheelchair-user standards?", size: "m" } %> + + <%= f.govuk_date_field :startdate, + legend: { text: "When did the first property in this location become available?", size: "m" }, + width: 20 %> <%= govuk_section_break(visible: true, size: "m") %> diff --git a/spec/requests/locations_controller_spec.rb b/spec/requests/locations_controller_spec.rb index c67b4358a..0f770ddb3 100644 --- a/spec/requests/locations_controller_spec.rb +++ b/spec/requests/locations_controller_spec.rb @@ -90,7 +90,8 @@ RSpec.describe LocationsController, type: :request do context "when signed in as a data coordinator" do let(:user) { FactoryBot.create(:user, :data_coordinator) } let!(:scheme) { FactoryBot.create(:scheme, owning_organisation: user.organisation) } - let(:params) { { location: { name: "Test", units: "5", type_of_unit: "Bungalow", wheelchair_adaptation: "No", add_another_location: "No", postcode: "ZZ1 1ZZ" } } } + let(:startdate) { Time.utc(2022, 2, 2) } + let(:params) { { location: { name: "Test", units: "5", type_of_unit: "Bungalow", wheelchair_adaptation: "No", add_another_location: "No", postcode: "ZZ1 1ZZ", startdate: } } } before do sign_in user @@ -111,6 +112,7 @@ RSpec.describe LocationsController, type: :request do expect(Location.last.units).to eq(5) expect(Location.last.type_of_unit).to eq("Bungalow") expect(Location.last.wheelchair_adaptation).to eq("No") + expect(Location.last.startdate).to eq(startdate) end context "when postcode is submitted with lower case" do @@ -389,8 +391,9 @@ RSpec.describe LocationsController, type: :request do context "when signed in as a data coordinator" do let(:user) { FactoryBot.create(:user, :data_coordinator) } let!(:scheme) { FactoryBot.create(:scheme, owning_organisation: user.organisation) } - let!(:location) { FactoryBot.create(:location, scheme:) } - let(:params) { { location: { name: "Test", units: "5", type_of_unit: "Bungalow", wheelchair_adaptation: "No", add_another_location: "No", postcode: "ZZ1 1ZZ", page: "edit" } } } + let!(:location) { FactoryBot.create(:location, scheme:) } + let(:startdate) { Time.utc(2021, 1, 2) } + let(:params) { { location: { name: "Test", units: "5", type_of_unit: "Bungalow", wheelchair_adaptation: "No", add_another_location: "No", postcode: "ZZ1 1ZZ", startdate:, page: "edit" } } } before do sign_in user @@ -410,6 +413,7 @@ RSpec.describe LocationsController, type: :request do expect(Location.last.units).to eq(5) expect(Location.last.type_of_unit).to eq("Bungalow") expect(Location.last.wheelchair_adaptation).to eq("No") + expect(Location.last.startdate).to eq(startdate) end context "when updating from edit-name page" do