diff --git a/app/models/form/setup/pages/location.rb b/app/models/form/setup/pages/location.rb index 76d90a292..5b22df634 100644 --- a/app/models/form/setup/pages/location.rb +++ b/app/models/form/setup/pages/location.rb @@ -9,7 +9,6 @@ class Form::Setup::Pages::Location < ::Form::Page "needstype" => 2, "scheme_has_multiple_locations?" => true, }] - @derived = true end def questions diff --git a/app/models/form/setup/pages/scheme.rb b/app/models/form/setup/pages/scheme.rb index 75e41ca14..b60d07964 100644 --- a/app/models/form/setup/pages/scheme.rb +++ b/app/models/form/setup/pages/scheme.rb @@ -8,7 +8,6 @@ class Form::Setup::Pages::Scheme < ::Form::Page "supported_housing_schemes_enabled?" => true, "needstype" => 2, }] - @derived = true end def questions diff --git a/app/models/form/setup/questions/location_id.rb b/app/models/form/setup/questions/location_id.rb index dac8f489b..4105c98f1 100644 --- a/app/models/form/setup/questions/location_id.rb +++ b/app/models/form/setup/questions/location_id.rb @@ -13,8 +13,8 @@ class Form::Setup::Questions::LocationId < ::Form::Question answer_opts = {} return answer_opts unless ActiveRecord::Base.connected? - Location.select(:id, :postcode, :address_line1).each_with_object(answer_opts) do |location, hsh| - hsh[location.id.to_s] = { "value" => location.postcode, "hint" => location.address_line1 } + Location.select(:id, :postcode, :name).each_with_object(answer_opts) do |location, hsh| + hsh[location.id.to_s] = { "value" => location.postcode, "hint" => location.name } hsh end end diff --git a/app/models/form/setup/questions/scheme_id.rb b/app/models/form/setup/questions/scheme_id.rb index 973d2931c..6994fd446 100644 --- a/app/models/form/setup/questions/scheme_id.rb +++ b/app/models/form/setup/questions/scheme_id.rb @@ -22,8 +22,9 @@ class Form::Setup::Questions::SchemeId < ::Form::Question def displayed_answer_options(case_log) return {} unless case_log.created_by - user_org_scheme_ids = Scheme.where(organisation_id: case_log.created_by.organisation_id).map(&:id).map(&:to_s) - answer_options.select { |k, _v| user_org_scheme_ids.include?(k) } + user_org_scheme_ids = Scheme.select(:id).where(organisation_id: case_log.created_by.organisation_id).map(&:id) + answer_options.select do |k, _v| user_org_scheme_ids.include?(k.to_i) + end end def hidden_in_check_answers?(case_log, _current_user = nil) diff --git a/app/views/schemes/locations.html.erb b/app/views/schemes/locations.html.erb index 4f85bec1c..59e2efff3 100644 --- a/app/views/schemes/locations.html.erb +++ b/app/views/schemes/locations.html.erb @@ -15,7 +15,7 @@

- <%= "#{location.address_line1}, #{location.address_line2}" %> + <%= location.name %>

diff --git a/db/migrate/20220704135746_rename_location_name.rb b/db/migrate/20220704135746_rename_location_name.rb new file mode 100644 index 000000000..a46f82e66 --- /dev/null +++ b/db/migrate/20220704135746_rename_location_name.rb @@ -0,0 +1,8 @@ +class RenameLocationName < ActiveRecord::Migration[7.0] + def change + change_table :locations, bulk: true do |t| + t.rename :address_line1, :name + t.remove :address_line2, type: :string + end + end +end diff --git a/db/schema.rb b/db/schema.rb index ea1e2e2e3..b38a76b1a 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_06_30_154441) do +ActiveRecord::Schema[7.0].define(version: 2022_07_04_135746) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -243,8 +243,7 @@ ActiveRecord::Schema[7.0].define(version: 2022_06_30_154441) do t.string "type_of_building" t.integer "wheelchair_adaptation" t.bigint "scheme_id", null: false - t.string "address_line1" - t.string "address_line2" + t.string "name" t.string "county" t.datetime "created_at", null: false t.datetime "updated_at", null: false diff --git a/db/seeds.rb b/db/seeds.rb index 654f1c777..0da986c48 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -116,8 +116,7 @@ unless Rails.env.test? scheme: scheme1, location_code: "S254-CU193AA", postcode: "CU19 3AA", - address_line1: "Rectory Road", - address_line2: "North Chaim", + name: "Rectory Road", type_of_unit: "Self-contained flat or bedsit", type_of_building: "Purpose-built", county: "Mid Sussex", @@ -128,8 +127,7 @@ unless Rails.env.test? scheme: scheme1, location_code: "S254-DM250DC", postcode: "DM25 0DC", - address_line1: "Smithy Lane", - address_line2: "North Kellieworth", + name: "Smithy Lane", type_of_unit: "Self-contained flat or bedsit with common facilities", type_of_building: "Converted from previous residential or non-residential property", county: "Fife", @@ -140,8 +138,7 @@ unless Rails.env.test? scheme: scheme2, location_code: "S254-YX130WP", postcode: "YX13 0WP", - address_line1: "Smithy Lane", - address_line2: "East Darwin", + name: "Smithy Lane", type_of_unit: "Shared house or hostel", type_of_building: "Converted from previous residential or non-residential property", county: "Rochford", diff --git a/spec/factories/location.rb b/spec/factories/location.rb index e4eaf43a0..e547e0bd2 100644 --- a/spec/factories/location.rb +++ b/spec/factories/location.rb @@ -2,8 +2,7 @@ FactoryBot.define do factory :location do location_code { Faker::Name.initials(number: 10) } postcode { Faker::Address.postcode.delete(" ") } - address_line1 { Faker::Address.street_name } - address_line2 { Faker::Address.city } + name { Faker::Address.street_name } type_of_unit { Faker::Lorem.word } type_of_building { Faker::Lorem.word } wheelchair_adaptation { 0 } diff --git a/spec/requests/schemes_controller_spec.rb b/spec/requests/schemes_controller_spec.rb index 30cba5cf2..e4e43ca0e 100644 --- a/spec/requests/schemes_controller_spec.rb +++ b/spec/requests/schemes_controller_spec.rb @@ -398,8 +398,7 @@ RSpec.describe SchemesController, type: :request do expect(page).to have_content(location.type_of_unit) expect(page).to have_content(location.type_of_building) expect(page).to have_content(location.wheelchair_adaptation) - expect(page).to have_content(location.address_line1) - expect(page).to have_content(location.address_line2) + expect(page).to have_content(location.name) end end