Browse Source

Code review fixes

pull/705/head
Stéphane Meny 3 years ago
parent
commit
0d80f0fe24
No known key found for this signature in database
GPG Key ID: 9D0AFEA988527923
  1. 1
      app/models/form/setup/pages/location.rb
  2. 1
      app/models/form/setup/pages/scheme.rb
  3. 4
      app/models/form/setup/questions/location_id.rb
  4. 5
      app/models/form/setup/questions/scheme_id.rb
  5. 2
      app/views/schemes/locations.html.erb
  6. 8
      db/migrate/20220704135746_rename_location_name.rb
  7. 5
      db/schema.rb
  8. 9
      db/seeds.rb
  9. 3
      spec/factories/location.rb
  10. 3
      spec/requests/schemes_controller_spec.rb

1
app/models/form/setup/pages/location.rb

@ -9,7 +9,6 @@ class Form::Setup::Pages::Location < ::Form::Page
"needstype" => 2, "needstype" => 2,
"scheme_has_multiple_locations?" => true, "scheme_has_multiple_locations?" => true,
}] }]
@derived = true
end end
def questions def questions

1
app/models/form/setup/pages/scheme.rb

@ -8,7 +8,6 @@ class Form::Setup::Pages::Scheme < ::Form::Page
"supported_housing_schemes_enabled?" => true, "supported_housing_schemes_enabled?" => true,
"needstype" => 2, "needstype" => 2,
}] }]
@derived = true
end end
def questions def questions

4
app/models/form/setup/questions/location_id.rb

@ -13,8 +13,8 @@ class Form::Setup::Questions::LocationId < ::Form::Question
answer_opts = {} answer_opts = {}
return answer_opts unless ActiveRecord::Base.connected? return answer_opts unless ActiveRecord::Base.connected?
Location.select(:id, :postcode, :address_line1).each_with_object(answer_opts) do |location, hsh| Location.select(:id, :postcode, :name).each_with_object(answer_opts) do |location, hsh|
hsh[location.id.to_s] = { "value" => location.postcode, "hint" => location.address_line1 } hsh[location.id.to_s] = { "value" => location.postcode, "hint" => location.name }
hsh hsh
end end
end end

5
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) def displayed_answer_options(case_log)
return {} unless case_log.created_by 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) user_org_scheme_ids = Scheme.select(:id).where(organisation_id: case_log.created_by.organisation_id).map(&:id)
answer_options.select { |k, _v| user_org_scheme_ids.include?(k) } answer_options.select do |k, _v| user_org_scheme_ids.include?(k.to_i)
end
end end
def hidden_in_check_answers?(case_log, _current_user = nil) def hidden_in_check_answers?(case_log, _current_user = nil)

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

@ -15,7 +15,7 @@
<section class="x-govuk-summary-card govuk-!-margin-bottom-6"> <section class="x-govuk-summary-card govuk-!-margin-bottom-6">
<header class="x-govuk-summary-card__header"> <header class="x-govuk-summary-card__header">
<h2 class="x-govuk-summary-card__title"> <h2 class="x-govuk-summary-card__title">
<%= "#{location.address_line1}, #{location.address_line2}" %> <%= location.name %>
</h2> </h2>
</header> </header>
<div class="x-govuk-summary-card__body"> <div class="x-govuk-summary-card__body">

8
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

5
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_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 # These are extensions that must be enabled in order to support this database
enable_extension "plpgsql" enable_extension "plpgsql"
@ -243,8 +243,7 @@ ActiveRecord::Schema[7.0].define(version: 2022_06_30_154441) do
t.string "type_of_building" t.string "type_of_building"
t.integer "wheelchair_adaptation" t.integer "wheelchair_adaptation"
t.bigint "scheme_id", null: false t.bigint "scheme_id", null: false
t.string "address_line1" t.string "name"
t.string "address_line2"
t.string "county" t.string "county"
t.datetime "created_at", null: false t.datetime "created_at", null: false
t.datetime "updated_at", null: false t.datetime "updated_at", null: false

9
db/seeds.rb

@ -116,8 +116,7 @@ unless Rails.env.test?
scheme: scheme1, scheme: scheme1,
location_code: "S254-CU193AA", location_code: "S254-CU193AA",
postcode: "CU19 3AA", postcode: "CU19 3AA",
address_line1: "Rectory Road", name: "Rectory Road",
address_line2: "North Chaim",
type_of_unit: "Self-contained flat or bedsit", type_of_unit: "Self-contained flat or bedsit",
type_of_building: "Purpose-built", type_of_building: "Purpose-built",
county: "Mid Sussex", county: "Mid Sussex",
@ -128,8 +127,7 @@ unless Rails.env.test?
scheme: scheme1, scheme: scheme1,
location_code: "S254-DM250DC", location_code: "S254-DM250DC",
postcode: "DM25 0DC", postcode: "DM25 0DC",
address_line1: "Smithy Lane", name: "Smithy Lane",
address_line2: "North Kellieworth",
type_of_unit: "Self-contained flat or bedsit with common facilities", type_of_unit: "Self-contained flat or bedsit with common facilities",
type_of_building: "Converted from previous residential or non-residential property", type_of_building: "Converted from previous residential or non-residential property",
county: "Fife", county: "Fife",
@ -140,8 +138,7 @@ unless Rails.env.test?
scheme: scheme2, scheme: scheme2,
location_code: "S254-YX130WP", location_code: "S254-YX130WP",
postcode: "YX13 0WP", postcode: "YX13 0WP",
address_line1: "Smithy Lane", name: "Smithy Lane",
address_line2: "East Darwin",
type_of_unit: "Shared house or hostel", type_of_unit: "Shared house or hostel",
type_of_building: "Converted from previous residential or non-residential property", type_of_building: "Converted from previous residential or non-residential property",
county: "Rochford", county: "Rochford",

3
spec/factories/location.rb

@ -2,8 +2,7 @@ FactoryBot.define do
factory :location do factory :location do
location_code { Faker::Name.initials(number: 10) } location_code { Faker::Name.initials(number: 10) }
postcode { Faker::Address.postcode.delete(" ") } postcode { Faker::Address.postcode.delete(" ") }
address_line1 { Faker::Address.street_name } name { Faker::Address.street_name }
address_line2 { Faker::Address.city }
type_of_unit { Faker::Lorem.word } type_of_unit { Faker::Lorem.word }
type_of_building { Faker::Lorem.word } type_of_building { Faker::Lorem.word }
wheelchair_adaptation { 0 } wheelchair_adaptation { 0 }

3
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_unit)
expect(page).to have_content(location.type_of_building) expect(page).to have_content(location.type_of_building)
expect(page).to have_content(location.wheelchair_adaptation) expect(page).to have_content(location.wheelchair_adaptation)
expect(page).to have_content(location.address_line1) expect(page).to have_content(location.name)
expect(page).to have_content(location.address_line2)
end end
end end

Loading…
Cancel
Save