Browse Source

Remove wheelchair_adaptation, use mobility_type to infer wchair

pull/763/head
Kat 3 years ago
parent
commit
e1e1db5c86
  1. 2
      app/controllers/locations_controller.rb
  2. 3
      app/models/derived_variables/case_log_variables.rb
  3. 8
      app/models/location.rb
  4. 8
      app/views/locations/edit.html.erb
  5. 2
      app/views/locations/index.html.erb
  6. 9
      app/views/locations/new.html.erb
  7. 2
      app/views/schemes/check_answers.html.erb
  8. 2
      config/locales/en.yml
  9. 5
      db/migrate/20220720111635_remove_wheelchair_adaptation.rb
  10. 3
      db/schema.rb
  11. 6
      db/seeds.rb
  12. 1
      spec/factories/location.rb
  13. 4
      spec/features/schemes_spec.rb
  14. 4
      spec/models/case_log_spec.rb
  15. 78
      spec/requests/locations_controller_spec.rb
  16. 4
      spec/services/imports/case_logs_import_service_spec.rb

2
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, :mobility_type).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

3
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

8
app/models/location.rb

@ -7,13 +7,6 @@ class Location < ApplicationRecord
attr_accessor :add_another_location
WHEELCHAIR_ADAPTATIONS = {
Yes: 1,
No: 2,
}.freeze
enum wheelchair_adaptation: WHEELCHAIR_ADAPTATIONS
MOBILITY_TYPE = {
"Wheelchair-user standard": "W",
"Fitted with equipment and adaptations": "A",
@ -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

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

@ -47,14 +47,6 @@
:description,
legend: { text: I18n.t("questions.location.mobility_type"), 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_date_field :startdate,
legend: { text: I18n.t("questions.location.startdate"), size: "m" },
width: 20 %>

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

@ -41,7 +41,7 @@
<% 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("<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 %>

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

@ -37,15 +37,6 @@
: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" } %>
<% mobility_types_to_display = Location.mobility_types.excluding("Property designed to accessible general standard", "Missing") %>
<% mobility_type_selection = 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}")) } %>

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

@ -101,7 +101,7 @@
<% 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("<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 %>

2
config/locales/en.yml

@ -323,7 +323,6 @@ 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?"
@ -339,7 +338,6 @@ en:
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}"

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.
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

6
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

1
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

4
spec/features/schemes_spec.rb

@ -407,7 +407,6 @@ 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"
@ -442,7 +441,6 @@ 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"
click_button "Save and continue"
end
@ -707,7 +705,6 @@ 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"
click_button "Save and continue"
end
@ -740,7 +737,6 @@ 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"
click_button "Save and continue"
end

4
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

78
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:, mobility_type: "A" } } }
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,13 +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" } } }
it "creates a new location for scheme with postcode " do
expect(Location.last.postcode).to eq("ZZ11ZZ")
@ -126,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" } } }
it "displays the new page with an error message" do
post "/schemes/#{another_scheme.id}/locations", params: params
@ -135,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", mobility_type: "N" } } }
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)
@ -149,13 +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" } } }
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)
@ -169,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", mobility_type: "W" } } }
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)
@ -188,13 +185,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("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)
@ -252,7 +248,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" } } }
before do
allow(user).to receive(:need_two_factor_authentication?).and_return(false)
@ -272,11 +268,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" } } }
it "creates a new location for scheme with postcode " do
expect(Location.last.postcode).to eq("ZZ11ZZ")
@ -284,7 +279,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
@ -294,7 +289,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" } } }
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)
@ -307,12 +302,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" } } }
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)
@ -325,12 +319,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" } } }
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)
@ -343,12 +336,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)
@ -497,7 +489,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
@ -516,7 +508,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
@ -535,7 +526,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")
@ -545,7 +536,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
@ -554,7 +545,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)
@ -563,7 +554,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!
@ -576,12 +567,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!
@ -594,12 +584,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!
@ -612,12 +601,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)
@ -632,7 +620,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)
@ -651,7 +639,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
@ -669,7 +656,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")
@ -677,7 +664,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)
@ -686,7 +673,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!
@ -698,12 +685,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!
@ -715,12 +701,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!
@ -732,12 +717,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)
@ -799,7 +783,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
@ -877,7 +861,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

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:)
# 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)

Loading…
Cancel
Save