diff --git a/app/models/case_log.rb b/app/models/case_log.rb index ae6e06fb6..7ea9af741 100644 --- a/app/models/case_log.rb +++ b/app/models/case_log.rb @@ -68,6 +68,7 @@ class CaseLog < ApplicationRecord enum housingneeds_f: POLAR, _suffix: true enum housingneeds_g: POLAR, _suffix: true enum housingneeds_h: POLAR, _suffix: true + enum accessibility_requirements_prefer_not_to_say: POLAR, _suffix: true enum illness_type_1: POLAR, _suffix: true enum illness_type_2: POLAR, _suffix: true enum illness_type_3: POLAR, _suffix: true @@ -183,6 +184,11 @@ private 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 self.incref = 1 if net_income_known == "Prefer not to say" self.hhmemb = other_hhmemb + 1 if other_hhmemb.present? self.renttype = RENT_TYPE_MAPPING[rent_type] diff --git a/app/models/constants/case_log.rb b/app/models/constants/case_log.rb index c503ec1b3..3a537035d 100644 --- a/app/models/constants/case_log.rb +++ b/app/models/constants/case_log.rb @@ -65,7 +65,7 @@ module Constants::CaseLog ILLNESS = { "Yes" => 1, "No" => 2, - "Do not know" => 3, + "Prefer not to say" => 3, }.freeze LEFTREG = { diff --git a/app/models/validations/household_validations.rb b/app/models/validations/household_validations.rb index ba29953e7..dc4e9acf2 100644 --- a/app/models/validations/household_validations.rb +++ b/app/models/validations/household_validations.rb @@ -74,6 +74,16 @@ module Validations::HouseholdValidations validate_person_age_matches_economic_status(record, 1) 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] + if all_options.count("Yes") > 1 + mobility_accessibility_options = [record.housingneeds_a, record.housingneeds_b, record.housingneeds_c] + unless all_options.count("Yes") == 2 && record.housingneeds_f == "Yes" && mobility_accessibility_options.any? { |x| x == "Yes" } + record.errors.add :housingneeds_a, "Only one box must be ticked or 'other disabilities' plus one of mobility disabilities" + end + end + end + def validate_shared_housing_rooms(record) unless record.unittype_gn.nil? if record.unittype_gn == "Bed-sit" && record.beds != 1 && record.beds.present? diff --git a/config/locales/devise.en.yml b/config/locales/devise.en.yml index ec502b562..d84886a71 100644 --- a/config/locales/devise.en.yml +++ b/config/locales/devise.en.yml @@ -45,6 +45,10 @@ en: update_needs_confirmation: "You updated your account successfully, but we need to verify your new email address. Please check your email and follow the confirmation link to confirm your new email address." updated: "Your account has been updated successfully." updated_but_not_signed_in: "Your account has been updated successfully, but since your password was changed, you need to sign in again." + sessions: + signed_in: "" + signed_out: "" + already_signed_out: "" unlocks: send_instructions: "You will receive an email with instructions for how to unlock your account in a few minutes." send_paranoid_instructions: "If your account exists, you will receive an email with instructions for how to unlock it in a few minutes." diff --git a/db/migrate/20211213122642_add_day_month_year_fields_for_start_date.rb b/db/migrate/20211213122642_add_day_month_year_fields_for_start_date.rb new file mode 100644 index 000000000..c0c7c51d9 --- /dev/null +++ b/db/migrate/20211213122642_add_day_month_year_fields_for_start_date.rb @@ -0,0 +1,9 @@ +class AddDayMonthYearFieldsForStartDate < ActiveRecord::Migration[6.1] + def change + change_table :case_logs, bulk: true do |t| + t.column :day, :integer + t.column :month, :integer + t.column :year, :integer + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 38fe84eb0..7f5ba379d 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.define(version: 2021_12_03_144855) do +ActiveRecord::Schema.define(version: 2021_12_13_122642) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -171,6 +171,9 @@ ActiveRecord::Schema.define(version: 2021_12_03_144855) do t.integer "lettype" t.integer "postcode_known" t.integer "la_known" + t.integer "day" + t.integer "month" + t.integer "year" t.index ["discarded_at"], name: "index_case_logs_on_discarded_at" 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" diff --git a/spec/factories/case_log.rb b/spec/factories/case_log.rb index cca98c002..b459e38fc 100644 --- a/spec/factories/case_log.rb +++ b/spec/factories/case_log.rb @@ -134,6 +134,9 @@ FactoryBot.define do incref { 0 } sale_completion_date { nil } startdate { Time.zone.now } + day { Time.zone.now.day } + month { Time.zone.now.month } + year { Time.zone.now.year } armedforces { 1 } builtype { 1 } unitletas { 2 } diff --git a/spec/features/form/saving_data_spec.rb b/spec/features/form/saving_data_spec.rb index ab7b03643..f419a3438 100644 --- a/spec/features/form/saving_data_spec.rb +++ b/spec/features/form/saving_data_spec.rb @@ -17,7 +17,6 @@ RSpec.describe "Form Saving Data" do FactoryBot.create( :case_log, :in_progress, housingneeds_a: "Yes", - housingneeds_c: "Yes", owning_organisation: user.organisation, managing_organisation: user.organisation ) @@ -93,9 +92,5 @@ RSpec.describe "Form Saving Data" do "case-log-accessibility-requirements-housingneeds-b-field", visible: false, ) - expect(page).to have_checked_field( - "case-log-accessibility-requirements-housingneeds-c-field", - visible: false, - ) end end diff --git a/spec/features/user_spec.rb b/spec/features/user_spec.rb index 2fb117941..71375f4d2 100644 --- a/spec/features/user_spec.rb +++ b/spec/features/user_spec.rb @@ -18,7 +18,6 @@ RSpec.describe "User Features" do fill_in("user[password]", with: "pAssword1") click_button("Sign in") expect(page).to have_current_path("/logs") - expect(page).to have_css(".govuk-notification-banner.govuk-notification-banner--success") end end diff --git a/spec/fixtures/complete_case_log.json b/spec/fixtures/complete_case_log.json index b41538a8f..c7cc65314 100644 --- a/spec/fixtures/complete_case_log.json +++ b/spec/fixtures/complete_case_log.json @@ -51,6 +51,9 @@ "condition_effects": "dummy", "tenancy_code": "BZ757", "startdate": "12/12/2020", + "day": 12, + "month": 12, + "year": 2020, "startertenancy": "No", "tenancylength": "5", "tenancy": "Secure (including flexible)", diff --git a/spec/models/case_log_spec.rb b/spec/models/case_log_spec.rb index ed39fcb1f..8086aa3e3 100644 --- a/spec/models/case_log_spec.rb +++ b/spec/models/case_log_spec.rb @@ -826,6 +826,61 @@ RSpec.describe Form, type: :model do }.not_to raise_error end end + + context "For accessibility requirements" do + it "validates that only one option can be selected" do + expect { + CaseLog.create!(housingneeds_a: "Yes", + housingneeds_b: "Yes", + rent_type: "London Affordable rent", + owning_organisation: owning_organisation, + managing_organisation: managing_organisation) + }.to raise_error(ActiveRecord::RecordInvalid) + end + + it "validates that only one option a, b, or c can be selected in conjunction with f" do + expect { + CaseLog.create!(housingneeds_a: "Yes", + housingneeds_f: "Yes", + rent_type: "London Affordable rent", + owning_organisation: owning_organisation, + managing_organisation: managing_organisation) + }.to_not raise_error + + expect { + CaseLog.create!(housingneeds_b: "Yes", + housingneeds_f: "Yes", + rent_type: "London Affordable rent", + owning_organisation: owning_organisation, + managing_organisation: managing_organisation) + }.to_not raise_error + + expect { + CaseLog.create!(housingneeds_c: "Yes", + housingneeds_f: "Yes", + rent_type: "London Affordable rent", + owning_organisation: owning_organisation, + managing_organisation: managing_organisation) + }.to_not raise_error + + expect { + CaseLog.create!(housingneeds_g: "Yes", + housingneeds_f: "Yes", + rent_type: "London Affordable rent", + owning_organisation: owning_organisation, + managing_organisation: managing_organisation) + }.to raise_error(ActiveRecord::RecordInvalid) + + expect { + CaseLog.create!(housingneeds_a: "Yes", + housingneeds_b: "Yes", + housingneeds_f: "Yes", + rent_type: "London Affordable rent", + owning_organisation: owning_organisation, + managing_organisation: managing_organisation) + }.to raise_error(ActiveRecord::RecordInvalid) + end + end end describe "status" do @@ -882,6 +937,7 @@ RSpec.describe Form, type: :model do property_postcode: "M1 1AE", previous_postcode: "M2 2AE", # rubocop:disable Style/DateTime + startdate: DateTime.new(2021, 10, 10), mrcdate: DateTime.new(2021, 5, 4), # rubocop:enable Style/DateTime net_income_known: "Prefer not to say", @@ -948,5 +1004,17 @@ RSpec.describe Form, type: :model do expect(case_log.lettype).to eq("Intermediate Rent General needs PRP") expect(record_from_db["lettype"]).to eq(9) end + + it "correctly derives and saves day, month, year from start date" do + case_log.reload + + record_from_db = ActiveRecord::Base.connection.execute("select day, month, year, 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 end end diff --git a/spec/requests/form_controller_spec.rb b/spec/requests/form_controller_spec.rb index b8f889cb9..ee9115184 100644 --- a/spec/requests/form_controller_spec.rb +++ b/spec/requests/form_controller_spec.rb @@ -135,9 +135,7 @@ RSpec.describe FormController, type: :request do case_log: { page: "accessibility_requirements", accessibility_requirements: - %w[ housingneeds_a - housingneeds_b - housingneeds_c], + %w[housingneeds_b], }, } end @@ -156,16 +154,13 @@ RSpec.describe FormController, type: :request do post "/logs/#{case_log.id}/form", params: case_log_form_params case_log.reload - expect(case_log.housingneeds_a).to eq("Yes") expect(case_log.housingneeds_b).to eq("Yes") - expect(case_log.housingneeds_c).to eq("Yes") end it "sets previously submitted items to false when resubmitted with new values" do post "/logs/#{case_log.id}/form", params: new_case_log_form_params case_log.reload - expect(case_log.housingneeds_a).to eq("No") expect(case_log.housingneeds_b).to eq("No") expect(case_log.housingneeds_c).to eq("Yes") end @@ -179,8 +174,7 @@ RSpec.describe FormController, type: :request do page: "accessibility_requirements", accessibility_requirements: %w[ housingneeds_a - housingneeds_b - housingneeds_c], + housingneeds_f], tenant_code: tenant_code, }, } @@ -213,8 +207,7 @@ RSpec.describe FormController, type: :request do case_log.reload expect(case_log.housingneeds_a).to eq("Yes") - expect(case_log.housingneeds_b).to eq("Yes") - expect(case_log.housingneeds_c).to eq("Yes") + expect(case_log.housingneeds_f).to eq("Yes") expect(case_log.tenant_code).to eq(tenant_code) end end