From cbdcde2bcd066b4c7375e5c1800295d94d7549a7 Mon Sep 17 00:00:00 2001 From: baarkerlounger Date: Wed, 13 Apr 2022 15:02:55 +0100 Subject: [PATCH 01/25] Hash syntax --- Gemfile.lock | 8 +- app/models/case_log.rb | 2 +- .../admin/admin_users_controller_spec.rb | 4 +- .../admin/case_logs_controller_spec.rb | 4 +- .../admin/organisations_controller_spec.rb | 4 +- .../admin/users_controller_spec.rb | 4 +- spec/helpers/question_view_helper_spec.rb | 2 +- .../auth/passwords_controller_spec.rb | 4 +- spec/requests/bulk_upload_controller_spec.rb | 2 +- spec/requests/case_logs_controller_spec.rb | 30 +++--- spec/requests/content_controller_spec.rb | 6 +- spec/requests/form_controller_spec.rb | 2 +- .../requests/organisations_controller_spec.rb | 30 +++--- spec/requests/users_controller_spec.rb | 92 +++++++++---------- spec/views/form/page_view_spec.rb | 2 +- 15 files changed, 98 insertions(+), 98 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 62d70821c..9dd02dde9 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -69,7 +69,7 @@ GEM erubi (~> 1.4) rails-dom-testing (~> 2.0) rails-html-sanitizer (~> 1.1, >= 1.2.0) - activeadmin (2.11.1) + activeadmin (2.11.2) arbre (~> 1.2, >= 1.2.1) formtastic (>= 3.1, < 5.0) formtastic_i18n (~> 0.4) @@ -105,8 +105,8 @@ GEM ruby2_keywords (>= 0.0.2, < 1.0) ast (2.4.2) aws-eventstream (1.2.0) - aws-partitions (1.575.0) - aws-sdk-core (3.130.0) + aws-partitions (1.576.0) + aws-sdk-core (3.130.1) aws-eventstream (~> 1, >= 1.0.2) aws-partitions (~> 1, >= 1.525.0) aws-sigv4 (~> 1.1) @@ -269,7 +269,7 @@ GEM globalid paper_trail (>= 3.0.0) parallel (1.22.1) - parser (3.1.1.0) + parser (3.1.2.0) ast (~> 2.4.1) pg (1.3.5) postcodes_io (0.4.0) diff --git a/app/models/case_log.rb b/app/models/case_log.rb index 4eb2ff467..d1558377c 100644 --- a/app/models/case_log.rb +++ b/app/models/case_log.rb @@ -34,7 +34,7 @@ class CaseLog < ApplicationRecord belongs_to :managing_organisation, class_name: "Organisation" scope :for_organisation, ->(org) { where(owning_organisation: org).or(where(managing_organisation: org)) } - scope :filter_by_status, ->(status, _user = nil) { where status: status } + scope :filter_by_status, ->(status, _user = nil) { where status: } scope :filter_by_years, lambda { |years, _user = nil| first_year = years.shift query = filter_by_year(first_year) diff --git a/spec/controllers/admin/admin_users_controller_spec.rb b/spec/controllers/admin/admin_users_controller_spec.rb index 5d4c57944..f1f2ebeab 100644 --- a/spec/controllers/admin/admin_users_controller_spec.rb +++ b/spec/controllers/admin/admin_users_controller_spec.rb @@ -28,7 +28,7 @@ describe Admin::AdminUsersController, type: :controller do let(:params) { { admin_user: { email: "test2@example.com", password: "pAssword1", phone: "07566126368" } } } it "creates a new admin user" do - expect { post :create, session: valid_session, params: params }.to change(AdminUser, :count).by(1) + expect { post :create, session: valid_session, params: }.to change(AdminUser, :count).by(1) end it "tracks who created the record" do @@ -59,7 +59,7 @@ describe Admin::AdminUsersController, type: :controller do let(:params) { { id: admin_user.id, admin_user: { email: } } } before do - patch :update, session: valid_session, params: params + patch :update, session: valid_session, params: end it "updates the user without needing to input a password" do diff --git a/spec/controllers/admin/case_logs_controller_spec.rb b/spec/controllers/admin/case_logs_controller_spec.rb index 35b5fafee..40ab44c4a 100644 --- a/spec/controllers/admin/case_logs_controller_spec.rb +++ b/spec/controllers/admin/case_logs_controller_spec.rb @@ -40,7 +40,7 @@ describe Admin::CaseLogsController, type: :controller do end it "creates a new case log" do - expect { post :create, session: valid_session, params: params }.to change(CaseLog, :count).by(1) + expect { post :create, session: valid_session, params: }.to change(CaseLog, :count).by(1) end it "tracks who created the record" do @@ -71,7 +71,7 @@ describe Admin::CaseLogsController, type: :controller do let(:params) { { id: case_log.id, case_log: { tenant_code: } } } before do - patch :update, session: valid_session, params: params + patch :update, session: valid_session, params: end it "updates the case log" do diff --git a/spec/controllers/admin/organisations_controller_spec.rb b/spec/controllers/admin/organisations_controller_spec.rb index f639a3b7e..d66bc3c4c 100644 --- a/spec/controllers/admin/organisations_controller_spec.rb +++ b/spec/controllers/admin/organisations_controller_spec.rb @@ -29,7 +29,7 @@ describe Admin::OrganisationsController, type: :controller do let(:params) { { organisation: { name: "DLUHC", provider_type: "LA" } } } it "creates a organisation" do - expect { post :create, session: valid_session, params: params }.to change(Organisation, :count).by(1) + expect { post :create, session: valid_session, params: }.to change(Organisation, :count).by(1) end it "tracks who created the record" do @@ -59,7 +59,7 @@ describe Admin::OrganisationsController, type: :controller do let(:params) { { id: organisation.id, organisation: { name: } } } before do - patch :update, session: valid_session, params: params + patch :update, session: valid_session, params: end it "updates the organisation" do diff --git a/spec/controllers/admin/users_controller_spec.rb b/spec/controllers/admin/users_controller_spec.rb index 7f32500a2..71e572493 100644 --- a/spec/controllers/admin/users_controller_spec.rb +++ b/spec/controllers/admin/users_controller_spec.rb @@ -40,7 +40,7 @@ describe Admin::UsersController, type: :controller do end it "creates a new user" do - expect { post :create, session: valid_session, params: params }.to change(User, :count).by(1) + expect { post :create, session: valid_session, params: }.to change(User, :count).by(1) end it "tracks who created the record" do @@ -73,7 +73,7 @@ describe Admin::UsersController, type: :controller do let(:params) { { id: user.id, user: { name: } } } before do - patch :update, session: valid_session, params: params + patch :update, session: valid_session, params: end it "updates the user without needing to input a password" do diff --git a/spec/helpers/question_view_helper_spec.rb b/spec/helpers/question_view_helper_spec.rb index e23929092..33341b0e5 100644 --- a/spec/helpers/question_view_helper_spec.rb +++ b/spec/helpers/question_view_helper_spec.rb @@ -48,7 +48,7 @@ RSpec.describe QuestionViewHelper do let(:size) { "m" } let(:tag) { "h2" } let(:legend_options_hash) do - { text: "Some question header".html_safe, size: size, tag: tag } + { text: "Some question header".html_safe, size:, tag: } end context "when viewing a page with a header" do diff --git a/spec/requests/auth/passwords_controller_spec.rb b/spec/requests/auth/passwords_controller_spec.rb index 0ec7a73c5..0adff32f5 100644 --- a/spec/requests/auth/passwords_controller_spec.rb +++ b/spec/requests/auth/passwords_controller_spec.rb @@ -139,7 +139,7 @@ RSpec.describe Auth::PasswordsController, type: :request do it "triggers an email" do expect(notify_client).to receive(:send_email) - put "/admin/password", headers: headers, params: params + put "/admin/password", headers:, params: end end end @@ -211,7 +211,7 @@ RSpec.describe Auth::PasswordsController, type: :request do it "triggers an email" do expect(notify_client).to receive(:send_email) - put "/account/password", headers: headers, params: params + put "/account/password", headers:, params: end end end diff --git a/spec/requests/bulk_upload_controller_spec.rb b/spec/requests/bulk_upload_controller_spec.rb index 4e10ef797..5e8a43124 100644 --- a/spec/requests/bulk_upload_controller_spec.rb +++ b/spec/requests/bulk_upload_controller_spec.rb @@ -14,7 +14,7 @@ RSpec.describe BulkUploadController, type: :request do context "when a user is not signed in" do describe "GET #show" do - before { get url, headers: headers, params: {} } + before { get url, headers:, params: {} } it "does not let you see the bulk upload page" do expect(response).to redirect_to("/account/sign-in") diff --git a/spec/requests/case_logs_controller_spec.rb b/spec/requests/case_logs_controller_spec.rb index 1031960bd..2ce18f942 100644 --- a/spec/requests/case_logs_controller_spec.rb +++ b/spec/requests/case_logs_controller_spec.rb @@ -47,7 +47,7 @@ RSpec.describe CaseLogsController, type: :request do end before do - post "/logs", headers: headers, params: params.to_json + post "/logs", headers:, params: params.to_json end it "returns http success" do @@ -124,7 +124,7 @@ RSpec.describe CaseLogsController, type: :request do before do RequestHelper.stub_http_requests sign_in user - post "/logs", headers: headers + post "/logs", headers: end it "tracks who created the record" do @@ -289,7 +289,7 @@ RSpec.describe CaseLogsController, type: :request do context "when there are less than 20 logs" do before do - get "/logs", headers: headers, params: {} + get "/logs", headers:, params: {} end it "shows a table of logs" do @@ -342,7 +342,7 @@ RSpec.describe CaseLogsController, type: :request do context "when on the first page" do before do - get "/logs", headers: headers, params: {} + get "/logs", headers:, params: {} end it "has pagination links" do @@ -363,7 +363,7 @@ RSpec.describe CaseLogsController, type: :request do context "when on the second page" do before do - get "/logs?page=2", headers: headers, params: {} + get "/logs?page=2", headers:, params: {} end it "shows the total log count" do @@ -394,7 +394,7 @@ RSpec.describe CaseLogsController, type: :request do let(:id) { completed_case_log.id } before do - get "/logs/#{id}", headers: headers + get "/logs/#{id}", headers: end it "returns http success" do @@ -428,7 +428,7 @@ RSpec.describe CaseLogsController, type: :request do context "with case logs that are owned or managed by your organisation" do before do sign_in user - get "/logs/#{case_log.id}", headers: headers, params: {} + get "/logs/#{case_log.id}", headers:, params: {} end it "shows the tasklist for case logs you have access to" do @@ -455,7 +455,7 @@ RSpec.describe CaseLogsController, type: :request do before do sign_in user - get "/logs/#{section_completed_case_log.id}", headers: headers, params: {} + get "/logs/#{section_completed_case_log.id}", headers:, params: {} end it "displays a section status for a case log" do @@ -468,7 +468,7 @@ RSpec.describe CaseLogsController, type: :request do context "with case logs that are not owned or managed by your organisation" do before do sign_in user - get "/logs/#{unauthorized_case_log.id}", headers: headers, params: {} + get "/logs/#{unauthorized_case_log.id}", headers:, params: {} end it "does not show the tasklist for case logs you don't have access to" do @@ -548,7 +548,7 @@ RSpec.describe CaseLogsController, type: :request do :completed, owning_organisation: organisation, managing_organisation: organisation) - get "/logs", headers: headers, params: {} + get "/logs", headers:, params: {} end it "downloads a CSV file with headers" do @@ -578,7 +578,7 @@ RSpec.describe CaseLogsController, type: :request do before do sign_in user FactoryBot.create_list(:case_log, 26, owning_organisation: organisation) - get "/logs", headers: headers, params: {} + get "/logs", headers:, params: {} end it "does not paginate, it downloads all the user's logs" do @@ -598,7 +598,7 @@ RSpec.describe CaseLogsController, type: :request do let(:id) { case_log.id } before do - patch "/logs/#{id}", headers: headers, params: params.to_json + patch "/logs/#{id}", headers:, params: params.to_json end it "returns http success" do @@ -656,7 +656,7 @@ RSpec.describe CaseLogsController, type: :request do let(:id) { case_log.id } before do - put "/logs/#{id}", headers: headers, params: params.to_json + put "/logs/#{id}", headers:, params: params.to_json end it "returns http success" do @@ -696,7 +696,7 @@ RSpec.describe CaseLogsController, type: :request do context "when deleting a case log" do before do - delete "/logs/#{id}", headers: headers + delete "/logs/#{id}", headers: end it "returns http success" do @@ -730,7 +730,7 @@ RSpec.describe CaseLogsController, type: :request do before do allow(CaseLog).to receive(:find_by).and_return(case_log) allow(case_log).to receive(:delete).and_return(false) - delete "/logs/#{id}", headers: headers + delete "/logs/#{id}", headers: end it "returns an unprocessable entity 422" do diff --git a/spec/requests/content_controller_spec.rb b/spec/requests/content_controller_spec.rb index 4b8ebdb79..07be4256b 100644 --- a/spec/requests/content_controller_spec.rb +++ b/spec/requests/content_controller_spec.rb @@ -6,7 +6,7 @@ RSpec.describe ContentController, type: :request do describe "render privacy notice content page" do before do - get "/privacy-notice", headers: headers, params: {} + get "/privacy-notice", headers:, params: {} end it "returns a 200" do @@ -20,7 +20,7 @@ RSpec.describe ContentController, type: :request do describe "render accessibility statement content page" do before do - get "/accessibility-statement", headers: headers, params: {} + get "/accessibility-statement", headers:, params: {} end it "returns a 200" do @@ -34,7 +34,7 @@ RSpec.describe ContentController, type: :request do describe "render data sharing agreement" do before do - get "/data-sharing-agreement", headers: headers, params: {} + get "/data-sharing-agreement", headers:, params: {} end it "returns a 200" do diff --git a/spec/requests/form_controller_spec.rb b/spec/requests/form_controller_spec.rb index 32d8016d9..f16712755 100644 --- a/spec/requests/form_controller_spec.rb +++ b/spec/requests/form_controller_spec.rb @@ -131,7 +131,7 @@ RSpec.describe FormController, type: :request do end before do - post "/logs/#{case_log.id}/form", params: params + post "/logs/#{case_log.id}/form", params: end context "with invalid answers" do diff --git a/spec/requests/organisations_controller_spec.rb b/spec/requests/organisations_controller_spec.rb index c19568516..44b7ca8ac 100644 --- a/spec/requests/organisations_controller_spec.rb +++ b/spec/requests/organisations_controller_spec.rb @@ -33,7 +33,7 @@ RSpec.describe OrganisationsController, type: :request do context "with an organisation that the user belongs to" do before do sign_in user - get "/organisations/#{organisation.id}", headers: headers, params: {} + get "/organisations/#{organisation.id}", headers:, params: {} end it "redirects to details" do @@ -44,7 +44,7 @@ RSpec.describe OrganisationsController, type: :request do context "with an organisation that are not in scope for the user, i.e. that they do not belong to" do before do sign_in user - get "/organisations/#{unauthorised_organisation.id}", headers: headers, params: {} + get "/organisations/#{unauthorised_organisation.id}", headers:, params: {} end it "returns not found 404 from org route" do @@ -62,7 +62,7 @@ RSpec.describe OrganisationsController, type: :request do context "with an organisation that the user belongs to" do before do sign_in user - get "/organisations/#{organisation.id}/details", headers: headers, params: {} + get "/organisations/#{organisation.id}/details", headers:, params: {} end it "shows the tab navigation" do @@ -90,7 +90,7 @@ RSpec.describe OrganisationsController, type: :request do context "with organisation that are not in scope for the user, i.e. that they do not belong to" do before do sign_in user - get "/organisations/#{unauthorised_organisation.id}/details", headers: headers, params: {} + get "/organisations/#{unauthorised_organisation.id}/details", headers:, params: {} end it "returns not found 404 from org details route" do @@ -103,7 +103,7 @@ RSpec.describe OrganisationsController, type: :request do context "with an organisation that the user belongs to" do before do sign_in user - get "/organisations/#{organisation.id}/users", headers: headers, params: {} + get "/organisations/#{organisation.id}/users", headers:, params: {} end it "shows the tab navigation" do @@ -130,7 +130,7 @@ RSpec.describe OrganisationsController, type: :request do context "with an organisation that are not in scope for the user, i.e. that they do not belong to" do before do sign_in user - get "/organisations/#{unauthorised_organisation.id}/users", headers: headers, params: {} + get "/organisations/#{unauthorised_organisation.id}/users", headers:, params: {} end it "returns not found 404 from users page" do @@ -143,7 +143,7 @@ RSpec.describe OrganisationsController, type: :request do context "with an organisation that the user belongs to" do before do sign_in user - get "/organisations/#{organisation.id}/edit", headers: headers, params: {} + get "/organisations/#{organisation.id}/edit", headers:, params: {} end it "shows an edit form" do @@ -156,7 +156,7 @@ RSpec.describe OrganisationsController, type: :request do context "with an organisation that the user does not belong to" do before do sign_in user - get "/organisations/#{unauthorised_organisation.id}/edit", headers: headers, params: {} + get "/organisations/#{unauthorised_organisation.id}/edit", headers:, params: {} end it "returns a 404 not found" do @@ -169,7 +169,7 @@ RSpec.describe OrganisationsController, type: :request do context "with an organisation that the user belongs to" do before do sign_in user - patch "/organisations/#{organisation.id}", headers: headers, params: params + patch "/organisations/#{organisation.id}", headers:, params: end it "updates the org" do @@ -197,7 +197,7 @@ RSpec.describe OrganisationsController, type: :request do context "with an organisation that the user does not belong to" do before do sign_in user - patch "/organisations/#{unauthorised_organisation.id}", headers: headers, params: {} + patch "/organisations/#{unauthorised_organisation.id}", headers:, params: {} end it "returns a 404 not found" do @@ -214,7 +214,7 @@ RSpec.describe OrganisationsController, type: :request do context "with an organisation that the user belongs to" do before do sign_in user - get "/organisations/#{organisation.id}/details", headers: headers, params: {} + get "/organisations/#{organisation.id}/details", headers:, params: {} end it "shows the tab navigation" do @@ -242,7 +242,7 @@ RSpec.describe OrganisationsController, type: :request do context "with an organisation that is not in scope for the user, i.e. that they do not belong to" do before do sign_in user - get "/organisations/#{unauthorised_organisation.id}/details", headers: headers, params: {} + get "/organisations/#{unauthorised_organisation.id}/details", headers:, params: {} end it "returns not found 404" do @@ -254,7 +254,7 @@ RSpec.describe OrganisationsController, type: :request do context "when accessing the users tab" do before do sign_in user - get "/organisations/#{organisation.id}/users", headers: headers, params: {} + get "/organisations/#{organisation.id}/users", headers:, params: {} end it "returns 200" do @@ -265,7 +265,7 @@ RSpec.describe OrganisationsController, type: :request do describe "#edit" do before do sign_in user - get "/organisations/#{organisation.id}/edit", headers: headers, params: {} + get "/organisations/#{organisation.id}/edit", headers:, params: {} end it "redirects to home" do @@ -276,7 +276,7 @@ RSpec.describe OrganisationsController, type: :request do describe "#update" do before do sign_in user - patch "/organisations/#{organisation.id}", headers: headers, params: params + patch "/organisations/#{organisation.id}", headers:, params: end it "redirects to home" do diff --git a/spec/requests/users_controller_spec.rb b/spec/requests/users_controller_spec.rb index 3da36083b..60d4cb035 100644 --- a/spec/requests/users_controller_spec.rb +++ b/spec/requests/users_controller_spec.rb @@ -63,7 +63,7 @@ RSpec.describe UsersController, type: :request do before do sign_in user - put "/account", headers: headers, params: params + put "/account", headers:, params: end it "shows an error if passwords don't match" do @@ -89,7 +89,7 @@ RSpec.describe UsersController, type: :request do before do allow(User).to receive(:find_or_initialize_with_error_by).and_return(user) allow(user).to receive(:reset_password_sent_at).and_return(4.hours.ago) - put "/account/password", headers: headers, params: params + put "/account/password", headers:, params: end it "shows an error" do @@ -115,7 +115,7 @@ RSpec.describe UsersController, type: :request do context "when the current user matches the user ID" do before do sign_in user - get "/users/#{user.id}", headers: headers, params: {} + get "/users/#{user.id}", headers:, params: {} end it "show the user details" do @@ -135,7 +135,7 @@ RSpec.describe UsersController, type: :request do context "when the current user does not match the user ID" do before do sign_in user - get "/users/#{other_user.id}", headers: headers, params: {} + get "/users/#{other_user.id}", headers:, params: {} end context "when the user is part of the same organisation" do @@ -172,7 +172,7 @@ RSpec.describe UsersController, type: :request do context "when the current user matches the user ID" do before do sign_in user - get "/users/#{user.id}/edit", headers: headers, params: {} + get "/users/#{user.id}/edit", headers:, params: {} end it "show the edit personal details page" do @@ -191,7 +191,7 @@ RSpec.describe UsersController, type: :request do context "when the current user does not match the user ID" do before do sign_in user - get "/users/#{other_user.id}/edit", headers: headers, params: {} + get "/users/#{other_user.id}/edit", headers:, params: {} end it "returns not found 404" do @@ -204,7 +204,7 @@ RSpec.describe UsersController, type: :request do context "when the current user matches the user ID" do before do sign_in user - get "/account/edit/password", headers: headers, params: {} + get "/account/edit/password", headers:, params: {} end it "shows the edit password page" do @@ -219,7 +219,7 @@ RSpec.describe UsersController, type: :request do context "when the current user does not match the user ID" do before do sign_in user - get "/users/#{other_user.id}/edit", headers: headers, params: {} + get "/users/#{other_user.id}/edit", headers:, params: {} end it "returns not found 404" do @@ -232,7 +232,7 @@ RSpec.describe UsersController, type: :request do context "when the current user matches the user ID" do before do sign_in user - patch "/users/#{user.id}", headers: headers, params: params + patch "/users/#{user.id}", headers:, params: end it "updates the user" do @@ -264,7 +264,7 @@ RSpec.describe UsersController, type: :request do sign_in user allow(User).to receive(:find_by).and_return(user) allow(user).to receive(:update).and_return(false) - patch "/users/#{user.id}", headers: headers, params: params + patch "/users/#{user.id}", headers:, params: end it "show an error" do @@ -277,7 +277,7 @@ RSpec.describe UsersController, type: :request do before do sign_in user - patch "/users/#{other_user.id}", headers: headers, params: params + patch "/users/#{other_user.id}", headers:, params: end it "returns not found 404" do @@ -294,7 +294,7 @@ RSpec.describe UsersController, type: :request do before do sign_in user - patch "/users/#{user.id}", headers: headers, params: params + patch "/users/#{user.id}", headers:, params: end it "shows an error if passwords don't match" do @@ -314,7 +314,7 @@ RSpec.describe UsersController, type: :request do }, } end - let(:request) { post "/users/", headers: headers, params: params } + let(:request) { post "/users/", headers:, params: } before do sign_in user @@ -339,7 +339,7 @@ RSpec.describe UsersController, type: :request do context "when the current user matches the user ID" do before do sign_in user - get "/users/#{user.id}", headers: headers, params: {} + get "/users/#{user.id}", headers:, params: {} end it "show the user details" do @@ -359,7 +359,7 @@ RSpec.describe UsersController, type: :request do context "when the current user does not match the user ID" do before do sign_in user - get "/users/#{other_user.id}", headers: headers, params: {} + get "/users/#{other_user.id}", headers:, params: {} end context "when the user is part of the same organisation as the current user" do @@ -399,7 +399,7 @@ RSpec.describe UsersController, type: :request do context "when the current user matches the user ID" do before do sign_in user - get "/users/#{user.id}/edit", headers: headers, params: {} + get "/users/#{user.id}/edit", headers:, params: {} end it "show the edit personal details page" do @@ -422,7 +422,7 @@ RSpec.describe UsersController, type: :request do context "when the current user does not match the user ID" do before do sign_in user - get "/users/#{other_user.id}/edit", headers: headers, params: {} + get "/users/#{other_user.id}/edit", headers:, params: {} end context "when the user is part of the same organisation as the current user" do @@ -457,7 +457,7 @@ RSpec.describe UsersController, type: :request do context "when the current user matches the user ID" do before do sign_in user - get "/account/edit/password", headers: headers, params: {} + get "/account/edit/password", headers:, params: {} end it "shows the edit password page" do @@ -476,7 +476,7 @@ RSpec.describe UsersController, type: :request do it "there is no route" do expect { - get "/users/#{other_user.id}/password/edit", headers: headers, params: {} + get "/users/#{other_user.id}/password/edit", headers:, params: {} }.to raise_error(ActionController::RoutingError) end end @@ -486,7 +486,7 @@ RSpec.describe UsersController, type: :request do context "when the current user matches the user ID" do before do sign_in user - patch "/users/#{user.id}", headers: headers, params: params + patch "/users/#{user.id}", headers:, params: end it "updates the user" do @@ -521,7 +521,7 @@ RSpec.describe UsersController, type: :request do before do sign_in user - patch "/users/#{user.id}", headers: headers, params: params + patch "/users/#{user.id}", headers:, params: end it "shows an error if passwords don't match" do @@ -538,12 +538,12 @@ RSpec.describe UsersController, type: :request do context "when the user is part of the same organisation as the current user" do it "updates the user" do - expect { patch "/users/#{other_user.id}", headers: headers, params: params } + expect { patch "/users/#{other_user.id}", headers:, params: } .to change { other_user.reload.name }.from(other_user.name).to(new_name) end it "tracks who updated the record" do - expect { patch "/users/#{other_user.id}", headers: headers, params: params } + expect { patch "/users/#{other_user.id}", headers:, params: } .to change { other_user.reload.versions.last.actor&.id }.from(nil).to(user.id) end @@ -574,12 +574,12 @@ RSpec.describe UsersController, type: :request do end it "does not update the password" do - expect { patch "/users/#{other_user.id}", headers: headers, params: params } + expect { patch "/users/#{other_user.id}", headers:, params: } .not_to change(other_user, :encrypted_password) end it "does update other values" do - expect { patch "/users/#{other_user.id}", headers: headers, params: params } + expect { patch "/users/#{other_user.id}", headers:, params: } .to change { other_user.reload.name }.from("Danny Rojas").to("new name") end end @@ -592,7 +592,7 @@ RSpec.describe UsersController, type: :request do before do sign_in user - patch "/users/#{other_user.id}", headers: headers, params: params + patch "/users/#{other_user.id}", headers:, params: end it "returns not found 404" do @@ -607,7 +607,7 @@ RSpec.describe UsersController, type: :request do sign_in user allow(User).to receive(:find_by).and_return(user) allow(user).to receive(:update).and_return(false) - patch "/users/#{user.id}", headers: headers, params: params + patch "/users/#{user.id}", headers:, params: end it "show an error" do @@ -627,7 +627,7 @@ RSpec.describe UsersController, type: :request do }, } end - let(:request) { post "/users/", headers: headers, params: params } + let(:request) { post "/users/", headers:, params: } before do sign_in user @@ -697,7 +697,7 @@ RSpec.describe UsersController, type: :request do context "when the current user matches the user ID" do before do sign_in user - get "/users/#{user.id}", headers: headers, params: {} + get "/users/#{user.id}", headers:, params: {} end it "show the user details" do @@ -717,7 +717,7 @@ RSpec.describe UsersController, type: :request do context "when the current user does not match the user ID" do before do sign_in user - get "/users/#{other_user.id}", headers: headers, params: {} + get "/users/#{other_user.id}", headers:, params: {} end context "when the user is part of the same organisation as the current user" do @@ -766,7 +766,7 @@ RSpec.describe UsersController, type: :request do context "when the current user matches the user ID" do before do sign_in user - get "/users/#{user.id}/edit", headers: headers, params: {} + get "/users/#{user.id}/edit", headers:, params: {} end it "show the edit personal details page" do @@ -789,7 +789,7 @@ RSpec.describe UsersController, type: :request do context "when the current user does not match the user ID" do before do sign_in user - get "/users/#{other_user.id}/edit", headers: headers, params: {} + get "/users/#{other_user.id}/edit", headers:, params: {} end context "when the user is part of the same organisation as the current user" do @@ -836,7 +836,7 @@ RSpec.describe UsersController, type: :request do context "when the current user matches the user ID" do before do sign_in user - get "/account/edit/password", headers: headers, params: {} + get "/account/edit/password", headers:, params: {} end it "shows the edit password page" do @@ -855,7 +855,7 @@ RSpec.describe UsersController, type: :request do it "there is no route" do expect { - get "/users/#{other_user.id}/password/edit", headers: headers, params: {} + get "/users/#{other_user.id}/password/edit", headers:, params: {} }.to raise_error(ActionController::RoutingError) end end @@ -865,7 +865,7 @@ RSpec.describe UsersController, type: :request do context "when the current user matches the user ID" do before do sign_in user - patch "/users/#{user.id}", headers: headers, params: params + patch "/users/#{user.id}", headers:, params: end it "updates the user" do @@ -900,7 +900,7 @@ RSpec.describe UsersController, type: :request do before do sign_in user - patch "/users/#{user.id}", headers: headers, params: params + patch "/users/#{user.id}", headers:, params: end it "shows an error if passwords don't match" do @@ -917,12 +917,12 @@ RSpec.describe UsersController, type: :request do context "when the user is part of the same organisation as the current user" do it "updates the user" do - expect { patch "/users/#{other_user.id}", headers: headers, params: params } + expect { patch "/users/#{other_user.id}", headers:, params: } .to change { other_user.reload.name }.from(other_user.name).to(new_name) end it "tracks who updated the record" do - expect { patch "/users/#{other_user.id}", headers: headers, params: params } + expect { patch "/users/#{other_user.id}", headers:, params: } .to change { other_user.reload.versions.last.actor&.id }.from(nil).to(user.id) end @@ -953,12 +953,12 @@ RSpec.describe UsersController, type: :request do end it "does not update the password" do - expect { patch "/users/#{other_user.id}", headers: headers, params: params } + expect { patch "/users/#{other_user.id}", headers:, params: } .not_to change(other_user, :encrypted_password) end it "does update other values" do - expect { patch "/users/#{other_user.id}", headers: headers, params: params } + expect { patch "/users/#{other_user.id}", headers:, params: } .to change { other_user.reload.name }.from("Danny Rojas").to("new name") end end @@ -974,12 +974,12 @@ RSpec.describe UsersController, type: :request do end it "updates the user" do - expect { patch "/users/#{other_user.id}", headers: headers, params: params } + expect { patch "/users/#{other_user.id}", headers:, params: } .to change { other_user.reload.name }.from(other_user.name).to(new_name) end it "tracks who updated the record" do - expect { patch "/users/#{other_user.id}", headers: headers, params: params } + expect { patch "/users/#{other_user.id}", headers:, params: } .to change { other_user.reload.versions.last.actor&.id }.from(nil).to(user.id) end @@ -1010,12 +1010,12 @@ RSpec.describe UsersController, type: :request do end it "does not update the password" do - expect { patch "/users/#{other_user.id}", headers: headers, params: params } + expect { patch "/users/#{other_user.id}", headers:, params: } .not_to change(other_user, :encrypted_password) end it "does update other values" do - expect { patch "/users/#{other_user.id}", headers: headers, params: params } + expect { patch "/users/#{other_user.id}", headers:, params: } .to change { other_user.reload.name }.from("Danny Rojas").to("new name") end end @@ -1028,7 +1028,7 @@ RSpec.describe UsersController, type: :request do sign_in user allow(User).to receive(:find_by).and_return(user) allow(user).to receive(:update).and_return(false) - patch "/users/#{user.id}", headers: headers, params: params + patch "/users/#{user.id}", headers:, params: end it "show an error" do @@ -1047,7 +1047,7 @@ RSpec.describe UsersController, type: :request do }, } end - let(:request) { post "/users/", headers: headers, params: params } + let(:request) { post "/users/", headers:, params: } before do sign_in user diff --git a/spec/views/form/page_view_spec.rb b/spec/views/form/page_view_spec.rb index 2cc5bde7d..19072c3a3 100644 --- a/spec/views/form/page_view_spec.rb +++ b/spec/views/form/page_view_spec.rb @@ -35,7 +35,7 @@ RSpec.describe "form/page" do context "with a page containing a description" do let(:description) { "Test description with link." } - let(:page_attributes) { { description: description } } + let(:page_attributes) { { description: } } let(:expected_html) { '

Test description with link.

' } it "renders the description" do From b710955f1e7d06aec2b5e9f99d084b1deccbd2ee Mon Sep 17 00:00:00 2001 From: Paul Robert Lloyd Date: Tue, 19 Apr 2022 14:59:33 +0100 Subject: [PATCH 02/25] Remove empty line --- app/frontend/controllers/accessible_autocomplete_controller.js | 1 - 1 file changed, 1 deletion(-) diff --git a/app/frontend/controllers/accessible_autocomplete_controller.js b/app/frontend/controllers/accessible_autocomplete_controller.js index 02d67e55d..db34213ee 100644 --- a/app/frontend/controllers/accessible_autocomplete_controller.js +++ b/app/frontend/controllers/accessible_autocomplete_controller.js @@ -3,7 +3,6 @@ import accessibleAutocomplete from "accessible-autocomplete" import 'accessible-autocomplete/dist/accessible-autocomplete.min.css' export default class extends Controller { - connect() { accessibleAutocomplete.enhanceSelectElement({ defaultValue: '', From a0434bf0d1c6ddf25c07c8084679481acce97b44 Mon Sep 17 00:00:00 2001 From: Paul Robert Lloyd Date: Tue, 19 Apr 2022 15:00:38 +0100 Subject: [PATCH 03/25] Refactor filter layout and toggle Ensure filters appear correctly, and that filter toggle behaves as expected (and across viewports) --- app/frontend/controllers/filter_controller.js | 16 --- .../controllers/filter_layout_controller.js | 26 ++++ app/frontend/controllers/index.js | 4 +- app/frontend/modules/filter_toggle.js | 112 ++++++++++++++++++ app/frontend/styles/_filter-layout.scss | 42 +++++++ app/frontend/styles/_filter.scss | 68 ++++------- app/frontend/styles/application.scss | 7 +- app/views/case_logs/_log_filters.erb | 37 +++--- app/views/case_logs/index.html.erb | 16 +-- app/views/filters/_checkbox_filter.html.erb | 16 ++- 10 files changed, 233 insertions(+), 111 deletions(-) delete mode 100644 app/frontend/controllers/filter_controller.js create mode 100644 app/frontend/controllers/filter_layout_controller.js create mode 100644 app/frontend/modules/filter_toggle.js create mode 100644 app/frontend/styles/_filter-layout.scss diff --git a/app/frontend/controllers/filter_controller.js b/app/frontend/controllers/filter_controller.js deleted file mode 100644 index ec55b72b5..000000000 --- a/app/frontend/controllers/filter_controller.js +++ /dev/null @@ -1,16 +0,0 @@ -import { Controller } from "@hotwired/stimulus"; - -export default class extends Controller { - toggleFilter() { - let filter_panel = document.getElementById("filter-panel"); - let toggle_filter_button = document.getElementById("toggle-filter-button"); - - if (filter_panel.style.display === "none" || !filter_panel.style.display) { - filter_panel.style.display = "block"; - toggle_filter_button.innerText = "Hide filters"; - } else { - filter_panel.style.display = "none"; - toggle_filter_button.innerText = "Show filters"; - } - } -} diff --git a/app/frontend/controllers/filter_layout_controller.js b/app/frontend/controllers/filter_layout_controller.js new file mode 100644 index 000000000..a44ba5c45 --- /dev/null +++ b/app/frontend/controllers/filter_layout_controller.js @@ -0,0 +1,26 @@ +import { Controller } from "@hotwired/stimulus"; +import { FilterToggle } from "../modules/filter_toggle.js" + +export default class extends Controller { + connect() { + const filterToggle = new FilterToggle({ + bigModeMediaQuery: '(min-width: 48.0625em)', + closeButton: { + container: this.element.querySelector('.app-filter__header'), + text: 'Close' + }, + filter: { + container: this.element.querySelector('.app-filter-layout__filter') + }, + startHidden: false, + toggleButton: { + container: this.element.querySelector('.app-filter-toggle'), + showText: 'Show filters', + hideText: 'Hide filters', + classes: 'govuk-button--secondary' + } + }) + + filterToggle.init() + } +} diff --git a/app/frontend/controllers/index.js b/app/frontend/controllers/index.js index 2227bea58..7c597baa9 100644 --- a/app/frontend/controllers/index.js +++ b/app/frontend/controllers/index.js @@ -15,5 +15,5 @@ application.register("govukfrontend", GovukfrontendController) import NumericQuestionController from "./numeric_question_controller.js" application.register("numeric-question", NumericQuestionController) -import FilterController from "./filter_controller.js" -application.register("filter", FilterController) +import FilterLayoutController from "./filter_layout_controller.js" +application.register("filter-layout", FilterLayoutController) diff --git a/app/frontend/modules/filter_toggle.js b/app/frontend/modules/filter_toggle.js new file mode 100644 index 000000000..917fed62b --- /dev/null +++ b/app/frontend/modules/filter_toggle.js @@ -0,0 +1,112 @@ +export class FilterToggle { + constructor (options) { + this.options = options + this.container = this.options.toggleButton.container + } + + setupResponsiveChecks () { + this.mq = window.matchMedia(this.options.bigModeMediaQuery) + this.mq.addListener(this.checkMode.bind(this)) + this.checkMode(this.mq) + } + + checkMode (mq) { + if (mq.matches) { + this.enableBigMode() + } else { + this.enableSmallMode() + } + } + + enableBigMode () { + this.showMenu() + this.removeMenuButton() + this.removeCloseButton() + } + + enableSmallMode () { + this.options.filter.container.setAttribute("tabindex", "-1") + this.hideMenu() + this.addMenuButton() + this.addCloseButton() + } + + addCloseButton () { + if (this.options.closeButton) { + this.closeButton = document.createElement("button") + this.closeButton.classList.add("app-filter__close") + this.closeButton.innerText = this.options.closeButton.text + this.closeButton.type = 'button' + this.closeButton.addEventListener('click', this.onCloseClick.bind(this)) + + this.options.closeButton.container.append(this.closeButton) + } + } + + onCloseClick () { + this.hideMenu() + this.menuButton.focus() + } + + removeCloseButton () { + if (this.closeButton) { + this.closeButton.remove() + this.closeButton = null + } + } + + addMenuButton () { + this.menuButton = document.createElement("button") + this.menuButton.setAttribute("aria-expanded", "false") + this.menuButton.setAttribute("aria-has-popup", "true") + this.menuButton.classList.add("govuk-button", this.options.toggleButton.classes, "app-filter-toggle__button") + this.menuButton.innerText = this.options.toggleButton.showText + this.menuButton.type = "button" + this.menuButton.addEventListener("click", this.onMenuButtonClick.bind(this)) + + this.options.toggleButton.container.prepend(this.menuButton) + } + + removeMenuButton () { + if (this.menuButton) { + this.menuButton.remove() + this.menuButton = null + } + } + + hideMenu () { + if (this.menuButton) { + this.menuButton.setAttribute("aria-expanded", "false") + this.menuButton.innerText = this.options.toggleButton.showText + } + this.options.filter.container.setAttribute("hidden", true) + } + + showMenu () { + if (this.menuButton) { + this.menuButton.setAttribute("aria-expanded", "true") + this.menuButton.innerText = this.options.toggleButton.hideText + } + this.options.filter.container.removeAttribute("hidden") + } + + onMenuButtonClick () { + this.toggle() + } + + toggle () { + if (this.options.filter.container.hidden) { + this.showMenu() + this.options.filter.container.focus() + } else { + this.hideMenu() + } + } + + init () { + this.setupResponsiveChecks() + if (this.options.startHidden) { + this.hideMenu() + } + } +} diff --git a/app/frontend/styles/_filter-layout.scss b/app/frontend/styles/_filter-layout.scss new file mode 100644 index 000000000..5dffc0e67 --- /dev/null +++ b/app/frontend/styles/_filter-layout.scss @@ -0,0 +1,42 @@ +.app-filter-layout { + @include govuk-clearfix; +} + +.app-filter-layout__filter { + @include govuk-media-query(desktop) { + float: left; + min-width: govuk-grid-width("one-quarter"); + } +} + +.js-enabled .app-filter-layout__filter { + outline: 0 none; + + @include govuk-media-query($until: desktop) { + background-color: govuk-colour("light-grey"); + bottom: govuk-spacing(1); + border: 1px solid govuk-colour("mid-grey"); + max-width: 310px; + min-width: 260px; + width: 100%; + overflow-y: scroll; + position: fixed; + right: govuk-spacing(1); + top: govuk-spacing(1); + z-index: 100; + + &:focus { + outline: $govuk-focus-width solid $govuk-focus-colour; + } + } +} + +.app-filter-layout__content { + @include govuk-media-query(desktop) { + float: right; + max-width: calc( + #{govuk-grid-width("three-quarters")} - #{govuk-spacing(6)} + ); + width: 100%; + } +} diff --git a/app/frontend/styles/_filter.scss b/app/frontend/styles/_filter.scss index 46783534f..d98ed5099 100644 --- a/app/frontend/styles/_filter.scss +++ b/app/frontend/styles/_filter.scss @@ -61,63 +61,41 @@ vertical-align: middle; width: 14px; } - - @include govuk-media-query(desktop) { - display: none; - } -} - -.app-filter-layout { - @include govuk-clearfix; } .app-filter-toggle__button { min-width: 128px; - @include govuk-media-query(desktop) { - display: none !important; - } } -.app-filter-layout__filter { - @include govuk-media-query(desktop) { - float: left; - min-width: govuk-grid-width("one-quarter"); +.app-filter__group { + border-bottom: 1px solid $govuk-border-colour; + margin-bottom: govuk-spacing(3); + padding-bottom: govuk-spacing(2); + + &:last-child { + border-bottom: none; + margin-bottom: 0; + padding-bottom: 0; } - display: none; - @include govuk-media-query(desktop) { - display: block; + .govuk-fieldset__legend { + margin-bottom: govuk-spacing(1); } -} -.js-enabled .app-filter-layout__filter { - outline: 0 none; - - @include govuk-media-query($until: desktop) { - background-color: govuk-colour("light-grey"); - bottom: govuk-spacing(1); - border: 1px solid govuk-colour("mid-grey"); - max-width: 310px; - min-width: 260px; - width: 100%; - overflow-y: scroll; - position: fixed; - right: govuk-spacing(1); - top: govuk-spacing(1); - z-index: 100; - - &:focus { - outline: $govuk-focus-width solid $govuk-focus-colour; + .govuk-form-group { + margin-bottom: 0; + + &:last-child { + margin-bottom: 0; } } -} -.app-filter-layout__content { - @include govuk-media-query(desktop) { - float: right; - max-width: calc( - #{govuk-grid-width("three-quarters")} - #{govuk-spacing(6)} - ); - width: 100%; + .govuk-checkboxes__label, + .govuk-radios__label { + @include govuk-font(16); + + &::before { + background-color: govuk-colour("white"); + } } } diff --git a/app/frontend/styles/application.scss b/app/frontend/styles/application.scss index 3d01074ec..258c21e4d 100644 --- a/app/frontend/styles/application.scss +++ b/app/frontend/styles/application.scss @@ -1,9 +1,9 @@ @function frontend-font-url($filename) { - @return url("~assets/fonts/"+$filename); + @return url("~assets/fonts/" + $filename); } @function frontend-image-url($filename) { - @return url("~assets/images/"+$filename); + @return url("~assets/images/" + $filename); } $govuk-font-url-function: frontend-font-url; @@ -15,6 +15,8 @@ $govuk-global-styles: true; @import "accessible-autocomplete"; @import "button"; @import "figure"; +@import "filter"; +@import "filter-layout"; @import "input"; @import "related-navigation"; @import "section-skip-link"; @@ -24,7 +26,6 @@ $govuk-global-styles: true; @import "template"; @import "pagination"; @import "panel"; -@import "filter"; // App utilities .app-\!-colour-muted { diff --git a/app/views/case_logs/_log_filters.erb b/app/views/case_logs/_log_filters.erb index 888028700..f76e8b876 100644 --- a/app/views/case_logs/_log_filters.erb +++ b/app/views/case_logs/_log_filters.erb @@ -1,25 +1,16 @@ -
-
-
-

Filters

- -
-
-
- <%= form_with url: "/logs", html: { method: :get } do |f| %> - <% years = {"2021": "2021/22", "2022": "2022/23"} %> - <%= render partial: "filters/checkbox_filter", locals: { f: f, options: years, label: "Collection year", category: "years" } %> - <%= render partial: "filters/checkbox_filter", locals: { f: f, options: status_filters, label: "Status", category: "status" } %> - <%= render partial: "filters/checkbox_filter", locals: { f: f, options: {"all": "All", "yours": "Yours"}, label: "Logs", category: "user" } %> - <%= f.govuk_submit "Apply filters", class: "govuk-!-margin-top-4" %> - <% end %> -
-
+
+
+
+

Filters

+
+ <%= form_with url: "/logs", html: { method: :get } do |f| %> + <% years = {"2021": "2021/22", "2022": "2022/23"} %> + <%= render partial: "filters/checkbox_filter", locals: { f: f, options: years, label: "Collection year", category: "years" } %> + <%= render partial: "filters/checkbox_filter", locals: { f: f, options: status_filters, label: "Status", category: "status" } %> + <%= render partial: "filters/checkbox_filter", locals: { f: f, options: {"all": "All", "yours": "Yours"}, label: "Logs", category: "user" } %> + <%= f.govuk_submit "Apply filters", class: "govuk-!-margin-bottom-0" %> + <% end %> +
+
diff --git a/app/views/case_logs/index.html.erb b/app/views/case_logs/index.html.erb index 8060f3c99..c3ddfb7b8 100644 --- a/app/views/case_logs/index.html.erb +++ b/app/views/case_logs/index.html.erb @@ -3,22 +3,12 @@

<%= content_for(:title) %>

-
-
- +
+
<%= govuk_button_to "Create a new lettings log", case_logs_path %> <%#= govuk_link_to "Upload logs", bulk_upload_case_logs_path %>
- + <%= render partial: "log_filters"%> <% if @case_logs.present? %>
diff --git a/app/views/filters/_checkbox_filter.html.erb b/app/views/filters/_checkbox_filter.html.erb index c49156be7..aa2fc71a4 100644 --- a/app/views/filters/_checkbox_filter.html.erb +++ b/app/views/filters/_checkbox_filter.html.erb @@ -1,10 +1,8 @@ -<%= f.govuk_check_boxes_fieldset category.to_sym, legend: { text: label, size: "s"} do %> -
- <% options.map do |key, option| %> - <%= f.govuk_check_box category, "#{key}", - label: { text: option }, - checked: filter_selected?(category, key), - size: "s" %> - <% end %> -
+<%= f.govuk_check_boxes_fieldset category.to_sym, legend: { text: label, size: "s"}, small: true, form_group: { classes: "app-filter__group" } do %> + <% options.map do |key, option| %> + <%= f.govuk_check_box category, "#{key}", + label: { text: option }, + checked: filter_selected?(category, key), + size: "s" %> + <% end %> <% end %> From feb7567c741fffacfae78e7492fd3d623848ec1b Mon Sep 17 00:00:00 2001 From: Paul Robert Lloyd Date: Wed, 20 Apr 2022 12:39:31 +0100 Subject: [PATCH 04/25] Remove reference to upcoming features from start page --- app/views/start/index.html.erb | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/app/views/start/index.html.erb b/app/views/start/index.html.erb index d687246b7..e59a15a89 100644 --- a/app/views/start/index.html.erb +++ b/app/views/start/index.html.erb @@ -6,13 +6,7 @@

Use this service to submit social housing lettings and sales data to the Department for Levelling Up, Housing and Communities (DLUHC).

We’ll ask you questions about a letting or sale, like details about the household or property. Your answers will create a log that you can submit directly to us.

-

Your organisation can also:

-
    -
  • upload data for multiple sales and lettings
  • -
  • transfer data using an API
  • - <%# TODO: Add link to lettings log form %> -
  • <%= govuk_link_to("download a copy of the 2021 to 2022 lettings log as a PDF", "#") %> (2MB)
  • -
+

Your organisation can also set up and manage user accounts.

The data will be used to update the national record for social housing. It will also help to inform policy about the cost of social housing and what type of housing needs to be built.

This service is only for social housing in England.

From fd675bdf010c80af635ef7dd6092e30cb5bc4f83 Mon Sep 17 00:00:00 2001 From: Paul Robert Lloyd Date: Wed, 20 Apr 2022 13:37:26 +0100 Subject: [PATCH 05/25] Add document list component --- .../document_list_component.html.erb | 15 +++++ app/components/document_list_component.rb | 8 +++ app/frontend/styles/_document-list.scss | 66 +++++++++++++++++++ app/frontend/styles/application.scss | 1 + .../document_list_component_spec.rb | 19 ++++++ 5 files changed, 109 insertions(+) create mode 100644 app/components/document_list_component.html.erb create mode 100644 app/components/document_list_component.rb create mode 100644 app/frontend/styles/_document-list.scss create mode 100644 spec/components/document_list_component_spec.rb diff --git a/app/components/document_list_component.html.erb b/app/components/document_list_component.html.erb new file mode 100644 index 000000000..6242ab3dc --- /dev/null +++ b/app/components/document_list_component.html.erb @@ -0,0 +1,15 @@ +
    + <% items.each do |item| %> +
  • +

    + <%= govuk_link_to item[:name], item[:href] %> +

    + <% if item[:description] %> +

    <%= item[:description] %>

    + <% end %> + <% if item[:metadata] %> + + <% end %> +
  • + <% end %> +
diff --git a/app/components/document_list_component.rb b/app/components/document_list_component.rb new file mode 100644 index 000000000..253370c98 --- /dev/null +++ b/app/components/document_list_component.rb @@ -0,0 +1,8 @@ +class DocumentListComponent < ViewComponent::Base + attr_reader :items + + def initialize(items:) + @items = items + super + end +end diff --git a/app/frontend/styles/_document-list.scss b/app/frontend/styles/_document-list.scss new file mode 100644 index 000000000..89c547ef6 --- /dev/null +++ b/app/frontend/styles/_document-list.scss @@ -0,0 +1,66 @@ +.app-document-list { + list-style: none; + padding: 0; +} + +.app-document-list__item { + margin-bottom: govuk-spacing(4); + + &:last-child { + border-bottom: 0; + margin-bottom: 0; + padding-bottom: 0; + } +} + +.app-document-list__item-title { + @include govuk-font($size: 16, $weight: "bold"); + margin: 0 0 govuk-spacing(1); +} + +.app-document-list__item-metadata { + padding: 0; + margin: 0; +} + +.app-document-list__item-description { + @include govuk-font($size: 16); + margin: govuk-spacing(1) 0; +} + +.app-document-list__item-metadata { + @include govuk-font($size: 16); + color: $govuk-secondary-text-colour; + margin: 0; +} +.app-document-list { + list-style: none; + padding: 0; +} + +.app-document-list__item { + margin-bottom: govuk-spacing(4); + + &:last-child { + border-bottom: 0; + margin-bottom: 0; + padding-bottom: 0; + } +} + +.app-document-list__item-title { + @include govuk-font($size: 16, $weight: "bold"); + margin: 0 0 govuk-spacing(1); +} + +.app-document-list__item-description { + @include govuk-font($size: 16); + margin: govuk-spacing(1) 0; +} + +.app-document-list__item-metadata { + @include govuk-font($size: 16); + color: $govuk-secondary-text-colour; + padding: 0; + margin: 0; +} diff --git a/app/frontend/styles/application.scss b/app/frontend/styles/application.scss index 258c21e4d..1c7642374 100644 --- a/app/frontend/styles/application.scss +++ b/app/frontend/styles/application.scss @@ -14,6 +14,7 @@ $govuk-global-styles: true; @import "accessible-autocomplete"; @import "button"; +@import "document-list"; @import "figure"; @import "filter"; @import "filter-layout"; diff --git a/spec/components/document_list_component_spec.rb b/spec/components/document_list_component_spec.rb new file mode 100644 index 000000000..ee0c32301 --- /dev/null +++ b/spec/components/document_list_component_spec.rb @@ -0,0 +1,19 @@ +require "rails_helper" + +RSpec.describe DocumentListComponent, type: :component do + let(:items) do + [{ name: "PDF Form", href: "/forms/form.pdf", description: "An important form", metadata: "4 pages" }, + { name: "Website", href: "https://example.com" }] + end + + context "when rendering tabs" do + it "all of the nav tabs specified in the items hash are passed to it" do + result = render_inline(described_class.new(items:)) + + expect(result.text).to include("PDF Form") + expect(result.text).to include("An important form") + expect(result.text).to include("4 pages") + expect(result.text).to include("Website") + end + end +end From bdf7cd011deceaa44d0f081a219b3da905d0bad0 Mon Sep 17 00:00:00 2001 From: Paul Robert Lloyd Date: Wed, 20 Apr 2022 13:37:49 +0100 Subject: [PATCH 06/25] Add card styles --- app/frontend/styles/_card.scss | 7 +++++++ app/frontend/styles/application.scss | 1 + 2 files changed, 8 insertions(+) create mode 100644 app/frontend/styles/_card.scss diff --git a/app/frontend/styles/_card.scss b/app/frontend/styles/_card.scss new file mode 100644 index 000000000..d0a9e9ecf --- /dev/null +++ b/app/frontend/styles/_card.scss @@ -0,0 +1,7 @@ +.app-card { + @include govuk-responsive-padding(4); + @include govuk-font($size: 19); + background-color: govuk-colour("light-grey"); + display: block; + position: relative; +} diff --git a/app/frontend/styles/application.scss b/app/frontend/styles/application.scss index 1c7642374..6d0e3ca55 100644 --- a/app/frontend/styles/application.scss +++ b/app/frontend/styles/application.scss @@ -14,6 +14,7 @@ $govuk-global-styles: true; @import "accessible-autocomplete"; @import "button"; +@import "card"; @import "document-list"; @import "figure"; @import "filter"; From a6fa99819211e1a36f63f3af9c8bb97e276457a4 Mon Sep 17 00:00:00 2001 From: Paul Robert Lloyd Date: Wed, 20 Apr 2022 13:40:54 +0100 Subject: [PATCH 07/25] Add collection resouces sidebar to start page and organisation page --- .../layouts/_collection_resources.html.erb | 9 ++++++++ app/views/organisations/show.html.erb | 4 ++++ app/views/start/index.html.erb | 21 +++---------------- 3 files changed, 16 insertions(+), 18 deletions(-) create mode 100644 app/views/layouts/_collection_resources.html.erb diff --git a/app/views/layouts/_collection_resources.html.erb b/app/views/layouts/_collection_resources.html.erb new file mode 100644 index 000000000..fb4028990 --- /dev/null +++ b/app/views/layouts/_collection_resources.html.erb @@ -0,0 +1,9 @@ +
+

2022/23 collection resources

+ + <%= render DocumentListComponent.new(items: [{ + name: "Lettings log for tenants", + href: "https://core.communities.gov.uk/public/download/guides-and-manuals/2022-23%20Lettings%20paper%20form.pdf?download-format=pdf", + metadata: "PDF, 654 KB, 4 pages" + }]) %> +
diff --git a/app/views/organisations/show.html.erb b/app/views/organisations/show.html.erb index c549605e6..8af61268f 100644 --- a/app/views/organisations/show.html.erb +++ b/app/views/organisations/show.html.erb @@ -26,4 +26,8 @@ <% end %> <% end %>
+ +
+ <%= render partial: "layouts/collection_resources" %> +
diff --git a/app/views/start/index.html.erb b/app/views/start/index.html.erb index e59a15a89..578fccc53 100644 --- a/app/views/start/index.html.erb +++ b/app/views/start/index.html.erb @@ -3,7 +3,7 @@
-
+

Use this service to submit social housing lettings and sales data to the Department for Levelling Up, Housing and Communities (DLUHC).

We’ll ask you questions about a letting or sale, like details about the household or property. Your answers will create a log that you can submit directly to us.

Your organisation can also set up and manage user accounts.

@@ -22,22 +22,7 @@

You can <%= govuk_link_to("request an account", "https://digital.dclg.gov.uk/jira/servicedesk/customer/portal/4/group/21") %> if your organisation doesn’t have one.

-
- +
+ <%= render partial: "layouts/collection_resources" %>
From 7c8f71c808042113f0904e48743f0ed5789115ad Mon Sep 17 00:00:00 2001 From: Paul Robert Lloyd Date: Wed, 20 Apr 2022 13:49:56 +0100 Subject: [PATCH 08/25] Add 2021/22 lettings log to collection resources list --- app/views/layouts/_collection_resources.html.erb | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/app/views/layouts/_collection_resources.html.erb b/app/views/layouts/_collection_resources.html.erb index fb4028990..4b45b0a8d 100644 --- a/app/views/layouts/_collection_resources.html.erb +++ b/app/views/layouts/_collection_resources.html.erb @@ -1,9 +1,13 @@
-

2022/23 collection resources

+

Collection resources

<%= render DocumentListComponent.new(items: [{ - name: "Lettings log for tenants", + name: "Lettings log for tenants (2022/23)", href: "https://core.communities.gov.uk/public/download/guides-and-manuals/2022-23%20Lettings%20paper%20form.pdf?download-format=pdf", metadata: "PDF, 654 KB, 4 pages" + }, { + name: "Lettings log for tenants (2021/22)", + href: "https://core.communities.gov.uk/public/download/guides-and-manuals/2021_22%20Lettings%20Log.pdf?download-format=pdf", + metadata: "PDF, 302 KB, 3 pages" }]) %>
From 956dbe1ace659736ce5b2c11909d041f086a15bb Mon Sep 17 00:00:00 2001 From: Paul Robert Lloyd Date: Wed, 20 Apr 2022 15:31:15 +0100 Subject: [PATCH 09/25] Use proper elipsis --- app/views/pagy/_nav.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/pagy/_nav.html.erb b/app/views/pagy/_nav.html.erb index 961d6fe5b..9aa325e3d 100644 --- a/app/views/pagy/_nav.html.erb +++ b/app/views/pagy/_nav.html.erb @@ -16,7 +16,7 @@ <% pagy.series.each do |item| %> <% if item == :gap %> -
  • ...
  • +
  • <% elsif item.is_a?(String) %>
  • Page <%= item %> (current page)
  • <% else %> From aafa7a8487af9e667206f37f7e20bddf2163aa67 Mon Sep 17 00:00:00 2001 From: Paul Robert Lloyd Date: Wed, 20 Apr 2022 16:47:04 +0100 Subject: [PATCH 10/25] Enable new link styles --- app/frontend/styles/application.scss | 1 + 1 file changed, 1 insertion(+) diff --git a/app/frontend/styles/application.scss b/app/frontend/styles/application.scss index 6d0e3ca55..0d172f26f 100644 --- a/app/frontend/styles/application.scss +++ b/app/frontend/styles/application.scss @@ -9,6 +9,7 @@ $govuk-font-url-function: frontend-font-url; $govuk-image-url-function: frontend-image-url; $govuk-global-styles: true; +$govuk-new-link-styles: true; @import "~govuk-frontend/govuk/all"; From b8d60a86ea4f59a287adb3d68f31f0caae4c9fbe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Meny?= Date: Wed, 20 Apr 2022 17:16:01 +0100 Subject: [PATCH 11/25] Import changes (#470) --- app/models/bulk_upload.rb | 26 +- app/models/case_log.rb | 133 +++-- app/models/form/question.rb | 24 +- app/models/validations/date_validations.rb | 12 +- .../validations/financial_validations.rb | 21 +- .../validations/household_validations.rb | 10 +- .../validations/property_validations.rb | 2 +- app/models/validations/setup_validations.rb | 6 +- app/models/validations/tenancy_validations.rb | 2 +- .../imports/case_logs_import_service.rb | 392 +++++++++++++ config/forms/2021_2022.json | 346 ++++++------ config/locales/en.yml | 40 +- ...20220207112310_additional_user_fields2.rb} | 0 .../20220411092231_update_case_logs_fields.rb | 13 + db/schema.rb | 29 +- docs/api/DLUHC-CORE-Data.v1.json | 4 +- spec/factories/case_log.rb | 42 +- spec/features/form/check_answers_page_spec.rb | 16 +- .../form/conditional_questions_spec.rb | 6 +- spec/features/form/form_navigation_spec.rb | 4 +- spec/features/form/page_routing_spec.rb | 6 +- spec/features/form/saving_data_spec.rb | 2 +- spec/features/form/validations_spec.rb | 4 +- spec/fixtures/complete_case_log.json | 30 +- spec/fixtures/exports/case_logs.xml | 41 +- spec/fixtures/forms/2021_2022.json | 66 +-- .../0ead17cb-1668-442d-898c-0d52879ff592.xml | 532 ++++++++++++++++++ .../166fc004-392e-47a8-acb8-1c018734882b.xml | 514 +++++++++++++++++ spec/helpers/check_answers_helper_spec.rb | 2 +- .../conditional_questions_helper_spec.rb | 2 +- .../helpers/interuption_screen_helper_spec.rb | 2 +- spec/models/case_log_spec.rb | 206 +++---- spec/models/form/page_spec.rb | 2 +- spec/models/form/question_spec.rb | 24 +- spec/models/form/subsection_spec.rb | 8 +- spec/models/form_spec.rb | 12 +- .../validations/date_validations_spec.rb | 24 +- .../validations/financial_validations_spec.rb | 50 +- .../validations/household_validations_spec.rb | 94 ++-- .../validations/property_validations_spec.rb | 24 +- .../validations/setup_validations_spec.rb | 20 +- .../validations/tenancy_validations_spec.rb | 22 +- spec/requests/form_controller_spec.rb | 8 +- .../imports/case_logs_import_service_spec.rb | 34 ++ 44 files changed, 2111 insertions(+), 746 deletions(-) create mode 100644 app/services/imports/case_logs_import_service.rb rename db/migrate/{202202071123100_additional_user_fields2.rb => 20220207112310_additional_user_fields2.rb} (100%) create mode 100644 db/migrate/20220411092231_update_case_logs_fields.rb create mode 100644 spec/fixtures/softwire_imports/case_logs/0ead17cb-1668-442d-898c-0d52879ff592.xml create mode 100644 spec/fixtures/softwire_imports/case_logs/166fc004-392e-47a8-acb8-1c018734882b.xml create mode 100644 spec/services/imports/case_logs_import_service_spec.rb diff --git a/app/models/bulk_upload.rb b/app/models/bulk_upload.rb index aeccfc4cd..9b8c8a9ba 100644 --- a/app/models/bulk_upload.rb +++ b/app/models/bulk_upload.rb @@ -57,7 +57,6 @@ class BulkUpload def map_row(row) { lettype: row[1], - landlord: row[2], # reg_num_la_core_code: row[3], # managementgroup: row[4], # schemecode: row[5], @@ -67,8 +66,7 @@ class BulkUpload tenancy: row[9], tenancyother: row[10], # tenancyduration: row[11], - other_hhmemb: other_hhmemb(row), - hhmemb: other_hhmemb(row) + 1, + hhmemb: hhmemb(row), age1: row[12], age2: row[13], age3: row[14], @@ -111,7 +109,7 @@ class BulkUpload earnings: row[50], # increfused: row[51], reason: row[52], - other_reason_for_leaving_last_settled_home: row[53], + reasonother: row[53], underoccupation_benefitcap: row[54], housingneeds_a: row[55], housingneeds_b: row[56], @@ -121,11 +119,9 @@ class BulkUpload housingneeds_h: row[60], prevten: row[61], prevloc: row[62], - # ppostc1: row[63], - # ppostc2: row[64], # prevpco_unknown: row[65], layear: row[66], - lawaitlist: row[67], + waityear: row[67], homeless: row[68], reasonpref: row[69], rp_homeless: row[70], @@ -147,15 +143,9 @@ class BulkUpload # no_rent_or_charge: row[86], hbrentshortfall: row[87], tshortfall: row[88], - property_void_date: row[89].to_s + row[90].to_s + row[91].to_s, - # property_void_date_day: row[89], - # property_void_date_month: row[90], - # property_void_date_year: row[91], + voiddate: row[89].to_s + row[90].to_s + row[91].to_s, majorrepairs: row[92].present? ? "1" : nil, mrcdate: row[92].to_s + row[93].to_s + row[94].to_s, - mrcday: row[92], - mrcmonth: row[93], - mrcyear: row[94], # supported_scheme: row[95], startdate: date_time(row[98], row[97], row[96]), # startdate_day: row[96], @@ -170,8 +160,6 @@ class BulkUpload property_relet: row[105], rsnvac: row[106], la: row[107], - # postcode: row[108], - # postcod2: row[109], # row[110] removed # row[111] is owning organisation used above # username: row[112], @@ -193,7 +181,7 @@ class BulkUpload illness_type_10: row[128], # london_affordable: row[129], rent_type: row[130], - intermediate_rent_product_name: row[131], + irproduct_other: row[131], # data_protection: row[132], sale_or_letting: "letting", declaration: 1, @@ -206,7 +194,7 @@ class BulkUpload Time.zone.local("20#{year}", month.to_s, day.to_s) end - def other_hhmemb(row) - [13, 14, 15, 16, 17, 18, 19].count { |idx| row[idx].present? } + def hhmemb(row) + [14, 15, 16, 17, 18, 19, 20].count { |idx| row[idx].present? } end end diff --git a/app/models/case_log.rb b/app/models/case_log.rb index 4eb2ff467..0cbd13ce9 100644 --- a/app/models/case_log.rb +++ b/app/models/case_log.rb @@ -122,19 +122,23 @@ class CaseLog < ApplicationRecord end def net_income_refused? + # 2: Tenant prefers not to say net_income_known == 2 end def net_income_is_weekly? - !!(incfreq && incfreq.zero?) + # 1: Weekly + !!(incfreq && incfreq == 1) end def net_income_is_monthly? - incfreq == 1 + # 2: Monthly + incfreq == 2 end def net_income_is_yearly? - incfreq == 2 + # 3: Yearly + incfreq == 3 end def net_income_soft_validation_triggered? @@ -142,138 +146,181 @@ class CaseLog < ApplicationRecord end def given_reasonable_preference? + # 1: Yes reasonpref == 1 end def is_renewal? + # 1: Yes renewal == 1 end def is_general_needs? + # 1: General Needs needstype == 1 end def is_supported_housing? - !!(needstype && needstype.zero?) + # 2: Supported Housing + needstype == 2 end def has_hbrentshortfall? - !!(hbrentshortfall && hbrentshortfall.zero?) + # 0: Yes + !!hbrentshortfall&.zero? end def postcode_known? + # 1: Yes postcode_known == 1 end def previous_postcode_known? + # 1: Yes previous_postcode_known == 1 end def la_known? + # 1: Yes la_known == 1 end def previous_la_known? + # 1: Yes previous_la_known == 1 end def is_secure_tenancy? - tenancy == 3 + # 1: Secure (including flexible) + tenancy == 1 end def is_assured_shorthold_tenancy? - tenancy == 1 + # 4: Assured Shorthold + tenancy == 4 end def is_internal_transfer? + # 1: Internal Transfer referral == 1 end def is_relet_to_temp_tenant? - rsnvac == 2 + # 9: Re-let to tenant who occupied same property as temporary accommodation + rsnvac == 9 end def is_bedsit? - unittype_gn == 1 + # 2: Bedsit + unittype_gn == 2 end def is_shared_housing? - [4, 5, 6].include?(unittype_gn) + # 4: Shared flat or maisonette + # 9: Shared house + # 10: Shared bungalow + [4, 9, 10].include?(unittype_gn) end def has_first_let_vacancy_reason? + # 15: First let of new-build property + # 16: First let of conversion, rehabilitation or acquired property + # 17: First let of leased property [15, 16, 17].include?(rsnvac) end def previous_tenancy_was_temporary? - ![4, 5, 16, 21, 22].include?(prevten) + # 4: Tied housing or renting with job + # 6: Supported housing + # 8: Sheltered accomodation + # 24: Housed by National Asylum Support Service (prev Home Office) + # 25: Other + ![4, 6, 8, 24, 25].include?(prevten) end def armed_forces_regular? - !!(armedforces && armedforces.zero?) + # 1: Yes – the person is a current or former regular + !!(armedforces && armedforces == 1) end def armed_forces_no? - armedforces == 3 + # 2: No + armedforces == 2 end def armed_forces_refused? - armedforces == 4 + # 3: Person prefers not to say / Refused + armedforces == 3 end def has_pregnancy? - !!(preg_occ && preg_occ.zero?) + # 1: Yes + !!(preg_occ && preg_occ == 1) end def pregnancy_refused? - preg_occ == 2 + # 3: Tenant prefers not to say / Refused + preg_occ == 3 end def is_assessed_homeless? + # 11: Assessed as homeless (or threatened with homelessness within 56 days) by a local authority and owed a homelessness duty homeless == 11 end def is_other_homeless? + # 7: Other homeless – not found statutorily homeless but considered homeless by landlord homeless == 7 end def is_not_homeless? + # 1: No homeless == 1 end def is_london_rent? + # 2: London Affordable Rent + # 4: London Living Rent rent_type == 2 || rent_type == 4 end def previous_tenancy_was_foster_care? + # 13: Children's home or foster care prevten == 13 end def previous_tenancy_was_refuge? + # 21: Refuge prevten == 21 end def is_reason_permanently_decanted? + # 1: Permanently decanted from another property owned by this landlord reason == 1 end def receives_housing_benefit_only? + # 1: Housing benefit hb == 1 end def receives_housing_benefit_and_universal_credit? + # 8: Housing benefit and Universal Credit (without housing element) hb == 8 end def receives_uc_with_housing_element_excl_housing_benefit? + # 6: Universal Credit with housing element (excluding housing benefit) hb == 6 end def receives_no_benefits? + # 9: None hb == 9 end def receives_universal_credit_but_no_housing_benefit? + # 7: Universal Credit (without housing element) hb == 7 end @@ -283,22 +330,18 @@ class CaseLog < ApplicationRecord end def benefits_unknown? + # 3: Don’t know hb == 3 end - def this_landlord? - landlord == 1 - end - - def other_landlord? - landlord == 2 - end - def local_housing_referral? + # 3: PRP lettings only - Nominated by local housing authority referral == 3 end def is_prevten_la_general_needs? + # 30: Fixed term Local Authority General Needs tenancy + # 31: Lifetime Local Authority General Needs tenancy [30, 31].any?(prevten) end @@ -379,30 +422,10 @@ private end def set_derived_fields! - if ppostcode_full.present? - self.ppostc1 = UKPostcode.parse(ppostcode_full).outcode - self.ppostc2 = UKPostcode.parse(ppostcode_full).incode - end - if mrcdate.present? - self.mrcday = mrcdate.day - self.mrcmonth = mrcdate.month - self.mrcyear = mrcdate.year - end - if startdate.present? - self.day = startdate.day - self.month = startdate.month - self.year = startdate.year - end - if property_void_date.present? - self.vday = property_void_date.day - self.vmonth = property_void_date.month - self.vyear = property_void_date.year - end if rsnvac.present? self.newprop = has_first_let_vacancy_reason? ? 1 : 2 end self.incref = 1 if net_income_refused? - self.other_hhmemb = hhmemb - 1 if hhmemb.present? self.renttype = RENT_TYPE_MAPPING[rent_type] self.lettype = get_lettype self.totchild = get_totchild @@ -431,14 +454,14 @@ private weekly_value(tshortfall) end self.nocharge = household_charge&.zero? ? 1 : 0 - self.underoccupation_benefitcap = 3 if renewal == 1 && year == 2021 self.housingneeds = get_housingneeds if is_renewal? - self.underoccupation_benefitcap = 2 if year == 2021 + self.underoccupation_benefitcap = 2 if collection_start_year == 2021 self.homeless = 2 self.referral = 0 self.layear = 1 if is_general_needs? + # fixed term self.prevten = 32 if managing_organisation.provider_type == "PRP" self.prevten = 30 if managing_organisation.provider_type == "LA" end @@ -450,47 +473,41 @@ private self["ecstat#{idx}"] = nil end end - self.landlord = 1 if owning_organisation.provider_type == "LA" - self.landlord = 2 if owning_organisation.provider_type == "PRP" end def process_postcode_changes! self.postcode_full = postcode_full.present? ? postcode_full.upcase.gsub(/\s+/, "") : postcode_full - process_postcode(postcode_full, "postcode_known", "is_la_inferred", "la", "postcode", "postcod2") + process_postcode(postcode_full, "postcode_known", "is_la_inferred", "la") end def process_previous_postcode_changes! self.ppostcode_full = ppostcode_full.present? ? ppostcode_full.upcase.gsub(/\s+/, "") : ppostcode_full - process_postcode(ppostcode_full, "previous_postcode_known", "is_previous_la_inferred", "prevloc", "ppostc1", "ppostc2") + process_postcode(ppostcode_full, "previous_postcode_known", "is_previous_la_inferred", "prevloc") end - def process_postcode(postcode, postcode_known_key, la_inferred_key, la_key, outcode_key, incode_key) + def process_postcode(postcode, postcode_known_key, la_inferred_key, la_key) return if postcode.blank? self[postcode_known_key] = 1 inferred_la = get_inferred_la(postcode) self[la_inferred_key] = inferred_la.present? self[la_key] = inferred_la if inferred_la.present? - self[outcode_key] = UKPostcode.parse(postcode).outcode - self[incode_key] = UKPostcode.parse(postcode).incode end def reset_location_fields! - reset_location(is_la_inferred, "la", "is_la_inferred", "postcode_full", "postcode", "postcod2", la_known) + reset_location(is_la_inferred, "la", "is_la_inferred", "postcode_full", la_known) end def reset_previous_location_fields! - reset_location(is_previous_la_inferred, "prevloc", "is_previous_la_inferred", "ppostcode_full", "ppostc1", "ppostc2", previous_la_known) + reset_location(is_previous_la_inferred, "prevloc", "is_previous_la_inferred", "ppostcode_full", previous_la_known) end - def reset_location(is_inferred, la_key, is_inferred_key, postcode_key, incode_key, outcode_key, is_la_known) + def reset_location(is_inferred, la_key, is_inferred_key, postcode_key, is_la_known) if is_inferred || is_la_known != 1 self[la_key] = nil end self[is_inferred_key] = false self[postcode_key] = nil - self[incode_key] = nil - self[outcode_key] = nil end def get_totelder diff --git a/app/models/form/question.rb b/app/models/form/question.rb index 5d3d50bb9..e451f0c3c 100644 --- a/app/models/form/question.rb +++ b/app/models/form/question.rb @@ -224,9 +224,9 @@ private end ANSWER_SUFFIX_LABELS = { - 0 => " every week", - 1 => " every month", - 2 => " every year", + 1 => " every week", + 2 => " every month", + 3 => " every year", }.freeze RADIO_YES_VALUE = { @@ -240,11 +240,11 @@ private majorrepairs: [1], startertenancy: [0], letting_in_sheltered_accommodation: [0, 1], - armedforces: [0, 1, 2], + armedforces: [1, 4, 5], leftreg: [0], reservist: [0], - preg_occ: [0], - illness: [0], + preg_occ: [1], + illness: [1], underoccupation_benefitcap: [4, 5, 6], reasonpref: [1], net_income_known: [0], @@ -265,11 +265,11 @@ private majorrepairs: [0], startertenancy: [1], letting_in_sheltered_accommodation: [2], - armedforces: [3], + armedforces: [2], leftreg: [1], reservist: [1], - preg_occ: [1], - illness: [1], + preg_occ: [2], + illness: [2], underoccupation_benefitcap: [2], reasonpref: [2], net_income_known: [1], @@ -289,6 +289,7 @@ private hb: [5], benefits: [3], unitletas: [3], + illness: [3], }.freeze RADIO_REFUSED_VALUE = { @@ -316,11 +317,10 @@ private ecstat7: [10], ecstat8: [10], letting_in_sheltered_accommodation: [3], - armedforces: [4], + armedforces: [3], leftreg: [3], reservist: [2], - preg_occ: [2], - illness: [2], + preg_occ: [3], hb: [6], }.freeze end diff --git a/app/models/validations/date_validations.rb b/app/models/validations/date_validations.rb index 0341cc365..669718868 100644 --- a/app/models/validations/date_validations.rb +++ b/app/models/validations/date_validations.rb @@ -15,16 +15,16 @@ module Validations::DateValidations end def validate_property_void_date(record) - if record["property_void_date"].present? && record["startdate"].present? && record["startdate"].to_date - record["property_void_date"].to_date > 3650 - record.errors.add :property_void_date, I18n.t("validations.property.void_date.ten_years_before_tenancy_start") + if record["voiddate"].present? && record["startdate"].present? && record["startdate"].to_date - record["voiddate"].to_date > 3650 + record.errors.add :voiddate, I18n.t("validations.property.void_date.ten_years_before_tenancy_start") end - if record["property_void_date"].present? && record["startdate"].present? && record["startdate"].to_date < record["property_void_date"].to_date - record.errors.add :property_void_date, I18n.t("validations.property.void_date.before_tenancy_start") + if record["voiddate"].present? && record["startdate"].present? && record["startdate"].to_date < record["voiddate"].to_date + record.errors.add :voiddate, I18n.t("validations.property.void_date.before_tenancy_start") end - if record["property_void_date"].present? && record["mrcdate"].present? && record["mrcdate"].to_date < record["property_void_date"].to_date - record.errors.add :property_void_date, I18n.t("validations.property.void_date.after_mrcdate") + if record["voiddate"].present? && record["mrcdate"].present? && record["mrcdate"].to_date < record["voiddate"].to_date + record.errors.add :voiddate, I18n.t("validations.property.void_date.after_mrcdate") end end diff --git a/app/models/validations/financial_validations.rb b/app/models/validations/financial_validations.rb index a85042996..a95cf25c1 100644 --- a/app/models/validations/financial_validations.rb +++ b/app/models/validations/financial_validations.rb @@ -84,46 +84,47 @@ private CHARGE_MAXIMUMS = { scharge: { - this_landlord: { + private_registered_provider: { general_needs: 55, supported_housing: 280, }, - other_landlord: { + local_authority: { general_needs: 45, supported_housing: 165, }, }, pscharge: { - this_landlord: { + private_registered_provider: { general_needs: 30, supported_housing: 200, }, - other_landlord: { + local_authority: { general_needs: 35, supported_housing: 75, }, }, supcharg: { - this_landlord: { + private_registered_provider: { general_needs: 40, supported_housing: 465, }, - other_landlord: { + local_authority: { general_needs: 60, supported_housing: 120, }, }, }.freeze - LANDLORD_VALUES = { 1 => :this_landlord, 2 => :other_landlord }.freeze - NEEDSTYPE_VALUES = { 0 => :supported_housing, 1 => :general_needs }.freeze + PROVIDER_TYPE = { 1 => :local_authority, 2 => :private_registered_provider }.freeze + NEEDSTYPE_VALUES = { 2 => :supported_housing, 1 => :general_needs }.freeze def validate_charges(record) + provider_type = record.owning_organisation.provider_type_before_type_cast %i[scharge pscharge supcharg].each do |charge| - maximum = CHARGE_MAXIMUMS.dig(charge, LANDLORD_VALUES[record.landlord], NEEDSTYPE_VALUES[record.needstype]) + maximum = CHARGE_MAXIMUMS.dig(charge, PROVIDER_TYPE[provider_type], NEEDSTYPE_VALUES[record.needstype]) if maximum.present? && record[:period].present? && record[charge].present? && !weekly_value_in_range(record, charge, 0.0, maximum) - record.errors.add charge, I18n.t("validations.financial.rent.#{charge}.#{LANDLORD_VALUES[record.landlord]}.#{NEEDSTYPE_VALUES[record.needstype]}") + record.errors.add charge, I18n.t("validations.financial.rent.#{charge}.#{PROVIDER_TYPE[provider_type]}.#{NEEDSTYPE_VALUES[record.needstype]}") end end end diff --git a/app/models/validations/household_validations.rb b/app/models/validations/household_validations.rb index a980e94be..5d0f52037 100644 --- a/app/models/validations/household_validations.rb +++ b/app/models/validations/household_validations.rb @@ -18,7 +18,7 @@ module Validations::HouseholdValidations record.errors.add :underoccupation_benefitcap, I18n.t("validations.household.underoccupation_benefitcap.dont_know_required") record.errors.add :reason, I18n.t("validations.household.underoccupation_benefitcap.dont_know_required") end - validate_other_field(record, 31, :reason, :other_reason_for_leaving_last_settled_home) + validate_other_field(record, 31, :reason, :reasonother) if record.is_reason_permanently_decanted? && record.referral.present? && !record.is_internal_transfer? record.errors.add :referral, I18n.t("validations.household.referral.reason_permanently_decanted") @@ -56,7 +56,7 @@ module Validations::HouseholdValidations end def validate_accessibility_requirements(record) - all_options = [record.housingneeds_a, record.housingneeds_b, record.housingneeds_c, record.housingneeds_f, record.housingneeds_g, record.housingneeds_h, record.accessibility_requirements_prefer_not_to_say] + all_options = [record.housingneeds_a, record.housingneeds_b, record.housingneeds_c, record.housingneeds_f, record.housingneeds_g, record.housingneeds_h] if all_options.count(1) > 1 mobility_accessibility_options = [record.housingneeds_a, record.housingneeds_b, record.housingneeds_c] unless all_options.count(1) == 2 && record.housingneeds_f == 1 && mobility_accessibility_options.any? { |x| x == 1 } @@ -105,12 +105,12 @@ module Validations::HouseholdValidations record.errors.add :homeless, I18n.t("validations.household.homeless.other.internal_transfer") end - if record.is_internal_transfer? && record.this_landlord? && record.is_prevten_la_general_needs? + if record.is_internal_transfer? && record.owning_organisation.provider_type == "PRP" && record.is_prevten_la_general_needs? record.errors.add :referral, I18n.t("validations.household.referral.la_general_needs.internal_transfer") record.errors.add :prevten, I18n.t("validations.household.prevten.la_general_needs.internal_transfer") end - if record.other_landlord? && record.local_housing_referral? + if record.owning_organisation.provider_type == "LA" && record.local_housing_referral? record.errors.add :referral, I18n.t("validations.household.referral.prp.local_housing_referral") end end @@ -124,7 +124,7 @@ module Validations::HouseholdValidations private def household_no_illness?(record) - record.illness != 0 + record.illness != 1 end def women_of_child_bearing_age_in_household(record) diff --git a/app/models/validations/property_validations.rb b/app/models/validations/property_validations.rb index ab97a20d4..720cad20d 100644 --- a/app/models/validations/property_validations.rb +++ b/app/models/validations/property_validations.rb @@ -112,7 +112,7 @@ module Validations::PropertyValidations record.errors.add :beds, I18n.t("validations.property.unittype_gn.one_bedroom_bedsit") end - if record.other_hhmemb&.zero? && record.is_shared_housing? && + if record.hhmemb == 1 && record.is_shared_housing? && !record.beds.to_i.between?(1, 3) && record.beds.present? record.errors.add :unittype_gn, I18n.t("validations.property.unittype_gn.one_three_bedroom_single_tenant_shared") record.errors.add :beds, I18n.t("validations.property.unittype_gn.one_three_bedroom_single_tenant_shared") diff --git a/app/models/validations/setup_validations.rb b/app/models/validations/setup_validations.rb index 927a32de9..44770c947 100644 --- a/app/models/validations/setup_validations.rb +++ b/app/models/validations/setup_validations.rb @@ -1,7 +1,7 @@ module Validations::SetupValidations - def validate_intermediate_rent_product_name(record) - if intermediate_product_rent_type?(record) && record.intermediate_rent_product_name.blank? - record.errors.add :intermediate_rent_product_name, I18n.t("validations.setup.intermediate_rent_product_name.blank") + def validate_irproduct_other(record) + if intermediate_product_rent_type?(record) && record.irproduct_other.blank? + record.errors.add :irproduct_other, I18n.t("validations.setup.intermediate_rent_product_name.blank") end end diff --git a/app/models/validations/tenancy_validations.rb b/app/models/validations/tenancy_validations.rb index b6991f1c6..84af343c6 100644 --- a/app/models/validations/tenancy_validations.rb +++ b/app/models/validations/tenancy_validations.rb @@ -30,6 +30,6 @@ module Validations::TenancyValidations end def validate_other_tenancy_type(record) - validate_other_field(record, 4, :tenancy, :tenancyother) + validate_other_field(record, 3, :tenancy, :tenancyother) end end diff --git a/app/services/imports/case_logs_import_service.rb b/app/services/imports/case_logs_import_service.rb new file mode 100644 index 000000000..806f55856 --- /dev/null +++ b/app/services/imports/case_logs_import_service.rb @@ -0,0 +1,392 @@ +module Imports + class CaseLogsImportService < ImportService + def create_logs(folder) + import_from(folder, :create_log) + end + + private + + GN_SH = { + general_needs: 1, + supported_housing: 2, + }.freeze + + SR_AR_IR = { + social_rent: 1, + affordable_rent: 2, + intermediate_rent: 3, + }.freeze + + # For providertype, values are reversed!!! + PRP_LA = { + private_registered_provider: 1, + local_authority: 2, + }.freeze + + IRPRODUCT = { + rent_to_buy: 1, + london_living_rent: 2, + other_intermediate_rent_product: 3, + }.freeze + + # These must match our form + RENT_TYPE = { + social_rent: 0, + affordable_rent: 1, + london_affordable_rent: 2, + rent_to_buy: 3, + london_living_rent: 4, + other_intermediate_rent_product: 5, + }.freeze + + def create_log(xml_doc) + attributes = {} + + # Required fields for status complete or logic to work + # Note: order matters when we derive from previous values (attributes parameter) + attributes["startdate"] = compose_date(xml_doc, "DAY", "MONTH", "YEAR") + attributes["owning_organisation_id"] = find_organisation_id(xml_doc, "OWNINGORGID", "OWNINGORGNAME", "HCNUM") + attributes["managing_organisation_id"] = find_organisation_id(xml_doc, "MANINGORGID", "MANINGORGNAME", "MANHCNUM") + attributes["startertenancy"] = unsafe_string_as_integer(xml_doc, "_2a") + attributes["tenancy"] = unsafe_string_as_integer(xml_doc, "Q2b") + attributes["tenancyother"] = string_or_nil(xml_doc, "Q2ba") + attributes["tenancylength"] = safe_string_as_integer(xml_doc, "_2cYears") + attributes["needstype"] = needs_type(xml_doc) + attributes["lar"] = london_affordable_rent(xml_doc) + attributes["irproduct"] = unsafe_string_as_integer(xml_doc, "IRProduct") + attributes["irproduct_other"] = string_or_nil(xml_doc, "IRProductOther") + attributes["rent_type"] = rent_type(xml_doc, attributes["lar"], attributes["irproduct"]) + attributes["hhmemb"] = safe_string_as_integer(xml_doc, "HHMEMB") + (1..8).each do |index| + attributes["age#{index}"] = safe_string_as_integer(xml_doc, "P#{index}Age") + attributes["age#{index}_known"] = age_known(xml_doc, index, attributes["hhmemb"]) + attributes["sex#{index}"] = sex(xml_doc, index) + attributes["ecstat#{index}"] = unsafe_string_as_integer(xml_doc, "P#{index}Eco") + end + (2..8).each do |index| + attributes["relat#{index}"] = relat(xml_doc, index) + end + attributes["ethnic"] = unsafe_string_as_integer(xml_doc, "P1Eth") + attributes["ethnic_group"] = ethnic_group(attributes["ethnic"]) + attributes["national"] = unsafe_string_as_integer(xml_doc, "P1Nat") + attributes["preg_occ"] = unsafe_string_as_integer(xml_doc, "Preg") + + attributes["armedforces"] = unsafe_string_as_integer(xml_doc, "ArmedF") + attributes["leftreg"] = unsafe_string_as_integer(xml_doc, "LeftAF") + attributes["reservist"] = unsafe_string_as_integer(xml_doc, "Inj") + + attributes["hb"] = unsafe_string_as_integer(xml_doc, "Q6Ben") + attributes["benefits"] = unsafe_string_as_integer(xml_doc, "Q7Ben") + attributes["earnings"] = safe_string_as_decimal(xml_doc, "Q8Money") + attributes["net_income_known"] = net_income_known(xml_doc, attributes["earnings"]) + attributes["incfreq"] = unsafe_string_as_integer(xml_doc, "Q8a") + + attributes["reason"] = unsafe_string_as_integer(xml_doc, "Q9a") + attributes["reasonother"] = string_or_nil(xml_doc, "Q9aa") + attributes["underoccupation_benefitcap"] = unsafe_string_as_integer(xml_doc, "_9b") + %w[a b c f g h].each do |letter| + attributes["housingneeds_#{letter}"] = housing_needs(xml_doc, letter) + end + + attributes["illness"] = unsafe_string_as_integer(xml_doc, "Q10ia") + (1..10).each do |index| + attributes["illness_type_#{index}"] = illness_type(xml_doc, index) + end + + attributes["prevten"] = unsafe_string_as_integer(xml_doc, "Q11") + attributes["prevloc"] = string_or_nil(xml_doc, "Q12aONS") + attributes["previous_postcode_known"] = previous_postcode_known(xml_doc) + attributes["ppostcode_full"] = compose_postcode(xml_doc, "PPOSTC1", "PPOSTC2") + attributes["layear"] = unsafe_string_as_integer(xml_doc, "Q12c") + attributes["waityear"] = unsafe_string_as_integer(xml_doc, "Q12d") + attributes["homeless"] = unsafe_string_as_integer(xml_doc, "Q13") + + attributes["reasonpref"] = unsafe_string_as_integer(xml_doc, "Q14a") + attributes["rp_homeless"] = unsafe_string_as_integer(xml_doc, "Q14b1") + attributes["rp_insan_unsat"] = unsafe_string_as_integer(xml_doc, "Q14b2") + attributes["rp_medwel"] = unsafe_string_as_integer(xml_doc, "Q14b3") + attributes["rp_hardship"] = unsafe_string_as_integer(xml_doc, "Q14b4") + attributes["rp_dontknow"] = unsafe_string_as_integer(xml_doc, "Q14b5") + + attributes["cbl"] = unsafe_string_as_integer(xml_doc, "Q15CBL") + attributes["chr"] = unsafe_string_as_integer(xml_doc, "Q15CHR") + attributes["cap"] = unsafe_string_as_integer(xml_doc, "Q15CAP") + + attributes["referral"] = unsafe_string_as_integer(xml_doc, "Q16") + attributes["period"] = unsafe_string_as_integer(xml_doc, "Q17") + + attributes["brent"] = safe_string_as_decimal(xml_doc, "Q18ai") + attributes["scharge"] = safe_string_as_decimal(xml_doc, "Q18aii") + attributes["pscharge"] = safe_string_as_decimal(xml_doc, "Q18aiii") + attributes["supcharg"] = safe_string_as_decimal(xml_doc, "Q18aiv") + attributes["tcharge"] = safe_string_as_decimal(xml_doc, "Q18av") + + attributes["hbrentshortfall"] = unsafe_string_as_integer(xml_doc, "Q18d") + + attributes["voiddate"] = compose_date(xml_doc, "VDAY", "VMONTH", "VYEAR") + attributes["mrcdate"] = compose_date(xml_doc, "MRCDAY", "MRCMONTH", "MRCYEAR") + + attributes["offered"] = safe_string_as_integer(xml_doc, "Q20") + attributes["propcode"] = string_or_nil(xml_doc, "Q21a") + attributes["beds"] = safe_string_as_integer(xml_doc, "Q22") + attributes["unittype_gn"] = unsafe_string_as_integer(xml_doc, "Q23") + attributes["builtype"] = unsafe_string_as_integer(xml_doc, "Q24") + attributes["wchair"] = unsafe_string_as_integer(xml_doc, "Q25") + attributes["unitletas"] = unsafe_string_as_integer(xml_doc, "Q26") + attributes["rsnvac"] = unsafe_string_as_integer(xml_doc, "Q27") + attributes["renewal"] = renewal(attributes["rsnvac"]) + + attributes["la"] = string_or_nil(xml_doc, "Q28ONS") + attributes["postcode_full"] = compose_postcode(xml_doc, "POSTCODE", "POSTCOD2") + attributes["postcode_known"] = attributes["postcode_full"].nil? ? 0 : 1 + + # Not specific to our form but required for CDS and can't be inferred + attributes["old_form_id"] = Integer(field_value(xml_doc, "xmlns", "FORM")) + + # Specific to us + attributes["previous_la_known"] = 1 # Defaulting to Yes (Required) + attributes["la_known"] = 1 # Defaulting to Yes (Required) + attributes["created_at"] = Date.parse(field_value(xml_doc, "meta", "created-date")) + attributes["updated_at"] = Date.parse(field_value(xml_doc, "meta", "modified-date")) + + case_log = CaseLog.new(attributes) + case_log.save! + end + + # Safe: A string that represents only an integer (or empty/nil) + def safe_string_as_integer(xml_doc, attribute) + str = field_value(xml_doc, "xmlns", attribute) + Integer(str, exception: false) + end + + # Safe: A string that represents only a decimal (or empty/nil) + def safe_string_as_decimal(xml_doc, attribute) + str = field_value(xml_doc, "xmlns", attribute) + BigDecimal(str, exception: false) + end + + # Unsafe: A string that has more than just the integer value + def unsafe_string_as_integer(xml_doc, attribute) + str = field_value(xml_doc, "xmlns", attribute) + if str.blank? + nil + else + str.to_i + end + end + + def compose_date(xml_doc, day_str, month_str, year_str) + day = Integer(field_value(xml_doc, "xmlns", day_str), exception: false) + month = Integer(field_value(xml_doc, "xmlns", month_str), exception: false) + year = Integer(field_value(xml_doc, "xmlns", year_str), exception: false) + if day.nil? || month.nil? || year.nil? + nil + else + Date.new(year, month, day) + end + end + + def get_form_name_component(xml_doc, index) + form_name = field_value(xml_doc, "meta", "form-name") + form_type_components = form_name.split("-") + form_type_components[index] + end + + def needs_type(xml_doc) + gn_sh = get_form_name_component(xml_doc, -1) + case gn_sh + when "GN" + GN_SH[:general_needs] + when "SH" + GN_SH[:supported_housing] + else + raise "Unknown needstype value: #{gn_sh}" + end + end + + # This does not match renttype (CDS) which is derived by case log logic + def rent_type(xml_doc, lar, irproduct) + sr_ar_ir = get_form_name_component(xml_doc, -2) + + case sr_ar_ir + when "SR" + RENT_TYPE[:social_rent] + when "AR" + if lar == 1 + RENT_TYPE[:london_affordable_rent] + else + RENT_TYPE[:affordable_rent] + end + when "IR" + if irproduct == IRPRODUCT[:rent_to_buy] + RENT_TYPE[:rent_to_buy] + elsif irproduct == IRPRODUCT[:london_living_rent] + RENT_TYPE[:london_living_rent] + elsif irproduct == IRPRODUCT[:other_intermediate_rent_product] + RENT_TYPE[:other_intermediate_rent_product] + end + else + raise "Could not infer rent type with '#{sr_ar_ir}'" + end + end + + def find_organisation_id(xml_doc, id_field, name_field, reg_field) + old_visible_id = unsafe_string_as_integer(xml_doc, id_field) + organisation = Organisation.find_by(old_visible_id:) + # Quick hack: should be removed when all organisations are imported + # Will fail in the future if the organisation is missing + if organisation.nil? + organisation = Organisation.new + organisation.old_visible_id = old_visible_id + let_type = unsafe_string_as_integer(xml_doc, "landlord") + organisation.provider_type = if let_type == PRP_LA[:local_authority] + 1 + else + 2 + end + organisation.name = string_or_nil(xml_doc, name_field) + organisation.housing_registration_no = string_or_nil(xml_doc, reg_field) + organisation.save! + end + organisation.id + end + + def sex(xml_doc, index) + sex = field_value(xml_doc, "xmlns", "P#{index}Sex") + case sex + when "Male" + "M" + when "Female" + "F" + when "Other", "Non-binary" + "X" + when "Refused" + "R" + end + end + + def relat(xml_doc, index) + relat = field_value(xml_doc, "xmlns", "P#{index}Rel") + case relat + when "Child" + "C" + when "Partner" + "P" + when "Other", "Non-binary" + "X" + when "Refused" + "R" + end + end + + def age_known(xml_doc, index, hhmemb) + return nil if index > hhmemb + + age_refused = field_value(xml_doc, "xmlns", "P#{index}AR") + if age_refused == "AGE_REFUSED" + 1 # No + else + 0 # Yes + end + end + + def previous_postcode_known(xml_doc) + previous_postcode_known = field_value(xml_doc, "xmlns", "Q12bnot") + if previous_postcode_known == "Temporary or Unknown" + 0 + else + 1 + end + end + + def compose_postcode(xml_doc, outcode, incode) + outcode_value = field_value(xml_doc, "xmlns", outcode) + incode_value = field_value(xml_doc, "xmlns", incode) + if outcode_value.blank? || incode_value.blank? + nil + else + "#{outcode_value} #{incode_value}" + end + end + + def london_affordable_rent(xml_doc) + lar = unsafe_string_as_integer(xml_doc, "LAR") + if lar == 1 + 1 + else + # We default to No for any other values (nil, not known) + 2 + end + end + + def renewal(rsnvac) + # Relet – renewal of fixed-term tenancy + if rsnvac == 14 + 1 + else + 0 + end + end + + def string_or_nil(xml_doc, attribute) + str = field_value(xml_doc, "xmlns", attribute) + str.presence + end + + def ethnic_group(ethnic) + case ethnic + when 1, 2, 3, 18 + # White + 0 + when 4, 5, 6, 7 + # Mixed + 1 + when 8, 9, 10, 11, 15 + # Asian + 2 + when 12, 13, 14 + # Black + 3 + when 16, 19 + # Others + 4 + when 17 + # Refused + 5 + end + end + + # Letters should be lowercase to match case + def housing_needs(xml_doc, letter) + housing_need = field_value(xml_doc, "xmlns", "Q10-#{letter}") + if housing_need == "Yes" + 1 + else + 0 + end + end + + def net_income_known(xml_doc, earnings) + incref = field_value(xml_doc, "xmlns", "Q8Refused") + if incref == "Refused" + # Tenant prefers not to say + 2 + elsif earnings.nil? + # No + 1 + else + # Yes + 0 + end + end + + def illness_type(xml_doc, index) + illness_type = string_or_nil(xml_doc, "Q10ib-#{index}") + if illness_type == "Yes" + 1 + else + 0 + end + end + end +end diff --git a/config/forms/2021_2022.json b/config/forms/2021_2022.json index 9695c29f4..2ede442db 100644 --- a/config/forms/2021_2022.json +++ b/config/forms/2021_2022.json @@ -22,7 +22,7 @@ "1": { "value": "General needs" }, - "0": { + "2": { "value": "Supported housing" } } @@ -587,13 +587,13 @@ "type": "radio", "answer_options": { "1": { - "value": "Affordable rent basis" + "value": "Social rent basis" }, "2": { - "value": "Intermediate rent basis" + "value": "Affordable rent basis" }, - "0": { - "value": "Social rent basis" + "4": { + "value": "Intermediate rent basis" }, "divider": { "value": true @@ -621,39 +621,39 @@ "hint_text": "", "type": "radio", "answer_options": { - "1": { + "13": { "value": "Internal transfer", "hint": "Excluding renewals of a fixed-term tenancy" }, - "10": { + "5": { "value": "Previous tenant died with no succession" }, - "2": { + "9": { "value": "Re-let to tenant who occupied same property as temporary accommodation" }, - "0": { + "14": { "value": "Renewal of fixed-term tenancy" }, - "7": { - "value": "Tenant abandoned property" - }, - "3": { + "19": { "value": "Tenant involved in a succession downsize" }, - "6": { - "value": "Tenant moved to care home" + "8": { + "value": "Tenant moved to private sector or other accommodation" }, - "5": { + "12": { "value": "Tenant moved to other social housing provider" }, - "4": { - "value": "Tenant moved to private sector or other accommodation" + "18": { + "value": "Tenant moved to care home" }, - "9": { - "value": "Tenant was evicted due to anti-social behaviour" + "6": { + "value": "Tenant abandoned property" }, - "8": { + "10": { "value": "Tenant was evicted due to rent arrears" + }, + "11": { + "value": "Tenant was evicted due to anti-social behaviour" } } } @@ -675,14 +675,14 @@ "hint_text": "", "type": "radio", "answer_options": { - "15": { - "value": "First let of new-build property" - }, "16": { "value": "First let of conversion, rehabilitation or acquired property" }, "17": { "value": "First let of leased property" + }, + "15": { + "value": "First let of new-build property" } } } @@ -748,28 +748,28 @@ "hint_text": "", "type": "radio", "answer_options": { - "1": { + "2": { "value": "Bedsit" }, - "3": { + "8": { "value": "Bungalow" }, - "0": { + "1": { "value": "Flat or maisonette" }, - "2": { + "7": { "value": "House" }, - "6": { + "10": { "value": "Shared bungalow" }, "4": { "value": "Shared flat or maisonette" }, - "5": { + "9": { "value": "Shared house" }, - "7": { + "6": { "value": "Other" } } @@ -786,10 +786,10 @@ "hint_text": "", "type": "radio", "answer_options": { - "1": { + "2": { "value": "Converted from previous residential or non-residential property" }, - "0": { + "1": { "value": "Purpose built" } } @@ -806,10 +806,10 @@ "hint_text": "", "type": "radio", "answer_options": { - "0": { + "1": { "value": "Yes" }, - "1": { + "2": { "value": "No" } } @@ -841,7 +841,7 @@ "header": "", "description": "", "questions": { - "property_void_date": { + "voiddate": { "check_answer_label": "Void or renewal date", "header": "What is the void or renewal date?", "hint_text": "For example, 27 3 2021.", @@ -863,7 +863,7 @@ "header": "", "description": "", "questions": { - "property_void_date": { + "voiddate": { "check_answer_label": "New-build handover date", "header": "What is the new-build handover date?", "hint_text": "", @@ -938,10 +938,10 @@ "hint_text": "", "type": "radio", "answer_options": { - "0": { + "1": { "value": "Yes" }, - "1": { + "2": { "value": "No" } } @@ -958,25 +958,25 @@ "hint_text": "", "type": "radio", "answer_options": { - "0": { + "2": { "value": "Assured" }, - "1": { + "4": { "value": "Assured Shorthold" }, - "2": { + "5": { "value": "Licence agreement (almshouses only)" }, - "3": { + "1": { "value": "Secure (including flexible)" }, - "4": { + "3": { "value": "Other" } }, "conditional_for": { "tenancyother": [ - 4 + 3 ] } }, @@ -1002,25 +1002,25 @@ "hint_text": "This is also known as an ‘introductory period’.", "type": "radio", "answer_options": { - "0": { + "2": { "value": "Assured" }, - "1": { + "4": { "value": "Assured Shorthold" }, - "2": { + "5": { "value": "Licence agreement (almshouses only)" }, - "3": { + "1": { "value": "Secure (including flexible)" }, - "4": { + "3": { "value": "Other" } }, "conditional_for": { "tenancyother": [ - 4 + 3 ] } }, @@ -1053,10 +1053,10 @@ }, "depends_on": [ { - "tenancy": 3 + "tenancy": 1 }, { - "tenancy": 1 + "tenancy": 4 } ] }, @@ -1064,25 +1064,25 @@ "header": "", "description": "", "questions": { - "letting_in_sheltered_accommodation": { + "shelteredaccom": { "check_answer_label": "Is this letting in sheltered accommodation?", "header": "Is this letting in sheltered accommodation?", "hint_text": "", "type": "radio", "answer_options": { - "0": { + "1": { "value": "Yes – sheltered housing" }, - "1": { + "2": { "value": "Yes – extra care housing" }, - "2": { + "3": { "value": "No" }, "divider": { "value": true }, - "3": { + "4": { "value": "Don’t know" } } @@ -1090,7 +1090,7 @@ }, "depends_on": [ { - "needstype": 0 + "needstype": 2 } ] } @@ -1228,7 +1228,7 @@ "divider": { "value": true }, - "5": { + "17": { "value": "Tenant prefers not to say" } } @@ -1245,16 +1245,16 @@ "hint_text": "The lead tenant is the person in the household who does the most paid work. If several people do the same paid work, the lead tenant is whoever is the oldest.", "type": "radio", "answer_options": { - "0": { + "19": { "value": "Arab" }, - "1": { + "16": { "value": "Other ethnic group" } }, "conditional_for": { "ethnic_other": [ - 1 + 16 ] } }, @@ -1280,25 +1280,25 @@ "hint_text": "The lead tenant is the person in the household who does the most paid work. If several people do the same paid work, the lead tenant is whoever is the oldest.", "type": "radio", "answer_options": { - "0": { + "10": { "value": "Bangladeshi" }, - "1": { + "15": { "value": "Chinese" }, - "2": { + "8": { "value": "Indian" }, - "3": { + "9": { "value": "Pakistani" }, - "4": { + "11": { "value": "Other ethnic group" } }, "conditional_for": { "ethnic_other": [ - 4 + 11 ] } }, @@ -1324,13 +1324,13 @@ "hint_text": "The lead tenant is the person in the household who does the most paid work. If several people do the same paid work, the lead tenant is whoever is the oldest.", "type": "radio", "answer_options": { - "0": { + "13": { "value": "African" }, - "1": { + "12": { "value": "Caribbean" }, - "2": { + "14": { "value": "Any other Black, African or Caribbean background" } }, @@ -1362,19 +1362,22 @@ "hint_text": "The lead tenant is the person in the household who does the most paid work. If several people do the same paid work, the lead tenant is whoever is the oldest.", "type": "radio", "answer_options": { - "0": { + "4": { "value": "White and Black Caribbean" }, - "1": { + "5": { "value": "White and Black African" }, - "2": { + "6": { + "value": "White and Asian" + }, + "7": { "value": "Any other Mixed or Multiple ethnic background" } }, "conditional_for": { "ethnic_other": [ - 2 + 7 ] } }, @@ -1400,17 +1403,14 @@ "hint_text": "The lead tenant is the person in the household who does the most paid work. If several people do the same paid work, the lead tenant is whoever is the oldest.", "type": "radio", "answer_options": { - "0": { + "1": { "value": "English, Welsh, Northern Irish, Scottish or British" }, - "1": { + "2": { "value": "Irish" }, - "2": { + "18": { "value": "Gypsy or Irish Traveller" - }, - "3": { - "value": "Any other White background" } }, "conditional_for": { @@ -1564,25 +1564,25 @@ }, "depends_on": [ { - "other_hhmemb": 1 + "hhmemb": 2 }, { - "other_hhmemb": 2 + "hhmemb": 3 }, { - "other_hhmemb": 3 + "hhmemb": 4 }, { - "other_hhmemb": 4 + "hhmemb": 5 }, { - "other_hhmemb": 5 + "hhmemb": 6 }, { - "other_hhmemb": 6 + "hhmemb": 7 }, { - "other_hhmemb": 7 + "hhmemb": 8 } ] }, @@ -1777,22 +1777,22 @@ }, "depends_on": [ { - "other_hhmemb": 2 + "hhmemb": 3 }, { - "other_hhmemb": 3 + "hhmemb": 4 }, { - "other_hhmemb": 4 + "hhmemb": 5 }, { - "other_hhmemb": 5 + "hhmemb": 6 }, { - "other_hhmemb": 6 + "hhmemb": 7 }, { - "other_hhmemb": 7 + "hhmemb": 8 } ] }, @@ -1987,19 +1987,19 @@ }, "depends_on": [ { - "other_hhmemb": 3 + "hhmemb": 4 }, { - "other_hhmemb": 4 + "hhmemb": 5 }, { - "other_hhmemb": 5 + "hhmemb": 6 }, { - "other_hhmemb": 6 + "hhmemb": 7 }, { - "other_hhmemb": 7 + "hhmemb": 8 } ] }, @@ -2194,16 +2194,16 @@ }, "depends_on": [ { - "other_hhmemb": 4 + "hhmemb": 5 }, { - "other_hhmemb": 5 + "hhmemb": 6 }, { - "other_hhmemb": 6 + "hhmemb": 7 }, { - "other_hhmemb": 7 + "hhmemb": 8 } ] }, @@ -2398,13 +2398,13 @@ }, "depends_on": [ { - "other_hhmemb": 5 + "hhmemb": 6 }, { - "other_hhmemb": 6 + "hhmemb": 7 }, { - "other_hhmemb": 7 + "hhmemb": 8 } ] }, @@ -2599,10 +2599,10 @@ }, "depends_on": [ { - "other_hhmemb": 6 + "hhmemb": 7 }, { - "other_hhmemb": 7 + "hhmemb": 8 } ] }, @@ -2797,7 +2797,7 @@ }, "depends_on": [ { - "other_hhmemb": 7 + "hhmemb": 8 } ] }, @@ -2992,22 +2992,22 @@ "type": "radio", "check_answer_label": "Household links to UK armed forces", "answer_options": { - "0": { + "1": { "value": "Yes – the person is a current or former regular" }, - "1": { + "4": { "value": "Yes – the person is a current or former reserve" }, - "2": { + "5": { "value": "Yes – the person is a spouse or civil partner of a UK armed forces member and has been bereaved or separated from them within the last 2 years" }, - "3": { + "2": { "value": "No" }, "divider": { "value": true }, - "4": { + "3": { "value": "Person prefers not to say" } } @@ -3019,7 +3019,7 @@ "description": "", "depends_on": [ { - "armedforces": 0 + "armedforces": 1 } ], "questions": { @@ -3053,10 +3053,10 @@ "description": "", "depends_on": [ { - "armedforces": 0 + "armedforces": 1 }, { - "armedforces": 1 + "armedforces": 4 } ], "questions": { @@ -3092,16 +3092,16 @@ "type": "radio", "check_answer_label": "Anybody in household pregnant", "answer_options": { - "0": { + "1": { "value": "Yes" }, - "1": { + "2": { "value": "No" }, "divider": { "value": true }, - "2": { + "3": { "value": "Tenant prefers not to say" } } @@ -3153,16 +3153,16 @@ "type": "radio", "check_answer_label": "Anybody in household with physical or mental health condition", "answer_options": { - "0": { + "1": { "value": "Yes" }, - "1": { + "2": { "value": "No" }, "divider": { "value": true }, - "2": { + "3": { "value": "Tenant prefers not to say" } } @@ -3174,7 +3174,7 @@ "description": "", "depends_on": [ { - "illness": 0 + "illness": 1 } ], "questions": { @@ -3284,37 +3284,37 @@ "header": "", "description": "", "questions": { - "lawaitlist": { + "waityear": { "check_answer_label": "Length of time on local authority waiting list", "header": "How long has the household been on the local authority waiting list for the new letting?", "hint_text": "", "type": "radio", "answer_options": { - "0": { + "1": { "value": "Just moved to local authority area" }, - "1": { + "2": { "value": "Less than 1 year" }, - "2": { + "7": { "value": "1 year but under 2 years" }, - "3": { + "8": { "value": "2 years but under 3 years" }, - "4": { + "9": { "value": "3 years but under 4 years" }, - "5": { + "10": { "value": "4 years but under 5 years" }, - "6": { + "5": { "value": "5 years or more" }, "divider": { "value": true }, - "7": { + "6": { "value": "Don’t know" } } @@ -3437,18 +3437,15 @@ }, "28": { "value": "Don’t know" - }, - "10000": { - "value": "Tenant prefers not to say" } }, "conditional_for": { - "other_reason_for_leaving_last_settled_home": [ - 31 + "reasonother": [ + 20 ] } }, - "other_reason_for_leaving_last_settled_home": { + "reasonother": { "header": "What is the reason?", "hint_text": "", "type": "text" @@ -3595,7 +3592,7 @@ "depends_on": [ { "renewal": 1, - "needstype": 0 + "needstype": 2 } ] }, @@ -4391,7 +4388,7 @@ "depends_on": [ { "managing_organisation.provider_type": "LA", - "needstype": 0, + "needstype": 2, "renewal": 0 } ] @@ -4451,7 +4448,7 @@ "depends_on": [ { "managing_organisation.provider_type": "PRP", - "needstype": 0, + "needstype": 2, "renewal": 0 } ] @@ -4520,19 +4517,19 @@ { "label": "every week", "depends_on": { - "incfreq": 0 + "incfreq": 1 } }, { "label": "every month", "depends_on": { - "incfreq": 1 + "incfreq": 2 } }, { - "label": "every month", + "label": "every year", "depends_on": { - "incfreq": 2 + "incfreq": 3 } } ] @@ -4543,13 +4540,13 @@ "hint_text": "", "type": "radio", "answer_options": { - "0": { + "1": { "value": "Weekly" }, - "1": { + "2": { "value": "Monthly" }, - "2": { + "3": { "value": "Yearly" } }, @@ -4611,9 +4608,6 @@ }, "3": { "value": "Don’t know" - }, - "6": { - "value": "Tenant prefers not to say" } } } @@ -4629,19 +4623,19 @@ "hint_text": "This excludes child and housing benefit, council tax support and tax credits.", "type": "radio", "answer_options": { - "0": { + "1": { "value": "All" }, - "1": { + "2": { "value": "Some" }, - "2": { + "3": { "value": "None" }, "divider": { "value": true }, - "3": { + "4": { "value": "Don’t know" } } @@ -4669,7 +4663,7 @@ }, "depends_on": [ { - "needstype": 0 + "needstype": 2 } ] }, @@ -4759,62 +4753,62 @@ "depends_on": [ { "period": 1, - "needstype": 0, + "needstype": 2, "household_charge": 0 }, { "period": 1, - "needstype": 0, + "needstype": 2, "household_charge": null }, { "period": 5, - "needstype": 0, + "needstype": 2, "household_charge": 0 }, { "period": 5, - "needstype": 0, + "needstype": 2, "household_charge": null }, { "period": 6, - "needstype": 0, + "needstype": 2, "household_charge": 0 }, { "period": 6, - "needstype": 0, + "needstype": 2, "household_charge": null }, { "period": 7, - "needstype": 0, + "needstype": 2, "household_charge": 0 }, { "period": 7, - "needstype": 0, + "needstype": 2, "household_charge": null }, { "period": 8, - "needstype": 0, + "needstype": 2, "household_charge": 0 }, { "period": 8, - "needstype": 0, + "needstype": 2, "household_charge": null }, { "period": 9, - "needstype": 0, + "needstype": 2, "household_charge": 0 }, { "period": 9, - "needstype": 0, + "needstype": 2, "household_charge": null } ] @@ -4856,12 +4850,12 @@ "depends_on": [ { "period": 2, - "needstype": 0, + "needstype": 2, "household_charge": 0 }, { "period": 2, - "needstype": 0, + "needstype": 2, "household_charge": null } ] @@ -4903,12 +4897,12 @@ "depends_on": [ { "period": 3, - "needstype": 0, + "needstype": 2, "household_charge": 0 }, { "period": 3, - "needstype": 0, + "needstype": 2, "household_charge": null } ] @@ -4950,12 +4944,12 @@ "depends_on": [ { "period": 4, - "needstype": 0, + "needstype": 2, "household_charge": 0 }, { "period": 4, - "needstype": 0, + "needstype": 2, "household_charge": null } ] diff --git a/config/locales/en.yml b/config/locales/en.yml index 3e024df62..ebd5762bc 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -101,26 +101,26 @@ en: rent: less_than_double_shortfall: "Answer must be more than double the shortfall in basic rent" scharge: - this_landlord: - general_needs: "Service charge must be between £0 and £55 per week if the landlord is the same and it is a general needs letting" - supported_housing: "Service charge must be between £0 and £280 per week if the landlord is the same and it is a supported housing letting" - other_landlord: - general_needs: "Service charge must be between £0 and £45 per week if the landlord is another registered provider and it is a general needs letting" - supported_housing: "Service charge must be between £0 and £165 per week if the landlord is another registered provider and it is a supported housing letting" + private_registered_provider: + general_needs: "Service charge must be between £0 and £55 per week if the landlord is a private registered provider and it is a general needs letting" + supported_housing: "Service charge must be between £0 and £280 per week if the landlord is a private registered provider and it is a supported housing letting" + local_authority: + general_needs: "Service charge must be between £0 and £45 per week if the landlord is a local authority and it is a general needs letting" + supported_housing: "Service charge must be between £0 and £165 per week if the landlord is a local authority and it is a supported housing letting" pscharge: - this_landlord: - general_needs: "Personal service charge must be between £0 and £30 per week if the landlord is the same and it is a general needs letting" - supported_housing: "Personal service charge must be between £0 and £200 per week if the landlord is the same and it is a supported housing letting" - other_landlord: - general_needs: "Personal service charge must be between £0 and £35 per week if the landlord is another registered provider and it is a general needs letting" - supported_housing: "Personal service charge must be between £0 and £75 per week if the landlord is another registered provider and it is a supported housing letting" + private_registered_provider: + general_needs: "Personal service charge must be between £0 and £30 per week if the landlord is a private registered provider and it is a general needs letting" + supported_housing: "Personal service charge must be between £0 and £200 per week if the landlord is a private registered provider and it is a supported housing letting" + local_authority: + general_needs: "Personal service charge must be between £0 and £35 per week if the landlord is a local authority and it is a general needs letting" + supported_housing: "Personal service charge must be between £0 and £75 per week if the landlord is a local authority and it is a supported housing letting" supcharg: - this_landlord: - general_needs: "Support charge must be between £0 and £40 per week if the landlord is the same and it is a general needs letting" - supported_housing: "Support charge must be between £0 and £465 per week if the landlord is the same and it is a supported housing letting" - other_landlord: - general_needs: "Support charge must be between £0 and £60 per week if the landlord is another registered provider and it is a general needs letting" - supported_housing: "Support charge must be between £0 and £120 per week if the landlord is another registered provider and it is a supported housing letting" + private_registered_provider: + general_needs: "Support charge must be between £0 and £40 per week if the landlord is a private registered provider and it is a general needs letting" + supported_housing: "Support charge must be between £0 and £465 per week if the landlord is a private registered provider and it is a supported housing letting" + local_authority: + general_needs: "Support charge must be between £0 and £60 per week if the landlord is a local authority and it is a general needs letting" + supported_housing: "Support charge must be between £0 and £120 per week if the landlord is a local authority and it is a supported housing letting" brent: not_in_range: "Basic rent is outside of the expected range based on the lettings type, local authority and number of bedrooms" la: @@ -183,7 +183,7 @@ en: male_refuge: "Answer cannot be refuge as the lead tenant identifies as male" internal_transfer: "Answer cannot be %{prevten} as you already told us this tenancy is an internal transfer" la_general_needs: - internal_transfer: "Answer cannot be a fixed-term or lifetime local authority general needs tenancy as you already told us it's the same landlord on the tenancy agreement and it is an internal transfer" + internal_transfer: "Answer cannot be a fixed-term or lifetime local authority general needs tenancy as you already told us it's a private registered provider on the tenancy agreement and it is an internal transfer" referral: secure_tenancy: "Answer must be internal transfer as you already told us this is a secure tenancy" rsnvac_non_temp: "Answer cannot be this source of referral as you already told us this is a re-let to tenant who occupied the same property as temporary accommodation" @@ -195,7 +195,7 @@ en: la_general_needs: internal_transfer: "Answer cannot be internal transfer as you already told us it's the same landlord on the tenancy agreement and the household had either a fixed-term or lifetime local authority general needs tenancy immediately before this letting" prp: - local_housing_referral: "Answer cannot be 'nominated by a local housing authority' as you already told us it's another landlord on the tenancy agreement" + local_housing_referral: "Answer cannot be 'nominated by a local housing authority' as you already told us it is a local authority on the tenancy agreement" homeless: assessed: internal_transfer: "Answer cannot be assessed as homeless as you already told us this tenancy is an internal transfer" diff --git a/db/migrate/202202071123100_additional_user_fields2.rb b/db/migrate/20220207112310_additional_user_fields2.rb similarity index 100% rename from db/migrate/202202071123100_additional_user_fields2.rb rename to db/migrate/20220207112310_additional_user_fields2.rb diff --git a/db/migrate/20220411092231_update_case_logs_fields.rb b/db/migrate/20220411092231_update_case_logs_fields.rb new file mode 100644 index 000000000..09b83e633 --- /dev/null +++ b/db/migrate/20220411092231_update_case_logs_fields.rb @@ -0,0 +1,13 @@ +class UpdateCaseLogsFields < ActiveRecord::Migration[7.0] + def change + change_table :case_logs, bulk: true do |t| + t.integer :old_form_id, :lar, :irproduct + t.remove :day, :month, :year, :vday, :vmonth, :vyear, :mrcday, :mrcmonth, :mrcyear, :other_hhmemb, :accessibility_requirements_prefer_not_to_say, :landlord, type: :integer + t.remove :ppostc1, :ppostc2, :postcode, :postcod2, type: :string + t.rename :intermediate_rent_product_name, :irproduct_other + t.rename :lawaitlist, :waityear + t.rename :other_reason_for_leaving_last_settled_home, :reasonother + t.rename :property_void_date, :voiddate + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 61368691c..8a8103a23 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: 202202071123100) do +ActiveRecord::Schema[7.0].define(version: 2022_04_11_092231) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -86,7 +86,6 @@ ActiveRecord::Schema[7.0].define(version: 202202071123100) do t.integer "startertenancy" t.integer "tenancylength" t.integer "tenancy" - t.integer "landlord" t.string "ppostcode_full" t.integer "rsnvac" t.integer "unittype_gn" @@ -98,20 +97,19 @@ ActiveRecord::Schema[7.0].define(version: 202202071123100) do t.integer "benefits" t.integer "period" t.integer "layear" - t.integer "lawaitlist" + t.integer "waityear" t.string "postcode_full" t.integer "reasonpref" t.integer "cbl" t.integer "chr" t.integer "cap" - t.string "other_reason_for_leaving_last_settled_home" + t.string "reasonother" t.integer "housingneeds_a" t.integer "housingneeds_b" t.integer "housingneeds_c" t.integer "housingneeds_f" t.integer "housingneeds_g" t.integer "housingneeds_h" - t.integer "accessibility_requirements_prefer_not_to_say" t.integer "illness_type_1" t.integer "illness_type_2" t.integer "illness_type_3" @@ -132,7 +130,7 @@ ActiveRecord::Schema[7.0].define(version: 202202071123100) do t.string "property_owner_organisation" t.string "property_manager_organisation" t.string "sale_or_letting" - t.string "intermediate_rent_product_name" + t.string "irproduct_other" t.string "purchaser_code" t.integer "reason" t.string "propcode" @@ -141,16 +139,8 @@ ActiveRecord::Schema[7.0].define(version: 202202071123100) do t.string "prevloc" t.integer "hb" t.integer "hbrentshortfall" - t.string "postcode" - t.string "postcod2" - t.string "ppostc1" - t.string "ppostc2" t.integer "property_relet" t.datetime "mrcdate", precision: nil - t.integer "mrcday" - t.integer "mrcmonth" - t.integer "mrcyear" - t.integer "other_hhmemb" t.integer "incref" t.datetime "sale_completion_date", precision: nil t.datetime "startdate", precision: nil @@ -158,7 +148,7 @@ ActiveRecord::Schema[7.0].define(version: 202202071123100) do t.integer "first_time_property_let_as_social_housing" t.integer "unitletas" t.integer "builtype" - t.datetime "property_void_date", precision: nil + t.datetime "voiddate", precision: nil t.bigint "owning_organisation_id" t.bigint "managing_organisation_id" t.integer "renttype" @@ -167,9 +157,6 @@ ActiveRecord::Schema[7.0].define(version: 202202071123100) do t.integer "postcode_known" t.integer "la_known" t.boolean "is_la_inferred" - t.integer "day" - t.integer "month" - t.integer "year" t.integer "totchild" t.integer "totelder" t.integer "totadult" @@ -219,9 +206,6 @@ ActiveRecord::Schema[7.0].define(version: 202202071123100) do t.decimal "wtshortfall", precision: 10, scale: 2 t.integer "refused" t.integer "housingneeds" - t.integer "vday" - t.integer "vmonth" - t.integer "vyear" t.decimal "wchchrg", precision: 10, scale: 2 t.integer "newprop" t.string "relat2" @@ -232,6 +216,9 @@ ActiveRecord::Schema[7.0].define(version: 202202071123100) do t.string "relat7" t.string "relat8" t.integer "rent_value_check" + t.integer "old_form_id" + t.integer "lar" + t.integer "irproduct" t.index ["managing_organisation_id"], name: "index_case_logs_on_managing_organisation_id" t.index ["owning_organisation_id"], name: "index_case_logs_on_owning_organisation_id" end diff --git a/docs/api/DLUHC-CORE-Data.v1.json b/docs/api/DLUHC-CORE-Data.v1.json index 742c2a571..dc709691b 100644 --- a/docs/api/DLUHC-CORE-Data.v1.json +++ b/docs/api/DLUHC-CORE-Data.v1.json @@ -361,7 +361,7 @@ "cap": 0, "hbrentshortfall": 0, "tshortfall": 12, - "other_reason_for_leaving_last_settled_home": null, + "reasonother": null, "housingneeds_a": 1, "housingneeds_b": 0, "housingneeds_c": 0, @@ -940,4 +940,4 @@ } } } -} \ No newline at end of file +} diff --git a/spec/factories/case_log.rb b/spec/factories/case_log.rb index 2bec19c48..ce2dfaf90 100644 --- a/spec/factories/case_log.rb +++ b/spec/factories/case_log.rb @@ -7,7 +7,6 @@ FactoryBot.define do needstype { 1 } rent_type { 1 } startdate { Time.zone.local(2022, 5, 1) } - year { 2022 } end trait :in_progress do status { 1 } @@ -21,7 +20,7 @@ FactoryBot.define do status { 1 } ecstat1 { 1 } earnings { 750 } - incfreq { 0 } + incfreq { 1 } end trait :conditional_section_complete do tenant_code { "TH356" } @@ -30,19 +29,17 @@ FactoryBot.define do ethnic { 2 } national { 4 } ecstat1 { 2 } - other_hhmemb { 0 } + hhmemb { 1 } end trait :completed do status { 2 } tenant_code { "BZ737" } - postcode { "NW1 7TY" } age1 { 35 } sex1 { "F" } ethnic { 2 } national { 4 } prevten { 6 } ecstat1 { 0 } - other_hhmemb { 1 } hhmemb { 2 } relat2 { "P" } age2 { 32 } @@ -52,25 +49,21 @@ FactoryBot.define do underoccupation_benefitcap { 0 } leftreg { 1 } reservist { 0 } - illness { 0 } - preg_occ { 1 } + illness { 1 } + preg_occ { 2 } tenancy_code { "BZ757" } startertenancy { 0 } tenancylength { 5 } - tenancy { 3 } - landlord { 1 } + tenancy { 1 } ppostcode_full { "SE2 6RT" } - rsnvac { 7 } - unittype_gn { 2 } + rsnvac { 6 } + unittype_gn { 7 } beds { 3 } - property_void_date { "03/11/2019" } - vday { 3 } - vmonth { 11 } - vyear { 2019 } + voiddate { "03/11/2019" } offered { 2 } wchair { 1 } earnings { 68 } - incfreq { 0 } + incfreq { 1 } benefits { 1 } period { 2 } brent { 200 } @@ -79,20 +72,19 @@ FactoryBot.define do supcharg { 35 } tcharge { 325 } layear { 2 } - lawaitlist { 1 } + waityear { 1 } postcode_full { "NW1 5TY" } reasonpref { 1 } cbl { 1 } chr { 1 } cap { 0 } - other_reason_for_leaving_last_settled_home { nil } + reasonother { nil } housingneeds_a { 1 } housingneeds_b { 0 } housingneeds_c { 0 } housingneeds_f { 0 } housingneeds_g { 0 } housingneeds_h { 0 } - accessibility_requirements_prefer_not_to_say { 0 } illness_type_1 { 0 } illness_type_2 { 1 } illness_type_3 { 0 } @@ -115,7 +107,6 @@ FactoryBot.define do property_manager_organisation { "Test" } renewal { 0 } rent_type { 1 } - intermediate_rent_product_name { 2 } needstype { 1 } purchaser_code { 798_794 } reason { 4 } @@ -126,21 +117,12 @@ FactoryBot.define do hb { 6 } hbrentshortfall { 0 } tshortfall { 12 } - postcod2 { "w3" } - ppostc1 { "w3" } - ppostc2 { "w3" } property_relet { 0 } mrcdate { Time.utc(2020, 5, 0o5, 10, 36, 49) } - mrcday { mrcdate.day } - mrcmonth { mrcdate.month } - mrcyear { mrcdate.year } incref { 0 } sale_completion_date { nil } startdate { Time.utc(2022, 2, 2, 10, 36, 49) } - day { startdate.day } - month { startdate.month } - year { startdate.year } - armedforces { 0 } + armedforces { 1 } builtype { 1 } unitletas { 2 } has_benefits { 1 } diff --git a/spec/features/form/check_answers_page_spec.rb b/spec/features/form/check_answers_page_spec.rb index 34125ee41..523e43038 100644 --- a/spec/features/form/check_answers_page_spec.rb +++ b/spec/features/form/check_answers_page_spec.rb @@ -53,7 +53,7 @@ RSpec.describe "Form Check Answers Page" do it "has question headings based on the subsection" do visit("/logs/#{id}/#{subsection}/check-answers") - question_labels = ["Tenant code", "Lead tenant’s age", "Lead tenant’s gender identity", "Number of Other Household Members"] + question_labels = ["Tenant code", "Lead tenant’s age", "Lead tenant’s gender identity", "Number of Household Members"] question_labels.each do |label| expect(page).to have_content(label) end @@ -113,7 +113,7 @@ RSpec.describe "Form Check Answers Page" do it "displays conditional question that were visited" do visit("/logs/#{id}/conditional-question") - choose("case-log-preg-occ-1-field", allow_label_click: true) + choose("case-log-preg-occ-2-field", allow_label_click: true) click_button("Save and continue") visit("/logs/#{id}/#{conditional_subsection}/check-answers") question_labels = ["Has the condition been met?", "Has the condition not been met?"] @@ -151,7 +151,7 @@ RSpec.describe "Form Check Answers Page" do tenant_code: "123", age1: 35, sex1: "M", - other_hhmemb: 0, + hhmemb: 1, ) end @@ -164,9 +164,9 @@ RSpec.describe "Form Check Answers Page" do tenant_code: "123", age1: 35, sex1: "M", - other_hhmemb: 0, + hhmemb: 1, armedforces: 3, - illness: 0, + illness: 1, ) end @@ -179,9 +179,9 @@ RSpec.describe "Form Check Answers Page" do tenant_code: "123", age1: 35, sex1: "M", - other_hhmemb: 0, + hhmemb: 1, armedforces: 3, - illness: 0, + illness: 1, housingneeds_h: 1, la: "E06000014", illness_type_1: 1, @@ -197,7 +197,7 @@ RSpec.describe "Form Check Answers Page" do tenant_code: nil, age1: nil, layear: 2, - lawaitlist: 1, + waityear: 1, postcode_full: "NW1 5TY", reason: 4, ppostcode_full: "SE2 6RT", diff --git a/spec/features/form/conditional_questions_spec.rb b/spec/features/form/conditional_questions_spec.rb index db558c93a..9b5c01a20 100644 --- a/spec/features/form/conditional_questions_spec.rb +++ b/spec/features/form/conditional_questions_spec.rb @@ -27,11 +27,11 @@ RSpec.describe "Form Conditional Questions" do it "shows conditional questions if the required answer is selected and hides it again when a different answer option is selected", js: true do visit("/logs/#{id}/armed-forces") # Something about our styling makes the selenium webdriver think the actual radio buttons are not visible so we allow label click here - choose("case-log-armedforces-0-field", allow_label_click: true) - fill_in("case-log-leftreg-field", with: "text") choose("case-log-armedforces-1-field", allow_label_click: true) + fill_in("case-log-leftreg-field", with: "text") + choose("case-log-armedforces-4-field", allow_label_click: true) expect(page).not_to have_field("case-log-leftreg-field") - choose("case-log-armedforces-0-field", allow_label_click: true) + choose("case-log-armedforces-1-field", allow_label_click: true) expect(page).to have_field("case-log-leftreg-field", with: "") end end diff --git a/spec/features/form/form_navigation_spec.rb b/spec/features/form/form_navigation_spec.rb index fd4f78b08..ef8bc7448 100644 --- a/spec/features/form/form_navigation_spec.rb +++ b/spec/features/form/form_navigation_spec.rb @@ -19,7 +19,7 @@ RSpec.describe "Form Navigation" do age1: { type: "numeric", answer: 25, path: "person-1-age" }, sex1: { type: "radio", answer: "Female", path: "person-1-gender" }, ecstat1: { type: "radio", answer: 3, path: "person-1-working-situation" }, - other_hhmemb: { type: "numeric", answer: 2, path: "household-number-of-other-members" }, + hhmemb: { type: "numeric", answer: 1, path: "household-number-of-members" }, } end @@ -71,7 +71,7 @@ RSpec.describe "Form Navigation" do visit("/logs") visit("/logs/#{id}/net-income") fill_in("case-log-earnings-field", with: 740) - choose("case-log-incfreq-0-field", allow_label_click: true) + choose("case-log-incfreq-1-field", allow_label_click: true) click_button("Save and continue") click_link(text: "Back") click_link(text: "Back") diff --git a/spec/features/form/page_routing_spec.rb b/spec/features/form/page_routing_spec.rb index d4f50f118..83a1078ff 100644 --- a/spec/features/form/page_routing_spec.rb +++ b/spec/features/form/page_routing_spec.rb @@ -24,12 +24,12 @@ RSpec.describe "Form Page Routing" do visit("/logs/#{id}/conditional-question") # using a question name that is already in the db to avoid # having to add a new column to the db for this test - choose("case-log-preg-occ-0-field", allow_label_click: true) + choose("case-log-preg-occ-1-field", allow_label_click: true) click_button("Save and continue") expect(page).to have_current_path("/logs/#{id}/conditional-question-yes-page") click_link(text: "Back") expect(page).to have_current_path("/logs/#{id}/conditional-question") - choose("case-log-preg-occ-1-field", allow_label_click: true) + choose("case-log-preg-occ-2-field", allow_label_click: true) click_button("Save and continue") expect(page).to have_current_path("/logs/#{id}/conditional-question-no-page") end @@ -40,7 +40,7 @@ RSpec.describe "Form Page Routing" do click_button("Save and continue") expect(page).to have_current_path("/logs/#{id}/person-1-working-situation") visit("/logs/#{id}/conditional-question") - choose("case-log-preg-occ-1-field", allow_label_click: true) + choose("case-log-preg-occ-2-field", allow_label_click: true) click_button("Save and continue") expect(page).to have_current_path("/logs/#{id}/conditional-question-no-page") click_button("Save and continue") diff --git a/spec/features/form/saving_data_spec.rb b/spec/features/form/saving_data_spec.rb index d9fa2feba..9e8d09f58 100644 --- a/spec/features/form/saving_data_spec.rb +++ b/spec/features/form/saving_data_spec.rb @@ -26,7 +26,7 @@ RSpec.describe "Form Saving Data" do tenant_code: { type: "text", answer: "BZ737", path: "tenant_code" }, age1: { type: "numeric", answer: 25, path: "person_1_age" }, sex1: { type: "radio", answer: { "F" => "Female" }, path: "person_1_gender" }, - other_hhmemb: { type: "numeric", answer: 2, path: "household_number_of_other_members" }, + hhmemb: { type: "numeric", answer: 3, path: "household_number_of_members" }, } end diff --git a/spec/features/form/validations_spec.rb b/spec/features/form/validations_spec.rb index b884264a4..75e7f3e99 100644 --- a/spec/features/form/validations_spec.rb +++ b/spec/features/form/validations_spec.rb @@ -127,7 +127,7 @@ RSpec.describe "validations" do it "prompts the user to confirm the value is correct with an interruption screen" do visit("/logs/#{case_log.id}/net-income") fill_in("case-log-earnings-field", with: income_over_soft_limit) - choose("case-log-incfreq-0-field", allow_label_click: true) + choose("case-log-incfreq-1-field", allow_label_click: true) click_button("Save and continue") expect(page).to have_current_path("/logs/#{case_log.id}/net-income-value-check") expect(page).to have_content("Net income is outside the expected range based on the lead tenant’s working situation") @@ -141,7 +141,7 @@ RSpec.describe "validations" do it "returns the user to the previous question if they do not confirm the value as correct on the interruption screen" do visit("/logs/#{case_log.id}/net-income") fill_in("case-log-earnings-field", with: income_over_soft_limit) - choose("case-log-incfreq-0-field", allow_label_click: true) + choose("case-log-incfreq-1-field", allow_label_click: true) click_button("Save and continue") choose("case-log-net-income-value-check-1-field", allow_label_click: true) click_button("Save and continue") diff --git a/spec/fixtures/complete_case_log.json b/spec/fixtures/complete_case_log.json index 9240f92de..d32fe927f 100644 --- a/spec/fixtures/complete_case_log.json +++ b/spec/fixtures/complete_case_log.json @@ -6,10 +6,9 @@ "ethnic": 0, "national": 0, "prevten": 6, - "armedforces": 0, + "armedforces": 1, "armed_forces_partner": "", "ecstat1": 1, - "other_hhmemb": 7, "hhmemb": 8, "relat2": "P", "age2": 32, @@ -43,39 +42,30 @@ "underoccupation_benefitcap": 0, "leftreg": 1, "reservist": 0, - "illness": 0, - "preg_occ": 0, + "illness": 1, + "preg_occ": 1, "tenancy_code": "BZ757", "startdate": "12/12/2021", - "day": 12, - "month": 12, - "year": 2021, "startertenancy": 0, "tenancylength": 5, - "tenancy": 3, + "tenancy": 1, "landlord": 1, "la": "Barnet", "postcode_full": "NW1 5TY", "property_relet": 0, - "rsnvac": 0, + "rsnvac": 14, "property_reference": "P9876", - "unittype_gn": 2, + "unittype_gn": 7, "property_building_type": "dummy", "beds": 3, - "property_void_date": "10/10/2020", - "vday": 10, - "vmonth": 10, - "vyear": 2020, + "voiddate": "10/10/2020", "majorrepairs": 1, "mrcdate": "11/11/2020", - "mrcday": 11, - "mrcmonth": 11, - "mrcyear": 2020, "offered": 2, "wchair": 1, "net_income_known": 1, "earnings": 150, - "incfreq": 0, + "incfreq": 1, "benefits": 1, "hb": 1, "period": 2, @@ -95,7 +85,7 @@ "cap": 0, "hbrentshortfall": 0, "tshortfall": 12, - "other_reason_for_leaving_last_settled_home": null, + "reasonother": null, "housingneeds_a": 1, "housingneeds_b": 0, "housingneeds_c": 0, @@ -131,8 +121,6 @@ "propcode": "123", "postcode": "a1", "postcod2": "w3", - "ppostc1": "w3", - "ppostc2": "w3", "first_time_property_let_as_social_housing": 0, "unitletas": 1, "builtype": 0, diff --git a/spec/fixtures/exports/case_logs.xml b/spec/fixtures/exports/case_logs.xml index 6ad128d05..a5dd626af 100644 --- a/spec/fixtures/exports/case_logs.xml +++ b/spec/fixtures/exports/case_logs.xml @@ -38,38 +38,36 @@ 0 1 0 - 0 - 1 + 1 + 2 BZ757 0 5 - 3 - 1 + 1 SE26RT - 7 - 2 + 6 + 7 3 2 1 68 - 0 + 1 1 2 2 - 1 + 1 NW15TY 1 1 1 0 - + 1 0 0 0 0 0 - 0 0 1 0 @@ -90,7 +88,7 @@ Test Test - 2 + 798794 4 123 @@ -99,24 +97,16 @@ E07000105 6 0 - NW1 - 5TY - SE2 - 6RT 0 2020-05-05 10:36:49 UTC - 5 - 5 - 2020 - 1 0 2022-02-02 10:36:49 UTC - 0 + 1 2 1 - 2019-11-03 00:00:00 UTC + 2019-11-03 00:00:00 UTC {owning_org_id} {managing_org_id} 2 @@ -125,9 +115,6 @@ 1 1 false - 2 - 2 - 2022 0 0 2 @@ -161,9 +148,6 @@ 6.0 0 1 - 3 - 11 - 2019 2 P @@ -174,6 +158,9 @@ + + + 1 diff --git a/spec/fixtures/forms/2021_2022.json b/spec/fixtures/forms/2021_2022.json index 77649d8c2..74f4b1916 100644 --- a/spec/fixtures/forms/2021_2022.json +++ b/spec/fixtures/forms/2021_2022.json @@ -114,21 +114,21 @@ } } }, - "household_number_of_other_members": { + "household_number_of_members": { "questions": { - "other_hhmemb": { - "check_answer_label": "Number of Other Household Members", - "header": "How many other people are there in the household?", - "hint_text": "The maximum number of others is 1", + "hhmemb": { + "check_answer_label": "Number of Household Members", + "header": "How many people are there in the household?", + "hint_text": "The maximum number of members is 8", "type": "numeric", "min": 0, - "max": 7, + "max": 8, "step": 1, "width": 2, "conditional_for": { - "relat2": ">0", - "age2": ">0", - "sex2": ">0" + "relat2": ">1", + "age2": ">1", + "sex2": ">1" } }, "relat2": { @@ -225,24 +225,24 @@ "type": "radio", "check_answer_label": "Household links to UK armed forces", "answer_options": { - "0": { + "1": { "value": "Yes, the person is a current or former regular" }, - "1": { + "4": { "value": "Yes, the person is a current or former reserve" }, - "2": { + "5": { "value": "Yes, the tenant is a spouse or civil partner of a UK armed forces member and has been bereaved or separated from them within the last 2 years" }, - "3": { + "2": { "value": "No" }, - "4": { + "3": { "value": "Person prefers not to say" } }, "conditional_for": { - "leftreg": [0] + "leftreg": [1] } }, "leftreg": { @@ -260,20 +260,14 @@ "type": "radio", "check_answer_label": "Physical, mental health or illness in the household", "answer_options": { - "0": { - "value": "Yes" - }, "1": { - "value": "No" - }, - "divider": { - "value": true + "value": "Yes" }, "2": { - "value": "Don’t know" + "value": "No" }, "3": { - "value": "Prefer not to say" + "value": "Don’t know" } } } @@ -463,10 +457,10 @@ "header": "Has the condition been met?", "type": "radio", "answer_options": { - "0": { + "1": { "value": "Yes" }, - "1": { + "2": { "value": "No" } } @@ -486,7 +480,7 @@ } } }, - "depends_on": [{ "preg_occ": 0 }, { "wchair" : 1 }] + "depends_on": [{ "preg_occ": 1 }, { "wchair" : 1 }] }, "conditional_question_no_page": { "questions": { @@ -504,7 +498,7 @@ } } }, - "depends_on": [{ "preg_occ": 1 }] + "depends_on": [{ "preg_occ": 2 }] }, "conditional_question_no_second_page": { "questions": { @@ -522,7 +516,7 @@ } } }, - "depends_on": [{ "preg_occ": 1, "sex1": "M" }] + "depends_on": [{ "preg_occ": 2, "sex1": "M" }] } } } @@ -548,9 +542,9 @@ "width": 5, "prefix": "£", "suffix": [ - { "label": "every week", "depends_on" : { "incfreq": 0 } }, - { "label": "every month", "depends_on" : { "incfreq": 1 } }, - { "label": "every month", "depends_on" : { "incfreq": 2 } } + { "label": "every week", "depends_on" : { "incfreq": 1 } }, + { "label": "every month", "depends_on" : { "incfreq": 2 } }, + { "label": "every month", "depends_on" : { "incfreq": 3 } } ] }, "incfreq": { @@ -558,13 +552,13 @@ "header": "How often do they receive this income?", "type": "radio", "answer_options": { - "0": { + "1": { "value": "Weekly" }, - "1": { + "2": { "value": "Monthly" }, - "2": { + "3": { "value": "Yearly" } } @@ -646,7 +640,7 @@ } }, "dependent_page": { - "depends_on": [{ "incfreq": 0 }], + "depends_on": [{ "incfreq": 1 }], "questions": { "dependent_question": { "check_answer_label": "Dependent Question", diff --git a/spec/fixtures/softwire_imports/case_logs/0ead17cb-1668-442d-898c-0d52879ff592.xml b/spec/fixtures/softwire_imports/case_logs/0ead17cb-1668-442d-898c-0d52879ff592.xml new file mode 100644 index 000000000..34ccc8e12 --- /dev/null +++ b/spec/fixtures/softwire_imports/case_logs/0ead17cb-1668-442d-898c-0d52879ff592.xml @@ -0,0 +1,532 @@ + + + + 2021-CORE-SR-GN + 0ead17cb-1668-442d-898c-0d52879ff592 + c3061a2e6ea0b702e6f6210d5c52d2a92612d2aa + + 7c5bd5fb549c09a2c55d7cb90d7ba84927e64618 + + 7c5bd5fb549c09a2c55d7cb90d7ba84927e64618 + + 2021-10-08T14:48:17.096123Z + 2021-10-08T14:48:17.096123Z + submitted-valid + 2021 + Manual Entry + + + + + Yes + 2021-09-30 +
    5786509
    + 1 Private Registered Provider + + <_1btenagree>1 This Landlord + <_1bifanother/> + <_1bCOREcode/> + +
    + + <_2a>1 Yes + 2 Assured + + <_2bTenCode>MAC003 + <_2cYears/> + + + 23 + + Female + 6) Not Seeking Work + 1 White: English/Scottish/Welsh/Northern Irish/British + 1 UK national resident in UK + 2 + + Male + Child + 9) Child under 16 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 2 No + + + 2 No + + + 6 UC – with housing element (and not in receipt of Housing + Benefit) + + + + 1 All + + 600.00 + 2 Monthly + + + 12 Property unsuitable because of overcrowding + + + + <_9b override-field="">2 No + + + + + Yes + + 2 No + + + + + + + + + + + 30 Fixed term Local Authority General Needs + tenancy + + Leeds + E08000035 + LS8 3HX + + 5 5 years or more + 2 Less than 1 year + + + 1 Not homeless + 1 Yes + + 2_Living_in_insanitary_or_overcrowded_or_unsatisfactory_housing + + + + + + + 1 Yes + 2 No + 2 No + + + 3 PRP lettings only - nominated by a local housing authority + + + + 4 Calendar monthly + 406.09 + 32.02 + + + 438.11 + 2 No + + 2021-09-30 + + 0 + MCB003 + + + 2 + 1 Flat / maisonette + 1 Purpose built + 2 No + + 15 First let of newbuild property + + + Leeds + E08000035 + LS16 6FT + + + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 1 + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + <_100>0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + <_70>0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 1 + 1 + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 23 + 2 + 0 + 0 + 0 + 0 + 0 + 0 + 2 + 23 + 21 + 23 + 2021-10-08Z + 2021-10-23Z + + + + + + + + + + + + + 0 + 0 + 0 + 0 + 20 + 0 + 20 + C + 1 + 1 + 1 + 1 + 4 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + 21.05 + 1 + 2 Existing Tenant + 1 + 1 + 0 + 2 + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 1 + 5 = 1 adult + 1 or more children + 133.33 + 154.38 + 7.00 + + 154.38 + 1 Private Registered Provider + + + E12000003 + 1034 + LEEDS & YORKSHIRE HA Ltd + LEEDS & YORKSHIRE HA Ltd + LH0704 + LH0704 + + 1034 + + + + + + + 7 + + + + + + + + + 7 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + 93.71 + 101.10 + 7.39 + + + + + + 93.71 + 101.10 + 7.39 + + + + + 0 + 1 + 0 + 0 + 0 + 0 + 0.5 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 1 + 0 + 2 + 0 + 93.71 + 0 + + 68.6 + 74.7 + 25 + + + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 30 + 9 + 2021 + 30 + 9 + 2021 + + + + LS8 + 3HX + LS16 + 6FT + +
    diff --git a/spec/fixtures/softwire_imports/case_logs/166fc004-392e-47a8-acb8-1c018734882b.xml b/spec/fixtures/softwire_imports/case_logs/166fc004-392e-47a8-acb8-1c018734882b.xml new file mode 100644 index 000000000..e119e81ce --- /dev/null +++ b/spec/fixtures/softwire_imports/case_logs/166fc004-392e-47a8-acb8-1c018734882b.xml @@ -0,0 +1,514 @@ + + + 2021-CORE-IR-GN + 166fc004-392e-47a8-acb8-1c018734882b + e29c492473446dca4d50224f2bb7cf965a261d6f + 26139d1be7a44ebb1af23d3f8882c14025e9903c + 26139d1be7a44ebb1af23d3f8882c14025e9903c + 2022-04-12T14:10:59.953121Z + 2022-04-12T14:10:59.953121Z + submitted-valid + 2021 + Manual Entry + + + + + Yes + 2 London Living Rent + + 2021-11-10 +
    300072
    + 1 Private Registered Provider + + <_1btenagree>1 This Landlord + <_1bifanother/> + <_1bCOREcode/> + +
    + + <_2a>2 No + 2 Assured + + <_2bTenCode>TEN0021 + <_2cYears/> + + + 37 + + Female + 1) Full Time + 1 White: English/Scottish/Welsh/Northern Irish/British + 1 UK national resident in UK + 34 + + Female + Other + 1) Full Time + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 2 No + + + 2 No + + + 9 Not in receipt of either UC or HB + + + 3 None + + 200.00 + 1 Weekly + + + 8 (Non-violent) relationship breakdown with partner + + + + <_9b override-field="">2 No + + + + + Yes + + 1 Yes + + + + Yes + + + + + + + 28 Living with friends or family + Blackpool + E09000009 + FY1 1JD + + 1 Just moved to Local Authority area + 1 Just moved to Local Authority area + + + 1 Not homeless + 2 No + + + + + + + + 2 No + 2 No + 2 No + + + 10 Other social landlord + + + + 1 Weekly for 52 weeks + 100.00 + + + + 100.00 + + + 2021-04-15 + + 0 + PROPREF0042 + + + 2 + 1 Flat / maisonette + 1 Purpose built + 2 No + 4 An Intermediate Rent basis + 10 Relet - tenant evicted due to arrears + + + Basingstoke & Deane + E07000084 + RG21 3HU + + + 1 + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 2 + 1 + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 2 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + <_100>0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + <_70>0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 1 + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 2 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 2 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 37 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 37 + 0 + 37 + 2022-04-12Z + 2022-04-27Z + + + + + + + + + + + + + 0 + 0 + 0 + 0 + 20 + 0 + 20 + C + 1 + 1 + 1 + 1 + 4 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + 2 + 2 Existing Tenant + 1 + 1 + 209 + 2 + 1 + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 2 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 4 = 2 adults + 200.00 + 200.00 + 13 + + 200.00 + 1 Private Registered Provider + + + E12000008 + 107138 + 1 Test + 1 Test + 655 + 655 + + 107138 + + + + + + + + + + + + + 13 + + + 13 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + 100.00 + 100.00 + + + + 0.00 + + + + 100.00 + 100.00 + + + + 0 + + + 0 + 2 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 2 + 0 + 100.00 + 23.35 + + 0 + 0 + 0 + + + 0 + 0 + 23.35 + 0 + 0 + 0 + 0 + 0 + 0 + 10 + 11 + 2021 + 15 + 4 + 2021 + + + + FY1 + 1JD + + + +
    diff --git a/spec/helpers/check_answers_helper_spec.rb b/spec/helpers/check_answers_helper_spec.rb index c0642db81..8c7b4e69d 100644 --- a/spec/helpers/check_answers_helper_spec.rb +++ b/spec/helpers/check_answers_helper_spec.rb @@ -16,7 +16,7 @@ RSpec.describe CheckAnswersHelper do context "when a section has been completed" do it "returns that you have answered all the questions" do case_log.sex1 = "F" - case_log.other_hhmemb = 0 + case_log.hhmemb = 1 case_log.propcode = "123" case_log.ecstat1 = 200 case_log.ecstat2 = 9 diff --git a/spec/helpers/conditional_questions_helper_spec.rb b/spec/helpers/conditional_questions_helper_spec.rb index 919984a09..ab3898ea0 100644 --- a/spec/helpers/conditional_questions_helper_spec.rb +++ b/spec/helpers/conditional_questions_helper_spec.rb @@ -14,7 +14,7 @@ RSpec.describe ConditionalQuestionsHelper do describe "find conditional question" do let(:question) { page.questions.find { |q| q.id == "armedforces" } } - let(:answer_value) { 0 } + let(:answer_value) { 1 } it "returns the conditional question for a given answer option" do expect(find_conditional_question(page, question, answer_value).id).to eq("leftreg") diff --git a/spec/helpers/interuption_screen_helper_spec.rb b/spec/helpers/interuption_screen_helper_spec.rb index efcf4d1e2..cb2fc3520 100644 --- a/spec/helpers/interuption_screen_helper_spec.rb +++ b/spec/helpers/interuption_screen_helper_spec.rb @@ -11,7 +11,7 @@ RSpec.describe InteruptionScreenHelper do :in_progress, ecstat1: 1, earnings: 750, - incfreq: 0, + incfreq: 1, owning_organisation: user.organisation, managing_organisation: user.organisation, ) diff --git a/spec/models/case_log_spec.rb b/spec/models/case_log_spec.rb index 3f10f92bd..bcf132aa0 100644 --- a/spec/models/case_log_spec.rb +++ b/spec/models/case_log_spec.rb @@ -2,7 +2,7 @@ require "rails_helper" RSpec.describe CaseLog do let(:owning_organisation) { FactoryBot.create(:organisation) } - let(:managing_organisation) { owning_organisation } + let(:different_managing_organisation) { FactoryBot.create(:organisation) } describe "#form" do let(:case_log) { FactoryBot.build(:case_log) } @@ -33,7 +33,7 @@ RSpec.describe CaseLog do let(:case_log) do described_class.create( owning_organisation:, - managing_organisation:, + managing_organisation: owning_organisation, ) end @@ -57,7 +57,7 @@ RSpec.describe CaseLog do end it "validates intermediate rent product name" do - expect(validator).to receive(:validate_intermediate_rent_product_name) + expect(validator).to receive(:validate_irproduct_other) end it "validates other household member details" do @@ -175,32 +175,31 @@ RSpec.describe CaseLog do let(:case_log) { FactoryBot.build(:case_log, earnings: net_income) } it "returns input income if frequency is already weekly" do - case_log.incfreq = 0 + case_log.incfreq = 1 expect(case_log.weekly_net_income).to eq(net_income) end it "calculates the correct weekly income from monthly income" do - case_log.incfreq = 1 + case_log.incfreq = 2 expect(case_log.weekly_net_income).to eq(1154) end it "calculates the correct weekly income from yearly income" do - case_log.incfreq = 2 + case_log.incfreq = 3 expect(case_log.weekly_net_income).to eq(417) end end describe "derived variables" do - let(:organisation) { FactoryBot.create(:organisation, provider_type: "PRP") } let!(:case_log) do described_class.create({ - managing_organisation: organisation, - owning_organisation: organisation, + managing_organisation: owning_organisation, + owning_organisation:, postcode_full: "M1 1AE", ppostcode_full: "M2 2AE", startdate: Time.gm(2021, 10, 10), mrcdate: Time.gm(2021, 5, 4), - property_void_date: Time.gm(2021, 3, 3), + voiddate: Time.gm(2021, 3, 3), net_income_known: 2, hhmemb: 7, rent_type: 4, @@ -210,36 +209,18 @@ RSpec.describe CaseLog do }) end - it "correctly derives and saves partial and full postcodes" do - record_from_db = ActiveRecord::Base.connection.execute("select postcode, postcod2 from case_logs where id=#{case_log.id}").to_a[0] - expect(record_from_db["postcode"]).to eq("M1") - expect(record_from_db["postcod2"]).to eq("1AE") - end - - it "correctly derives and saves partial and full previous postcodes" do - record_from_db = ActiveRecord::Base.connection.execute("select ppostc1, ppostc2 from case_logs where id=#{case_log.id}").to_a[0] - expect(record_from_db["ppostc1"]).to eq("M2") - expect(record_from_db["ppostc2"]).to eq("2AE") - end - it "correctly derives and saves partial and full major repairs date" do - record_from_db = ActiveRecord::Base.connection.execute("select mrcday, mrcmonth, mrcyear, mrcdate from case_logs where id=#{case_log.id}").to_a[0] + record_from_db = ActiveRecord::Base.connection.execute("select mrcdate from case_logs where id=#{case_log.id}").to_a[0] expect(record_from_db["mrcdate"].day).to eq(4) expect(record_from_db["mrcdate"].month).to eq(5) expect(record_from_db["mrcdate"].year).to eq(2021) - expect(record_from_db["mrcday"]).to eq(4) - expect(record_from_db["mrcmonth"]).to eq(5) - expect(record_from_db["mrcyear"]).to eq(2021) end it "correctly derives and saves partial and full major property void date" do - record_from_db = ActiveRecord::Base.connection.execute("select vday, vmonth, vyear, property_void_date from case_logs where id=#{case_log.id}").to_a[0] - expect(record_from_db["property_void_date"].day).to eq(3) - expect(record_from_db["property_void_date"].month).to eq(3) - expect(record_from_db["property_void_date"].year).to eq(2021) - expect(record_from_db["vday"]).to eq(3) - expect(record_from_db["vmonth"]).to eq(3) - expect(record_from_db["vyear"]).to eq(2021) + record_from_db = ActiveRecord::Base.connection.execute("select voiddate from case_logs where id=#{case_log.id}").to_a[0] + expect(record_from_db["voiddate"].day).to eq(3) + expect(record_from_db["voiddate"].month).to eq(3) + expect(record_from_db["voiddate"].year).to eq(2021) end it "correctly derives and saves incref" do @@ -247,40 +228,19 @@ RSpec.describe CaseLog do expect(record_from_db["incref"]).to eq(1) end - it "correctly derives and saves other_hhmemb" do - record_from_db = ActiveRecord::Base.connection.execute("select other_hhmemb from case_logs where id=#{case_log.id}").to_a[0] - expect(record_from_db["other_hhmemb"]).to eq(6) - end - it "correctly derives and saves renttype" do record_from_db = ActiveRecord::Base.connection.execute("select renttype from case_logs where id=#{case_log.id}").to_a[0] expect(case_log.renttype).to eq(3) expect(record_from_db["renttype"]).to eq(3) end - context "when the owning organisation is a PRP" do - it "correctly derives and saves landlord based on owning_organisation provider_type" do - record_from_db = ActiveRecord::Base.connection.execute("select landlord from case_logs where id=#{case_log.id}").to_a[0] - expect(case_log.landlord).to eq(2) - expect(record_from_db["landlord"]).to eq(2) - end - end - - context "when the owning organisation is an LA" do - let(:organisation) { FactoryBot.create(:organisation) } - - it "correctly derives and saves landlord based on owning_organisation provider_type" do - record_from_db = ActiveRecord::Base.connection.execute("select landlord from case_logs where id=#{case_log.id}").to_a[0] - expect(case_log.landlord).to eq(1) - expect(record_from_db["landlord"]).to eq(1) - end - end - context "when deriving lettype" do context "when the owning organisation is a PRP" do + before { case_log.owning_organisation.update!(provider_type: 2) } + context "when the rent type is intermediate rent and supported housing" do it "correctly derives and saves lettype" do - case_log.update!(rent_type: 4, needstype: 0) + case_log.update!(rent_type: 4, needstype: 2) record_from_db = ActiveRecord::Base.connection.execute("select lettype from case_logs where id=#{case_log.id}").to_a[0] expect(case_log.lettype).to eq(10) expect(record_from_db["lettype"]).to eq(10) @@ -298,7 +258,7 @@ RSpec.describe CaseLog do context "when the rent type is affordable rent and supported housing" do it "correctly derives and saves lettype" do - case_log.update!(rent_type: 2, needstype: 0) + case_log.update!(rent_type: 2, needstype: 2) record_from_db = ActiveRecord::Base.connection.execute("select lettype from case_logs where id=#{case_log.id}").to_a[0] expect(case_log.lettype).to eq(6) expect(record_from_db["lettype"]).to eq(6) @@ -316,7 +276,7 @@ RSpec.describe CaseLog do context "when the rent type is social rent and supported housing" do it "correctly derives and saves lettype" do - case_log.update!(rent_type: 0, needstype: 0) + case_log.update!(rent_type: 0, needstype: 2) record_from_db = ActiveRecord::Base.connection.execute("select lettype from case_logs where id=#{case_log.id}").to_a[0] expect(case_log.lettype).to eq(2) expect(record_from_db["lettype"]).to eq(2) @@ -357,17 +317,17 @@ RSpec.describe CaseLog do end it "correctly derives and saves weekly personal service charge" do - case_log.update!(pscharge: 70, period: 2) + case_log.update!(pscharge: 60, period: 2) record_from_db = ActiveRecord::Base.connection.execute("select wpschrge from case_logs where id=#{case_log.id}").to_a[0] - expect(case_log.wpschrge).to eq(35.0) - expect(record_from_db["wpschrge"]).to eq(35.0) + expect(case_log.wpschrge).to eq(30.0) + expect(record_from_db["wpschrge"]).to eq(30.0) end it "correctly derives and saves weekly support charge" do - case_log.update!(supcharg: 100, period: 2) + case_log.update!(supcharg: 80, period: 2) record_from_db = ActiveRecord::Base.connection.execute("select wsupchrg from case_logs where id=#{case_log.id}").to_a[0] - expect(case_log.wsupchrg).to eq(50.0) - expect(record_from_db["wsupchrg"]).to eq(50.0) + expect(case_log.wsupchrg).to eq(40.0) + expect(record_from_db["wsupchrg"]).to eq(40.0) end it "correctly derives and saves weekly total charge" do @@ -407,18 +367,18 @@ RSpec.describe CaseLog do end it "correctly derives floats" do - case_log.update!(supcharg: 60.12, pscharge: 60.13, scharge: 60.98, brent: 60.97, period: 2) + case_log.update!(supcharg: 60.12, pscharge: 50.13, scharge: 60.98, brent: 60.97, period: 2) record_from_db = ActiveRecord::Base.connection.execute("select wtcharge, wsupchrg, wpschrge, wscharge, wrent from case_logs where id=#{case_log.id}").to_a[0] expect(case_log.wsupchrg).to eq(30.06) - expect(case_log.wpschrge).to eq(30.06) + expect(case_log.wpschrge).to eq(25.06) expect(case_log.wscharge).to eq(30.49) expect(case_log.wrent).to eq(30.49) - expect(case_log.wtcharge).to eq(121.1) + expect(case_log.wtcharge).to eq(116.1) expect(record_from_db["wsupchrg"]).to eq(30.06) - expect(record_from_db["wpschrge"]).to eq(30.06) + expect(record_from_db["wpschrge"]).to eq(25.06) expect(record_from_db["wscharge"]).to eq(30.49) expect(record_from_db["wrent"]).to eq(30.49) - expect(record_from_db["wtcharge"]).to eq(121.1) + expect(record_from_db["wtcharge"]).to eq(116.1) end end @@ -1055,28 +1015,28 @@ RSpec.describe CaseLog do end it "correctly derives floats" do - case_log.update!(supcharg: 30.12, pscharge: 30.13, scharge: 30.98, brent: 100.97, period: 1) + case_log.update!(supcharg: 30.12, pscharge: 25.13, scharge: 30.98, brent: 100.97, period: 1) record_from_db = ActiveRecord::Base.connection.execute("select wtcharge, wsupchrg, wpschrge, wscharge, wrent from case_logs where id=#{case_log.id}").to_a[0] expect(case_log.wsupchrg).to eq(30.12) - expect(case_log.wpschrge).to eq(30.13) + expect(case_log.wpschrge).to eq(25.13) expect(case_log.wscharge).to eq(30.98) expect(case_log.wrent).to eq(100.97) - expect(case_log.wtcharge).to eq(192.2) + expect(case_log.wtcharge).to eq(187.2) expect(record_from_db["wsupchrg"]).to eq(30.12) - expect(record_from_db["wpschrge"]).to eq(30.13) + expect(record_from_db["wpschrge"]).to eq(25.13) expect(record_from_db["wscharge"]).to eq(30.98) expect(record_from_db["wrent"]).to eq(100.97) - expect(record_from_db["wtcharge"]).to eq(192.2) + expect(record_from_db["wtcharge"]).to eq(187.2) end end end - context "when the owning organisation is an LA" do - let(:organisation) { FactoryBot.create(:organisation, provider_type: "LA") } + context "when the owning organisation is a LA" do + before { case_log.owning_organisation.update!(provider_type: "LA") } context "when the rent type is intermediate rent and supported housing" do it "correctly derives and saves lettype" do - case_log.update!(rent_type: 4, needstype: 0) + case_log.update!(rent_type: 4, needstype: 2) record_from_db = ActiveRecord::Base.connection.execute("select lettype from case_logs where id=#{case_log.id}").to_a[0] expect(case_log.lettype).to eq(12) expect(record_from_db["lettype"]).to eq(12) @@ -1094,7 +1054,7 @@ RSpec.describe CaseLog do context "when the rent type is affordable rent and supported housing" do it "correctly derives and saves lettype" do - case_log.update!(rent_type: 2, needstype: 0) + case_log.update!(rent_type: 2, needstype: 2) record_from_db = ActiveRecord::Base.connection.execute("select lettype from case_logs where id=#{case_log.id}").to_a[0] expect(case_log.lettype).to eq(8) expect(record_from_db["lettype"]).to eq(8) @@ -1112,7 +1072,7 @@ RSpec.describe CaseLog do context "when the rent type is social rent and supported housing" do it "correctly derives and saves lettype" do - case_log.update!(rent_type: 0, needstype: 0) + case_log.update!(rent_type: 0, needstype: 2) record_from_db = ActiveRecord::Base.connection.execute("select lettype from case_logs where id=#{case_log.id}").to_a[0] expect(case_log.lettype).to eq(4) expect(record_from_db["lettype"]).to eq(4) @@ -1131,13 +1091,10 @@ RSpec.describe CaseLog do end it "correctly derives and saves day, month, year from start date" do - record_from_db = ActiveRecord::Base.connection.execute("select day, month, year, startdate from case_logs where id=#{case_log.id}").to_a[0] + record_from_db = ActiveRecord::Base.connection.execute("select startdate from case_logs where id=#{case_log.id}").to_a[0] expect(record_from_db["startdate"].day).to eq(10) expect(record_from_db["startdate"].month).to eq(10) expect(record_from_db["startdate"].year).to eq(2021) - expect(record_from_db["day"]).to eq(10) - expect(record_from_db["month"]).to eq(10) - expect(record_from_db["year"]).to eq(2021) end context "when any charge field is set" do @@ -1152,14 +1109,16 @@ RSpec.describe CaseLog do end end - def check_postcode_fields(postcode_field, outcode_field, incode_field) - record_from_db = ActiveRecord::Base.connection.execute("select #{postcode_field}, #{outcode_field}, #{incode_field} from case_logs where id=#{address_case_log.id}").to_a[0] + def check_postcode_fields(postcode_field) + record_from_db = ActiveRecord::Base.connection.execute("select #{postcode_field} from case_logs where id=#{address_case_log.id}").to_a[0] + expect(address_case_log[postcode_field]).to eq("M11AE") + expect(record_from_db[postcode_field]).to eq("M11AE") + end + + def check_previous_postcode_fields(postcode_field) + record_from_db = ActiveRecord::Base.connection.execute("select #{postcode_field} from case_logs where id=#{address_case_log.id}").to_a[0] expect(address_case_log[postcode_field]).to eq("M11AE") expect(record_from_db[postcode_field]).to eq("M11AE") - expect(address_case_log[outcode_field]).to eq("M1") - expect(record_from_db[outcode_field]).to eq("M1") - expect(address_case_log[incode_field]).to eq("1AE") - expect(record_from_db[incode_field]).to eq("1AE") end context "when saving addresses" do before do @@ -1169,15 +1128,15 @@ RSpec.describe CaseLog do let!(:address_case_log) do described_class.create({ - managing_organisation: organisation, - owning_organisation: organisation, + managing_organisation: owning_organisation, + owning_organisation:, postcode_known: 1, postcode_full: "M1 1AE", }) end def check_property_postcode_fields - check_postcode_fields("postcode_full", "postcode", "postcod2") + check_postcode_fields("postcode_full") end it "correctly formats previous postcode" do @@ -1256,29 +1215,29 @@ RSpec.describe CaseLog do let!(:address_case_log) do described_class.create({ - managing_organisation: organisation, - owning_organisation: organisation, + managing_organisation: owning_organisation, + owning_organisation:, previous_postcode_known: 1, ppostcode_full: "M1 1AE", }) end - def check_previous_postcode_fields - check_postcode_fields("ppostcode_full", "ppostc1", "ppostc2") + def previous_postcode_fields + check_previous_postcode_fields("ppostcode_full") end it "correctly formats previous postcode" do address_case_log.update!(ppostcode_full: "M1 1AE") - check_previous_postcode_fields + previous_postcode_fields address_case_log.update!(ppostcode_full: "m1 1ae") - check_previous_postcode_fields + previous_postcode_fields address_case_log.update!(ppostcode_full: "m11Ae") - check_previous_postcode_fields + previous_postcode_fields address_case_log.update!(ppostcode_full: "m11ae") - check_previous_postcode_fields + previous_postcode_fields end it "correctly infers prevloc" do @@ -1340,8 +1299,8 @@ RSpec.describe CaseLog do context "when saving rent and charges" do let!(:case_log) do described_class.create({ - managing_organisation: organisation, - owning_organisation: organisation, + managing_organisation: owning_organisation, + owning_organisation:, brent: 5.77, scharge: 10.01, pscharge: 3, @@ -1358,9 +1317,9 @@ RSpec.describe CaseLog do context "when validating household members derived vars" do let!(:household_case_log) do described_class.create!({ - managing_organisation: organisation, - owning_organisation: organisation, - other_hhmemb: 4, + managing_organisation: owning_organisation, + owning_organisation:, + hhmemb: 3, relat2: "X", relat3: "C", relat4: "X", @@ -1411,10 +1370,10 @@ RSpec.describe CaseLog do context "when it is a renewal" do let!(:case_log) do described_class.create({ - managing_organisation: organisation, - owning_organisation: organisation, + managing_organisation: owning_organisation, + owning_organisation:, renewal: 1, - year: 2021, + startdate: Time.zone.local(2021, 4, 10), }) end @@ -1431,6 +1390,7 @@ RSpec.describe CaseLog do end it "correctly derives and saves prevten" do + case_log.managing_organisation.update!({ provider_type: "PRP" }) case_log.update!({ needstype: 1 }) record_from_db = ActiveRecord::Base.connection.execute("select prevten from case_logs where id=#{case_log.id}").to_a[0] @@ -1455,8 +1415,8 @@ RSpec.describe CaseLog do context "when answering the household characteristics questions" do let!(:case_log) do described_class.create({ - managing_organisation: organisation, - owning_organisation: organisation, + managing_organisation: owning_organisation, + owning_organisation:, age1_known: 1, sex1: "R", relat2: "R", @@ -1474,8 +1434,8 @@ RSpec.describe CaseLog do context "when the data provider is filling in household needs" do let!(:case_log) do described_class.create({ - managing_organisation: organisation, - owning_organisation: organisation, + managing_organisation: owning_organisation, + owning_organisation:, }) end @@ -1501,9 +1461,9 @@ RSpec.describe CaseLog do context "when it is supported housing and a care home charge has been supplied" do let!(:case_log) do described_class.create({ - managing_organisation: organisation, - owning_organisation: organisation, - needstype: 0, + managing_organisation: owning_organisation, + owning_organisation:, + needstype: 2, }) end @@ -1655,16 +1615,16 @@ RSpec.describe CaseLog do context "when the data provider is filling in the reason for the property being vacant" do let!(:first_let_case_log) do described_class.create({ - managing_organisation: organisation, - owning_organisation: organisation, + managing_organisation: owning_organisation, + owning_organisation:, first_time_property_let_as_social_housing: 1, }) end let!(:relet_case_log) do described_class.create({ - managing_organisation: organisation, - owning_organisation: organisation, + managing_organisation: owning_organisation, + owning_organisation:, first_time_property_let_as_social_housing: 0, }) end @@ -1687,7 +1647,7 @@ RSpec.describe CaseLog do describe "resetting invalidated fields" do context "when a question that has already been answered, no longer has met dependencies" do - let(:case_log) { FactoryBot.create(:case_log, :in_progress, cbl: 1, preg_occ: 1, wchair: 1) } + let(:case_log) { FactoryBot.create(:case_log, :in_progress, cbl: 1, preg_occ: 2, wchair: 1) } it "clears the answer" do expect { case_log.update!(preg_occ: nil) }.to change(case_log, :cbl).from(1).to(nil) @@ -1703,7 +1663,7 @@ RSpec.describe CaseLog do end context "with two pages having the same question key, only one's dependency is met" do - let(:case_log) { FactoryBot.create(:case_log, :in_progress, cbl: 0, preg_occ: 1, wchair: 1) } + let(:case_log) { FactoryBot.create(:case_log, :in_progress, cbl: 0, preg_occ: 2, wchair: 1) } it "does not clear the value for answers that apply to both pages" do expect(case_log.cbl).to eq(0) @@ -1712,7 +1672,7 @@ RSpec.describe CaseLog do it "does clear the value for answers that do not apply for invalidated page" do case_log.update!({ wchair: 1, sex2: "F", age2: 33 }) case_log.update!({ cbl: 1 }) - case_log.update!({ preg_occ: 0 }) + case_log.update!({ preg_occ: 1 }) expect(case_log.cbl).to eq(nil) end diff --git a/spec/models/form/page_spec.rb b/spec/models/form/page_spec.rb index a09fcace6..57c9393b3 100644 --- a/spec/models/form/page_spec.rb +++ b/spec/models/form/page_spec.rb @@ -56,7 +56,7 @@ RSpec.describe Form::Page, type: :model do end it "evaluates met conditions correctly" do - case_log.incfreq = "Weekly" + case_log.incfreq = 1 expect(page.routed_to?(case_log)).to be true end end diff --git a/spec/models/form/question_spec.rb b/spec/models/form/question_spec.rb index 227e99126..094351870 100644 --- a/spec/models/form/question_spec.rb +++ b/spec/models/form/question_spec.rb @@ -75,16 +75,16 @@ RSpec.describe Form::Question, type: :model do let(:question_id) { "incfreq" } it "has answer options" do - expected_answer_options = { "0" => { "value" => "Weekly" }, "1" => { "value" => "Monthly" }, "2" => { "value" => "Yearly" } } + expected_answer_options = { "1" => { "value" => "Weekly" }, "2" => { "value" => "Monthly" }, "3" => { "value" => "Yearly" } } expect(question.answer_options).to eq(expected_answer_options) end it "can map value from label" do - expect(question.value_from_label("Monthly")).to eq("1") + expect(question.value_from_label("Monthly")).to eq("2") end it "can map label from value" do - expect(question.label_from_value(2)).to eq("Yearly") + expect(question.label_from_value(3)).to eq("Yearly") end context "when answer options include yes, no, prefer not to say" do @@ -94,11 +94,11 @@ RSpec.describe Form::Question, type: :model do let(:question_id) { "illness" } it "maps those options" do - expect(question).to be_value_is_yes(0) - expect(question).not_to be_value_is_no(0) - expect(question).not_to be_value_is_refused(0) - expect(question).to be_value_is_no(1) - expect(question).to be_value_is_refused(2) + expect(question).to be_value_is_yes(1) + expect(question).not_to be_value_is_no(1) + expect(question).not_to be_value_is_refused(1) + expect(question).to be_value_is_no(2) + expect(question).to be_value_is_dont_know(3) end end @@ -221,7 +221,7 @@ RSpec.describe Form::Question, type: :model do let(:question_id) { "incfreq" } it "has an answer label" do - case_log.incfreq = 0 + case_log.incfreq = 1 expect(question.answer_label(case_log)).to eq("Weekly") end @@ -321,12 +321,12 @@ RSpec.describe Form::Question, type: :model do let(:question_id) { "earnings" } it "displays the correct label for given suffix and answer the suffix depends on" do - case_log.incfreq = 0 + case_log.incfreq = 1 case_log.earnings = 500 expect(question.answer_label(case_log)).to eq("£500.00 every week") - case_log.incfreq = 1 - expect(question.answer_label(case_log)).to eq("£500.00 every month") case_log.incfreq = 2 + expect(question.answer_label(case_log)).to eq("£500.00 every month") + case_log.incfreq = 3 expect(question.answer_label(case_log)).to eq("£500.00 every year") end end diff --git a/spec/models/form/subsection_spec.rb b/spec/models/form/subsection_spec.rb index cb0bed8a2..a9c573816 100644 --- a/spec/models/form/subsection_spec.rb +++ b/spec/models/form/subsection_spec.rb @@ -25,12 +25,12 @@ RSpec.describe Form::Subsection, type: :model do end it "has pages" do - expected_pages = %w[tenant_code person_1_age person_1_gender person_1_working_situation household_number_of_other_members person_2_working_situation propcode] + expected_pages = %w[tenant_code person_1_age person_1_gender person_1_working_situation household_number_of_members person_2_working_situation propcode] expect(subsection.pages.map(&:id)).to eq(expected_pages) end it "has questions" do - expected_questions = %w[tenant_code age1 sex1 ecstat1 other_hhmemb relat2 age2 sex2 ecstat2 propcode] + expected_questions = %w[tenant_code age1 sex1 ecstat1 hhmemb relat2 age2 sex2 ecstat2 propcode] expect(subsection.questions.map(&:id)).to eq(expected_questions) end @@ -73,7 +73,7 @@ RSpec.describe Form::Subsection, type: :model do end it "has question helpers for the number of applicable questions" do - expected_questions = %w[tenant_code age1 sex1 ecstat1 other_hhmemb ecstat2 propcode] + expected_questions = %w[tenant_code age1 sex1 ecstat1 hhmemb ecstat2 propcode] expect(subsection.applicable_questions(case_log).map(&:id)).to eq(expected_questions) expect(subsection.applicable_questions_count(case_log)).to eq(7) end @@ -94,7 +94,7 @@ RSpec.describe Form::Subsection, type: :model do end it "has a question helpers for the unanswered questions" do - expected_questions = %w[sex1 ecstat1 other_hhmemb ecstat2 propcode] + expected_questions = %w[sex1 ecstat1 hhmemb ecstat2 propcode] expect(subsection.unanswered_questions(case_log).map(&:id)).to eq(expected_questions) end end diff --git a/spec/models/form_spec.rb b/spec/models/form_spec.rb index d9c8b5ee9..9bc9369db 100644 --- a/spec/models/form_spec.rb +++ b/spec/models/form_spec.rb @@ -16,7 +16,7 @@ RSpec.describe Form, type: :model do context "when the current page is a value check page" do before do - case_log.incfreq = 0 + case_log.incfreq = 1 case_log.earnings = 140 case_log.ecstat1 = 1 end @@ -39,7 +39,7 @@ RSpec.describe Form, type: :model do let!(:page_ids) { subsection.pages.map(&:id) } before do - case_log.preg_occ = 1 + case_log.preg_occ = 2 end it "returns the previous page if the page is routed to" do @@ -68,7 +68,7 @@ RSpec.describe Form, type: :model do end it "returns a correct page path if there is conditional routing" do - case_log["preg_occ"] = 1 + case_log["preg_occ"] = 2 expect(form.next_page_redirect_path(previous_conditional_page, case_log)).to eq("case_log_conditional_question_no_page_path") end end @@ -102,7 +102,7 @@ RSpec.describe Form, type: :model do def answer_income_and_benefits(case_log) case_log.earnings = 30_000 - case_log.incfreq = "Yearly" + case_log.incfreq = 3 case_log.benefits = "Some" case_log.hb = "Tenant prefers not to say" end @@ -118,7 +118,7 @@ RSpec.describe Form, type: :model do def answer_local_authority(case_log) case_log.layear = "1 year but under 2 years" - case_log.lawaitlist = "Less than 1 year" + case_log.waityear = "Less than 1 year" case_log.postcode_full = "NW1 5TY" case_log.reason = "Permanently decanted from another property owned by this landlord" case_log.ppostcode_full = "SE2 6RT" @@ -130,7 +130,7 @@ RSpec.describe Form, type: :model do case_log.age1 = 35 case_log.sex1 = "M" case_log.ecstat1 = 0 - case_log.other_hhmemb = 1 + case_log.hhmemb = 2 case_log.relat2 = "P" case_log.sex2 = "F" case_log.ecstat2 = 1 diff --git a/spec/models/validations/date_validations_spec.rb b/spec/models/validations/date_validations_spec.rb index 9ab24f747..9cf8e1d8d 100644 --- a/spec/models/validations/date_validations_spec.rb +++ b/spec/models/validations/date_validations_spec.rb @@ -102,48 +102,48 @@ RSpec.describe Validations::DateValidations do describe "property void date" do it "cannot be after the tenancy start date" do record.startdate = Time.zone.local(2022, 1, 1) - record.property_void_date = Time.zone.local(2022, 2, 1) + record.voiddate = Time.zone.local(2022, 2, 1) date_validator.validate_property_void_date(record) - expect(record.errors["property_void_date"]) + expect(record.errors["voiddate"]) .to include(match I18n.t("validations.property.void_date.before_tenancy_start")) end it "must be before the tenancy start date" do record.startdate = Time.zone.local(2022, 2, 1) - record.property_void_date = Time.zone.local(2022, 1, 1) + record.voiddate = Time.zone.local(2022, 1, 1) date_validator.validate_property_void_date(record) - expect(record.errors["property_void_date"]).to be_empty + expect(record.errors["voiddate"]).to be_empty end it "cannot be more than 10 years before the tenancy start date" do record.startdate = Time.zone.local(2022, 2, 1) - record.property_void_date = Time.zone.local(2012, 1, 1) + record.voiddate = Time.zone.local(2012, 1, 1) date_validator.validate_property_void_date(record) - expect(record.errors["property_void_date"]) + expect(record.errors["voiddate"]) .to include(match I18n.t("validations.property.void_date.ten_years_before_tenancy_start")) end it "must be within 10 years of the tenancy start date" do record.startdate = Time.zone.local(2022, 2, 1) - record.property_void_date = Time.zone.local(2012, 3, 1) + record.voiddate = Time.zone.local(2012, 3, 1) date_validator.validate_property_void_date(record) - expect(record.errors["property_void_date"]).to be_empty + expect(record.errors["voiddate"]).to be_empty end context "when major repairs have been carried out" do it "cannot be after major repairs date" do record.mrcdate = Time.zone.local(2022, 1, 1) - record.property_void_date = Time.zone.local(2022, 2, 1) + record.voiddate = Time.zone.local(2022, 2, 1) date_validator.validate_property_void_date(record) - expect(record.errors["property_void_date"]) + expect(record.errors["voiddate"]) .to include(match I18n.t("validations.property.void_date.after_mrcdate")) end it "must be before major repairs date" do record.mrcdate = Time.zone.local(2022, 2, 1) - record.property_void_date = Time.zone.local(2022, 1, 1) + record.voiddate = Time.zone.local(2022, 1, 1) date_validator.validate_property_void_date(record) - expect(record.errors["property_void_date"]).to be_empty + expect(record.errors["voiddate"]).to be_empty end end end diff --git a/spec/models/validations/financial_validations_spec.rb b/spec/models/validations/financial_validations_spec.rb index 7582190a3..68b5f4629 100644 --- a/spec/models/validations/financial_validations_spec.rb +++ b/spec/models/validations/financial_validations_spec.rb @@ -17,7 +17,7 @@ RSpec.describe Validations::FinancialValidations do it "when income frequency is provided it validates that earnings must be provided" do record.earnings = nil - record.incfreq = 0 + record.incfreq = 1 financial_validator.validate_net_income(record) expect(record.errors["earnings"]) .to include(match I18n.t("validations.financial.earnings.earnings_missing")) @@ -124,7 +124,7 @@ RSpec.describe Validations::FinancialValidations do describe "Net income validations" do it "validates that the net income is within the expected range for the tenant's employment status" do record.earnings = 200 - record.incfreq = 0 + record.incfreq = 1 record.ecstat1 = 1 financial_validator.validate_net_income(record) expect(record.errors["earnings"]).to be_empty @@ -133,7 +133,7 @@ RSpec.describe Validations::FinancialValidations do context "when the net income is higher than the hard max for their employment status" do it "adds an error" do record.earnings = 5000 - record.incfreq = 0 + record.incfreq = 1 record.ecstat1 = 1 financial_validator.validate_net_income(record) expect(record.errors["earnings"]) @@ -144,7 +144,7 @@ RSpec.describe Validations::FinancialValidations do context "when the net income is lower than the hard min for their employment status" do it "adds an error" do record.earnings = 50 - record.incfreq = 0 + record.incfreq = 1 record.ecstat1 = 1 financial_validator.validate_net_income(record) expect(record.errors["earnings"]) @@ -201,12 +201,11 @@ RSpec.describe Validations::FinancialValidations do end end - context "when the landlord is this landlord" do + context "when the owning organisation is a private registered provider" do + before { record.owning_organisation.provider_type = 2 } + context "when needstype is general needs" do - before do - record.needstype = 1 - record.landlord = 1 - end + before { record.needstype = 1 } [{ period: { label: "weekly", value: 1 }, @@ -249,7 +248,7 @@ RSpec.describe Validations::FinancialValidations do record[test_case[:charge][:field]] = test_case[:charge][:value] financial_validator.validate_rent_amount(record) expect(record.errors[test_case[:charge][:field]]) - .to include(match I18n.t("validations.financial.rent.#{test_case[:charge][:field]}.this_landlord.general_needs")) + .to include(match I18n.t("validations.financial.rent.#{test_case[:charge][:field]}.private_registered_provider.general_needs")) end end @@ -300,10 +299,7 @@ RSpec.describe Validations::FinancialValidations do end context "when needstype is supported housing" do - before do - record.needstype = 0 - record.landlord = 1 - end + before { record.needstype = 2 } [{ period: { label: "weekly", value: 1 }, @@ -346,7 +342,7 @@ RSpec.describe Validations::FinancialValidations do record[test_case[:charge][:field]] = test_case[:charge][:value] financial_validator.validate_rent_amount(record) expect(record.errors[test_case[:charge][:field]]) - .to include(match I18n.t("validations.financial.rent.#{test_case[:charge][:field]}.this_landlord.supported_housing")) + .to include(match I18n.t("validations.financial.rent.#{test_case[:charge][:field]}.private_registered_provider.supported_housing")) end end @@ -397,12 +393,11 @@ RSpec.describe Validations::FinancialValidations do end end - context "when the landlord is another RP" do + context "when the owning organisation is a local authority" do + before { record.owning_organisation.provider_type = 1 } + context "when needstype is general needs" do - before do - record.needstype = 1 - record.landlord = 2 - end + before { record.needstype = 1 } [{ period: { label: "weekly", value: 1 }, @@ -445,7 +440,7 @@ RSpec.describe Validations::FinancialValidations do record[test_case[:charge][:field]] = test_case[:charge][:value] financial_validator.validate_rent_amount(record) expect(record.errors[test_case[:charge][:field]]) - .to include(match I18n.t("validations.financial.rent.#{test_case[:charge][:field]}.other_landlord.general_needs")) + .to include(match I18n.t("validations.financial.rent.#{test_case[:charge][:field]}.local_authority.general_needs")) end end @@ -496,10 +491,7 @@ RSpec.describe Validations::FinancialValidations do end context "when needstype is supported housing" do - before do - record.needstype = 0 - record.landlord = 2 - end + before { record.needstype = 2 } [{ period: { label: "weekly", value: 1 }, @@ -542,7 +534,7 @@ RSpec.describe Validations::FinancialValidations do record[test_case[:charge][:field]] = test_case[:charge][:value] financial_validator.validate_rent_amount(record) expect(record.errors[test_case[:charge][:field]]) - .to include(match I18n.t("validations.financial.rent.#{test_case[:charge][:field]}.other_landlord.supported_housing")) + .to include(match I18n.t("validations.financial.rent.#{test_case[:charge][:field]}.local_authority.supported_housing")) end end @@ -757,7 +749,6 @@ RSpec.describe Validations::FinancialValidations do record.period = 1 record.la = "E07000223" record.beds = 1 - record.year = 2021 record.startdate = Time.zone.local(2021, 9, 17) record.brent = 9.17 @@ -772,7 +763,6 @@ RSpec.describe Validations::FinancialValidations do record.la = "E07000223" record.beds = 1 record.startdate = Time.zone.local(2021, 9, 17) - record.year = 2021 record.brent = 200 financial_validator.validate_rent_amount(record) @@ -794,9 +784,6 @@ RSpec.describe Validations::FinancialValidations do record.la = "E07000223" record.startdate = Time.zone.local(2022, 2, 5) record.beds = 1 - record.year = 2022 - record.month = 2 - record.day = 5 record.brent = 200 financial_validator.validate_rent_amount(record) @@ -814,7 +801,6 @@ RSpec.describe Validations::FinancialValidations do it "does not error if some of the fields are missing" do record.managing_organisation.provider_type = 2 - record.year = 2021 record.startdate = Time.zone.local(2021, 9, 17) record.brent = 200 diff --git a/spec/models/validations/household_validations_spec.rb b/spec/models/validations/household_validations_spec.rb index 36edd3f12..6fdf72dc9 100644 --- a/spec/models/validations/household_validations_spec.rb +++ b/spec/models/validations/household_validations_spec.rb @@ -58,7 +58,7 @@ RSpec.describe Validations::HouseholdValidations do describe "pregnancy validations" do context "when there are no female tenants" do it "validates that pregnancy cannot be yes" do - record.preg_occ = 0 + record.preg_occ = 1 record.sex1 = "M" household_validator.validate_pregnancy(record) expect(record.errors["preg_occ"]) @@ -66,7 +66,7 @@ RSpec.describe Validations::HouseholdValidations do end it "validates that pregnancy cannot be prefer not to say" do - record.preg_occ = 2 + record.preg_occ = 3 record.sex1 = "M" household_validator.validate_pregnancy(record) expect(record.errors["preg_occ"]) @@ -77,7 +77,7 @@ RSpec.describe Validations::HouseholdValidations do context "when there are female tenants" do context "but they are older than 50" do it "validates that pregnancy cannot be yes" do - record.preg_occ = 0 + record.preg_occ = 1 record.sex1 = "F" record.age1 = 51 household_validator.validate_pregnancy(record) @@ -113,7 +113,7 @@ RSpec.describe Validations::HouseholdValidations do describe "reason for leaving last settled home validations" do let(:field) { "validations.other_field_not_required" } let(:main_field_label) { "reason" } - let(:other_field_label) { "other reason for leaving last settled home" } + let(:other_field_label) { "reasonother" } let(:expected_error) { I18n.t(field, main_field_label:, other_field_label:) } context "when reason is other" do @@ -121,34 +121,34 @@ RSpec.describe Validations::HouseholdValidations do it "validates that a reason is provided" do record.reason = 31 - record.other_reason_for_leaving_last_settled_home = nil + record.reasonother = nil household_validator.validate_reason_for_leaving_last_settled_home(record) - expect(record.errors["other_reason_for_leaving_last_settled_home"]) + expect(record.errors["reasonother"]) .to include(match(expected_error)) end it "expects that a reason is provided" do record.reason = 31 - record.other_reason_for_leaving_last_settled_home = "Some unusual reason" + record.reasonother = "Some unusual reason" household_validator.validate_reason_for_leaving_last_settled_home(record) - expect(record.errors["other_reason_for_leaving_last_settled_home"]).to be_empty + expect(record.errors["reasonother"]).to be_empty end end context "when reason is not other" do it "validates that other reason is not provided" do record.reason = 18 - record.other_reason_for_leaving_last_settled_home = "Some other reason" + record.reasonother = "Some other reason" household_validator.validate_reason_for_leaving_last_settled_home(record) - expect(record.errors["other_reason_for_leaving_last_settled_home"]) + expect(record.errors["reasonother"]) .to include(match(expected_error)) end it "expects that other reason is not provided" do record.reason = 18 - record.other_reason_for_leaving_last_settled_home = nil + record.reasonother = nil household_validator.validate_reason_for_leaving_last_settled_home(record) - expect(record.errors["other_reason_for_leaving_last_settled_home"]).to be_empty + expect(record.errors["reasonother"]).to be_empty end end @@ -197,8 +197,8 @@ RSpec.describe Validations::HouseholdValidations do .to be_empty end - it "cannot have `this landlord` as landlord and Housing situation before this letting cannot be LA general needs" do - record.landlord = 1 + it "cannot have a PRP as landlord and Housing situation before this letting cannot be LA general needs" do + record.owning_organisation.provider_type = "PRP" record.prevten = 30 record.referral = 1 household_validator.validate_referral(record) @@ -217,17 +217,17 @@ RSpec.describe Validations::HouseholdValidations do end context "when referral is nominated by a local housing authority" do - it "cannot have `other landlord`" do - record.landlord = 2 + it "cannot have a local authority" do + record.owning_organisation.provider_type = "LA" record.referral = 3 household_validator.validate_referral(record) expect(record.errors["referral"]) .to include(match(I18n.t("validations.household.referral.prp.local_housing_referral"))) end - it "can have `this landlord`" do + it "can have a private registered provider" do + record.owning_organisation.provider_type = "PRP" record.referral = 3 - record.landlord = 1 household_validator.validate_referral(record) expect(record.errors["referral"]) .to be_empty @@ -238,7 +238,7 @@ RSpec.describe Validations::HouseholdValidations do describe "armed forces validations" do context "when the tenant or partner was and is not a member of the armed forces" do it "validates that injured in the armed forces is not yes" do - record.armedforces = 3 + record.armedforces = 2 record.reservist = 0 household_validator.validate_armed_forces(record) expect(record.errors["reservist"]) @@ -248,7 +248,7 @@ RSpec.describe Validations::HouseholdValidations do context "when the tenant prefers not to say if they were or are in the armed forces" do it "validates that injured in the armed forces is not yes" do - record.armedforces = 4 + record.armedforces = 3 record.reservist = 0 household_validator.validate_armed_forces(record) expect(record.errors["reservist"]) @@ -276,7 +276,7 @@ RSpec.describe Validations::HouseholdValidations do context "when the tenant's partner was or is a member of the armed forces" do it "expects that injured in the armed forces can be yes" do - record.armedforces = 2 + record.armedforces = 5 record.reservist = 0 household_validator.validate_armed_forces(record) expect(record.errors["reservist"]).to be_empty @@ -285,7 +285,7 @@ RSpec.describe Validations::HouseholdValidations do context "when the tenant or partner has left the armed forces" do it "validates that they served in the armed forces" do - record.armedforces = 3 + record.armedforces = 2 record.leftreg = 0 household_validator.validate_armed_forces(record) expect(record.errors["leftreg"]) @@ -293,14 +293,14 @@ RSpec.describe Validations::HouseholdValidations do end it "expects that they served in the armed forces" do - record.armedforces = 0 + record.armedforces = 1 record.leftreg = 0 household_validator.validate_armed_forces(record) expect(record.errors["leftreg"]).to be_empty end it "expects that they served in the armed forces and may have been injured" do - record.armedforces = 0 + record.armedforces = 1 record.leftreg = 0 record.reservist = 0 household_validator.validate_armed_forces(record) @@ -462,24 +462,24 @@ RSpec.describe Validations::HouseholdValidations do expect(record.errors["age2"]).to be_empty end - it "validates that the number of other household members cannot be less than 0" do - record.other_hhmemb = -1 + it "validates that the number of household members cannot be less than 0" do + record.hhmemb = -1 household_validator.validate_numeric_min_max(record) - expect(record.errors["other_hhmemb"]) - .to include(match I18n.t("validations.numeric.valid", field: "Number of Other Household Members", min: 0, max: 7)) + expect(record.errors["hhmemb"]) + .to include(match I18n.t("validations.numeric.valid", field: "Number of Household Members", min: 0, max: 8)) end - it "validates that the number of other household members cannot be more than 7" do - record.other_hhmemb = 8 + it "validates that the number of household members cannot be more than 8" do + record.hhmemb = 9 household_validator.validate_numeric_min_max(record) - expect(record.errors["other_hhmemb"]) - .to include(match I18n.t("validations.numeric.valid", field: "Number of Other Household Members", min: 0, max: 7)) + expect(record.errors["hhmemb"]) + .to include(match I18n.t("validations.numeric.valid", field: "Number of Household Members", min: 0, max: 8)) end it "expects that the number of other household members is between the min and max" do - record.other_hhmemb = 5 + record.hhmemb = 5 household_validator.validate_numeric_min_max(record) - expect(record.errors["other_hhmemb"]).to be_empty + expect(record.errors["hhmemb"]).to be_empty end end @@ -512,7 +512,7 @@ RSpec.describe Validations::HouseholdValidations do describe "condition effects validation" do it "validates vision can't be selected if answer to anyone in household with health condition is not yes" do - record.illness = 1 + record.illness = 2 record.illness_type_1 = 1 household_validator.validate_condition_effects(record) expect(record.errors["condition_effects"]) @@ -520,7 +520,7 @@ RSpec.describe Validations::HouseholdValidations do end it "validates hearing can't be selected if answer to anyone in household with health condition is not yes" do - record.illness = 1 + record.illness = 2 record.illness_type_2 = 1 household_validator.validate_condition_effects(record) expect(record.errors["condition_effects"]) @@ -528,7 +528,7 @@ RSpec.describe Validations::HouseholdValidations do end it "validates mobility can't be selected if answer to anyone in household with health condition is not yes" do - record.illness = 1 + record.illness = 2 record.illness_type_3 = 1 household_validator.validate_condition_effects(record) expect(record.errors["condition_effects"]) @@ -536,7 +536,7 @@ RSpec.describe Validations::HouseholdValidations do end it "validates dexterity can't be selected if answer to anyone in household with health condition is not yes" do - record.illness = 1 + record.illness = 2 record.illness_type_4 = 1 household_validator.validate_condition_effects(record) expect(record.errors["condition_effects"]) @@ -544,7 +544,7 @@ RSpec.describe Validations::HouseholdValidations do end it "validates learning or understanding or concentrating can't be selected if answer to anyone in household with health condition is not yes" do - record.illness = 1 + record.illness = 2 record.illness_type_5 = 1 household_validator.validate_condition_effects(record) expect(record.errors["condition_effects"]) @@ -552,7 +552,7 @@ RSpec.describe Validations::HouseholdValidations do end it "validates memory can't be selected if answer to anyone in household with health condition is not yes" do - record.illness = 1 + record.illness = 2 record.illness_type_6 = 1 household_validator.validate_condition_effects(record) expect(record.errors["condition_effects"]) @@ -560,7 +560,7 @@ RSpec.describe Validations::HouseholdValidations do end it "validates mental health can't be selected if answer to anyone in household with health condition is not yes" do - record.illness = 1 + record.illness = 2 record.illness_type_7 = 1 household_validator.validate_condition_effects(record) expect(record.errors["condition_effects"]) @@ -568,7 +568,7 @@ RSpec.describe Validations::HouseholdValidations do end it "validates stamina or breathing or fatigue can't be selected if answer to anyone in household with health condition is not yes" do - record.illness = 1 + record.illness = 2 record.illness_type_8 = 1 household_validator.validate_condition_effects(record) expect(record.errors["condition_effects"]) @@ -576,7 +576,7 @@ RSpec.describe Validations::HouseholdValidations do end it "validates socially or behaviourally can't be selected if answer to anyone in household with health condition is not yes" do - record.illness = 1 + record.illness = 2 record.illness_type_9 = 1 household_validator.validate_condition_effects(record) expect(record.errors["condition_effects"]) @@ -584,7 +584,7 @@ RSpec.describe Validations::HouseholdValidations do end it "validates other can't be selected if answer to anyone in household with health condition is not yes" do - record.illness = 1 + record.illness = 2 record.illness_type_10 = 1 household_validator.validate_condition_effects(record) expect(record.errors["condition_effects"]) @@ -592,7 +592,7 @@ RSpec.describe Validations::HouseholdValidations do end it "expects that an illness can be selected if answer to anyone in household with health condition is yes " do - record.illness = 0 + record.illness = 1 record.illness_type_1 = 1 record.illness_type_2 = 1 record.illness_type_3 = 1 @@ -654,6 +654,7 @@ RSpec.describe Validations::HouseholdValidations do end it "can be non internal transfer" do + record.owning_organisation.provider_type = "PRP" record.homeless = 0 record.referral = 3 household_validator.validate_referral(record) @@ -674,6 +675,7 @@ RSpec.describe Validations::HouseholdValidations do end it "can be non internal transfer" do + record.owning_organisation.provider_type = "PRP" record.referral = 3 record.homeless = 1 household_validator.validate_referral(record) @@ -697,7 +699,7 @@ RSpec.describe Validations::HouseholdValidations do describe "previous housing situation validations" do context "when the property is being relet to a previously temporary tenant" do it "validates that previous tenancy was temporary" do - record.rsnvac = 2 + record.rsnvac = 9 record.prevten = 4 household_validator.validate_previous_housing_situation(record) expect(record.errors["prevten"]) diff --git a/spec/models/validations/property_validations_spec.rb b/spec/models/validations/property_validations_spec.rb index 5dd339984..08052ee7e 100644 --- a/spec/models/validations/property_validations_spec.rb +++ b/spec/models/validations/property_validations_spec.rb @@ -43,7 +43,7 @@ RSpec.describe Validations::PropertyValidations do context "when number of bedrooms has not been answered" do it "does not add an error" do record.beds = nil - record.unittype_gn = 1 + record.unittype_gn = 2 property_validator.validate_shared_housing_rooms(record) expect(record.errors).to be_empty end @@ -52,7 +52,7 @@ RSpec.describe Validations::PropertyValidations do context "when unit type is shared and number of bedrooms has not been answered" do it "does not add an error" do record.beds = nil - record.unittype_gn = 6 + record.unittype_gn = 10 property_validator.validate_shared_housing_rooms(record) expect(record.errors).to be_empty end @@ -72,7 +72,7 @@ RSpec.describe Validations::PropertyValidations do it "adds an error" do record.beds = 2 - record.unittype_gn = 1 + record.unittype_gn = 2 property_validator.validate_shared_housing_rooms(record) expect(record.errors["unittype_gn"]).to include(match(expected_error)) expect(record.errors["beds"]).to include(I18n.t("validations.property.unittype_gn.one_bedroom_bedsit")) @@ -84,7 +84,7 @@ RSpec.describe Validations::PropertyValidations do it "adds an error" do record.beds = 0 - record.unittype_gn = 1 + record.unittype_gn = 2 property_validator.validate_shared_housing_rooms(record) expect(record.errors["unittype_gn"]).to include(match(expected_error)) expect(record.errors["beds"]).to include(I18n.t("validations.property.unittype_gn.one_bedroom_bedsit")) @@ -96,8 +96,8 @@ RSpec.describe Validations::PropertyValidations do it "adds an error if the number of bedrooms is not between 1 and 7" do record.beds = 8 - record.unittype_gn = 5 - record.other_hhmemb = 2 + record.unittype_gn = 9 + record.hhmemb = 3 property_validator.validate_shared_housing_rooms(record) expect(record.errors["unittype_gn"]).to include(match(expected_error)) expect(record.errors["beds"]).to include(I18n.t("validations.property.unittype_gn.one_seven_bedroom_shared")) @@ -109,8 +109,8 @@ RSpec.describe Validations::PropertyValidations do it "adds an error if the number of bedrooms is not between 1 and 7" do record.beds = 0 - record.unittype_gn = 5 - record.other_hhmemb = 2 + record.unittype_gn = 9 + record.hhmemb = 3 property_validator.validate_shared_housing_rooms(record) expect(record.errors["unittype_gn"]).to include(match(expected_error)) expect(record.errors["beds"]).to include(I18n.t("validations.property.unittype_gn.one_seven_bedroom_shared")) @@ -122,8 +122,8 @@ RSpec.describe Validations::PropertyValidations do it "adds an error" do record.beds = 4 - record.unittype_gn = 5 - record.other_hhmemb = 0 + record.unittype_gn = 9 + record.hhmemb = 1 property_validator.validate_shared_housing_rooms(record) expect(record.errors["unittype_gn"]).to include(match(expected_error)) expect(record.errors["beds"]).to include(I18n.t("validations.property.unittype_gn.one_three_bedroom_single_tenant_shared")) @@ -286,7 +286,7 @@ RSpec.describe Validations::PropertyValidations do it "validates that the property is not being relet to tenant who occupied as temporary" do non_temporary_previous_tenancies.each do |prevten| - record.rsnvac = 2 + record.rsnvac = 9 record.prevten = prevten property_validator.validate_rsnvac(record) expect(record.errors["rsnvac"]) @@ -296,7 +296,7 @@ RSpec.describe Validations::PropertyValidations do it "validates that the letting source is not a referral" do referral_sources.each do |src| - record.rsnvac = 2 + record.rsnvac = 9 record.referral = src property_validator.validate_rsnvac(record) expect(record.errors["rsnvac"]) diff --git a/spec/models/validations/setup_validations_spec.rb b/spec/models/validations/setup_validations_spec.rb index 0c333d6d7..56b335464 100644 --- a/spec/models/validations/setup_validations_spec.rb +++ b/spec/models/validations/setup_validations_spec.rb @@ -6,28 +6,28 @@ RSpec.describe Validations::SetupValidations do let(:setup_validator_class) { Class.new { include Validations::SetupValidations } } let(:record) { FactoryBot.create(:case_log) } - describe "#validate_intermediate_rent_product_name" do + describe "#validate_irproduct" do it "adds an error when the intermediate rent product name is not provided but the rent type was given as other intermediate rent product" do record.rent_type = 5 - record.intermediate_rent_product_name = nil - setup_validator.validate_intermediate_rent_product_name(record) - expect(record.errors["intermediate_rent_product_name"]) + record.irproduct_other = nil + setup_validator.validate_irproduct_other(record) + expect(record.errors["irproduct_other"]) .to include(match I18n.t("validations.setup.intermediate_rent_product_name.blank")) end it "adds an error when the intermediate rent product name is blank but the rent type was given as other intermediate rent product" do record.rent_type = 5 - record.intermediate_rent_product_name = "" - setup_validator.validate_intermediate_rent_product_name(record) - expect(record.errors["intermediate_rent_product_name"]) + record.irproduct_other = "" + setup_validator.validate_irproduct_other(record) + expect(record.errors["irproduct_other"]) .to include(match I18n.t("validations.setup.intermediate_rent_product_name.blank")) end it "Does not add an error when the intermediate rent product name is provided and the rent type was given as other intermediate rent product" do record.rent_type = 5 - record.intermediate_rent_product_name = "Example" - setup_validator.validate_intermediate_rent_product_name(record) - expect(record.errors["intermediate_rent_product_name"]).to be_empty + record.irproduct_other = "Example" + setup_validator.validate_irproduct_other(record) + expect(record.errors["irproduct_other"]).to be_empty end end end diff --git a/spec/models/validations/tenancy_validations_spec.rb b/spec/models/validations/tenancy_validations_spec.rb index 689a7f383..711b1481a 100644 --- a/spec/models/validations/tenancy_validations_spec.rb +++ b/spec/models/validations/tenancy_validations_spec.rb @@ -12,7 +12,7 @@ RSpec.describe Validations::TenancyValidations do let(:expected_error) { I18n.t("validations.tenancy.length.fixed_term_not_required") } it "tenancy length should not be present" do - record.tenancy = 4 + record.tenancy = 3 record.tenancylength = 10 tenancy_validator.validate_fixed_term_tenancy(record) expect(record.errors["tenancylength"]).to include(match(expected_error)) @@ -23,9 +23,10 @@ RSpec.describe Validations::TenancyValidations do context "when type of tenancy is assured shorthold" do let(:expected_error) { I18n.t("validations.tenancy.length.shorthold") } + before { record.tenancy = 4 } + context "when tenancy length is greater than 1" do it "adds an error" do - record.tenancy = 1 record.tenancylength = 1 tenancy_validator.validate_fixed_term_tenancy(record) expect(record.errors["tenancylength"]).to include(match(expected_error)) @@ -35,7 +36,6 @@ RSpec.describe Validations::TenancyValidations do context "when tenancy length is less than 100" do it "adds an error" do - record.tenancy = 1 record.tenancylength = 100 tenancy_validator.validate_fixed_term_tenancy(record) expect(record.errors["tenancylength"]).to include(match(expected_error)) @@ -45,7 +45,6 @@ RSpec.describe Validations::TenancyValidations do context "when tenancy length is between 2-99" do it "does not add an error" do - record.tenancy = 1 record.tenancylength = 3 tenancy_validator.validate_fixed_term_tenancy(record) expect(record.errors["tenancylength"]).to be_empty @@ -55,7 +54,6 @@ RSpec.describe Validations::TenancyValidations do context "when tenancy length has not been answered" do it "does not add an error" do - record.tenancy = 1 record.tenancylength = nil tenancy_validator.validate_fixed_term_tenancy(record) expect(record.errors["tenancylength"]).to be_empty @@ -67,9 +65,10 @@ RSpec.describe Validations::TenancyValidations do context "when type of tenancy is secure" do let(:expected_error) { I18n.t("validations.tenancy.length.secure") } + before { record.tenancy = 1 } + context "when tenancy length is greater than 1" do it "adds an error" do - record.tenancy = 3 record.tenancylength = 1 tenancy_validator.validate_fixed_term_tenancy(record) expect(record.errors["tenancylength"]).to include(match(expected_error)) @@ -79,7 +78,6 @@ RSpec.describe Validations::TenancyValidations do context "when tenancy length is less than 100" do it "adds an error" do - record.tenancy = 3 record.tenancylength = 100 tenancy_validator.validate_fixed_term_tenancy(record) expect(record.errors["tenancylength"]).to include(match(expected_error)) @@ -89,7 +87,6 @@ RSpec.describe Validations::TenancyValidations do context "when tenancy length is between 2-99" do it "does not add an error" do - record.tenancy = 3 record.tenancylength = 3 tenancy_validator.validate_fixed_term_tenancy(record) expect(record.errors["tenancylength"]).to be_empty @@ -99,7 +96,6 @@ RSpec.describe Validations::TenancyValidations do context "when tenancy length has not been answered" do it "does not add an error" do - record.tenancy = 3 record.tenancylength = nil tenancy_validator.validate_fixed_term_tenancy(record) expect(record.errors["tenancylength"]).to be_empty @@ -117,15 +113,15 @@ RSpec.describe Validations::TenancyValidations do let(:expected_error) { I18n.t(field, main_field_label:, other_field_label:) } context "when tenancy type is other" do + before { record.tenancy = 3 } + it "validates that other tenancy type is provided" do - record.tenancy = 4 record.tenancyother = nil tenancy_validator.validate_other_tenancy_type(record) expect(record.errors[other_field_label]).to include(match(expected_error)) end it "expects that other tenancy type is provided" do - record.tenancy = 4 record.tenancyother = "Some other tenancy type" tenancy_validator.validate_other_tenancy_type(record) expect(record.errors[other_field_label]).to be_empty @@ -136,14 +132,14 @@ RSpec.describe Validations::TenancyValidations do let(:field) { "validations.other_field_not_required" } it "validates that other tenancy type is not provided" do - record.tenancy = 0 + record.tenancy = 2 record.tenancyother = "Some other tenancy type" tenancy_validator.validate_other_tenancy_type(record) expect(record.errors[other_field_label]).to include(match(expected_error)) end it "expects that other tenancy type is not provided" do - record.tenancy = 3 + record.tenancy = 1 record.tenancyother = nil tenancy_validator.validate_other_tenancy_type(record) expect(record.errors[other_field_label]).to be_empty diff --git a/spec/requests/form_controller_spec.rb b/spec/requests/form_controller_spec.rb index 32d8016d9..8e99f7e78 100644 --- a/spec/requests/form_controller_spec.rb +++ b/spec/requests/form_controller_spec.rb @@ -248,9 +248,7 @@ RSpec.describe FormController, type: :request do "housingneeds_f" => "Other disability requirements", "housingneeds_g" => "No disability requirements", "divider_a" => true, - "housingneeds_h" => "Don’t know", - "divider_b" => true, - "accessibility_requirements_prefer_not_to_say" => "Prefer not to say" }, + "housingneeds_h" => "Don’t know" }, }, nil ), Form::Question.new("tenant_code", { "type" => "text" }, nil), @@ -277,7 +275,7 @@ RSpec.describe FormController, type: :request do id: case_log.id, case_log: { page: "conditional_question", - preg_occ: 0, + preg_occ: 1, }, } end @@ -286,7 +284,7 @@ RSpec.describe FormController, type: :request do id: case_log.id, case_log: { page: "conditional_question", - preg_occ: 1, + preg_occ: 2, }, } end diff --git a/spec/services/imports/case_logs_import_service_spec.rb b/spec/services/imports/case_logs_import_service_spec.rb new file mode 100644 index 000000000..55b6cadca --- /dev/null +++ b/spec/services/imports/case_logs_import_service_spec.rb @@ -0,0 +1,34 @@ +require "rails_helper" + +RSpec.describe Imports::CaseLogsImportService do + let(:remote_folder) { "case_logs" } + let(:fixture_directory) { "spec/fixtures/softwire_imports/case_logs" } + let(:case_log_id) { "0ead17cb-1668-442d-898c-0d52879ff592" } + let(:case_log_id2) { "166fc004-392e-47a8-acb8-1c018734882b" } + let(:case_log_file) { File.open("#{fixture_directory}/#{case_log_id}.xml") } + let(:case_log_file2) { File.open("#{fixture_directory}/#{case_log_id2}.xml") } + let(:storage_service) { instance_double(StorageService) } + let(:real_2021_2022_form) { Form.new("config/forms/2021_2022.json", "2021_2022") } + + context "when importing users" do + subject(:case_log_service) { described_class.new(storage_service) } + + before do + # Stub the S3 file listing and download + allow(storage_service).to receive(:list_files) + .and_return(%W[#{remote_folder}/#{case_log_id}.xml #{remote_folder}/#{case_log_id2}.xml]) + allow(storage_service).to receive(:get_file_io) + .with("#{remote_folder}/#{case_log_id}.xml") + .and_return(case_log_file) + allow(storage_service).to receive(:get_file_io) + .with("#{remote_folder}/#{case_log_id2}.xml") + .and_return(case_log_file2) + # Stub the form handler to use the real form + allow(FormHandler.instance).to receive(:get_form).with(anything).and_return(real_2021_2022_form) + end + + it "successfully create a case log with the expected data" do + case_log_service.create_logs(remote_folder) + end + end +end From 4f1df84d36a7e6fa233ddc04f856f13bcfad26b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Meny?= Date: Wed, 20 Apr 2022 18:09:32 +0100 Subject: [PATCH 12/25] Rename attribute irproduct_other in JSON (#481) --- config/forms/2021_2022.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/config/forms/2021_2022.json b/config/forms/2021_2022.json index 2ede442db..71ab5ad47 100644 --- a/config/forms/2021_2022.json +++ b/config/forms/2021_2022.json @@ -90,12 +90,12 @@ } }, "conditional_for": { - "intermediate_rent_product_name": [ + "irproduct_other": [ 5 ] } }, - "intermediate_rent_product_name": { + "irproduct_other": { "check_answer_label": "Product name", "header": "Name of rent product", "type": "text" From d0484c63bbd3a19211e3ef9afe1cf9a921ca6199 Mon Sep 17 00:00:00 2001 From: Paul Robert Lloyd Date: Wed, 20 Apr 2022 17:07:34 +0100 Subject: [PATCH 13/25] Add ERB Lint --- .erb-lint.yml | 24 ++++++++++++++++++++++++ Gemfile | 1 + Gemfile.lock | 19 +++++++++++++++++++ 3 files changed, 44 insertions(+) create mode 100644 .erb-lint.yml diff --git a/.erb-lint.yml b/.erb-lint.yml new file mode 100644 index 000000000..2d88a7447 --- /dev/null +++ b/.erb-lint.yml @@ -0,0 +1,24 @@ +--- +EnableDefaultLinters: true +linters: + Rubocop: + enabled: true + rubocop_config: + inherit_from: + - .rubocop.yml + Layout/ArgumentAlignment: + Enabled: false + Layout/CommentIndentation: + Enabled: false + Layout/FirstArgumentIndentation: + Enabled: false + Layout/FirstArrayElementIndentation: + Enabled: false + Layout/FirstHashElementIndentation: + Enabled: false + Layout/InitialIndentation: + Enabled: false + Layout/TrailingEmptyLines: + Enabled: false + Lint/UselessAssignment: + Enabled: false diff --git a/Gemfile b/Gemfile index 09562e673..9fc19e4d0 100644 --- a/Gemfile +++ b/Gemfile @@ -78,6 +78,7 @@ group :development do gem "web-console", ">= 4.1.0" # Display performance information such as SQL time and flame graphs for each request in your browser. # Can be configured to work on production as well see: https://github.com/MiniProfiler/rack-mini-profiler/blob/master/README.md + gem "erb_lint", require: false gem "rack-mini-profiler", "~> 2.0" gem "rubocop-govuk", require: false gem "rubocop-performance", require: false diff --git a/Gemfile.lock b/Gemfile.lock index 62d70821c..00b5c74e2 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -121,6 +121,14 @@ GEM aws-sigv4 (1.4.0) aws-eventstream (~> 1, >= 1.0.2) bcrypt (3.1.17) + better_html (1.0.16) + actionview (>= 4.0) + activesupport (>= 4.0) + ast (~> 2.0) + erubi (~> 1.4) + html_tokenizer (~> 0.0.6) + parser (>= 2.4) + smart_properties bindex (0.8.1) bootsnap (1.11.1) msgpack (~> 1.2) @@ -159,6 +167,14 @@ GEM dotenv (= 2.7.6) railties (>= 3.2) encryptor (3.0.0) + erb_lint (0.1.1) + activesupport + better_html (~> 1.0.7) + html_tokenizer + parser (>= 2.7.1.4) + rainbow + rubocop + smart_properties erubi (1.10.0) excon (0.92.2) factory_bot (6.2.1) @@ -188,6 +204,7 @@ GEM actionpack (>= 5.2) activesupport (>= 5.2) hashdiff (1.0.1) + html_tokenizer (0.0.7) i18n (1.10.0) concurrent-ruby (~> 1.0) inherited_resources (1.13.1) @@ -420,6 +437,7 @@ GEM simplecov_json_formatter (~> 0.1) simplecov-html (0.12.3) simplecov_json_formatter (0.1.4) + smart_properties (1.17.0) stimulus-rails (1.0.4) railties (>= 6.0.0) strscan (3.0.1) @@ -469,6 +487,7 @@ DEPENDENCIES chartkick devise! dotenv-rails + erb_lint factory_bot_rails govuk-components govuk_design_system_formbuilder From 42cb583332d0ba1433c7806e1cc7f60687d5b22c Mon Sep 17 00:00:00 2001 From: Paul Robert Lloyd Date: Wed, 20 Apr 2022 18:03:36 +0100 Subject: [PATCH 14/25] Run default linters on ERB templates --- app/views/case_logs/_log_list.html.erb | 1 - app/views/case_logs/bulk_upload.html.erb | 5 +- app/views/case_logs/index.html.erb | 3 +- app/views/devise/confirmations/new.html.erb | 3 +- app/views/devise/passwords/edit.html.erb | 6 +- app/views/devise/passwords/new.html.erb | 3 +- .../devise/passwords/reset_password.html.erb | 6 +- app/views/devise/sessions/new.html.erb | 6 +- app/views/devise/shared/_links.html.erb | 12 ++-- .../two_factor_authentication/show.html.erb | 3 +- app/views/devise/unlocks/new.html.erb | 3 +- app/views/form/_check_answers_table.html.erb | 4 +- app/views/form/_checkbox_question.html.erb | 3 +- app/views/form/_date_question.html.erb | 11 ++-- .../_interruption_screen_question.html.erb | 5 +- app/views/form/_numeric_question.html.erb | 17 +++--- app/views/form/_radio_question.html.erb | 55 +++++++++---------- app/views/form/_select_question.html.erb | 5 +- app/views/form/_text_question.html.erb | 11 ++-- app/views/form/_textarea_question.html.erb | 11 ++-- app/views/form/check_answers.html.erb | 2 +- app/views/form/page.html.erb | 10 ++-- app/views/layouts/application.html.erb | 34 ++++++------ app/views/layouts/mailer.html.erb | 2 +- app/views/organisations/edit.html.erb | 15 ++--- app/views/pagy/_nav.html.erb | 6 +- app/views/users/edit.html.erb | 15 ++--- app/views/users/new.html.erb | 15 ++--- spec/features/reset_password.html.erb | 6 +- 29 files changed, 119 insertions(+), 159 deletions(-) diff --git a/app/views/case_logs/_log_list.html.erb b/app/views/case_logs/_log_list.html.erb index a2fe5645c..cf6b3927e 100644 --- a/app/views/case_logs/_log_list.html.erb +++ b/app/views/case_logs/_log_list.html.erb @@ -59,4 +59,3 @@ - diff --git a/app/views/case_logs/bulk_upload.html.erb b/app/views/case_logs/bulk_upload.html.erb index 2ae6b94a9..1d6017972 100644 --- a/app/views/case_logs/bulk_upload.html.erb +++ b/app/views/case_logs/bulk_upload.html.erb @@ -5,8 +5,7 @@ <%= f.govuk_file_field :case_log_bulk_upload, label: { text: content_for(:title), size: "l" }, - hint: { text: "Upload a spreadsheet using the template" } - %> + hint: { text: "Upload a spreadsheet using the template" } %> - <%= f.govuk_submit "Upload" %> + <%= f.govuk_submit "Upload" %> <% end %> diff --git a/app/views/case_logs/index.html.erb b/app/views/case_logs/index.html.erb index c3ddfb7b8..0812fefc4 100644 --- a/app/views/case_logs/index.html.erb +++ b/app/views/case_logs/index.html.erb @@ -9,7 +9,7 @@ <%#= govuk_link_to "Upload logs", bulk_upload_case_logs_path %>
    - <%= render partial: "log_filters"%> + <%= render partial: "log_filters" %> <% if @case_logs.present? %>
    <%= render partial: "log_list", locals: { case_logs: @case_logs, title: "Logs", pagy: @pagy } %> @@ -17,4 +17,3 @@
    <% end %>
    - diff --git a/app/views/devise/confirmations/new.html.erb b/app/views/devise/confirmations/new.html.erb index ac0537c68..fe57a4a06 100644 --- a/app/views/devise/confirmations/new.html.erb +++ b/app/views/devise/confirmations/new.html.erb @@ -7,8 +7,7 @@ label: { text: "Email address" }, autocomplete: "email", spellcheck: "false", - value: (resource.pending_reconfirmation? ? resource.unconfirmed_email : resource.email) - %> + value: (resource.pending_reconfirmation? ? resource.unconfirmed_email : resource.email) %> <%= f.govuk_submit "Resend confirmation instructions" %> <% end %> diff --git a/app/views/devise/passwords/edit.html.erb b/app/views/devise/passwords/edit.html.erb index 68ff77514..74e5cc3a9 100644 --- a/app/views/devise/passwords/edit.html.erb +++ b/app/views/devise/passwords/edit.html.erb @@ -19,12 +19,10 @@ <%= f.govuk_password_field :password, label: { text: "New password" }, hint: @minimum_password_length ? { text: "Your password must be at least #{@minimum_password_length} characters and hard to guess." } : nil, - autocomplete: "new-password" - %> + autocomplete: "new-password" %> <%= f.govuk_password_field :password_confirmation, - label: { text: "Confirm new password" } - %> + label: { text: "Confirm new password" } %> <%= f.govuk_submit "Update" %>
    diff --git a/app/views/devise/passwords/new.html.erb b/app/views/devise/passwords/new.html.erb index bd0ae816b..3982b6e61 100644 --- a/app/views/devise/passwords/new.html.erb +++ b/app/views/devise/passwords/new.html.erb @@ -22,8 +22,7 @@ <%= f.govuk_email_field :email, label: { text: "Email address" }, autocomplete: "email", - spellcheck: "false" - %> + spellcheck: "false" %> <%= f.govuk_submit "Send email" %>
    diff --git a/app/views/devise/passwords/reset_password.html.erb b/app/views/devise/passwords/reset_password.html.erb index bd96a9c5d..bd57b7611 100644 --- a/app/views/devise/passwords/reset_password.html.erb +++ b/app/views/devise/passwords/reset_password.html.erb @@ -20,12 +20,10 @@ <%= f.govuk_password_field :password, label: { text: "New password" }, hint: @minimum_password_length ? { text: "Your password must be at least #{@minimum_password_length} characters and hard to guess." } : nil, - autocomplete: "new-password" - %> + autocomplete: "new-password" %> <%= f.govuk_password_field :password_confirmation, - label: { text: "Confirm new password" } - %> + label: { text: "Confirm new password" } %> <%= f.govuk_submit "Update" %>
    diff --git a/app/views/devise/sessions/new.html.erb b/app/views/devise/sessions/new.html.erb index 9daa5fab6..aeb260b96 100644 --- a/app/views/devise/sessions/new.html.erb +++ b/app/views/devise/sessions/new.html.erb @@ -19,12 +19,10 @@ <%= f.govuk_email_field :email, label: { text: "Email address" }, autocomplete: "email", - spellcheck: "false" - %> + spellcheck: "false" %> <%= f.govuk_password_field :password, - autocomplete: "current-password" - %> + autocomplete: "current-password" %> <%= f.hidden_field :start, value: request["start"] %> <%= f.govuk_submit "Sign in" %> diff --git a/app/views/devise/shared/_links.html.erb b/app/views/devise/shared/_links.html.erb index f66521541..05035e08b 100644 --- a/app/views/devise/shared/_links.html.erb +++ b/app/views/devise/shared/_links.html.erb @@ -1,25 +1,25 @@ <%- if controller_name != 'sessions' %> -

    Already have an account? <%= govuk_link_to "Sign in", new_session_path(resource_name) %>.


    +

    Already have an account? <%= govuk_link_to "Sign in", new_session_path(resource_name) %>.

    <% end %> <%- if devise_mapping.registerable? && controller_name != 'registrations' %> - <%= govuk_link_to "Sign up", new_registration_path(resource_name) %>
    + <%= govuk_link_to "Sign up", new_registration_path(resource_name) %>
    <% end %> <%- if devise_mapping.recoverable? && controller_name != 'passwords' && controller_name != 'registrations' %> -

    You can <%= govuk_link_to "reset your password", new_password_path(resource_name) %> if you’ve forgotten it.


    +

    You can <%= govuk_link_to "reset your password", new_password_path(resource_name) %> if you’ve forgotten it.

    <% end %> <%- if devise_mapping.confirmable? && controller_name != 'confirmations' %> - <%= govuk_link_to "Didn’t receive confirmation instructions?", new_confirmation_path(resource_name) %>
    + <%= govuk_link_to "Didn’t receive confirmation instructions?", new_confirmation_path(resource_name) %>
    <% end %> <%- if devise_mapping.lockable? && resource_class.unlock_strategy_enabled?(:email) && controller_name != 'unlocks' %> - <%= govuk_link_to "Didn’t receive unlock instructions?", new_unlock_path(resource_name) %>
    + <%= govuk_link_to "Didn’t receive unlock instructions?", new_unlock_path(resource_name) %>
    <% end %> <%- if devise_mapping.omniauthable? %> <%- resource_class.omniauth_providers.each do |provider| %> - <%= govuk_link_to "Sign in with #{OmniAuth::Utils.camelize(provider)}", omniauth_authorize_path(resource_name, provider), method: :post %>
    + <%= govuk_link_to "Sign in with #{OmniAuth::Utils.camelize(provider)}", omniauth_authorize_path(resource_name, provider), method: :post %>
    <% end %> <% end %> diff --git a/app/views/devise/two_factor_authentication/show.html.erb b/app/views/devise/two_factor_authentication/show.html.erb index 5177f012e..008377b3c 100644 --- a/app/views/devise/two_factor_authentication/show.html.erb +++ b/app/views/devise/two_factor_authentication/show.html.erb @@ -16,8 +16,7 @@ label: { text: "Security code", size: "m" }, width: 5, autocomplete: 'one-time-code', - autofocus: true - %> + autofocus: true %> <%= f.govuk_submit "Submit" %>
    diff --git a/app/views/devise/unlocks/new.html.erb b/app/views/devise/unlocks/new.html.erb index c20182b23..4f0de4c0b 100644 --- a/app/views/devise/unlocks/new.html.erb +++ b/app/views/devise/unlocks/new.html.erb @@ -6,8 +6,7 @@ <%= f.govuk_email_field :email, label: { text: "Email address" }, autocomplete: "email", - spellcheck: "false" - %> + spellcheck: "false" %> <%= f.govuk_submit "Resend unlock instructions" %> <% end %> diff --git a/app/views/form/_check_answers_table.html.erb b/app/views/form/_check_answers_table.html.erb index ae22a0c14..f72381d12 100644 --- a/app/views/form/_check_answers_table.html.erb +++ b/app/views/form/_check_answers_table.html.erb @@ -3,9 +3,9 @@ <%= question.check_answer_label.to_s.present? ? question.check_answer_label.to_s : question.header.to_s %>
    - <%= get_answer_label(question, @case_log) %>
    + <%= get_answer_label(question, @case_log) %>
    <% question.get_inferred_answers(@case_log).each do |inferred_answer| %> - <%= inferred_answer %>
    + <%= inferred_answer %>
    <% end %>
    diff --git a/app/views/form/_checkbox_question.html.erb b/app/views/form/_checkbox_question.html.erb index 3c1bb0da9..941a32a17 100644 --- a/app/views/form/_checkbox_question.html.erb +++ b/app/views/form/_checkbox_question.html.erb @@ -16,8 +16,7 @@ hint: { text: options['hint'] }, checked: @case_log[key] == 1, exclusive: after_divider, - **stimulus_html_attributes(question) - %> + **stimulus_html_attributes(question) %> <% end %> <% end %> <% end %> diff --git a/app/views/form/_date_question.html.erb b/app/views/form/_date_question.html.erb index c453e1019..c9862037d 100644 --- a/app/views/form/_date_question.html.erb +++ b/app/views/form/_date_question.html.erb @@ -1,9 +1,8 @@ <%= render partial: "form/guidance/#{question.guidance_partial}" if question.guidance_partial %> <%= f.govuk_date_field question.id.to_sym, - caption: caption(caption_text, page_header, conditional), - legend: legend(question, page_header, conditional), - hint: { text: question.hint_text&.html_safe }, - width: 20, - **stimulus_html_attributes(question) -%> + caption: caption(caption_text, page_header, conditional), + legend: legend(question, page_header, conditional), + hint: { text: question.hint_text&.html_safe }, + width: 20, + **stimulus_html_attributes(question) %> diff --git a/app/views/form/_interruption_screen_question.html.erb b/app/views/form/_interruption_screen_question.html.erb index 36c797064..923d323b3 100644 --- a/app/views/form/_interruption_screen_question.html.erb +++ b/app/views/form/_interruption_screen_question.html.erb @@ -14,10 +14,9 @@ key, label: { text: options['value'] }, hint: { text: options['hint'] }, - **stimulus_html_attributes(question) - %> + **stimulus_html_attributes(question) %> <% end %> <% end %> <% end %> <%= f.govuk_submit "Save and continue", accesskey: "s", class: "app-button--inverse govuk-!-margin-bottom-0" %> -<% end %> \ No newline at end of file +<% end %> diff --git a/app/views/form/_numeric_question.html.erb b/app/views/form/_numeric_question.html.erb index 1e9702310..933cf7abd 100644 --- a/app/views/form/_numeric_question.html.erb +++ b/app/views/form/_numeric_question.html.erb @@ -1,12 +1,11 @@ <%= render partial: "form/guidance/#{question.guidance_partial}" if question.guidance_partial %> <%= f.govuk_number_field question.id.to_sym, - caption: caption(caption_text, page_header, conditional), - label: legend(question, page_header, conditional), - hint: { text: question.hint_text&.html_safe }, - min: question.min, max: question.max, step: question.step, - width: question.width, :readonly => question.read_only?, - prefix_text: question.prefix.to_s, - suffix_text: question.suffix.is_a?(String) ? question.suffix : nil, - **stimulus_html_attributes(question) -%> + caption: caption(caption_text, page_header, conditional), + label: legend(question, page_header, conditional), + hint: { text: question.hint_text&.html_safe }, + min: question.min, max: question.max, step: question.step, + width: question.width, :readonly => question.read_only?, + prefix_text: question.prefix.to_s, + suffix_text: question.suffix.is_a?(String) ? question.suffix : nil, + **stimulus_html_attributes(question) %> diff --git a/app/views/form/_radio_question.html.erb b/app/views/form/_radio_question.html.erb index 12a8052b1..5b770994a 100644 --- a/app/views/form/_radio_question.html.erb +++ b/app/views/form/_radio_question.html.erb @@ -1,37 +1,36 @@ <%= render partial: "form/guidance/#{question.guidance_partial}" if question.guidance_partial %> <%= f.govuk_radio_buttons_fieldset question.id.to_sym, - caption: caption(caption_text, page_header, conditional), - legend: legend(question, page_header, conditional), - hint: { text: question.hint_text&.html_safe } do %> + caption: caption(caption_text, page_header, conditional), + legend: legend(question, page_header, conditional), + hint: { text: question.hint_text&.html_safe } do %> - <% question.displayed_answer_options.map do |key, options| %> - <% if key.starts_with?("divider") %> - <%= f.govuk_radio_divider %> + <% question.displayed_answer_options.map do |key, options| %> + <% if key.starts_with?("divider") %> + <%= f.govuk_radio_divider %> + <% else %> + <% conditional_question = find_conditional_question(@page, question, key) %> + <% if conditional_question.nil? %> + <%= f.govuk_radio_button question.id, + key, + label: { text: options['value'] }, + hint: { text: options['hint'] }, + **stimulus_html_attributes(question) %> <% else %> - <% conditional_question = find_conditional_question(@page, question, key) %> - <% if conditional_question.nil? %> - <%= f.govuk_radio_button question.id, - key, - label: { text: options['value'] }, - hint: { text: options['hint'] }, - **stimulus_html_attributes(question) - %> - <% else %> - <%= f.govuk_radio_button question.id, - key, - label: { text: options['value'] }, - hint: { text: options['hint'] }, - **stimulus_html_attributes(question) do %> - <%= render partial: "#{conditional_question.type}_question", locals: { - question: conditional_question, - caption_text: caption_text, - page_header: page_header, - f: f, - conditional: true - } %> - <% end %> + <%= f.govuk_radio_button question.id, + key, + label: { text: options['value'] }, + hint: { text: options['hint'] }, + **stimulus_html_attributes(question) do %> + <%= render partial: "#{conditional_question.type}_question", locals: { + question: conditional_question, + caption_text: caption_text, + page_header: page_header, + f: f, + conditional: true + } %> <% end %> <% end %> <% end %> + <% end %> <% end %> diff --git a/app/views/form/_select_question.html.erb b/app/views/form/_select_question.html.erb index 88a080bda..d758f3a85 100644 --- a/app/views/form/_select_question.html.erb +++ b/app/views/form/_select_question.html.erb @@ -2,7 +2,7 @@ <% selected = @case_log.public_send(question.id) || "" %> <%= answers = question.displayed_answer_options.map { |key, value| OpenStruct.new(id: key, name: value) } - f.govuk_collection_select question.id.to_sym, + f.govuk_collection_select question.id.to_sym, answers, :id, :name, @@ -10,5 +10,4 @@ label: legend(question, page_header, conditional), hint: { text: question.hint_text&.html_safe }, options: { disabled: [""], selected: selected }, - "data-controller": "accessible-autocomplete" - %> + "data-controller": "accessible-autocomplete" %> diff --git a/app/views/form/_text_question.html.erb b/app/views/form/_text_question.html.erb index 1fb67b84a..f842982bd 100644 --- a/app/views/form/_text_question.html.erb +++ b/app/views/form/_text_question.html.erb @@ -1,9 +1,8 @@ <%= render partial: "form/guidance/#{question.guidance_partial}" if question.guidance_partial %> <%= f.govuk_text_field question.id.to_sym, - caption: caption(caption_text, page_header, conditional), - label: legend(question, page_header, conditional), - hint: { text: question.hint_text&.html_safe }, - width: question.width ? question.width : nil, - **stimulus_html_attributes(question) -%> + caption: caption(caption_text, page_header, conditional), + label: legend(question, page_header, conditional), + hint: { text: question.hint_text&.html_safe }, + width: question.width ? question.width : nil, + **stimulus_html_attributes(question) %> diff --git a/app/views/form/_textarea_question.html.erb b/app/views/form/_textarea_question.html.erb index 59a8ca163..5499b100b 100644 --- a/app/views/form/_textarea_question.html.erb +++ b/app/views/form/_textarea_question.html.erb @@ -1,9 +1,8 @@ <%= render partial: "form/guidance/#{question.guidance_partial}" if question.guidance_partial %> <%= f.govuk_text_area question.id.to_sym, - caption: caption(caption_text, page_header, conditional), - label: legend(question, page_header, conditional), - hint: { text: question.hint_text&.html_safe }, - width: question.width ? question.width : nil, - **stimulus_html_attributes(question) -%> + caption: caption(caption_text, page_header, conditional), + label: legend(question, page_header, conditional), + hint: { text: question.hint_text&.html_safe }, + width: question.width ? question.width : nil, + **stimulus_html_attributes(question) %> diff --git a/app/views/form/check_answers.html.erb b/app/views/form/check_answers.html.erb index c4c8b023c..fb912990c 100644 --- a/app/views/form/check_answers.html.erb +++ b/app/views/form/check_answers.html.erb @@ -26,7 +26,7 @@ <%= govuk_button_link_to 'Save and go to next incomplete section', "/logs/#{@case_log.id}/#{@case_log.form.next_incomplete_section_redirect_path(subsection, @case_log)}", secondary: true %> <% elsif @case_log.status == "completed" || @case_log.form.all_subsections_except_declaration_completed?(@case_log) %> <%= govuk_button_link_to 'Save and go to submit', "/logs/#{@case_log.id}/#{@case_log.form.next_incomplete_section_redirect_path(subsection, @case_log)}", secondary: true %> - <% end%> + <% end %> <% end %> <% end %>
    diff --git a/app/views/form/page.html.erb b/app/views/form/page.html.erb index ab006ccdc..2a09d6253 100644 --- a/app/views/form/page.html.erb +++ b/app/views/form/page.html.erb @@ -11,7 +11,7 @@ <%= form_with model: @case_log, url: form_case_log_path(@case_log), method: "post", local: true do |f| %>
    -
    > +
    "> <% remove_other_page_errors(@case_log, @page) %> <%= f.govuk_error_summary %> @@ -29,7 +29,7 @@ <% end %> <% @page.non_conditional_questions.map do |question| %> -
    <%= display_question_key_div(@page, question) %> > +
    > <% if question.read_only? %>
    <% end %> @@ -44,11 +44,11 @@ <%= f.hidden_field :page, value: @page.id %> <% if @case_log.form.is_last_question?(@page, @subsection, @case_log) %> <%= f.govuk_submit "Submit lettings log", accesskey: "s" %> - <%else %> + <% else %> <% if !@page.id.include?("value_check") %> - <%= f.govuk_submit "Save and continue", accesskey: "s" %> + <%= f.govuk_submit "Save and continue", accesskey: "s" %> <% end %> - <%end %> + <% end %>
    <% end %> diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index c46d256dd..9b0ba04b7 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -15,10 +15,10 @@ <%= favicon_link_tag asset_path('images/govuk-apple-touch-icon-180x180.png'), rel: 'apple-touch-icon', type: 'image/png', size: '180x180' %> <%= stylesheet_link_tag "application" %> <%= javascript_include_tag "vendor/html5shiv.min.js" %> - <%= javascript_tag do -%> + <%= javascript_include_tag "vendor/polyfill-output-value.js" %> <%= javascript_include_tag "vendor/outerHTML.js" %> <%= javascript_include_tag "application", defer: true %> @@ -43,20 +43,19 @@ <%= govuk_skip_link %> <%= govuk_header( - logotype: 'GOV.UK', - service_name: t('service_name'), - service_url: current_user.nil? ? "/" : '/logs' - ) do |component| - if current_user.nil? - component.navigation_item(text: 'Sign in', href: user_session_path) - elsif - component.navigation_item(text: 'Logs', href: case_logs_path) - component.navigation_item(text: 'Your organisation', href: "/organisations/#{current_user.organisation.id}") - component.navigation_item(text: 'Your account', href: account_path) - component.navigation_item(text: 'Sign out', href: destroy_user_session_path) - end + logotype: 'GOV.UK', + service_name: t('service_name'), + service_url: current_user.nil? ? "/" : '/logs' + ) do |component| + if current_user.nil? + component.navigation_item(text: 'Sign in', href: user_session_path) + elsif + component.navigation_item(text: 'Logs', href: case_logs_path) + component.navigation_item(text: 'Your organisation', href: "/organisations/#{current_user.organisation.id}") + component.navigation_item(text: 'Your account', href: account_path) + component.navigation_item(text: 'Sign out', href: destroy_user_session_path) end - %> + end %>
    - <% if flash.notice && !flash.notice.include?('translation missing') %> + <% if flash.notice && !flash.notice.include?('translation missing') %> <%= govuk_notification_banner( title_text: 'Success', success: true, title_heading_level: 3, title_id: "swanky-notifications") do |notification_banner| notification_banner.heading(text: flash.notice) - end - %> + end %> <% end %> <%= content_for?(:content) ? yield(:content) : yield %>
    diff --git a/app/views/layouts/mailer.html.erb b/app/views/layouts/mailer.html.erb index cbd34d2e9..3aac9002e 100644 --- a/app/views/layouts/mailer.html.erb +++ b/app/views/layouts/mailer.html.erb @@ -1,7 +1,7 @@ - + diff --git a/app/views/organisations/edit.html.erb b/app/views/organisations/edit.html.erb index 43d8dab9a..b0c0d6adb 100644 --- a/app/views/organisations/edit.html.erb +++ b/app/views/organisations/edit.html.erb @@ -15,29 +15,24 @@ <%= f.govuk_text_field :name, - autocomplete: "name" - %> + autocomplete: "name" %> <%= f.govuk_text_field :address_line1, label: { text: "Address line 1" }, - autocomplete: "address-line1" - %> + autocomplete: "address-line1" %> <%= f.govuk_text_field :address_line2, label: { text: "Address line 2" }, - autocomplete: "address-line2" - %> + autocomplete: "address-line2" %> <%= f.govuk_text_field :postcode, autocomplete: "postal-code", - width: 10 - %> + width: 10 %> <%= f.govuk_phone_field :phone, label: { text: "Telephone number" }, autocomplete: "tel", - width: 20 - %> + width: 20 %> <%= f.govuk_submit "Save changes" %>
    diff --git a/app/views/pagy/_nav.html.erb b/app/views/pagy/_nav.html.erb index 9aa325e3d..d288ebddc 100644 --- a/app/views/pagy/_nav.html.erb +++ b/app/views/pagy/_nav.html.erb @@ -5,7 +5,7 @@
    diff --git a/spec/features/reset_password.html.erb b/spec/features/reset_password.html.erb index e12a0beed..a1735c5ec 100644 --- a/spec/features/reset_password.html.erb +++ b/spec/features/reset_password.html.erb @@ -20,12 +20,10 @@ <%= f.govuk_password_field :password, label: { text: "New password" }, hint: @minimum_password_length ? { text: "Your password must be at least #{@minimum_password_length} characters and hard to guess." } : nil, - autocomplete: "new-password" - %> + autocomplete: "new-password" %> <%= f.govuk_password_field :password_confirmation, - label: { text: "Confirm new password" } - %> + label: { text: "Confirm new password" } %> <%= f.govuk_submit "Update" %>
    From 716dc59acc1eb1a22b320a4ebad6fa54f668a1f9 Mon Sep 17 00:00:00 2001 From: Paul Robert Lloyd Date: Wed, 20 Apr 2022 20:10:48 +0100 Subject: [PATCH 15/25] Run Rubocop on ERB templates --- .../tab_navigation_component.html.erb | 4 +- app/views/case_logs/_log_list.html.erb | 10 +- app/views/case_logs/edit.html.erb | 2 +- app/views/case_logs/index.html.erb | 2 +- app/views/devise/passwords/edit.html.erb | 2 +- app/views/devise/passwords/new.html.erb | 2 +- .../devise/passwords/reset_password.html.erb | 2 +- .../two_factor_authentication/resend.html.erb | 4 +- .../two_factor_authentication/show.html.erb | 2 +- app/views/filters/_checkbox_filter.html.erb | 4 +- app/views/form/_check_answers_table.html.erb | 2 +- app/views/form/_checkbox_question.html.erb | 4 +- .../_interruption_screen_question.html.erb | 8 +- .../form/_numeric_output_question.html.erb | 2 +- app/views/form/_numeric_question.html.erb | 3 +- app/views/form/_radio_question.html.erb | 16 +-- app/views/form/_select_question.html.erb | 6 +- app/views/form/_text_question.html.erb | 2 +- app/views/form/_textarea_question.html.erb | 2 +- app/views/form/check_answers.html.erb | 12 +- .../guidance/_what_counts_as_income.html.erb | 2 +- app/views/form/page.html.erb | 10 +- .../layouts/_collection_resources.html.erb | 21 +-- app/views/layouts/application.html.erb | 53 ++++---- app/views/layouts/organisations.html.erb | 2 +- app/views/organisations/edit.html.erb | 2 +- app/views/organisations/show.html.erb | 24 ++-- app/views/organisations/users.html.erb | 20 +-- app/views/start/index.html.erb | 6 +- app/views/users/edit.html.erb | 10 +- app/views/users/new.html.erb | 11 +- app/views/users/show.html.erb | 122 ++++++++++-------- spec/features/reset_password.html.erb | 2 +- 33 files changed, 205 insertions(+), 171 deletions(-) diff --git a/app/components/tab_navigation_component.html.erb b/app/components/tab_navigation_component.html.erb index 874caaf39..871cd4cbf 100644 --- a/app/components/tab_navigation_component.html.erb +++ b/app/components/tab_navigation_component.html.erb @@ -3,11 +3,11 @@ <% items.each do |item| %> <% if item.fetch(:current, false) || current_page?(strip_query(item.fetch(:url))) %>
  • - <%= govuk_link_to item[:name], item[:url], class: 'app-tab-navigation__link', aria: { current: 'page' } %> + <%= govuk_link_to item[:name], item[:url], class: "app-tab-navigation__link", aria: { current: "page" } %>
  • <% else %>
  • - <%= govuk_link_to item[:name], item[:url], class: 'app-tab-navigation__link' %> + <%= govuk_link_to item[:name], item[:url], class: "app-tab-navigation__link" %>
  • <% end %> <% end %> diff --git a/app/views/case_logs/_log_list.html.erb b/app/views/case_logs/_log_list.html.erb index cf6b3927e..3cde563c5 100644 --- a/app/views/case_logs/_log_list.html.erb +++ b/app/views/case_logs/_log_list.html.erb @@ -28,21 +28,21 @@ <%= govuk_link_to log.id, case_log_path(log) %> - <%= log.tenant_code? ? log.tenant_code : '–' %> + <%= log.tenant_code? ? log.tenant_code : "–" %> - <%= log.propcode? ? log.propcode : '–' %> + <%= log.propcode? ? log.propcode : "–" %> - <%= log.startdate.present? ? log.startdate.to_formatted_s(:govuk_date) : '–' %> + <%= log.startdate.present? ? log.startdate.to_formatted_s(:govuk_date) : "–" %> <%= log.created_at.to_formatted_s(:govuk_date) %> <%= govuk_tag( - colour: log.status == 'completed' ? 'blue' : 'grey', - text: log.status.humanize + colour: log.status == "completed" ? "blue" : "grey", + text: log.status.humanize, ) %> <% if current_user.support? %> diff --git a/app/views/case_logs/edit.html.erb b/app/views/case_logs/edit.html.erb index 015db4454..26f3509d3 100644 --- a/app/views/case_logs/edit.html.erb +++ b/app/views/case_logs/edit.html.erb @@ -1,7 +1,7 @@ <% content_for :title, "Log #{@case_log.id}" %> <% content_for :breadcrumbs, govuk_breadcrumbs(breadcrumbs: { "Logs" => "/logs", - content_for(:title) => "" + content_for(:title) => "", }) %>
    diff --git a/app/views/case_logs/index.html.erb b/app/views/case_logs/index.html.erb index 0812fefc4..857b1dbd8 100644 --- a/app/views/case_logs/index.html.erb +++ b/app/views/case_logs/index.html.erb @@ -13,7 +13,7 @@ <% if @case_logs.present? %>
    <%= render partial: "log_list", locals: { case_logs: @case_logs, title: "Logs", pagy: @pagy } %> - <%== render partial: 'pagy/nav', locals: { pagy: @pagy, item_name: "logs" } %> + <%== render partial: "pagy/nav", locals: { pagy: @pagy, item_name: "logs" } %>
    <% end %>
    diff --git a/app/views/devise/passwords/edit.html.erb b/app/views/devise/passwords/edit.html.erb index 74e5cc3a9..579eb64c6 100644 --- a/app/views/devise/passwords/edit.html.erb +++ b/app/views/devise/passwords/edit.html.erb @@ -2,7 +2,7 @@ <% content_for :before_content do %> <%= govuk_back_link( - text: 'Back', + text: "Back", href: :back, ) %> <% end %> diff --git a/app/views/devise/passwords/new.html.erb b/app/views/devise/passwords/new.html.erb index 3982b6e61..b677b4c17 100644 --- a/app/views/devise/passwords/new.html.erb +++ b/app/views/devise/passwords/new.html.erb @@ -2,7 +2,7 @@ <% content_for :before_content do %> <%= govuk_back_link( - text: 'Back', + text: "Back", href: :back, ) %> <% end %> diff --git a/app/views/devise/passwords/reset_password.html.erb b/app/views/devise/passwords/reset_password.html.erb index bd57b7611..04353c7b2 100644 --- a/app/views/devise/passwords/reset_password.html.erb +++ b/app/views/devise/passwords/reset_password.html.erb @@ -2,7 +2,7 @@ <% content_for :before_content do %> <%= govuk_back_link( - text: 'Back', + text: "Back", href: :back, ) %> <% end %> diff --git a/app/views/devise/two_factor_authentication/resend.html.erb b/app/views/devise/two_factor_authentication/resend.html.erb index c8bb5eec5..a2cc00198 100644 --- a/app/views/devise/two_factor_authentication/resend.html.erb +++ b/app/views/devise/two_factor_authentication/resend.html.erb @@ -2,8 +2,8 @@ <% content_for :before_content do %> <%= govuk_back_link( - text: 'Back', - href: 'javascript:history.back()', + text: "Back", + href: "javascript:history.back()", ) %> <% end %> diff --git a/app/views/devise/two_factor_authentication/show.html.erb b/app/views/devise/two_factor_authentication/show.html.erb index 008377b3c..55df4caeb 100644 --- a/app/views/devise/two_factor_authentication/show.html.erb +++ b/app/views/devise/two_factor_authentication/show.html.erb @@ -15,7 +15,7 @@ <%= f.govuk_number_field :code, label: { text: "Security code", size: "m" }, width: 5, - autocomplete: 'one-time-code', + autocomplete: "one-time-code", autofocus: true %> <%= f.govuk_submit "Submit" %> diff --git a/app/views/filters/_checkbox_filter.html.erb b/app/views/filters/_checkbox_filter.html.erb index aa2fc71a4..cbbf5c39d 100644 --- a/app/views/filters/_checkbox_filter.html.erb +++ b/app/views/filters/_checkbox_filter.html.erb @@ -1,6 +1,6 @@ -<%= f.govuk_check_boxes_fieldset category.to_sym, legend: { text: label, size: "s"}, small: true, form_group: { classes: "app-filter__group" } do %> +<%= f.govuk_check_boxes_fieldset category.to_sym, legend: { text: label, size: "s" }, small: true, form_group: { classes: "app-filter__group" } do %> <% options.map do |key, option| %> - <%= f.govuk_check_box category, "#{key}", + <%= f.govuk_check_box category, key.to_s, label: { text: option }, checked: filter_selected?(category, key), size: "s" %> diff --git a/app/views/form/_check_answers_table.html.erb b/app/views/form/_check_answers_table.html.erb index f72381d12..c34c868e0 100644 --- a/app/views/form/_check_answers_table.html.erb +++ b/app/views/form/_check_answers_table.html.erb @@ -1,6 +1,6 @@
    - <%= question.check_answer_label.to_s.present? ? question.check_answer_label.to_s : question.header.to_s %> + <%= question.check_answer_label.to_s.presence || question.header.to_s %>
    <%= get_answer_label(question, @case_log) %>
    diff --git a/app/views/form/_checkbox_question.html.erb b/app/views/form/_checkbox_question.html.erb index 941a32a17..99551bac1 100644 --- a/app/views/form/_checkbox_question.html.erb +++ b/app/views/form/_checkbox_question.html.erb @@ -12,8 +12,8 @@ <%= f.govuk_check_box_divider %> <% else %> <%= f.govuk_check_box question.id, key, - label: { text: options['value'] }, - hint: { text: options['hint'] }, + label: { text: options["value"] }, + hint: { text: options["hint"] }, checked: @case_log[key] == 1, exclusive: after_divider, **stimulus_html_attributes(question) %> diff --git a/app/views/form/_interruption_screen_question.html.erb b/app/views/form/_interruption_screen_question.html.erb index 923d323b3..8913aa1e7 100644 --- a/app/views/form/_interruption_screen_question.html.erb +++ b/app/views/form/_interruption_screen_question.html.erb @@ -1,6 +1,6 @@ <%= govuk_panel( - title_text: title_text, - classes: 'app-panel--interruption', + title_text:, + classes: "app-panel--interruption", ) do %> <%= display_informative_text(informative_text, case_log) %> <%= f.govuk_radio_buttons_fieldset question.id.to_sym, @@ -12,8 +12,8 @@ <% else %> <%= f.govuk_radio_button question.id, key, - label: { text: options['value'] }, - hint: { text: options['hint'] }, + label: { text: options["value"] }, + hint: { text: options["hint"] }, **stimulus_html_attributes(question) %> <% end %> <% end %> diff --git a/app/views/form/_numeric_output_question.html.erb b/app/views/form/_numeric_output_question.html.erb index 01527be09..e3019a62c 100644 --- a/app/views/form/_numeric_output_question.html.erb +++ b/app/views/form/_numeric_output_question.html.erb @@ -15,7 +15,7 @@ step="<%= question.step %>" type="number" name="case_log[tcharge]" - for="<%= question.fields_added.present? ? question.fields_added.map { |x| "case-log-#{x}-field"}.join(" ") : "" %>"> + for="<%= question.fields_added.present? ? question.fields_added.map { |x| "case-log-#{x}-field" }.join(" ") : "" %>"> <%= case_log[question.id] %> <%= question.suffix %>
    diff --git a/app/views/form/_numeric_question.html.erb b/app/views/form/_numeric_question.html.erb index 933cf7abd..c392ebaf1 100644 --- a/app/views/form/_numeric_question.html.erb +++ b/app/views/form/_numeric_question.html.erb @@ -5,7 +5,8 @@ label: legend(question, page_header, conditional), hint: { text: question.hint_text&.html_safe }, min: question.min, max: question.max, step: question.step, - width: question.width, :readonly => question.read_only?, + width: question.width, + readonly: question.read_only?, prefix_text: question.prefix.to_s, suffix_text: question.suffix.is_a?(String) ? question.suffix : nil, **stimulus_html_attributes(question) %> diff --git a/app/views/form/_radio_question.html.erb b/app/views/form/_radio_question.html.erb index 5b770994a..a79e9422d 100644 --- a/app/views/form/_radio_question.html.erb +++ b/app/views/form/_radio_question.html.erb @@ -13,21 +13,21 @@ <% if conditional_question.nil? %> <%= f.govuk_radio_button question.id, key, - label: { text: options['value'] }, - hint: { text: options['hint'] }, + label: { text: options["value"] }, + hint: { text: options["hint"] }, **stimulus_html_attributes(question) %> <% else %> <%= f.govuk_radio_button question.id, key, - label: { text: options['value'] }, - hint: { text: options['hint'] }, + label: { text: options["value"] }, + hint: { text: options["hint"] }, **stimulus_html_attributes(question) do %> <%= render partial: "#{conditional_question.type}_question", locals: { question: conditional_question, - caption_text: caption_text, - page_header: page_header, - f: f, - conditional: true + caption_text:, + page_header:, + f:, + conditional: true, } %> <% end %> <% end %> diff --git a/app/views/form/_select_question.html.erb b/app/views/form/_select_question.html.erb index d758f3a85..fb12a203b 100644 --- a/app/views/form/_select_question.html.erb +++ b/app/views/form/_select_question.html.erb @@ -1,13 +1,13 @@ <%= render partial: "form/guidance/#{question.guidance_partial}" if question.guidance_partial %> <% selected = @case_log.public_send(question.id) || "" %> -<%= answers = question.displayed_answer_options.map { |key, value| OpenStruct.new(id: key, name: value) } - f.govuk_collection_select question.id.to_sym, +<%= answers = question.displayed_answer_options.map { |key, value| OpenStruct.new(id: key, name: value) } %> + <%= f.govuk_collection_select question.id.to_sym, answers, :id, :name, caption: caption(caption_text, page_header, conditional), label: legend(question, page_header, conditional), hint: { text: question.hint_text&.html_safe }, - options: { disabled: [""], selected: selected }, + options: { disabled: [""], selected: }, "data-controller": "accessible-autocomplete" %> diff --git a/app/views/form/_text_question.html.erb b/app/views/form/_text_question.html.erb index f842982bd..4b11bea36 100644 --- a/app/views/form/_text_question.html.erb +++ b/app/views/form/_text_question.html.erb @@ -4,5 +4,5 @@ caption: caption(caption_text, page_header, conditional), label: legend(question, page_header, conditional), hint: { text: question.hint_text&.html_safe }, - width: question.width ? question.width : nil, + width: question.width || nil, **stimulus_html_attributes(question) %> diff --git a/app/views/form/_textarea_question.html.erb b/app/views/form/_textarea_question.html.erb index 5499b100b..e87cb558b 100644 --- a/app/views/form/_textarea_question.html.erb +++ b/app/views/form/_textarea_question.html.erb @@ -4,5 +4,5 @@ caption: caption(caption_text, page_header, conditional), label: legend(question, page_header, conditional), hint: { text: question.hint_text&.html_safe }, - width: question.width ? question.width : nil, + width: question.width || nil, **stimulus_html_attributes(question) %> diff --git a/app/views/form/check_answers.html.erb b/app/views/form/check_answers.html.erb index fb912990c..94f5757b6 100644 --- a/app/views/form/check_answers.html.erb +++ b/app/views/form/check_answers.html.erb @@ -1,8 +1,8 @@ <% content_for :title, "#{subsection.id.humanize} - Check your answers" %> <% content_for :breadcrumbs, govuk_breadcrumbs(breadcrumbs: { "Logs" => "/logs", - "Log #{@case_log.id.to_s}" => "/logs/" + @case_log.id.to_s, - subsection.label => "" + "Log #{@case_log.id}" => "/logs/#{@case_log.id}", + subsection.label => "", }) %>
    @@ -16,16 +16,16 @@
    <% subsection.applicable_questions(@case_log).each do |question| %> - <%= render partial: 'form/check_answers_table', locals: { question: question, case_log: @case_log } %> + <%= render partial: "form/check_answers_table", locals: { question:, case_log: @case_log } %> <% end %>
    <%= form_with model: @case_log, method: "get" do |f| %> - <%= f.govuk_submit 'Save and return to log' do %> + <%= f.govuk_submit "Save and return to log" do %> <% if @case_log.status == "in_progress" && @case_log.status == "completed" || @case_log.form.all_subsections_except_declaration_completed?(@case_log) == false %> - <%= govuk_button_link_to 'Save and go to next incomplete section', "/logs/#{@case_log.id}/#{@case_log.form.next_incomplete_section_redirect_path(subsection, @case_log)}", secondary: true %> + <%= govuk_button_link_to "Save and go to next incomplete section", "/logs/#{@case_log.id}/#{@case_log.form.next_incomplete_section_redirect_path(subsection, @case_log)}", secondary: true %> <% elsif @case_log.status == "completed" || @case_log.form.all_subsections_except_declaration_completed?(@case_log) %> - <%= govuk_button_link_to 'Save and go to submit', "/logs/#{@case_log.id}/#{@case_log.form.next_incomplete_section_redirect_path(subsection, @case_log)}", secondary: true %> + <%= govuk_button_link_to "Save and go to submit", "/logs/#{@case_log.id}/#{@case_log.form.next_incomplete_section_redirect_path(subsection, @case_log)}", secondary: true %> <% end %> <% end %> <% end %> diff --git a/app/views/form/guidance/_what_counts_as_income.html.erb b/app/views/form/guidance/_what_counts_as_income.html.erb index 79326d909..55362d941 100644 --- a/app/views/form/guidance/_what_counts_as_income.html.erb +++ b/app/views/form/guidance/_what_counts_as_income.html.erb @@ -1,4 +1,4 @@ -<%= govuk_details(summary_text: 'What counts as income?') do %> +<%= govuk_details(summary_text: "What counts as income?") do %>

    You should include any income after tax from:

    • employment
    • diff --git a/app/views/form/page.html.erb b/app/views/form/page.html.erb index 2a09d6253..37c6bc18e 100644 --- a/app/views/form/page.html.erb +++ b/app/views/form/page.html.erb @@ -1,9 +1,9 @@ -<% content_for :title, @page.header.present? ? @page.header : @page.questions.first().header.html_safe %> +<% content_for :title, @page.header.presence || @page.questions.first.header.html_safe %> <% content_for :before_content do %> <%= govuk_back_link( - text: 'Back', - href: 'javascript:history.back()', + text: "Back", + href: "javascript:history.back()", ) %> <% end %> @@ -34,9 +34,9 @@
      <% end %> <% if question.type == "interruption_screen" %> - <%= render partial: "form/#{question.type}_question", locals: { question: question, caption_text: @subsection.label, page_header: @page.header, case_log: @case_log, title_text: @page.title_text, informative_text: @page.informative_text, form: @form, f: f, conditional: false } %> + <%= render partial: "form/#{question.type}_question", locals: { question:, caption_text: @subsection.label, page_header: @page.header, case_log: @case_log, title_text: @page.title_text, informative_text: @page.informative_text, form: @form, f:, conditional: false } %> <% else %> - <%= render partial: "form/#{question.type}_question", locals: { question: question, caption_text: @subsection.label, page_header: @page.header, case_log: @case_log, f: f, conditional: false } %> + <%= render partial: "form/#{question.type}_question", locals: { question:, caption_text: @subsection.label, page_header: @page.header, case_log: @case_log, f:, conditional: false } %> <% end %>
    <% end %> diff --git a/app/views/layouts/_collection_resources.html.erb b/app/views/layouts/_collection_resources.html.erb index 4b45b0a8d..4be268e7a 100644 --- a/app/views/layouts/_collection_resources.html.erb +++ b/app/views/layouts/_collection_resources.html.erb @@ -1,13 +1,16 @@

    Collection resources

    - <%= render DocumentListComponent.new(items: [{ - name: "Lettings log for tenants (2022/23)", - href: "https://core.communities.gov.uk/public/download/guides-and-manuals/2022-23%20Lettings%20paper%20form.pdf?download-format=pdf", - metadata: "PDF, 654 KB, 4 pages" - }, { - name: "Lettings log for tenants (2021/22)", - href: "https://core.communities.gov.uk/public/download/guides-and-manuals/2021_22%20Lettings%20Log.pdf?download-format=pdf", - metadata: "PDF, 302 KB, 3 pages" - }]) %> + <%= render DocumentListComponent.new(items: [ + { + name: "Lettings log for tenants (2022/23)", + href: "https://core.communities.gov.uk/public/download/guides-and-manuals/2022-23%20Lettings%20paper%20form.pdf?download-format=pdf", + metadata: "PDF, 654 KB, 4 pages", + }, + { + name: "Lettings log for tenants (2021/22)", + href: "https://core.communities.gov.uk/public/download/guides-and-manuals/2021_22%20Lettings%20Log.pdf?download-format=pdf", + metadata: "PDF, 302 KB, 3 pages", + }, + ]) %>
    diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 9b0ba04b7..701c42b95 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -4,19 +4,19 @@ <%= browser_title(yield(:title), @pagy, @admin_user, @user, @organisation, @case_log, @resource) %> <%= csrf_meta_tags %> <%= csp_meta_tag %> - <%= tag :meta, name: 'viewport', content: 'width=device-width, initial-scale=1' %> - <%= tag :meta, property: 'og:image', content: asset_path('images/govuk-opengraph-image.png') %> - <%= tag :meta, name: 'theme-color', content: '#0b0c0c' %> - <%= favicon_link_tag asset_path('images/favicon.ico') %> - <%= favicon_link_tag asset_path('images/govuk-mask-icon.svg'), rel: 'mask-icon', type: 'image/svg', color: "#0b0c0c" %> - <%= favicon_link_tag asset_path('images/govuk-apple-touch-icon.png'), rel: 'apple-touch-icon', type: 'image/png' %> - <%= favicon_link_tag asset_path('images/govuk-apple-touch-icon-152x152.png'), rel: 'apple-touch-icon', type: 'image/png', size: '152x152' %> - <%= favicon_link_tag asset_path('images/govuk-apple-touch-icon-167x167.png'), rel: 'apple-touch-icon', type: 'image/png', size: '167x167' %> - <%= favicon_link_tag asset_path('images/govuk-apple-touch-icon-180x180.png'), rel: 'apple-touch-icon', type: 'image/png', size: '180x180' %> + <%= tag.meta name: "viewport", content: "width=device-width, initial-scale=1" %> + <%= tag.meta property: "og:image", content: asset_path("images/govuk-opengraph-image.png") %> + <%= tag.meta name: "theme-color", content: "#0b0c0c" %> + <%= favicon_link_tag asset_path("images/favicon.ico") %> + <%= favicon_link_tag asset_path("images/govuk-mask-icon.svg"), rel: "mask-icon", type: "image/svg", color: "#0b0c0c" %> + <%= favicon_link_tag asset_path("images/govuk-apple-touch-icon.png"), rel: "apple-touch-icon", type: "image/png" %> + <%= favicon_link_tag asset_path("images/govuk-apple-touch-icon-152x152.png"), rel: "apple-touch-icon", type: "image/png", size: "152x152" %> + <%= favicon_link_tag asset_path("images/govuk-apple-touch-icon-167x167.png"), rel: "apple-touch-icon", type: "image/png", size: "167x167" %> + <%= favicon_link_tag asset_path("images/govuk-apple-touch-icon-180x180.png"), rel: "apple-touch-icon", type: "image/png", size: "180x180" %> <%= stylesheet_link_tag "application" %> <%= javascript_include_tag "vendor/html5shiv.min.js" %> <%= javascript_include_tag "vendor/polyfill-output-value.js" %> @@ -37,43 +37,44 @@ <%= govuk_skip_link %> <%= govuk_header( - logotype: 'GOV.UK', - service_name: t('service_name'), - service_url: current_user.nil? ? "/" : '/logs' + logotype: "GOV.UK", + service_name: t("service_name"), + service_url: current_user.nil? ? "/" : "/logs", ) do |component| if current_user.nil? - component.navigation_item(text: 'Sign in', href: user_session_path) - elsif - component.navigation_item(text: 'Logs', href: case_logs_path) - component.navigation_item(text: 'Your organisation', href: "/organisations/#{current_user.organisation.id}") - component.navigation_item(text: 'Your account', href: account_path) - component.navigation_item(text: 'Sign out', href: destroy_user_session_path) + component.navigation_item(text: "Sign in", href: user_session_path) + else + component.navigation_item(text: "Logs", href: case_logs_path) + component.navigation_item(text: "Your organisation", href: "/organisations/#{current_user.organisation.id}") + component.navigation_item(text: "Your account", href: account_path) + component.navigation_item(text: "Sign out", href: destroy_user_session_path) end end %>
    - <% if flash.notice && !flash.notice.include?('translation missing') %> + <% if flash.notice && !flash.notice.include?("translation missing") %> <%= govuk_notification_banner( - title_text: 'Success', + title_text: "Success", success: true, title_heading_level: 3, - title_id: "swanky-notifications") do |notification_banner| - notification_banner.heading(text: flash.notice) + title_id: "swanky-notifications" + ) do |notification_banner| + notification_banner.heading(text: flash.notice) end %> <% end %> <%= content_for?(:content) ? yield(:content) : yield %> diff --git a/app/views/layouts/organisations.html.erb b/app/views/layouts/organisations.html.erb index b316bf64f..aea5983c3 100644 --- a/app/views/layouts/organisations.html.erb +++ b/app/views/layouts/organisations.html.erb @@ -5,7 +5,7 @@ <% items = tab_items(current_user) %> - <%= render TabNavigationComponent.new(items: items) %> + <%= render TabNavigationComponent.new(items:) %>

    <%= content_for(:tab_title) %>

    diff --git a/app/views/organisations/edit.html.erb b/app/views/organisations/edit.html.erb index b0c0d6adb..93dafc4a7 100644 --- a/app/views/organisations/edit.html.erb +++ b/app/views/organisations/edit.html.erb @@ -2,7 +2,7 @@ <% content_for :before_content do %> <%= govuk_back_link( - text: 'Back', + text: "Back", href: :back, ) %> <% end %> diff --git a/app/views/organisations/show.html.erb b/app/views/organisations/show.html.erb index 8af61268f..f98ea86a9 100644 --- a/app/views/organisations/show.html.erb +++ b/app/views/organisations/show.html.erb @@ -10,17 +10,21 @@ <% @organisation.display_attributes.each do |attr| %> <% if current_user.data_coordinator? && attr[:editable] %> - <%= summary_list.row do |row| - row.key { attr[:name].to_s.humanize } - row.value { simple_format(attr[:value].to_s, {}, wrapper_tag: "div") } - row.action(visually_hidden_text: 'name', href: edit_organisation_path, html_attributes: { 'data-qa': "change-#{attr[:name]}" }) - end %> + <%= summary_list.row do |row| %> + <% row.key { attr[:name].to_s.humanize } %> + <% row.value { simple_format(attr[:value].to_s, {}, wrapper_tag: "div") } %> + <% row.action( + visually_hidden_text: "name", + href: edit_organisation_path, + html_attributes: { "data-qa": "change-#{attr[:name]}" }, + ) %> + <% end %> <% else %> - <%= summary_list.row do |row| - row.key { attr[:name].to_s.humanize } - row.value { simple_format(attr[:value].to_s, {}, wrapper_tag: "div") } - row.action() - end %> + <%= summary_list.row do |row| %> + <% row.key { attr[:name].to_s.humanize } %> + <% row.value { simple_format(attr[:value].to_s, {}, wrapper_tag: "div") } %> + <% row.action %> + <% end %> <% end %> <% end %> diff --git a/app/views/organisations/users.html.erb b/app/views/organisations/users.html.erb index 304528016..8c0e5e5d0 100644 --- a/app/views/organisations/users.html.erb +++ b/app/views/organisations/users.html.erb @@ -9,19 +9,19 @@ <% end %> <%= govuk_table do |table| %> <%= table.head do |head| %> - <%= head.row do |row| - row.cell(header: true, text: "Name and email adress") - row.cell(header: true, text: "Organisation and role") - row.cell(header: true, text: "Last logged in") - end %> + <%= head.row do |row| %> + <% row.cell(header: true, text: "Name and email adress") %> + <% row.cell(header: true, text: "Organisation and role") %> + <% row.cell(header: true, text: "Last logged in") %> + <% end %> <% end %> <% @organisation.users.each do |user| %> <%= table.body do |body| %> - <%= body.row do |row| - row.cell(text: simple_format(user_cell(user), {}, wrapper_tag: "div")) - row.cell(text: simple_format(org_cell(user), {}, wrapper_tag: "div")) - row.cell(text: user.last_sign_in_at&.to_formatted_s(:govuk_date) ) - end %> + <%= body.row do |row| %> + <% row.cell(text: simple_format(user_cell(user), {}, wrapper_tag: "div")) %> + <% row.cell(text: simple_format(org_cell(user), {}, wrapper_tag: "div")) %> + <% row.cell(text: user.last_sign_in_at&.to_formatted_s(:govuk_date)) %> + <% end %> <% end %> <% end %> <% end %> diff --git a/app/views/start/index.html.erb b/app/views/start/index.html.erb index 578fccc53..72a6619e4 100644 --- a/app/views/start/index.html.erb +++ b/app/views/start/index.html.erb @@ -10,10 +10,10 @@

    The data will be used to update the national record for social housing. It will also help to inform policy about the cost of social housing and what type of housing needs to be built.

    This service is only for social housing in England.

    - <% start_path = current_user ? case_logs_path : (user_session_path + "?start=true") %> + <% start_path = current_user ? case_logs_path : "#{user_session_path}?start=true" %> <%= govuk_start_button( - text: 'Start now', - href: start_path + text: "Start now", + href: start_path, ) %>

    Before you start

    diff --git a/app/views/users/edit.html.erb b/app/views/users/edit.html.erb index 257764f7f..d357f69fc 100644 --- a/app/views/users/edit.html.erb +++ b/app/views/users/edit.html.erb @@ -2,7 +2,7 @@ <% content_for :before_content do %> <%= govuk_back_link( - text: 'Back', + text: "Back", href: :back, ) %> <% end %> @@ -25,9 +25,13 @@ spellcheck: "false" %> <% if current_user.data_coordinator? || current_user.support? %> - <%= roles = current_user.assignable_roles.map { |key, _| OpenStruct.new(id: key, name: key.to_s.humanize) } + <%= roles = current_user.assignable_roles.map { |key, _| OpenStruct.new(id: key, name: key.to_s.humanize) } %> - f.govuk_collection_radio_buttons :role, roles, :id, :name, legend: { text: "Role", size: "m" } %> + <%= f.govuk_collection_radio_buttons :role, + roles, + :id, + :name, + legend: { text: "Role", size: "m" } %> <%= f.govuk_collection_radio_buttons :is_dpo, [OpenStruct.new(id: false, name: "No"), OpenStruct.new(id: true, name: "Yes")], diff --git a/app/views/users/new.html.erb b/app/views/users/new.html.erb index 903af4d3b..488290ee2 100644 --- a/app/views/users/new.html.erb +++ b/app/views/users/new.html.erb @@ -2,7 +2,7 @@ <% content_for :before_content do %> <%= govuk_back_link( - text: 'Back', + text: "Back", href: :back, ) %> <% end %> @@ -25,8 +25,13 @@ spellcheck: "false", value: @resource.email %> - <%= roles = current_user.assignable_roles.map { |key, _| OpenStruct.new(id: key, name: key.to_s.humanize) } - f.govuk_collection_radio_buttons :role, roles, :id, :name, legend: { text: "Role", size: "m" } %> + <%= roles = current_user.assignable_roles.map { |key, _| OpenStruct.new(id: key, name: key.to_s.humanize) } %> + + <%= f.govuk_collection_radio_buttons :role, + roles, + :id, + :name, + legend: { text: "Role", size: "m" } %> <%= f.govuk_collection_radio_buttons :is_dpo, [OpenStruct.new(id: false, name: "No"), OpenStruct.new(id: true, name: "Yes")], diff --git a/app/views/users/show.html.erb b/app/views/users/show.html.erb index 846472ca1..af0aa0599 100644 --- a/app/views/users/show.html.erb +++ b/app/views/users/show.html.erb @@ -12,70 +12,86 @@ <%= govuk_summary_list do |summary_list| %> <%= summary_list.row do |row| - row.key { "Name" } - row.value { @user.name } - if can_edit_names?(@user, current_user) - row.action(visually_hidden_text: "name", href: aliased_user_edit(@user, current_user), html_attributes: { "data-qa": "change-name" }) - else - row.action() - end - end %> + row.key { "Name" } + row.value { @user.name } + if can_edit_names?(@user, current_user) + row.action(visually_hidden_text: "name", href: aliased_user_edit(@user, current_user), html_attributes: { "data-qa": "change-name" }) + else + row.action + end + end %> - <%= summary_list.row() do |row| - row.key { "Email address" } - row.value { @user.email } - if can_edit_emails?(@user, current_user) - row.action(visually_hidden_text: "email address", href: aliased_user_edit(@user, current_user), html_attributes: { "data-qa": "change-email-address" }) - else - row.action() - end - end %> + <%= summary_list.row do |row| + row.key { "Email address" } + row.value { @user.email } + if can_edit_emails?(@user, current_user) + row.action(visually_hidden_text: "email address", href: aliased_user_edit(@user, current_user), html_attributes: { "data-qa": "change-email-address" }) + else + row.action + end + end %> <%= summary_list.row do |row| - row.key { "Password" } - row.value { "••••••••" } - if can_edit_password?(@user, current_user) - row.action(visually_hidden_text: "password", href: edit_password_account_path, html_attributes: { "data-qa": "change-password" }) - else - row.action() - end - end %> + row.key { "Password" } + row.value { "••••••••" } + if can_edit_password?(@user, current_user) + row.action( + visually_hidden_text: "password", + href: edit_password_account_path, + html_attributes: { "data-qa": "change-password" }, + ) + else + row.action + end + end %> <%= summary_list.row do |row| - row.key { "Organisation" } - row.value { @user.organisation.name } - row.action() - end %> + row.key { "Organisation" } + row.value { @user.organisation.name } + row.action + end %> <%= summary_list.row do |row| - row.key { "Role" } - row.value { @user.role.humanize } - if can_edit_roles?(@user, current_user) - row.action(visually_hidden_text: "role", href: aliased_user_edit(@user, current_user), html_attributes: { "data-qa": "change-role" }) - else - row.action() - end - end %> + row.key { "Role" } + row.value { @user.role.humanize } + if can_edit_roles?(@user, current_user) + row.action( + visually_hidden_text: "role", + href: aliased_user_edit(@user, current_user), + html_attributes: { "data-qa": "change-role" }, + ) + else + row.action + end + end %> <%= summary_list.row do |row| - row.key { "Data protection officer" } - row.value { @user.is_data_protection_officer? ? "Yes" : "No" } - if can_edit_dpo?(@user, current_user) - row.action(visually_hidden_text: "are #{pronoun(@user, current_user)} a data protection officer?", href: aliased_user_edit(@user, current_user), html_attributes: { "data-qa": "change-are-#{pronoun(@user, current_user)}-a-data-protection-officer" }) - else - row.action() - end - end %> + row.key { "Data protection officer" } + row.value { @user.is_data_protection_officer? ? "Yes" : "No" } + if can_edit_dpo?(@user, current_user) + row.action( + visually_hidden_text: "are #{pronoun(@user, current_user)} a data protection officer?", + href: aliased_user_edit(@user, current_user), + html_attributes: { "data-qa": "change-are-#{pronoun(@user, current_user)}-a-data-protection-officer" }, + ) + else + row.action + end + end %> <%= summary_list.row do |row| - row.key { "Key contact" } - row.value { @user.is_key_contact? ? "Yes" : "No" } - if can_edit_key_contact?(@user, current_user) - row.action(visually_hidden_text: "are #{pronoun(@user, current_user)} a key contact?", href: aliased_user_edit(@user, current_user), html_attributes: { "data-qa": "change-are-#{pronoun(@user, current_user)}-a-key-contact" }) - else - row.action() - end - end %> + row.key { "Key contact" } + row.value { @user.is_key_contact? ? "Yes" : "No" } + if can_edit_key_contact?(@user, current_user) + row.action( + visually_hidden_text: "are #{pronoun(@user, current_user)} a key contact?", + href: aliased_user_edit(@user, current_user), + html_attributes: { "data-qa": "change-are-#{pronoun(@user, current_user)}-a-key-contact" }, + ) + else + row.action + end + end %> <% end %>
    diff --git a/spec/features/reset_password.html.erb b/spec/features/reset_password.html.erb index a1735c5ec..1bf271dab 100644 --- a/spec/features/reset_password.html.erb +++ b/spec/features/reset_password.html.erb @@ -2,7 +2,7 @@ <% content_for :before_content do %> <%= govuk_back_link( - text: 'Back', + text: "Back", href: :back, ) %> <% end %> From ed9a32a7fba132c8006ac2bbd20510c26addf512 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Meny?= Date: Thu, 21 Apr 2022 09:28:13 +0100 Subject: [PATCH 16/25] Correct weekly income calculation based on a given yearly income (#483) --- app/models/case_log.rb | 2 +- config/locales/en.yml | 4 ++-- spec/models/case_log_spec.rb | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/models/case_log.rb b/app/models/case_log.rb index aa591d33d..9bbba8c46 100644 --- a/app/models/case_log.rb +++ b/app/models/case_log.rb @@ -100,7 +100,7 @@ class CaseLog < ApplicationRecord elsif net_income_is_monthly? ((earnings * 12) / 52.0).round(0) elsif net_income_is_yearly? - (earnings / 12.0).round(0) + (earnings / 52.0).round(0) end end diff --git a/config/locales/en.yml b/config/locales/en.yml index ebd5762bc..076f547bf 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -93,8 +93,8 @@ en: benefits: part_or_full_time: "Answer cannot be 'all' for income from Universal Credit, state pensions or benefits if the tenant or their partner works part-time or full-time" earnings: - over_hard_max: "Net income cannot be greater than %{hard_max} given the tenant’s working situation" - under_hard_min: "Net income cannot be less than %{hard_min} given the tenant’s working situation" + over_hard_max: "Net income cannot be greater than £%{hard_max} per week given the tenant’s working situation" + under_hard_min: "Net income cannot be less than £%{hard_min} per week given the tenant’s working situation" freq_missing: "Select how often the household receives income" earnings_missing: "Enter how much income the household has in total" negative_currency: "Enter an amount above 0" diff --git a/spec/models/case_log_spec.rb b/spec/models/case_log_spec.rb index bcf132aa0..3633fba51 100644 --- a/spec/models/case_log_spec.rb +++ b/spec/models/case_log_spec.rb @@ -186,7 +186,7 @@ RSpec.describe CaseLog do it "calculates the correct weekly income from yearly income" do case_log.incfreq = 3 - expect(case_log.weekly_net_income).to eq(417) + expect(case_log.weekly_net_income).to eq(96) end end From 1c004f97272c04b43cdb6eca66496ab357acbb4e Mon Sep 17 00:00:00 2001 From: Kat Date: Wed, 20 Apr 2022 09:59:14 +0100 Subject: [PATCH 17/25] Add navigation tab, remove the old navigation --- .../tab_navigation_component.html.erb | 15 ---- app/components/tab_navigation_component.rb | 14 ---- app/controllers/organisations_controller.rb | 13 +++- app/controllers/users_controller.rb | 6 ++ app/frontend/styles/_primary-navigation.scss | 69 +++++++++++++++++ app/frontend/styles/_tab-navigation.scss | 76 ------------------- app/frontend/styles/application.scss | 10 ++- .../layouts/_primary_navigation.html.erb | 18 +++++ app/views/layouts/application.html.erb | 19 +++++ app/views/layouts/organisations.html.erb | 2 - app/views/organisations/index.html.erb | 0 app/views/users/index.html.erb | 0 12 files changed, 131 insertions(+), 111 deletions(-) delete mode 100644 app/components/tab_navigation_component.html.erb delete mode 100644 app/components/tab_navigation_component.rb create mode 100644 app/frontend/styles/_primary-navigation.scss delete mode 100644 app/frontend/styles/_tab-navigation.scss create mode 100644 app/views/layouts/_primary_navigation.html.erb create mode 100644 app/views/organisations/index.html.erb create mode 100644 app/views/users/index.html.erb diff --git a/app/components/tab_navigation_component.html.erb b/app/components/tab_navigation_component.html.erb deleted file mode 100644 index 871cd4cbf..000000000 --- a/app/components/tab_navigation_component.html.erb +++ /dev/null @@ -1,15 +0,0 @@ - diff --git a/app/components/tab_navigation_component.rb b/app/components/tab_navigation_component.rb deleted file mode 100644 index 06c879389..000000000 --- a/app/components/tab_navigation_component.rb +++ /dev/null @@ -1,14 +0,0 @@ -class TabNavigationComponent < ViewComponent::Base - attr_reader :items - - def initialize(items:) - @items = items - super - end - - def strip_query(url) - url = Addressable::URI.parse(url) - url.query_values = nil - url.to_s - end -end diff --git a/app/controllers/organisations_controller.rb b/app/controllers/organisations_controller.rb index 3ba167453..94405eadf 100644 --- a/app/controllers/organisations_controller.rb +++ b/app/controllers/organisations_controller.rb @@ -1,8 +1,14 @@ class OrganisationsController < ApplicationController - before_action :authenticate_user! - before_action :find_resource + before_action :authenticate_user!, except: [:index] + before_action :find_resource, except: [:index] before_action :authenticate_scope! + def index + if !current_user.support? + redirect_to user_path(current_user) + end + end + def show redirect_to details_organisation_path(@organisation) end @@ -41,10 +47,11 @@ private end def authenticate_scope! - render_not_found if current_user.organisation != @organisation + render_not_found if current_user.organisation != @organisation && !current_user.support? end def find_resource + return if current_user.support? @organisation = Organisation.find(params[:id]) end end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 0c44b679b..5f600b71f 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -5,6 +5,12 @@ class UsersController < ApplicationController before_action :find_resource, except: %i[new create] before_action :authenticate_scope!, except: %i[new] + def index + if !current_user.support? + redirect_to user_path(@user) + end + end + def update if @user.update(user_params) if @user == current_user diff --git a/app/frontend/styles/_primary-navigation.scss b/app/frontend/styles/_primary-navigation.scss new file mode 100644 index 000000000..bdadaa107 --- /dev/null +++ b/app/frontend/styles/_primary-navigation.scss @@ -0,0 +1,69 @@ +.app-primary-navigation { + @include govuk-font(19, $weight: bold); + background-color: govuk-colour("light-grey"); + border-bottom: 1px solid $govuk-border-colour; + } + + .govuk-phase-banner + .app-primary-navigation { + margin-top: -1px; + } + + .app-primary-navigation__list { + @include govuk-clearfix; + left: govuk-spacing(-3); + list-style: none; + margin: 0; + padding: 0; + position: relative; + right: govuk-spacing(-3); + width: calc(100% + #{govuk-spacing(6)}); + } + + .app-primary-navigation__item { + box-sizing: border-box; + display: block; + float: left; + line-height: 50px; + height: 50px; + padding: 0 govuk-spacing(3); + position: relative; + } + + .app-primary-navigation__item--current { + border-bottom: $govuk-border-width-narrow solid $govuk-link-colour; + + &:hover { + border-bottom-color: $govuk-link-hover-colour; + } + + &:active { + border-bottom-color: $govuk-link-active-colour; + } + } + + .app-primary-navigation__item--align-right { + @include govuk-media-query($from: tablet) { + float: right; + } + } + + .app-primary-navigation__link { + @include govuk-link-common; + @include govuk-link-style-no-visited-state; + @include govuk-link-style-no-underline; + @include govuk-typography-weight-bold; + + // Extend the touch area of the link to the list + &:after { + bottom: 0; + content: ""; + left: 0; + position: absolute; + right: 0; + top: 0; + } + } + + .app-primary-navigation__item--current .app-primary-navigation__link:hover { + text-decoration: none; + } \ No newline at end of file diff --git a/app/frontend/styles/_tab-navigation.scss b/app/frontend/styles/_tab-navigation.scss deleted file mode 100644 index 0b5ebb6db..000000000 --- a/app/frontend/styles/_tab-navigation.scss +++ /dev/null @@ -1,76 +0,0 @@ -.app-tab-navigation { - @include govuk-font(19, $weight: bold); - @include govuk-responsive-margin(6, "bottom"); -} - -.app-tab-navigation__list { - @include govuk-clearfix; - left: govuk-spacing(-3); - list-style: none; - margin: 0; - padding: 0; - position: relative; - right: govuk-spacing(-3); - width: calc(100% + #{govuk-spacing(6)}); - - @include govuk-media-query($from: tablet) { - box-shadow: inset 0 -1px 0 $govuk-border-colour; - } -} - -.app-tab-navigation__item { - box-sizing: border-box; - display: block; - line-height: 40px; - height: 40px; - padding: 0 govuk-spacing(3); - - @include govuk-media-query($from: tablet) { - box-shadow: none; - display: block; - float: left; - line-height: 50px; - height: 50px; - padding: 0 govuk-spacing(3); - position: relative; - } -} - -.app-tab-navigation__item--current { - @include govuk-media-query($until: tablet) { - border-left: 4px solid $govuk-link-colour; - padding-left: 11px; - } - - @include govuk-media-query($from: tablet) { - border-bottom: 4px solid $govuk-link-colour; - padding-left: govuk-spacing(3); - } -} - -.app-tab-navigation__link { - @include govuk-link-common; - @include govuk-link-style-no-visited-state; - @include govuk-link-style-no-underline; - @include govuk-typography-weight-bold; - - &:not(:focus):hover { - color: $govuk-link-colour; - } - - // Extend the touch area of the link to the list - &:after { - bottom: 0; - content: ""; - left: 0; - position: absolute; - right: 0; - top: 0; - } -} - -.app-tab-navigation__item--current .app-tab-navigation__link { - &:hover { - text-decoration: none; - } -} diff --git a/app/frontend/styles/application.scss b/app/frontend/styles/application.scss index 0d172f26f..8dd6fc1a3 100644 --- a/app/frontend/styles/application.scss +++ b/app/frontend/styles/application.scss @@ -23,12 +23,12 @@ $govuk-new-link-styles: true; @import "input"; @import "related-navigation"; @import "section-skip-link"; -@import "tab-navigation"; @import "table-group"; @import "task-list"; @import "template"; @import "pagination"; @import "panel"; +@import "primary-navigation"; // App utilities .app-\!-colour-muted { @@ -53,3 +53,11 @@ $govuk-new-link-styles: true; width: 100%; } } + +.govuk-header__logo { + width: 80%; +} + +.govuk-header__content { + width: 20%; +} diff --git a/app/views/layouts/_primary_navigation.html.erb b/app/views/layouts/_primary_navigation.html.erb new file mode 100644 index 000000000..0fd8529bd --- /dev/null +++ b/app/views/layouts/_primary_navigation.html.erb @@ -0,0 +1,18 @@ + \ No newline at end of file diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 701c42b95..f2c40fe13 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -66,7 +66,26 @@ <%= content_for(:breadcrumbs) %> <%= content_for(:before_content) %> + + + <% if !current_user.nil? %> + <% if current_user.support? %> + <% items = [ + { name: t("Organisations"), url: "/organisations" }, + { name: t("Users"), url: "/users" }, + { name: t("Logs"), url: case_logs_path }, + ] %> + <% else %> + <% items = [ + { name: t("Logs"), url: case_logs_path }, + { name: t("Users"), url: users_organisation_path(current_user.organisation) }, + { name: t("About your organisation"), url: "/organisations/#{current_user.organisation.id}" }, + ] %> + <% end %> + <%= render partial: "layouts/primary_navigation", locals: {items: items} %> + <% end %> +
    <% if flash.notice && !flash.notice.include?("translation missing") %> <%= govuk_notification_banner( diff --git a/app/views/layouts/organisations.html.erb b/app/views/layouts/organisations.html.erb index aea5983c3..e258aa2aa 100644 --- a/app/views/layouts/organisations.html.erb +++ b/app/views/layouts/organisations.html.erb @@ -5,8 +5,6 @@ <% items = tab_items(current_user) %> - <%= render TabNavigationComponent.new(items:) %> -

    <%= content_for(:tab_title) %>

    <%= content_for?(:organisations_content) ? yield(:organisations_content) : yield %> diff --git a/app/views/organisations/index.html.erb b/app/views/organisations/index.html.erb new file mode 100644 index 000000000..e69de29bb diff --git a/app/views/users/index.html.erb b/app/views/users/index.html.erb new file mode 100644 index 000000000..e69de29bb From 88d4de0a25b5ace22ecc0ee84cb59d190a5ffdd3 Mon Sep 17 00:00:00 2001 From: Kat Date: Wed, 20 Apr 2022 10:08:14 +0100 Subject: [PATCH 18/25] lint and remove old tests --- app/controllers/organisations_controller.rb | 3 ++- app/controllers/users_controller.rb | 2 +- .../tab_navigation_component_spec.rb | 27 ------------------- 3 files changed, 3 insertions(+), 29 deletions(-) delete mode 100644 spec/components/tab_navigation_component_spec.rb diff --git a/app/controllers/organisations_controller.rb b/app/controllers/organisations_controller.rb index 94405eadf..36818db4b 100644 --- a/app/controllers/organisations_controller.rb +++ b/app/controllers/organisations_controller.rb @@ -4,7 +4,7 @@ class OrganisationsController < ApplicationController before_action :authenticate_scope! def index - if !current_user.support? + unless current_user.support? redirect_to user_path(current_user) end end @@ -52,6 +52,7 @@ private def find_resource return if current_user.support? + @organisation = Organisation.find(params[:id]) end end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 5f600b71f..f687b0b6a 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -6,7 +6,7 @@ class UsersController < ApplicationController before_action :authenticate_scope!, except: %i[new] def index - if !current_user.support? + unless current_user.support? redirect_to user_path(@user) end end diff --git a/spec/components/tab_navigation_component_spec.rb b/spec/components/tab_navigation_component_spec.rb deleted file mode 100644 index e160a3766..000000000 --- a/spec/components/tab_navigation_component_spec.rb +++ /dev/null @@ -1,27 +0,0 @@ -require "rails_helper" - -RSpec.describe TabNavigationComponent, type: :component do - let(:items) do - [{ name: "Application", url: "#", current: true }, - { name: "Notes", url: "#" }, - { name: "Timeline", url: "#" }] - end - - context "when the item is 'current' in nav tabs" do - it "then that tab appears as selected" do - result = render_inline(described_class.new(items:)) - - expect(result.css('.app-tab-navigation__link[aria-current="page"]').text).to include("Application") - end - end - - context "when rendering tabs" do - it "all of the nav tabs specified in the items hash are passed to it" do - result = render_inline(described_class.new(items:)) - - expect(result.text).to include("Application") - expect(result.text).to include("Notes") - expect(result.text).to include("Timeline") - end - end -end From 1678e8c6a4d7e7a6829dde6b251ca276aab3c3af Mon Sep 17 00:00:00 2001 From: Kat Date: Wed, 20 Apr 2022 11:13:05 +0100 Subject: [PATCH 19/25] tests --- spec/features/organisation_spec.rb | 9 +++++---- spec/requests/organisations_controller_spec.rb | 6 +++--- spec/requests/users_controller_spec.rb | 7 +++++-- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/spec/features/organisation_spec.rb b/spec/features/organisation_spec.rb index 3fa703c79..600cb7daa 100644 --- a/spec/features/organisation_spec.rb +++ b/spec/features/organisation_spec.rb @@ -24,7 +24,7 @@ RSpec.describe "User Features" do context "when viewing organisation page" do it "defaults to organisation details" do visit("/logs") - click_link("Your organisation") + click_link("About Your Organisation") expect(page).to have_content(user.organisation.name) end @@ -32,7 +32,7 @@ RSpec.describe "User Features" do visit("/organisations/#{org_id}") click_link("Users") expect(page).to have_current_path("/organisations/#{org_id}/users") - click_link("Details") + click_link("About Your Organisation") expect(page).to have_current_path("/organisations/#{org_id}/details") end end @@ -72,10 +72,11 @@ RSpec.describe "User Features" do context "when viewing organisation page" do it "can see the details tab and users tab" do visit("/logs") - click_link("Your organisation") + click_link("About Your Organisation") expect(page).to have_current_path("/organisations/#{org_id}/details") - expect(page).to have_link("Details") + expect(page).to have_link("Logs") expect(page).to have_link("Users") + expect(page).to have_link("About Your Organisation") end end end diff --git a/spec/requests/organisations_controller_spec.rb b/spec/requests/organisations_controller_spec.rb index 44b7ca8ac..8d4e22690 100644 --- a/spec/requests/organisations_controller_spec.rb +++ b/spec/requests/organisations_controller_spec.rb @@ -66,7 +66,7 @@ RSpec.describe OrganisationsController, type: :request do end it "shows the tab navigation" do - expected_html = "