Browse Source

Merge branch 'main' into CLDC-492/validate_hbrentshortfall

pull/162/head
Matthew Phelan 3 years ago
parent
commit
bd0de8418b
  1. 6
      app/models/case_log.rb
  2. 2
      app/models/constants/case_log.rb
  3. 10
      app/models/validations/household_validations.rb
  4. 4
      config/locales/devise.en.yml
  5. 9
      db/migrate/20211213122642_add_day_month_year_fields_for_start_date.rb
  6. 5
      db/schema.rb
  7. 3
      spec/factories/case_log.rb
  8. 5
      spec/features/form/saving_data_spec.rb
  9. 1
      spec/features/user_spec.rb
  10. 3
      spec/fixtures/complete_case_log.json
  11. 68
      spec/models/case_log_spec.rb
  12. 13
      spec/requests/form_controller_spec.rb

6
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]

2
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 = {

10
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?

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

9
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

5
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"

3
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 }

5
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

1
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

3
spec/fixtures/complete_case_log.json vendored

@ -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)",

68
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

13
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

Loading…
Cancel
Save