Browse Source

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
pull/766/head
kosiakkatrina 2 years ago committed by GitHub
parent
commit
9a72ac3a63
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      app/controllers/locations_controller.rb
  2. 20
      app/helpers/locations_helper.rb
  3. 3
      app/models/derived_variables/case_log_variables.rb
  4. 14
      app/models/location.rb
  5. 11
      app/views/locations/edit.html.erb
  6. 6
      app/views/locations/index.html.erb
  7. 14
      app/views/locations/new.html.erb
  8. 6
      app/views/schemes/check_answers.html.erb
  9. 11
      config/locales/en.yml
  10. 5
      db/migrate/20220720111635_remove_wheelchair_adaptation.rb
  11. 3
      db/schema.rb
  12. 6
      db/seeds.rb
  13. 1
      spec/factories/location.rb
  14. 2
      spec/features/form/check_answers_page_spec.rb
  15. 15
      spec/features/schemes_spec.rb
  16. 49
      spec/helpers/locations_helper_spec.rb
  17. 4
      spec/models/case_log_spec.rb
  18. 90
      spec/requests/locations_controller_spec.rb
  19. 4
      spec/services/imports/case_logs_import_service_spec.rb
  20. 2
      spec/services/imports/scheme_location_import_service_spec.rb

2
app/controllers/locations_controller.rb

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

20
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

3
app/models/derived_variables/case_log_variables.rb

@ -70,8 +70,7 @@ module DerivedVariables::CaseLogVariables
if is_supported_housing? if is_supported_housing?
if location if location
# TODO: Remove and replace with mobility type self.wchair = location.mobility_type_before_type_cast == "W" ? 1 : 2
self.wchair = location.wheelchair_adaptation_before_type_cast
end end
if is_renewal? if is_renewal?
self.voiddate = startdate self.voiddate = startdate

14
app/models/location.rb

@ -1,24 +1,17 @@
class Location < ApplicationRecord class Location < ApplicationRecord
validate :validate_postcode validate :validate_postcode
validates :units, :type_of_unit, presence: true validates :units, :type_of_unit, :mobility_type, presence: true
belongs_to :scheme belongs_to :scheme
before_save :infer_la!, if: :postcode_changed? before_save :infer_la!, if: :postcode_changed?
attr_accessor :add_another_location attr_accessor :add_another_location
WHEELCHAIR_ADAPTATIONS = {
Yes: 1,
No: 2,
}.freeze
enum wheelchair_adaptation: WHEELCHAIR_ADAPTATIONS
MOBILITY_TYPE = { 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", "Property designed to accessible general standard": "M",
"None": "N", "None": "N",
"Property designed to wheelchair user standard": "W",
"Missing": "X", "Missing": "X",
}.freeze }.freeze
@ -41,7 +34,6 @@ class Location < ApplicationRecord
{ name: "Postcode", value: postcode, suffix: county }, { name: "Postcode", value: postcode, suffix: county },
{ name: "Type of unit", value: type_of_unit, suffix: false }, { name: "Type of unit", value: type_of_unit, suffix: false },
{ name: "Type of building", value: type_of_building, suffix: false }, { name: "Type of building", value: type_of_building, suffix: false },
{ name: "Wheelchair adaptation", value: wheelchair_adaptation, suffix: false },
] ]
end end

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

@ -29,20 +29,18 @@
hint: { text: I18n.t("hints.location.units") }, hint: { text: I18n.t("hints.location.units") },
autofocus: true %> 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, <%= f.govuk_collection_radio_buttons :type_of_unit,
type_of_units_selection, type_of_units_selection,
:id, :id,
:name, :name,
legend: { text: I18n.t("questions.location.type_of_unit"), size: "m" } %> 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 :mobility_type,
<%= f.govuk_collection_radio_buttons :wheelchair_adaptation, mobility_type_selection,
wheelchair_user_selection,
:id, :id,
:name, :name,
hint: { text: I18n.t("hints.location.wheelchair_adaptation") }, :description,
legend: { text: I18n.t("questions.location.wheelchair_adaptation"), size: "m" } %> legend: { text: I18n.t("questions.location.mobility_type"), size: "m" } %>
<%= f.govuk_date_field :startdate, <%= f.govuk_date_field :startdate,
legend: { text: I18n.t("questions.location.startdate"), size: "m" }, legend: { text: I18n.t("questions.location.startdate"), size: "m" },
@ -50,7 +48,6 @@
<%= 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) } %>
<%= f.govuk_collection_radio_buttons :add_another_location, <%= f.govuk_collection_radio_buttons :add_another_location,
another_location_selection, another_location_selection,
:id, :id,

6
app/views/locations/index.html.erb

@ -30,6 +30,9 @@
<% row.cell(header: true, text: "Common unit type", html_attributes: { <% row.cell(header: true, text: "Common unit type", html_attributes: {
scope: "col", scope: "col",
}) %> }) %>
<% row.cell(header: true, text: "Mobility type", html_attributes: {
scope: "col",
}) %>
<% end %> <% end %>
<% end %> <% end %>
<% @locations.each do |location| %> <% @locations.each do |location| %>
@ -38,7 +41,8 @@
<% row.cell(text: location.id) %> <% 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: 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: location.units) %>
<% row.cell(text: simple_format("<span>#{location.type_of_unit}</span>#{location.wheelchair_adaptation == 'Yes' ? "\n<span class=\"govuk-!-font-weight-regular app-!-colour-muted\">With wheelchair adaptations</span>" : ''}")) %> <% row.cell(text: simple_format("<span>#{location.type_of_unit}</span>")) %>
<% row.cell(text: location.mobility_type) %>
<% end %> <% end %>
<% end %> <% end %>
<% end %> <% end %>

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

@ -29,22 +29,18 @@
hint: { text: I18n.t("hints.location.units") }, hint: { text: I18n.t("hints.location.units") },
autofocus: true %> 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, <%= f.govuk_collection_radio_buttons :type_of_unit,
type_of_units_selection, type_of_units_selection,
:id, :id,
:name, :name,
legend: { text: I18n.t("questions.location.type_of_unit"), size: "m" } %> 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 :mobility_type,
mobility_type_selection,
<%= f.govuk_collection_radio_buttons :wheelchair_adaptation,
wheelchair_user_selection,
:id, :id,
:name, :name,
hint: { text: I18n.t("hints.location.wheelchair_adaptation") }, :description,
legend: { text: I18n.t("questions.location.wheelchair_adaptation"), size: "m" } %> legend: { text: I18n.t("questions.location.mobility_type"), size: "m" } %>
<%= f.govuk_date_field :startdate, <%= f.govuk_date_field :startdate,
legend: { text: I18n.t("questions.location.startdate"), size: "m" }, legend: { text: I18n.t("questions.location.startdate"), size: "m" },
@ -52,8 +48,6 @@
<%= 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) } %>
<%= f.govuk_collection_radio_buttons :add_another_location, <%= f.govuk_collection_radio_buttons :add_another_location,
another_location_selection, another_location_selection,
:id, :id,

6
app/views/schemes/check_answers.html.erb

@ -90,6 +90,9 @@
<% row.cell(header: true, text: "Common unit type", html_attributes: { <% row.cell(header: true, text: "Common unit type", html_attributes: {
scope: "col", scope: "col",
}) %> }) %>
<% row.cell(header: true, text: "Mobility type", html_attributes: {
scope: "col",
}) %>
<% end %> <% end %>
<% end %> <% end %>
<% @scheme.locations.each do |location| %> <% @scheme.locations.each do |location| %>
@ -98,7 +101,8 @@
<% row.cell(text: location.id) %> <% 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: 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: location.units) %>
<% row.cell(text: simple_format("<span>#{location.type_of_unit}</span>#{location.wheelchair_adaptation == 'Yes' ? "\n<span class=\"govuk-!-font-weight-regular app-!-colour-muted\">With wheelchair adaptations</span>" : ''}")) %> <% row.cell(text: simple_format("<span>#{location.type_of_unit}</span>")) %>
<% row.cell(text: location.mobility_type) %>
<% end %> <% end %>
<% end %> <% end %>
<% end %> <% end %>

11
config/locales/en.yml

@ -76,6 +76,8 @@ en:
blank: "Enter total number of units at this location" blank: "Enter total number of units at this location"
type_of_unit: type_of_unit:
blank: "Select the most common type of unit at this location" 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: validations:
organisation: organisation:
@ -323,16 +325,21 @@ en:
name: "Location name (optional)" name: "Location name (optional)"
units: "Total number of units at this location" units: "Total number of units at this location"
type_of_unit: "What is the most common type of unit 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?" startdate: "When did the first property in this location become available under this scheme?"
add_another_location: "Do you want to add another location?" 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: hints:
location: location:
postcode: "For example, SW1P 4DF." postcode: "For example, SW1P 4DF."
name: "This is how you refer to this location within your organisation" 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." 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: test:
one_argument: "This is based on the tenant’s work situation: %{ecstat1}" one_argument: "This is based on the tenant’s work situation: %{ecstat1}"

5
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

3
db/schema.rb

@ -10,7 +10,7 @@
# #
# It's strongly recommended that you check this file into your version control system. # 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 # These are extensions that must be enabled in order to support this database
enable_extension "plpgsql" enable_extension "plpgsql"
@ -240,7 +240,6 @@ ActiveRecord::Schema[7.0].define(version: 2022_07_15_133937) do
t.string "location_code" t.string "location_code"
t.string "postcode" t.string "postcode"
t.string "type_of_building" t.string "type_of_building"
t.integer "wheelchair_adaptation"
t.bigint "scheme_id", null: false t.bigint "scheme_id", null: false
t.string "name" t.string "name"
t.datetime "created_at", null: false t.datetime "created_at", null: false

6
db/seeds.rb

@ -117,7 +117,7 @@ unless Rails.env.test?
type_of_unit: 4, type_of_unit: 4,
units: 1, units: 1,
type_of_building: "Purpose built", type_of_building: "Purpose built",
wheelchair_adaptation: 2, mobility_type: "N",
) )
Location.create!( Location.create!(
@ -128,7 +128,7 @@ unless Rails.env.test?
type_of_unit: 1, type_of_unit: 1,
units: 1, units: 1,
type_of_building: "Converted from previous residential or non-residential property", type_of_building: "Converted from previous residential or non-residential property",
wheelchair_adaptation: 1, mobility_type: "W",
) )
Location.create!( Location.create!(
@ -139,7 +139,7 @@ unless Rails.env.test?
type_of_unit: 2, type_of_unit: 2,
units: 1, units: 1,
type_of_building: "Converted from previous residential or non-residential property", type_of_building: "Converted from previous residential or non-residential property",
wheelchair_adaptation: 1, mobility_type: "W",
) )
end end

1
spec/factories/location.rb

@ -6,7 +6,6 @@ FactoryBot.define do
units { [1, 2, 3, 4, 6, 7].sample } units { [1, 2, 3, 4, 6, 7].sample }
type_of_building { "Purpose built" } type_of_building { "Purpose built" }
mobility_type { %w[A M N W X].sample } mobility_type { %w[A M N W X].sample }
wheelchair_adaptation { 2 }
scheme scheme
end end
end end

2
spec/features/form/check_answers_page_spec.rb

@ -7,7 +7,7 @@ RSpec.describe "Form Check Answers Page" do
let(:subsection) { "household-characteristics" } let(:subsection) { "household-characteristics" }
let(:conditional_subsection) { "conditional-question" } let(:conditional_subsection) { "conditional-question" }
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:, mobility_type: "N") }
let(:case_log) do let(:case_log) do
FactoryBot.create( FactoryBot.create(

15
spec/features/schemes_spec.rb

@ -209,6 +209,10 @@ RSpec.describe "Schemes scheme Features" do
it "shows details of those locations" do it "shows details of those locations" do
locations.each do |location| locations.each do |location|
expect(page).to have_content(location.id) 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 end
end end
@ -403,8 +407,8 @@ RSpec.describe "Schemes scheme Features" do
fill_in "Location name (optional)", with: "Some name" fill_in "Location name (optional)", with: "Some name"
fill_in "Total number of units at this location", with: 1 fill_in "Total number of units at this location", with: 1
choose "Self-contained house" choose "Self-contained house"
choose "location-wheelchair-adaptation-no-field"
choose "location-add-another-location-no-field" choose "location-add-another-location-no-field"
choose "location-mobility-type-none-field"
click_button "Save and continue" click_button "Save and continue"
end end
@ -426,6 +430,7 @@ RSpec.describe "Schemes scheme Features" do
expect(page).to have_content "SW1P4DF" expect(page).to have_content "SW1P4DF"
expect(page).to have_content "Some name" expect(page).to have_content "Some name"
expect(page).to have_content "Self-contained house" expect(page).to have_content "Self-contained house"
expect(page).to have_content "None"
end end
end end
@ -436,8 +441,8 @@ RSpec.describe "Schemes scheme Features" do
fill_in "Location name (optional)", with: "Other name" fill_in "Location name (optional)", with: "Other name"
fill_in "Total number of units at this location", with: 2 fill_in "Total number of units at this location", with: 2
choose "Self-contained house" choose "Self-contained house"
choose "location-wheelchair-adaptation-no-field"
choose "location-add-another-location-no-field" choose "location-add-another-location-no-field"
choose "location-mobility-type-none-field"
click_button "Save and continue" click_button "Save and continue"
end end
@ -465,6 +470,7 @@ RSpec.describe "Schemes scheme Features" do
before do before do
click_link "XX11XX" click_link "XX11XX"
fill_in "Postcode", with: "ZZ1 1ZZ" fill_in "Postcode", with: "ZZ1 1ZZ"
choose "location-mobility-type-wheelchair-user-standard-field"
click_button "Save and continue" click_button "Save and continue"
end end
@ -472,6 +478,7 @@ RSpec.describe "Schemes scheme Features" do
expect(page).to have_content "Locations" expect(page).to have_content "Locations"
expect(page).to have_content "#{scheme.locations.count} location" expect(page).to have_content "#{scheme.locations.count} location"
expect(page).to have_content "ZZ11ZZ" expect(page).to have_content "ZZ11ZZ"
expect(page).to have_content("Wheelchair-user standard")
end end
end end
end end
@ -699,8 +706,8 @@ RSpec.describe "Schemes scheme Features" do
fill_in "Location name (optional)", with: "Some name" fill_in "Location name (optional)", with: "Some name"
fill_in "Total number of units at this location", with: 1 fill_in "Total number of units at this location", with: 1
choose "Self-contained house" choose "Self-contained house"
choose "location-wheelchair-adaptation-no-field"
choose "location-add-another-location-no-field" choose "location-add-another-location-no-field"
choose "location-mobility-type-none-field"
click_button "Save and continue" click_button "Save and continue"
end end
@ -732,8 +739,8 @@ RSpec.describe "Schemes scheme Features" do
fill_in "Location name (optional)", with: "Other name" fill_in "Location name (optional)", with: "Other name"
fill_in "Total number of units at this location", with: 2 fill_in "Total number of units at this location", with: 2
choose "Self-contained house" choose "Self-contained house"
choose "location-wheelchair-adaptation-no-field"
choose "location-add-another-location-no-field" choose "location-add-another-location-no-field"
choose "location-mobility-type-none-field"
click_button "Save and continue" click_button "Save and continue"
end end

49
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

4
spec/models/case_log_spec.rb

@ -1702,7 +1702,7 @@ RSpec.describe CaseLog do
context "and not renewal" do context "and not renewal" do
let(:scheme) { FactoryBot.create(:scheme) } 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 let(:supported_housing_case_log) do
described_class.create!({ described_class.create!({
@ -1739,7 +1739,7 @@ RSpec.describe CaseLog do
it "correctly infers and saves wchair" 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] 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
end end

90
spec/requests/locations_controller_spec.rb

@ -91,7 +91,7 @@ RSpec.describe LocationsController, type: :request 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(:startdate) { Time.utc(2022, 2, 2) } 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 before do
sign_in user sign_in user
@ -111,12 +111,12 @@ RSpec.describe LocationsController, type: :request do
expect(Location.last.postcode).to eq("ZZ11ZZ") expect(Location.last.postcode).to eq("ZZ11ZZ")
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.startdate).to eq(startdate) expect(Location.last.startdate).to eq(startdate)
expect(Location.last.mobility_type).to eq("Fitted with equipment and adaptations")
end end
context "when postcode is submitted with lower case" do 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 it "creates a new location for scheme with postcode " do
expect(Location.last.postcode).to eq("ZZ11ZZ") 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 context "when trying to add location to a scheme that belongs to another organisation" do
let(:another_scheme) { FactoryBot.create(:scheme) } 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 it "displays the new page with an error message" do
post "/schemes/#{another_scheme.id}/locations", params: params post "/schemes/#{another_scheme.id}/locations", params: params
@ -134,7 +134,7 @@ RSpec.describe LocationsController, type: :request do
end end
context "when do you want to add another location is selected as yes" do 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 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) 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.name).to eq("Test")
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.mobility_type).to eq("None")
end end
end end
context "when do you want to add another location is selected as no" do 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 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) 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.name).to eq("Test")
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")
end end
end end
context "when do you want to add another location is not selected" do 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 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) 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.name).to eq("Test")
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.mobility_type).to eq("Wheelchair-user standard")
end end
end end
context "when required param are missing" do 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 it "displays the new page with an error message" do
expect(response).to have_http_status(:unprocessable_entity) expect(response).to have_http_status(:unprocessable_entity)
expect(page).to have_content(I18n.t("validations.postcode")) 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.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.type_of_unit.blank"))
expect(page).to have_content(I18n.t("activerecord.errors.models.location.attributes.mobility_type.blank"))
end end
end end
@ -207,7 +207,7 @@ RSpec.describe LocationsController, type: :request do
name: "Test", name: "Test",
units: "5", units: "5",
type_of_unit: "Bungalow", type_of_unit: "Bungalow",
wheelchair_adaptation: "No", mobility_type: "N",
add_another_location: "No", add_another_location: "No",
postcode: "ZZ1 1ZZ", postcode: "ZZ1 1ZZ",
"startdate(3i)" => "1", "startdate(3i)" => "1",
@ -228,7 +228,7 @@ RSpec.describe LocationsController, type: :request do
name: "Test", name: "Test",
units: "5", units: "5",
type_of_unit: "Bungalow", type_of_unit: "Bungalow",
wheelchair_adaptation: "No", mobility_type: "N",
add_another_location: "No", add_another_location: "No",
postcode: "ZZ1 1ZZ", postcode: "ZZ1 1ZZ",
"startdate(3i)" => "", "startdate(3i)" => "",
@ -249,7 +249,7 @@ RSpec.describe LocationsController, type: :request do
context "when signed in as a support user" do context "when signed in as a support user" do
let(:user) { FactoryBot.create(:user, :support) } let(:user) { FactoryBot.create(:user, :support) }
let!(:scheme) { FactoryBot.create(:scheme) } 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 before do
allow(user).to receive(:need_two_factor_authentication?).and_return(false) 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.postcode).to eq("ZZ11ZZ")
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")
end end
context "when postcode is submitted with lower case" do 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 it "creates a new location for scheme with postcode " do
expect(Location.last.postcode).to eq("ZZ11ZZ") expect(Location.last.postcode).to eq("ZZ11ZZ")
@ -281,7 +280,7 @@ RSpec.describe LocationsController, type: :request do
end end
context "when required postcode param is missing" do 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 it "displays the new page with an error message" do
post "/schemes/#{scheme.id}/locations", params: params post "/schemes/#{scheme.id}/locations", params: params
@ -291,7 +290,7 @@ RSpec.describe LocationsController, type: :request do
end end
context "when do you want to add another location is selected as yes" do 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 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) 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.name).to eq("Test")
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")
end end
end end
context "when do you want to add another location is selected as no" do 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 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) 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.name).to eq("Test")
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")
end end
end end
context "when do you want to add another location is not selected" do 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 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) 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.name).to eq("Test")
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")
end end
end end
context "when required param are missing" do 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 it "displays the new page with an error message" do
expect(response).to have_http_status(:unprocessable_entity) expect(response).to have_http_status(:unprocessable_entity)
@ -361,7 +357,7 @@ RSpec.describe LocationsController, type: :request do
name: "Test", name: "Test",
units: "5", units: "5",
type_of_unit: "Bungalow", type_of_unit: "Bungalow",
wheelchair_adaptation: "No", mobility_type: "N",
add_another_location: "No", add_another_location: "No",
postcode: "ZZ1 1ZZ", postcode: "ZZ1 1ZZ",
"startdate(3i)" => "1", "startdate(3i)" => "1",
@ -382,7 +378,7 @@ RSpec.describe LocationsController, type: :request do
name: "Test", name: "Test",
units: "5", units: "5",
type_of_unit: "Bungalow", type_of_unit: "Bungalow",
wheelchair_adaptation: "No", mobility_type: "N",
add_another_location: "No", add_another_location: "No",
postcode: "ZZ1 1ZZ", postcode: "ZZ1 1ZZ",
"startdate(3i)" => "", "startdate(3i)" => "",
@ -494,7 +490,7 @@ RSpec.describe LocationsController, type: :request do
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(:startdate) { Time.utc(2021, 1, 2) } 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 before do
sign_in user sign_in user
@ -513,7 +509,6 @@ RSpec.describe LocationsController, type: :request do
expect(Location.last.postcode).to eq("ZZ11ZZ") expect(Location.last.postcode).to eq("ZZ11ZZ")
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.startdate).to eq(startdate) expect(Location.last.startdate).to eq(startdate)
end end
@ -532,7 +527,7 @@ RSpec.describe LocationsController, type: :request do
end end
context "when postcode is submitted with lower case" do 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 it "updates existing location for scheme with postcode " do
expect(Location.last.postcode).to eq("ZZ11ZZ") 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 context "when trying to update location for a scheme that belongs to another organisation" do
let(:another_scheme) { FactoryBot.create(:scheme) } let(:another_scheme) { FactoryBot.create(:scheme) }
let(:another_location) { FactoryBot.create(:location) } 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 it "displays the new page with an error message" do
patch "/schemes/#{another_scheme.id}/locations/#{another_location.id}", params: params patch "/schemes/#{another_scheme.id}/locations/#{another_location.id}", params: params
@ -551,7 +546,7 @@ RSpec.describe LocationsController, type: :request do
end end
context "when required postcode param is invalid" do 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 it "displays the new page with an error message" do
expect(response).to have_http_status(:unprocessable_entity) expect(response).to have_http_status(:unprocessable_entity)
@ -560,7 +555,7 @@ RSpec.describe LocationsController, type: :request do
end end
context "when do you want to add another location is selected as yes" do 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 it "updates existing location for scheme with valid params and redirects to correct page" do
follow_redirect! follow_redirect!
@ -573,12 +568,11 @@ RSpec.describe LocationsController, type: :request do
expect(Location.last.name).to eq("Test") expect(Location.last.name).to eq("Test")
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")
end end
end end
context "when do you want to add another location is selected as no" do 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 it "updates existing location for scheme with valid params and redirects to correct page" do
follow_redirect! follow_redirect!
@ -591,12 +585,11 @@ RSpec.describe LocationsController, type: :request do
expect(Location.last.name).to eq("Test") expect(Location.last.name).to eq("Test")
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")
end end
end end
context "when do you want to add another location is not selected" do 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 it "updates existing location for scheme with valid params and redirects to correct page" do
follow_redirect! follow_redirect!
@ -609,12 +602,11 @@ RSpec.describe LocationsController, type: :request do
expect(Location.last.name).to eq("Test") expect(Location.last.name).to eq("Test")
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")
end end
end end
context "when required param are missing" do 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 it "displays the new page with an error message" do
expect(response).to have_http_status(:unprocessable_entity) 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(: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(:params) { { location: { name: "Test", units: "5", type_of_unit: "Bungalow", add_another_location: "No", postcode: "ZZ1 1ZZ", page: "edit" } } }
before do before do
allow(user).to receive(:need_two_factor_authentication?).and_return(false) 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.postcode).to eq("ZZ11ZZ")
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")
end end
context "when updating from edit-name page" do context "when updating from edit-name page" do
@ -666,7 +657,7 @@ RSpec.describe LocationsController, type: :request do
end end
context "when postcode is submitted with lower case" do 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 it "updates a location for scheme with postcode " do
expect(Location.last.postcode).to eq("ZZ11ZZ") expect(Location.last.postcode).to eq("ZZ11ZZ")
@ -674,7 +665,7 @@ RSpec.describe LocationsController, type: :request do
end end
context "when required postcode param is missing" do 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 it "displays the new page with an error message" do
expect(response).to have_http_status(:unprocessable_entity) expect(response).to have_http_status(:unprocessable_entity)
@ -683,7 +674,7 @@ RSpec.describe LocationsController, type: :request do
end end
context "when do you want to add another location is selected as yes" do 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 it "updates location for scheme with valid params and redirects to correct page" do
follow_redirect! follow_redirect!
@ -695,12 +686,11 @@ RSpec.describe LocationsController, type: :request do
expect(Location.last.name).to eq("Test") expect(Location.last.name).to eq("Test")
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")
end end
end end
context "when do you want to add another location is selected as no" do 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 it "updates a location for scheme with valid params and redirects to correct page" do
follow_redirect! follow_redirect!
@ -712,12 +702,11 @@ RSpec.describe LocationsController, type: :request do
expect(Location.last.name).to eq("Test") expect(Location.last.name).to eq("Test")
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")
end end
end end
context "when do you want to add another location is not selected" do 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 it "updates a location for scheme with valid params and redirects to correct page" do
follow_redirect! follow_redirect!
@ -729,12 +718,11 @@ RSpec.describe LocationsController, type: :request do
expect(Location.last.name).to eq("Test") expect(Location.last.name).to eq("Test")
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")
end end
end end
context "when required param are missing" do 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 it "displays the new page with an error message" do
expect(response).to have_http_status(:unprocessable_entity) 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.id)
expect(page).to have_content(location.postcode) expect(page).to have_content(location.postcode)
expect(page).to have_content(location.type_of_unit) 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
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.id)
expect(page).to have_content(location.postcode) expect(page).to have_content(location.postcode)
expect(page).to have_content(location.type_of_unit) 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
end end

4
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:) FactoryBot.create(:user, old_user_id: "e29c492473446dca4d50224f2bb7cf965a261d6f", organisation:)
# Location setup # 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, 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 # 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) allow(FormHandler.instance).to receive(:get_form).with("2021_2022").and_return(real_2021_2022_form)

2
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.name).to eq("Location 1")
expect(location.postcode).to eq("S44 6EJ") expect(location.postcode).to eq("S44 6EJ")
expect(location.units).to eq(5) 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.type_of_unit).to eq("Bungalow")
expect(location.old_id).to eq(first_location_id) expect(location.old_id).to eq(first_location_id)
expect(location.old_visible_id).to eq(10) expect(location.old_visible_id).to eq(10)

Loading…
Cancel
Save