From 9a72ac3a633c62d4666dbd3e8955d938dd86fe0e Mon Sep 17 00:00:00 2001 From: kosiakkatrina <54268893+kosiakkatrina@users.noreply.github.com> Date: Wed, 20 Jul 2022 16:53:22 +0100 Subject: [PATCH] Add mobility type question (#763) * Add mobility type question * Remove wheelchair_adaptation, use mobility_type to infer wchair * Add validatio to mobility type * tests * Rebase main * CYA test * extract selection methods into a helper --- app/controllers/locations_controller.rb | 2 +- app/helpers/locations_helper.rb | 20 +++++ .../derived_variables/case_log_variables.rb | 3 +- app/models/location.rb | 14 +-- app/views/locations/edit.html.erb | 15 ++-- app/views/locations/index.html.erb | 8 +- app/views/locations/new.html.erb | 18 ++-- app/views/schemes/check_answers.html.erb | 8 +- config/locales/en.yml | 11 ++- ...0720111635_remove_wheelchair_adaptation.rb | 5 ++ db/schema.rb | 3 +- db/seeds.rb | 6 +- spec/factories/location.rb | 1 - spec/features/form/check_answers_page_spec.rb | 2 +- spec/features/schemes_spec.rb | 15 +++- spec/helpers/locations_helper_spec.rb | 49 ++++++++++ spec/models/case_log_spec.rb | 4 +- spec/requests/locations_controller_spec.rb | 90 ++++++++----------- .../imports/case_logs_import_service_spec.rb | 4 +- .../scheme_location_import_service_spec.rb | 2 +- 20 files changed, 172 insertions(+), 108 deletions(-) create mode 100644 app/helpers/locations_helper.rb create mode 100644 db/migrate/20220720111635_remove_wheelchair_adaptation.rb create mode 100644 spec/helpers/locations_helper_spec.rb diff --git a/app/controllers/locations_controller.rb b/app/controllers/locations_controller.rb index ffb68c226..483c183fe 100644 --- a/app/controllers/locations_controller.rb +++ b/app/controllers/locations_controller.rb @@ -88,7 +88,7 @@ private end def location_params - 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 = params.require(:location).permit(:postcode, :name, :units, :type_of_unit, :add_another_location, :startdate, :mobility_type).merge(scheme_id: @scheme.id) required_params[:postcode] = PostcodeService.clean(required_params[:postcode]) if required_params[:postcode] required_params end diff --git a/app/helpers/locations_helper.rb b/app/helpers/locations_helper.rb new file mode 100644 index 000000000..1d2412184 --- /dev/null +++ b/app/helpers/locations_helper.rb @@ -0,0 +1,20 @@ +module LocationsHelper + def mobility_type_selection + mobility_types_to_display = Location.mobility_types.excluding("Property designed to accessible general standard", "Missing") + mobility_types_to_display.map { |key, value| OpenStruct.new(id: key, name: key.to_s.humanize, description: I18n.t("questions.descriptions.location.mobility_type.#{value}")) } + end + + def another_location_selection + selection_options(%w[Yes No]) + end + + def type_of_units_selection + selection_options(Location.type_of_units) + end + + def selection_options(resource) + return [] if resource.blank? + + resource.map { |key, _| OpenStruct.new(id: key, name: key.to_s.humanize) } + end +end diff --git a/app/models/derived_variables/case_log_variables.rb b/app/models/derived_variables/case_log_variables.rb index 31209dd50..edbece2a1 100644 --- a/app/models/derived_variables/case_log_variables.rb +++ b/app/models/derived_variables/case_log_variables.rb @@ -70,8 +70,7 @@ module DerivedVariables::CaseLogVariables if is_supported_housing? if location - # TODO: Remove and replace with mobility type - self.wchair = location.wheelchair_adaptation_before_type_cast + self.wchair = location.mobility_type_before_type_cast == "W" ? 1 : 2 end if is_renewal? self.voiddate = startdate diff --git a/app/models/location.rb b/app/models/location.rb index 0d5bf1a76..4812e2cd5 100644 --- a/app/models/location.rb +++ b/app/models/location.rb @@ -1,24 +1,17 @@ class Location < ApplicationRecord validate :validate_postcode - validates :units, :type_of_unit, presence: true + validates :units, :type_of_unit, :mobility_type, presence: true belongs_to :scheme before_save :infer_la!, if: :postcode_changed? attr_accessor :add_another_location - WHEELCHAIR_ADAPTATIONS = { - Yes: 1, - No: 2, - }.freeze - - enum wheelchair_adaptation: WHEELCHAIR_ADAPTATIONS - MOBILITY_TYPE = { - "Property fitted with equipment and adaptations (if not designed to above standards)": "A", + "Wheelchair-user standard": "W", + "Fitted with equipment and adaptations": "A", "Property designed to accessible general standard": "M", "None": "N", - "Property designed to wheelchair user standard": "W", "Missing": "X", }.freeze @@ -41,7 +34,6 @@ class Location < ApplicationRecord { name: "Postcode", value: postcode, suffix: county }, { name: "Type of unit", value: type_of_unit, suffix: false }, { name: "Type of building", value: type_of_building, suffix: false }, - { name: "Wheelchair adaptation", value: wheelchair_adaptation, suffix: false }, ] end diff --git a/app/views/locations/edit.html.erb b/app/views/locations/edit.html.erb index 227605485..bee510eaf 100644 --- a/app/views/locations/edit.html.erb +++ b/app/views/locations/edit.html.erb @@ -29,20 +29,18 @@ hint: { text: I18n.t("hints.location.units") }, autofocus: true %> - <% type_of_units_selection = Location.type_of_units.keys.map { |key, _| OpenStruct.new(id: key, name: key.to_s.humanize) } %> <%= f.govuk_collection_radio_buttons :type_of_unit, type_of_units_selection, :id, :name, legend: { text: I18n.t("questions.location.type_of_unit"), size: "m" } %> - <% wheelchair_user_selection = Location.wheelchair_adaptations.keys.map { |key, _| OpenStruct.new(id: key, name: key.to_s.humanize) } %> - <%= f.govuk_collection_radio_buttons :wheelchair_adaptation, - wheelchair_user_selection, - :id, - :name, - hint: { text: I18n.t("hints.location.wheelchair_adaptation") }, - legend: { text: I18n.t("questions.location.wheelchair_adaptation"), size: "m" } %> + <%= f.govuk_collection_radio_buttons :mobility_type, + mobility_type_selection, + :id, + :name, + :description, + legend: { text: I18n.t("questions.location.mobility_type"), size: "m" } %> <%= f.govuk_date_field :startdate, legend: { text: I18n.t("questions.location.startdate"), size: "m" }, @@ -50,7 +48,6 @@ <%= govuk_section_break(visible: true, size: "m") %> - <% another_location_selection = %w[Yes no].map { |key, _| OpenStruct.new(id: key, name: key.to_s.humanize) } %> <%= f.govuk_collection_radio_buttons :add_another_location, another_location_selection, :id, diff --git a/app/views/locations/index.html.erb b/app/views/locations/index.html.erb index 2fa495d2a..891b4c320 100644 --- a/app/views/locations/index.html.erb +++ b/app/views/locations/index.html.erb @@ -30,6 +30,9 @@ <% row.cell(header: true, text: "Common unit type", html_attributes: { scope: "col", }) %> + <% row.cell(header: true, text: "Mobility type", html_attributes: { + scope: "col", + }) %> <% end %> <% end %> <% @locations.each do |location| %> @@ -38,8 +41,9 @@ <% row.cell(text: location.id) %> <% row.cell(text: simple_format(location_cell(location, "/schemes/#{@scheme.id}/locations/#{location.id}/edit-name"), { class: "govuk-!-font-weight-bold" }, wrapper_tag: "div")) %> <% row.cell(text: location.units) %> - <% row.cell(text: simple_format("#{location.type_of_unit}#{location.wheelchair_adaptation == 'Yes' ? "\nWith wheelchair adaptations" : ''}")) %> - <% end %> + <% row.cell(text: simple_format("#{location.type_of_unit}")) %> + <% row.cell(text: location.mobility_type) %> + <% end %> <% end %> <% end %> <% end %> diff --git a/app/views/locations/new.html.erb b/app/views/locations/new.html.erb index 669a39594..184fed8bb 100644 --- a/app/views/locations/new.html.erb +++ b/app/views/locations/new.html.erb @@ -29,22 +29,18 @@ hint: { text: I18n.t("hints.location.units") }, autofocus: true %> - <% type_of_units_selection = Location.type_of_units.keys.map { |key, _| OpenStruct.new(id: key, name: key.to_s.humanize) } %> - <%= f.govuk_collection_radio_buttons :type_of_unit, type_of_units_selection, :id, :name, legend: { text: I18n.t("questions.location.type_of_unit"), size: "m" } %> - <% wheelchair_user_selection = Location.wheelchair_adaptations.keys.map { |key, _| OpenStruct.new(id: key, name: key.to_s.humanize) } %> - - <%= f.govuk_collection_radio_buttons :wheelchair_adaptation, - wheelchair_user_selection, - :id, - :name, - hint: { text: I18n.t("hints.location.wheelchair_adaptation") }, - legend: { text: I18n.t("questions.location.wheelchair_adaptation"), size: "m" } %> + <%= f.govuk_collection_radio_buttons :mobility_type, + mobility_type_selection, + :id, + :name, + :description, + legend: { text: I18n.t("questions.location.mobility_type"), size: "m" } %> <%= f.govuk_date_field :startdate, legend: { text: I18n.t("questions.location.startdate"), size: "m" }, @@ -52,8 +48,6 @@ <%= govuk_section_break(visible: true, size: "m") %> - <% another_location_selection = %w[Yes No].map { |key, _| OpenStruct.new(id: key, name: key.to_s.humanize) } %> - <%= f.govuk_collection_radio_buttons :add_another_location, another_location_selection, :id, diff --git a/app/views/schemes/check_answers.html.erb b/app/views/schemes/check_answers.html.erb index ef3bd16ed..74009a84e 100644 --- a/app/views/schemes/check_answers.html.erb +++ b/app/views/schemes/check_answers.html.erb @@ -90,6 +90,9 @@ <% row.cell(header: true, text: "Common unit type", html_attributes: { scope: "col", }) %> + <% row.cell(header: true, text: "Mobility type", html_attributes: { + scope: "col", + }) %> <% end %> <% end %> <% @scheme.locations.each do |location| %> @@ -98,8 +101,9 @@ <% row.cell(text: location.id) %> <% row.cell(text: simple_format(location_cell(location, "/schemes/#{@scheme.id}/locations/#{location.id}/edit"), { class: "govuk-!-font-weight-bold" }, wrapper_tag: "div")) %> <% row.cell(text: location.units) %> - <% row.cell(text: simple_format("#{location.type_of_unit}#{location.wheelchair_adaptation == 'Yes' ? "\nWith wheelchair adaptations" : ''}")) %> - <% end %> + <% row.cell(text: simple_format("#{location.type_of_unit}")) %> + <% row.cell(text: location.mobility_type) %> + <% end %> <% end %> <% end %> <% end %> diff --git a/config/locales/en.yml b/config/locales/en.yml index 895bf023e..dfdc65874 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -76,6 +76,8 @@ en: blank: "Enter total number of units at this location" type_of_unit: blank: "Select the most common type of unit at this location" + mobility_type: + blank: "Select the mobility standards for the majority of units in this location" validations: organisation: @@ -323,16 +325,21 @@ en: name: "Location name (optional)" units: "Total number of units at this location" type_of_unit: "What is the most common type of unit at this location?" - wheelchair_adaptation: "Are the majority of units in this location built or adapted to wheelchair-user standards?" startdate: "When did the first property in this location become available under this scheme?" add_another_location: "Do you want to add another location?" + mobility_type: "What are the mobility standards for the majority of units in this location?" + descriptions: + location: + mobility_type: + W: "The majority of units are suitable for someone who uses a wheelchair and offer the full use of all rooms and facilities." + A: "For example, the majority of units have been fitted with stairlifts, ramps, level access showers or grab rails." + N: "The majority of units are not designed to wheelchair-user standards or fitted with any equipment and adaptations." hints: location: postcode: "For example, SW1P 4DF." name: "This is how you refer to this location within your organisation" units: "A unit can be a bedroom in a shared house or flat, or a house with 4 bedrooms. Do not include bedrooms used for wardens, managers, volunteers or sleep-in staff." - wheelchair_adaptation: "This includes stairlifts, ramps, level-access showers or grab rails" test: one_argument: "This is based on the tenant’s work situation: %{ecstat1}" diff --git a/db/migrate/20220720111635_remove_wheelchair_adaptation.rb b/db/migrate/20220720111635_remove_wheelchair_adaptation.rb new file mode 100644 index 000000000..8c3ee91e9 --- /dev/null +++ b/db/migrate/20220720111635_remove_wheelchair_adaptation.rb @@ -0,0 +1,5 @@ +class RemoveWheelchairAdaptation < ActiveRecord::Migration[7.0] + def change + remove_column :locations, :wheelchair_adaptation, :integer + end +end diff --git a/db/schema.rb b/db/schema.rb index 096056489..20d2612d2 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.0].define(version: 2022_07_15_133937) do +ActiveRecord::Schema[7.0].define(version: 2022_07_20_111635) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -240,7 +240,6 @@ ActiveRecord::Schema[7.0].define(version: 2022_07_15_133937) do t.string "location_code" t.string "postcode" t.string "type_of_building" - t.integer "wheelchair_adaptation" t.bigint "scheme_id", null: false t.string "name" t.datetime "created_at", null: false diff --git a/db/seeds.rb b/db/seeds.rb index 03a61cf59..3a084e436 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -117,7 +117,7 @@ unless Rails.env.test? type_of_unit: 4, units: 1, type_of_building: "Purpose built", - wheelchair_adaptation: 2, + mobility_type: "N", ) Location.create!( @@ -128,7 +128,7 @@ unless Rails.env.test? type_of_unit: 1, units: 1, type_of_building: "Converted from previous residential or non-residential property", - wheelchair_adaptation: 1, + mobility_type: "W", ) Location.create!( @@ -139,7 +139,7 @@ unless Rails.env.test? type_of_unit: 2, units: 1, type_of_building: "Converted from previous residential or non-residential property", - wheelchair_adaptation: 1, + mobility_type: "W", ) end diff --git a/spec/factories/location.rb b/spec/factories/location.rb index 934f6d1be..ed333f8de 100644 --- a/spec/factories/location.rb +++ b/spec/factories/location.rb @@ -6,7 +6,6 @@ FactoryBot.define do units { [1, 2, 3, 4, 6, 7].sample } type_of_building { "Purpose built" } mobility_type { %w[A M N W X].sample } - wheelchair_adaptation { 2 } scheme end end diff --git a/spec/features/form/check_answers_page_spec.rb b/spec/features/form/check_answers_page_spec.rb index ef01fc81a..f495e9897 100644 --- a/spec/features/form/check_answers_page_spec.rb +++ b/spec/features/form/check_answers_page_spec.rb @@ -7,7 +7,7 @@ RSpec.describe "Form Check Answers Page" do let(:subsection) { "household-characteristics" } let(:conditional_subsection) { "conditional-question" } let(:scheme) { FactoryBot.create(:scheme, owning_organisation: user.organisation) } - let(:location) { FactoryBot.create(:location, scheme:) } + let(:location) { FactoryBot.create(:location, scheme:, mobility_type: "N") } let(:case_log) do FactoryBot.create( diff --git a/spec/features/schemes_spec.rb b/spec/features/schemes_spec.rb index 6d94123ce..aa80a3b99 100644 --- a/spec/features/schemes_spec.rb +++ b/spec/features/schemes_spec.rb @@ -209,6 +209,10 @@ RSpec.describe "Schemes scheme Features" do it "shows details of those locations" do locations.each do |location| expect(page).to have_content(location.id) + expect(page).to have_content(location.postcode) + expect(page).to have_content(location.units) + expect(page).to have_content(location.type_of_unit) + expect(page).to have_content(location.mobility_type) end end end @@ -403,8 +407,8 @@ RSpec.describe "Schemes scheme Features" do fill_in "Location name (optional)", with: "Some name" fill_in "Total number of units at this location", with: 1 choose "Self-contained house" - choose "location-wheelchair-adaptation-no-field" choose "location-add-another-location-no-field" + choose "location-mobility-type-none-field" click_button "Save and continue" end @@ -426,6 +430,7 @@ RSpec.describe "Schemes scheme Features" do expect(page).to have_content "SW1P4DF" expect(page).to have_content "Some name" expect(page).to have_content "Self-contained house" + expect(page).to have_content "None" end end @@ -436,8 +441,8 @@ RSpec.describe "Schemes scheme Features" do fill_in "Location name (optional)", with: "Other name" fill_in "Total number of units at this location", with: 2 choose "Self-contained house" - choose "location-wheelchair-adaptation-no-field" choose "location-add-another-location-no-field" + choose "location-mobility-type-none-field" click_button "Save and continue" end @@ -465,6 +470,7 @@ RSpec.describe "Schemes scheme Features" do before do click_link "XX11XX" fill_in "Postcode", with: "ZZ1 1ZZ" + choose "location-mobility-type-wheelchair-user-standard-field" click_button "Save and continue" end @@ -472,6 +478,7 @@ RSpec.describe "Schemes scheme Features" do expect(page).to have_content "Locations" expect(page).to have_content "#{scheme.locations.count} location" expect(page).to have_content "ZZ11ZZ" + expect(page).to have_content("Wheelchair-user standard") end end end @@ -699,8 +706,8 @@ RSpec.describe "Schemes scheme Features" do fill_in "Location name (optional)", with: "Some name" fill_in "Total number of units at this location", with: 1 choose "Self-contained house" - choose "location-wheelchair-adaptation-no-field" choose "location-add-another-location-no-field" + choose "location-mobility-type-none-field" click_button "Save and continue" end @@ -732,8 +739,8 @@ RSpec.describe "Schemes scheme Features" do fill_in "Location name (optional)", with: "Other name" fill_in "Total number of units at this location", with: 2 choose "Self-contained house" - choose "location-wheelchair-adaptation-no-field" choose "location-add-another-location-no-field" + choose "location-mobility-type-none-field" click_button "Save and continue" end diff --git a/spec/helpers/locations_helper_spec.rb b/spec/helpers/locations_helper_spec.rb new file mode 100644 index 000000000..402772dec --- /dev/null +++ b/spec/helpers/locations_helper_spec.rb @@ -0,0 +1,49 @@ +require "rails_helper" + +RSpec.describe LocationsHelper do + describe "mobility type selection" do + expected_selection = [OpenStruct.new(id: "Wheelchair-user standard", name: "Wheelchair-user standard", description: "The majority of units are suitable for someone who uses a wheelchair and offer the full use of all rooms and facilities."), + OpenStruct.new(id: "Fitted with equipment and adaptations", name: "Fitted with equipment and adaptations", description: "For example, the majority of units have been fitted with stairlifts, ramps, level access showers or grab rails."), + OpenStruct.new(id: "None", name: "None", description: "The majority of units are not designed to wheelchair-user standards or fitted with any equipment and adaptations.")] + it "returns correct selection to display" do + expect(mobility_type_selection).to eq(expected_selection) + end + end + + describe "another location selection" do + it "returns correct selection to display" do + expected_selection = [OpenStruct.new(id: "Yes", name: "Yes"), OpenStruct.new(id: "No", name: "No")] + expect(another_location_selection).to eq(expected_selection) + end + end + + describe "type of units selection" do + it "returns correct selection to display" do + expected_selection = [OpenStruct.new(id: "Bungalow", name: "Bungalow"), + OpenStruct.new(id: "Self-contained flat or bedsit", name: "Self-contained flat or bedsit"), + OpenStruct.new(id: "Self-contained flat or bedsit with common facilities", name: "Self-contained flat or bedsit with common facilities"), + OpenStruct.new(id: "Self-contained house", name: "Self-contained house"), + OpenStruct.new(id: "Shared flat", name: "Shared flat"), + OpenStruct.new(id: "Shared house or hostel", name: "Shared house or hostel")] + expect(type_of_units_selection).to eq(expected_selection) + end + end + + describe "selection options" do + it "returns empty array for nil" do + expect(selection_options(nil)).to eq([]) + end + + it "returns empty array for empty string" do + expect(selection_options("")).to eq([]) + end + + it "returns empty array for empty object" do + expect(selection_options({})).to eq([]) + end + + it "can map a resource with values" do + expect(selection_options(%w[example])).to eq([OpenStruct.new(id: "example", name: "Example")]) + end + end +end diff --git a/spec/models/case_log_spec.rb b/spec/models/case_log_spec.rb index 877925dff..af64ab06f 100644 --- a/spec/models/case_log_spec.rb +++ b/spec/models/case_log_spec.rb @@ -1702,7 +1702,7 @@ RSpec.describe CaseLog do context "and not renewal" do let(:scheme) { FactoryBot.create(:scheme) } - let(:location) { FactoryBot.create(:location, scheme:, postcode: "M11AE", type_of_unit: 1, type_of_building: "Purpose built") } + let(:location) { FactoryBot.create(:location, scheme:, postcode: "M11AE", type_of_unit: 1, type_of_building: "Purpose built", mobility_type: "W") } let(:supported_housing_case_log) do described_class.create!({ @@ -1739,7 +1739,7 @@ RSpec.describe CaseLog do it "correctly infers and saves wchair" do record_from_db = ActiveRecord::Base.connection.execute("SELECT wchair from case_logs WHERE id=#{supported_housing_case_log.id}").to_a[0] - expect(record_from_db["wchair"]).to eq(2) + expect(record_from_db["wchair"]).to eq(1) end end diff --git a/spec/requests/locations_controller_spec.rb b/spec/requests/locations_controller_spec.rb index 9bcab3544..381727455 100644 --- a/spec/requests/locations_controller_spec.rb +++ b/spec/requests/locations_controller_spec.rb @@ -91,7 +91,7 @@ RSpec.describe LocationsController, type: :request do let(:user) { FactoryBot.create(:user, :data_coordinator) } let!(:scheme) { FactoryBot.create(:scheme, owning_organisation: user.organisation) } 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: } } } + let(:params) { { location: { name: "Test", units: "5", type_of_unit: "Bungalow", add_another_location: "No", postcode: "ZZ1 1ZZ", startdate:, mobility_type: "A" } } } before do sign_in user @@ -111,12 +111,12 @@ RSpec.describe LocationsController, type: :request do expect(Location.last.postcode).to eq("ZZ11ZZ") 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) + expect(Location.last.mobility_type).to eq("Fitted with equipment and adaptations") end context "when postcode is submitted with lower case" do - let(:params) { { location: { name: "Test", units: "5", type_of_unit: "Bungalow", wheelchair_adaptation: "No", add_another_location: "No", postcode: "zz1 1zz" } } } + let(:params) { { location: { name: "Test", units: "5", type_of_unit: "Bungalow", add_another_location: "No", postcode: "zz1 1zz", mobility_type: "N" } } } it "creates a new location for scheme with postcode " do expect(Location.last.postcode).to eq("ZZ11ZZ") @@ -125,7 +125,7 @@ RSpec.describe LocationsController, type: :request do context "when trying to add location to a scheme that belongs to another organisation" do let(:another_scheme) { FactoryBot.create(:scheme) } - let(:params) { { location: { name: "Test", units: "5", type_of_unit: "Bungalow", wheelchair_adaptation: "No", add_another_location: "No", postcode: "ZZ1 1ZZ" } } } + let(:params) { { location: { name: "Test", units: "5", type_of_unit: "Bungalow", add_another_location: "No", postcode: "ZZ1 1ZZ", mobility_type: "N" } } } it "displays the new page with an error message" do post "/schemes/#{another_scheme.id}/locations", params: params @@ -134,7 +134,7 @@ RSpec.describe LocationsController, type: :request do end context "when do you want to add another location is selected as yes" do - let(:params) { { location: { name: "Test", units: "5", type_of_unit: "Bungalow", wheelchair_adaptation: "No", add_another_location: "Yes", postcode: "ZZ1 1ZZ" } } } + let(:params) { { location: { name: "Test", units: "5", type_of_unit: "Bungalow", add_another_location: "Yes", postcode: "ZZ1 1ZZ", mobility_type: "N" } } } it "creates a new location for scheme with valid params and redirects to correct page" do expect { post "/schemes/#{scheme.id}/locations", params: }.to change(Location, :count).by(1) @@ -148,12 +148,12 @@ RSpec.describe LocationsController, type: :request do expect(Location.last.name).to eq("Test") 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.mobility_type).to eq("None") end end context "when do you want to add another location is selected as no" do - let(:params) { { location: { name: "Test", units: "5", type_of_unit: "Bungalow", wheelchair_adaptation: "No", add_another_location: "No", postcode: "ZZ1 1ZZ" } } } + let(:params) { { location: { name: "Test", units: "5", type_of_unit: "Bungalow", add_another_location: "No", postcode: "ZZ1 1ZZ", mobility_type: "N" } } } it "creates a new location for scheme with valid params and redirects to correct page" do expect { post "/schemes/#{scheme.id}/locations", params: }.to change(Location, :count).by(1) @@ -167,12 +167,11 @@ RSpec.describe LocationsController, type: :request do expect(Location.last.name).to eq("Test") expect(Location.last.units).to eq(5) expect(Location.last.type_of_unit).to eq("Bungalow") - expect(Location.last.wheelchair_adaptation).to eq("No") end end context "when do you want to add another location is not selected" do - let(:params) { { location: { name: "Test", units: "5", type_of_unit: "Bungalow", wheelchair_adaptation: "No", postcode: "ZZ1 1ZZ" } } } + let(:params) { { location: { name: "Test", units: "5", type_of_unit: "Bungalow", postcode: "ZZ1 1ZZ", mobility_type: "W" } } } it "creates a new location for scheme with valid params and redirects to correct page" do expect { post "/schemes/#{scheme.id}/locations", params: }.to change(Location, :count).by(1) @@ -186,18 +185,19 @@ RSpec.describe LocationsController, type: :request do expect(Location.last.name).to eq("Test") 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.mobility_type).to eq("Wheelchair-user standard") end end context "when required param are missing" do - let(:params) { { location: { postcode: "", name: "Test", units: "", type_of_unit: "", wheelchair_adaptation: "No", add_another_location: "No" } } } + let(:params) { { location: { postcode: "", name: "Test", units: "", type_of_unit: "", add_another_location: "No" } } } 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.postcode")) expect(page).to have_content(I18n.t("activerecord.errors.models.location.attributes.units.blank")) expect(page).to have_content(I18n.t("activerecord.errors.models.location.attributes.type_of_unit.blank")) + expect(page).to have_content(I18n.t("activerecord.errors.models.location.attributes.mobility_type.blank")) end end @@ -207,7 +207,7 @@ RSpec.describe LocationsController, type: :request do name: "Test", units: "5", type_of_unit: "Bungalow", - wheelchair_adaptation: "No", + mobility_type: "N", add_another_location: "No", postcode: "ZZ1 1ZZ", "startdate(3i)" => "1", @@ -228,7 +228,7 @@ RSpec.describe LocationsController, type: :request do name: "Test", units: "5", type_of_unit: "Bungalow", - wheelchair_adaptation: "No", + mobility_type: "N", add_another_location: "No", postcode: "ZZ1 1ZZ", "startdate(3i)" => "", @@ -249,7 +249,7 @@ RSpec.describe LocationsController, type: :request do context "when signed in as a support user" do let(:user) { FactoryBot.create(:user, :support) } let!(:scheme) { FactoryBot.create(:scheme) } - let(:params) { { location: { name: "Test", units: "5", type_of_unit: "Bungalow", wheelchair_adaptation: "No", add_another_location: "No", postcode: "ZZ1 1ZZ" } } } + let(:params) { { location: { name: "Test", units: "5", type_of_unit: "Bungalow", add_another_location: "No", postcode: "ZZ1 1ZZ", mobility_type: "N" } } } before do allow(user).to receive(:need_two_factor_authentication?).and_return(false) @@ -269,11 +269,10 @@ RSpec.describe LocationsController, type: :request do expect(Location.last.postcode).to eq("ZZ11ZZ") expect(Location.last.units).to eq(5) expect(Location.last.type_of_unit).to eq("Bungalow") - expect(Location.last.wheelchair_adaptation).to eq("No") end context "when postcode is submitted with lower case" do - let(:params) { { location: { name: "Test", units: "5", type_of_unit: "Bungalow", wheelchair_adaptation: "No", add_another_location: "No", postcode: "zz1 1zz" } } } + let(:params) { { location: { name: "Test", units: "5", type_of_unit: "Bungalow", add_another_location: "No", postcode: "zz1 1zz", mobility_type: "N" } } } it "creates a new location for scheme with postcode " do expect(Location.last.postcode).to eq("ZZ11ZZ") @@ -281,7 +280,7 @@ RSpec.describe LocationsController, type: :request do end context "when required postcode param is missing" do - let(:params) { { location: { name: "Test", units: "5", type_of_unit: "Bungalow", wheelchair_adaptation: "No", add_another_location: "No" } } } + let(:params) { { location: { name: "Test", units: "5", type_of_unit: "Bungalow", add_another_location: "No" } } } it "displays the new page with an error message" do post "/schemes/#{scheme.id}/locations", params: params @@ -291,7 +290,7 @@ RSpec.describe LocationsController, type: :request do end context "when do you want to add another location is selected as yes" do - let(:params) { { location: { name: "Test", units: "5", type_of_unit: "Bungalow", wheelchair_adaptation: "No", add_another_location: "Yes", postcode: "ZZ1 1ZZ" } } } + let(:params) { { location: { name: "Test", units: "5", type_of_unit: "Bungalow", add_another_location: "Yes", postcode: "ZZ1 1ZZ", mobility_type: "N" } } } it "creates a new location for scheme with valid params and redirects to correct page" do expect { post "/schemes/#{scheme.id}/locations", params: }.to change(Location, :count).by(1) @@ -304,12 +303,11 @@ RSpec.describe LocationsController, type: :request do expect(Location.last.name).to eq("Test") expect(Location.last.units).to eq(5) expect(Location.last.type_of_unit).to eq("Bungalow") - expect(Location.last.wheelchair_adaptation).to eq("No") end end context "when do you want to add another location is selected as no" do - let(:params) { { location: { name: "Test", units: "5", type_of_unit: "Bungalow", wheelchair_adaptation: "No", add_another_location: "No", postcode: "ZZ1 1ZZ" } } } + let(:params) { { location: { name: "Test", units: "5", type_of_unit: "Bungalow", add_another_location: "No", postcode: "ZZ1 1ZZ", mobility_type: "N" } } } it "creates a new location for scheme with valid params and redirects to correct page" do expect { post "/schemes/#{scheme.id}/locations", params: }.to change(Location, :count).by(1) @@ -322,12 +320,11 @@ RSpec.describe LocationsController, type: :request do expect(Location.last.name).to eq("Test") expect(Location.last.units).to eq(5) expect(Location.last.type_of_unit).to eq("Bungalow") - expect(Location.last.wheelchair_adaptation).to eq("No") end end context "when do you want to add another location is not selected" do - let(:params) { { location: { name: "Test", units: "5", type_of_unit: "Bungalow", wheelchair_adaptation: "No", postcode: "ZZ1 1ZZ" } } } + let(:params) { { location: { name: "Test", units: "5", type_of_unit: "Bungalow", postcode: "ZZ1 1ZZ", mobility_type: "N" } } } it "creates a new location for scheme with valid params and redirects to correct page" do expect { post "/schemes/#{scheme.id}/locations", params: }.to change(Location, :count).by(1) @@ -340,12 +337,11 @@ RSpec.describe LocationsController, type: :request do expect(Location.last.name).to eq("Test") expect(Location.last.units).to eq(5) expect(Location.last.type_of_unit).to eq("Bungalow") - expect(Location.last.wheelchair_adaptation).to eq("No") end end context "when required param are missing" do - let(:params) { { location: { postcode: "", name: "Test", units: "", type_of_unit: "", wheelchair_adaptation: "No", add_another_location: "No" } } } + let(:params) { { location: { postcode: "", name: "Test", units: "", type_of_unit: "", add_another_location: "No" } } } it "displays the new page with an error message" do expect(response).to have_http_status(:unprocessable_entity) @@ -361,7 +357,7 @@ RSpec.describe LocationsController, type: :request do name: "Test", units: "5", type_of_unit: "Bungalow", - wheelchair_adaptation: "No", + mobility_type: "N", add_another_location: "No", postcode: "ZZ1 1ZZ", "startdate(3i)" => "1", @@ -382,7 +378,7 @@ RSpec.describe LocationsController, type: :request do name: "Test", units: "5", type_of_unit: "Bungalow", - wheelchair_adaptation: "No", + mobility_type: "N", add_another_location: "No", postcode: "ZZ1 1ZZ", "startdate(3i)" => "", @@ -494,7 +490,7 @@ RSpec.describe LocationsController, type: :request do let!(:scheme) { FactoryBot.create(:scheme, owning_organisation: user.organisation) } 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" } } } + let(:params) { { location: { name: "Test", units: "5", type_of_unit: "Bungalow", add_another_location: "No", postcode: "ZZ1 1ZZ", startdate:, page: "edit" } } } before do sign_in user @@ -513,7 +509,6 @@ RSpec.describe LocationsController, type: :request do expect(Location.last.postcode).to eq("ZZ11ZZ") 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 @@ -532,7 +527,7 @@ RSpec.describe LocationsController, type: :request do end context "when postcode is submitted with lower case" do - let(:params) { { location: { name: "Test", units: "5", type_of_unit: "Bungalow", wheelchair_adaptation: "No", add_another_location: "No", postcode: "zz1 1zz", page: "edit" } } } + let(:params) { { location: { name: "Test", units: "5", type_of_unit: "Bungalow", add_another_location: "No", postcode: "zz1 1zz", page: "edit" } } } it "updates existing location for scheme with postcode " do expect(Location.last.postcode).to eq("ZZ11ZZ") @@ -542,7 +537,7 @@ RSpec.describe LocationsController, type: :request do context "when trying to update location for a scheme that belongs to another organisation" do let(:another_scheme) { FactoryBot.create(:scheme) } let(:another_location) { FactoryBot.create(:location) } - let(:params) { { location: { name: "Test", units: "5", type_of_unit: "Bungalow", wheelchair_adaptation: "No", add_another_location: "No", postcode: "ZZ1 1ZZ", page: "edit" } } } + let(:params) { { location: { name: "Test", units: "5", type_of_unit: "Bungalow", add_another_location: "No", postcode: "ZZ1 1ZZ", page: "edit" } } } it "displays the new page with an error message" do patch "/schemes/#{another_scheme.id}/locations/#{another_location.id}", params: params @@ -551,7 +546,7 @@ RSpec.describe LocationsController, type: :request do end context "when required postcode param is invalid" do - let(:params) { { location: { name: "Test", units: "5", type_of_unit: "Bungalow", wheelchair_adaptation: "No", add_another_location: "No", postcode: "invalid", page: "edit" } } } + let(:params) { { location: { name: "Test", units: "5", type_of_unit: "Bungalow", add_another_location: "No", postcode: "invalid", page: "edit" } } } it "displays the new page with an error message" do expect(response).to have_http_status(:unprocessable_entity) @@ -560,7 +555,7 @@ RSpec.describe LocationsController, type: :request do end context "when do you want to add another location is selected as yes" do - let(:params) { { location: { name: "Test", units: "5", type_of_unit: "Bungalow", wheelchair_adaptation: "No", add_another_location: "Yes", postcode: "ZZ1 1ZZ", page: "edit" } } } + let(:params) { { location: { name: "Test", units: "5", type_of_unit: "Bungalow", add_another_location: "Yes", postcode: "ZZ1 1ZZ", page: "edit" } } } it "updates existing location for scheme with valid params and redirects to correct page" do follow_redirect! @@ -573,12 +568,11 @@ RSpec.describe LocationsController, type: :request do expect(Location.last.name).to eq("Test") expect(Location.last.units).to eq(5) expect(Location.last.type_of_unit).to eq("Bungalow") - expect(Location.last.wheelchair_adaptation).to eq("No") end end context "when do you want to add another location is selected as no" do - let(:params) { { location: { name: "Test", units: "5", type_of_unit: "Bungalow", wheelchair_adaptation: "No", add_another_location: "No", postcode: "ZZ1 1ZZ", page: "edit" } } } + let(:params) { { location: { name: "Test", units: "5", type_of_unit: "Bungalow", add_another_location: "No", postcode: "ZZ1 1ZZ", page: "edit" } } } it "updates existing location for scheme with valid params and redirects to correct page" do follow_redirect! @@ -591,12 +585,11 @@ RSpec.describe LocationsController, type: :request do expect(Location.last.name).to eq("Test") expect(Location.last.units).to eq(5) expect(Location.last.type_of_unit).to eq("Bungalow") - expect(Location.last.wheelchair_adaptation).to eq("No") end end context "when do you want to add another location is not selected" do - let(:params) { { location: { name: "Test", units: "5", type_of_unit: "Bungalow", wheelchair_adaptation: "No", postcode: "ZZ1 1ZZ", page: "edit" } } } + let(:params) { { location: { name: "Test", units: "5", type_of_unit: "Bungalow", postcode: "ZZ1 1ZZ", page: "edit" } } } it "updates existing location for scheme with valid params and redirects to correct page" do follow_redirect! @@ -609,12 +602,11 @@ RSpec.describe LocationsController, type: :request do expect(Location.last.name).to eq("Test") expect(Location.last.units).to eq(5) expect(Location.last.type_of_unit).to eq("Bungalow") - expect(Location.last.wheelchair_adaptation).to eq("No") end end context "when required param are missing" do - let(:params) { { location: { postcode: "", name: "Test", units: "", type_of_unit: "", wheelchair_adaptation: "No", add_another_location: "No" } } } + let(:params) { { location: { postcode: "", name: "Test", units: "", type_of_unit: "", add_another_location: "No" } } } it "displays the new page with an error message" do expect(response).to have_http_status(:unprocessable_entity) @@ -629,7 +621,7 @@ RSpec.describe LocationsController, type: :request 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(:params) { { location: { name: "Test", units: "5", type_of_unit: "Bungalow", add_another_location: "No", postcode: "ZZ1 1ZZ", page: "edit" } } } before do allow(user).to receive(:need_two_factor_authentication?).and_return(false) @@ -648,7 +640,6 @@ RSpec.describe LocationsController, type: :request do expect(Location.last.postcode).to eq("ZZ11ZZ") expect(Location.last.units).to eq(5) expect(Location.last.type_of_unit).to eq("Bungalow") - expect(Location.last.wheelchair_adaptation).to eq("No") end context "when updating from edit-name page" do @@ -666,7 +657,7 @@ RSpec.describe LocationsController, type: :request do end context "when postcode is submitted with lower case" do - let(:params) { { location: { name: "Test", units: "5", type_of_unit: "Bungalow", wheelchair_adaptation: "No", add_another_location: "No", postcode: "zz1 1zz", page: "edit" } } } + let(:params) { { location: { name: "Test", units: "5", type_of_unit: "Bungalow", add_another_location: "No", postcode: "zz1 1zz", page: "edit" } } } it "updates a location for scheme with postcode " do expect(Location.last.postcode).to eq("ZZ11ZZ") @@ -674,7 +665,7 @@ RSpec.describe LocationsController, type: :request do end context "when required postcode param is missing" do - let(:params) { { location: { name: "Test", units: "5", type_of_unit: "Bungalow", wheelchair_adaptation: "No", add_another_location: "No", postcode: "invalid", page: "edit" } } } + let(:params) { { location: { name: "Test", units: "5", type_of_unit: "Bungalow", add_another_location: "No", postcode: "invalid", page: "edit" } } } it "displays the new page with an error message" do expect(response).to have_http_status(:unprocessable_entity) @@ -683,7 +674,7 @@ RSpec.describe LocationsController, type: :request do end context "when do you want to add another location is selected as yes" do - let(:params) { { location: { name: "Test", units: "5", type_of_unit: "Bungalow", wheelchair_adaptation: "No", add_another_location: "Yes", postcode: "ZZ1 1ZZ", page: "edit" } } } + let(:params) { { location: { name: "Test", units: "5", type_of_unit: "Bungalow", add_another_location: "Yes", postcode: "ZZ1 1ZZ", page: "edit" } } } it "updates location for scheme with valid params and redirects to correct page" do follow_redirect! @@ -695,12 +686,11 @@ RSpec.describe LocationsController, type: :request do expect(Location.last.name).to eq("Test") expect(Location.last.units).to eq(5) expect(Location.last.type_of_unit).to eq("Bungalow") - expect(Location.last.wheelchair_adaptation).to eq("No") end end context "when do you want to add another location is selected as no" do - let(:params) { { location: { name: "Test", units: "5", type_of_unit: "Bungalow", wheelchair_adaptation: "No", add_another_location: "No", postcode: "ZZ1 1ZZ", page: "edit" } } } + let(:params) { { location: { name: "Test", units: "5", type_of_unit: "Bungalow", add_another_location: "No", postcode: "ZZ1 1ZZ", page: "edit" } } } it "updates a location for scheme with valid params and redirects to correct page" do follow_redirect! @@ -712,12 +702,11 @@ RSpec.describe LocationsController, type: :request do expect(Location.last.name).to eq("Test") expect(Location.last.units).to eq(5) expect(Location.last.type_of_unit).to eq("Bungalow") - expect(Location.last.wheelchair_adaptation).to eq("No") end end context "when do you want to add another location is not selected" do - let(:params) { { location: { name: "Test", units: "5", type_of_unit: "Bungalow", wheelchair_adaptation: "No", postcode: "ZZ1 1ZZ", page: "edit" } } } + let(:params) { { location: { name: "Test", units: "5", type_of_unit: "Bungalow", postcode: "ZZ1 1ZZ", page: "edit" } } } it "updates a location for scheme with valid params and redirects to correct page" do follow_redirect! @@ -729,12 +718,11 @@ RSpec.describe LocationsController, type: :request do expect(Location.last.name).to eq("Test") expect(Location.last.units).to eq(5) expect(Location.last.type_of_unit).to eq("Bungalow") - expect(Location.last.wheelchair_adaptation).to eq("No") end end context "when required param are missing" do - let(:params) { { location: { postcode: "", name: "Test", units: "", type_of_unit: "", wheelchair_adaptation: "No", add_another_location: "No" } } } + let(:params) { { location: { postcode: "", name: "Test", units: "", type_of_unit: "", add_another_location: "No" } } } it "displays the new page with an error message" do expect(response).to have_http_status(:unprocessable_entity) @@ -796,7 +784,7 @@ RSpec.describe LocationsController, type: :request do expect(page).to have_content(location.id) expect(page).to have_content(location.postcode) expect(page).to have_content(location.type_of_unit) - expect(page).to have_content(location.wheelchair_adaptation) + expect(page).to have_content(location.mobility_type) end end @@ -874,7 +862,7 @@ RSpec.describe LocationsController, type: :request do expect(page).to have_content(location.id) expect(page).to have_content(location.postcode) expect(page).to have_content(location.type_of_unit) - expect(page).to have_content(location.wheelchair_adaptation) + expect(page).to have_content(location.mobility_type) end end diff --git a/spec/services/imports/case_logs_import_service_spec.rb b/spec/services/imports/case_logs_import_service_spec.rb index 836d1a45b..281a7b600 100644 --- a/spec/services/imports/case_logs_import_service_spec.rb +++ b/spec/services/imports/case_logs_import_service_spec.rb @@ -30,9 +30,9 @@ RSpec.describe Imports::CaseLogsImportService do FactoryBot.create(:user, old_user_id: "e29c492473446dca4d50224f2bb7cf965a261d6f", organisation:) # Location setup - FactoryBot.create(:location, old_visible_id: 10, wheelchair_adaptation: 1, postcode: "LS166FT", scheme_id: scheme1.id) + FactoryBot.create(:location, old_visible_id: 10, postcode: "LS166FT", scheme_id: scheme1.id, mobility_type: "W") FactoryBot.create(:location, scheme_id: scheme1.id) - FactoryBot.create(:location, old_visible_id: 10, wheelchair_adaptation: 1, postcode: "LS166FT", scheme_id: scheme2.id) + FactoryBot.create(:location, old_visible_id: 10, postcode: "LS166FT", scheme_id: scheme2.id, mobility_type: "W") # Stub the form handler to use the real form allow(FormHandler.instance).to receive(:get_form).with("2021_2022").and_return(real_2021_2022_form) diff --git a/spec/services/imports/scheme_location_import_service_spec.rb b/spec/services/imports/scheme_location_import_service_spec.rb index a7c13aaca..8683087cb 100644 --- a/spec/services/imports/scheme_location_import_service_spec.rb +++ b/spec/services/imports/scheme_location_import_service_spec.rb @@ -134,7 +134,7 @@ RSpec.describe Imports::SchemeLocationImportService do expect(location.name).to eq("Location 1") expect(location.postcode).to eq("S44 6EJ") expect(location.units).to eq(5) - expect(location.mobility_type).to eq("Property fitted with equipment and adaptations (if not designed to above standards)") + expect(location.mobility_type).to eq("Fitted with equipment and adaptations") expect(location.type_of_unit).to eq("Bungalow") expect(location.old_id).to eq(first_location_id) expect(location.old_visible_id).to eq(10)