Browse Source

Add startdate to the form

pull/744/head
Kat 3 years ago
parent
commit
0b03245b07
  1. 2
      app/controllers/locations_controller.rb
  2. 4
      app/views/locations/edit.html.erb
  3. 4
      app/views/locations/new.html.erb
  4. 10
      spec/requests/locations_controller_spec.rb

2
app/controllers/locations_controller.rb

@ -69,7 +69,7 @@ private
end end
def location_params 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[:postcode] = PostcodeService.clean(required_params[:postcode]) if required_params[:postcode]
required_params required_params
end end

4
app/views/locations/edit.html.erb

@ -44,6 +44,10 @@
hint: { text: "This includes stairlifts, ramps, level-access showers or grab rails" }, 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" } %> 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") %> <%= govuk_section_break(visible: true, size: "m") %>
<% another_location_selection = %w[Yes no].map { |key, _| OpenStruct.new(id: key, name: key.to_s.humanize) } %> <% another_location_selection = %w[Yes no].map { |key, _| OpenStruct.new(id: key, name: key.to_s.humanize) } %>

4
app/views/locations/new.html.erb

@ -46,6 +46,10 @@
hint: { text: "This includes stairlifts, ramps, level-access showers or grab rails" }, 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" } %> 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") %> <%= govuk_section_break(visible: true, size: "m") %>
<% another_location_selection = %w[Yes No].map { |key, _| OpenStruct.new(id: key, name: key.to_s.humanize) } %> <% another_location_selection = %w[Yes No].map { |key, _| OpenStruct.new(id: key, name: key.to_s.humanize) } %>

10
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 context "when signed in as a data coordinator" do
let(:user) { FactoryBot.create(:user, :data_coordinator) } let(:user) { FactoryBot.create(:user, :data_coordinator) }
let!(:scheme) { FactoryBot.create(:scheme, owning_organisation: user.organisation) } 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 before do
sign_in user sign_in user
@ -111,6 +112,7 @@ RSpec.describe LocationsController, type: :request do
expect(Location.last.units).to eq(5) expect(Location.last.units).to eq(5)
expect(Location.last.type_of_unit).to eq("Bungalow") expect(Location.last.type_of_unit).to eq("Bungalow")
expect(Location.last.wheelchair_adaptation).to eq("No") expect(Location.last.wheelchair_adaptation).to eq("No")
expect(Location.last.startdate).to eq(startdate)
end end
context "when postcode is submitted with lower case" do 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 context "when signed in as a data coordinator" do
let(:user) { FactoryBot.create(:user, :data_coordinator) } let(:user) { FactoryBot.create(:user, :data_coordinator) }
let!(:scheme) { FactoryBot.create(:scheme, owning_organisation: user.organisation) } let!(:scheme) { FactoryBot.create(:scheme, owning_organisation: user.organisation) }
let!(:location) { FactoryBot.create(:location, scheme:) } 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(: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 before do
sign_in user sign_in user
@ -410,6 +413,7 @@ RSpec.describe LocationsController, type: :request do
expect(Location.last.units).to eq(5) expect(Location.last.units).to eq(5)
expect(Location.last.type_of_unit).to eq("Bungalow") expect(Location.last.type_of_unit).to eq("Bungalow")
expect(Location.last.wheelchair_adaptation).to eq("No") expect(Location.last.wheelchair_adaptation).to eq("No")
expect(Location.last.startdate).to eq(startdate)
end end
context "when updating from edit-name page" do context "when updating from edit-name page" do

Loading…
Cancel
Save