From 45abe2fa362cc97cadec1e50444aebda9cdcdfc1 Mon Sep 17 00:00:00 2001 From: JG Date: Fri, 17 Jun 2022 06:49:27 +0100 Subject: [PATCH] refactored scheme to enums --- app/helpers/tab_nav_helper.rb | 2 +- app/models/scheme.rb | 147 +++++++++-------------- spec/helpers/tab_nav_helper_spec.rb | 4 +- spec/requests/schemes_controller_spec.rb | 32 ++--- 4 files changed, 79 insertions(+), 106 deletions(-) diff --git a/app/helpers/tab_nav_helper.rb b/app/helpers/tab_nav_helper.rb index bb163ddd8..c718ebb83 100644 --- a/app/helpers/tab_nav_helper.rb +++ b/app/helpers/tab_nav_helper.rb @@ -8,7 +8,7 @@ module TabNavHelper def scheme_cell(scheme) link_text = scheme.service_name.presence - [govuk_link_to(link_text, scheme), "Scheme #{scheme.primary_client_group_display}"].join("\n") + [govuk_link_to(link_text, scheme), "Scheme #{scheme.primary_client_group}"].join("\n") end def org_cell(user) diff --git a/app/models/scheme.rb b/app/models/scheme.rb index 219b06aa3..459ab658b 100644 --- a/app/models/scheme.rb +++ b/app/models/scheme.rb @@ -8,113 +8,86 @@ class Scheme < ApplicationRecord scope :search_by_postcode, ->(postcode) { joins(:locations).where("locations.postcode ILIKE ?", "%#{postcode.delete(' ')}%") } scope :search_by, ->(param) { search_by_postcode(param).or(search_by_service_name(param)).or(search_by_code(param)).distinct } - SCHEME_TYPE = { - 0 => "Missing", - 4 => "Foyer", - 5 => "Direct Access Hostel", - 6 => "Other Supported Housing", - 7 => "Housing for older people", + enum sensitive: [:no, :yes] + + REGISTERED_UNDER_CARE_ACT = { + "No": 0, + "Yes – registered care home providing nursing care": 1, + "Yes – registered care home providing personal care": 2, + "Yes – part registered as a care home": 3, }.freeze - PRIMARY_CLIENT_GROUP = { - "O" => "Homeless families with support needs", - "H" => "Offenders & people at risk of offending", - "M" => "Older people with support needs", - "L" => "People at risk of domestic violence", - "A" => "People with a physical or sensory disability", - "G" => "People with alcohol problems", - "F" => "People with drug problems", - "B" => "People with HIV or AIDS", - "D" => "People with learning disabilities", - "E" => "People with mental health problems", - "I" => "Refugees (permanent)", - "S" => "Rough sleepers", - "N" => "Single homeless people with support needs", - "R" => "Teenage parents", - "Q" => "Young people at risk", - "P" => "Young people leaving care", - "X" => "Missing", + enum registered_under_care_act: REGISTERED_UNDER_CARE_ACT + + SCHEME_TYPE = { + "Missing": 0, + "Foyer": 4, + "Direct Access Hostel": 5, + "Other Supported Housing": 6, + "Housing for older people": 7, }.freeze + enum scheme_type: SCHEME_TYPE, _suffix: true + SUPPORT_TYPE = { - 0 => "Missing", - 1 => "Resettlement Support", - 2 => "Low levels of support", - 3 => "Medium levels of support", - 4 => "High levels of care and support", - 5 => "Nursing care services to a care home", - 6 => "Floating Support", + "Missing": 0, + "Resettlement Support": 1, + "Low levels of support": 2, + "Medium levels of support": 3, + "High levels of care and support": 4, + "Nursing care services to a care home": 5, + "Floating Support": 6, }.freeze - INTENDED_STAY = { - "M" => "Medium stay", - "P" => "Permanent", - "S" => "Short Stay", - "V" => "Very short stay", - "X" => "Missing", - }.freeze + enum support_type: SUPPORT_TYPE, _suffix: true - REGISTERED_UNDER_CARE_ACT = { - 0 => "No", - 1 => "Yes – registered care home providing nursing care", - 1 => "Yes – registered care home providing personal care", - 1 => "Yes – part registered as a care home", + PRIMARY_CLIENT_GROUP = { + "Homeless families with support needs": "O", + "Offenders & people at risk of offending": "H", + "Older people with support needs": "M", + "People at risk of domestic violence": "L", + "People with a physical or sensory disability": "A", + "People with alcohol problems": "G", + "People with drug problems": "F", + "People with HIV or AIDS": "B", + "People with learning disabilities": "D", + "People with mental health problems": "E", + "Refugees (permanent)": "I", + "Rough sleepers": "S", + "Single homeless people with support needs": "N", + "Teenage parents": "R", + "Young people at risk": "Q", + "Young people leaving care": "P", + "Missing": "X", }.freeze - SENSITIVE = { - 0 => "No", - 1 => "Yes", + enum primary_client_group: PRIMARY_CLIENT_GROUP, _suffix: true + enum secondary_client_group: PRIMARY_CLIENT_GROUP, _suffix: true + + INTENDED_STAY = { + "Medium stay": "M", + "Permanent": "P", + "Short Stay": "S", + "Very short stay": "V", + "Missing": "X", }.freeze - def scheme_types - SCHEME_TYPE.values - end + enum intended_stay: INTENDED_STAY, _suffix: true - def care_act_types - REGISTERED_UNDER_CARE_ACT.values - end def display_attributes [ { name: "Service code", value: code }, { name: "Name", value: service_name }, - { name: "Confidential information", value: sensitive_display }, + { name: "Confidential information", value: sensitive }, { name: "Managed by", value: organisation.name }, - { name: "Type of scheme", value: scheme_type_display }, - { name: "Registered under Care Standards Act 2000", value: registered_under_care_act_display }, + { name: "Type of scheme", value: scheme_type }, + { name: "Registered under Care Standards Act 2000", value: registered_under_care_act }, { name: "Total number of units", value: total_units }, - { name: "Primary client group", value: primary_client_group_display }, - { name: "Secondary client group", value: secondary_client_group_display }, - { name: "Level of support given", value: support_type_display }, - { name: "Intended length of stay", value: intended_stay_display }, + { name: "Primary client group", value: primary_client_group }, + { name: "Secondary client group", value: secondary_client_group }, + { name: "Level of support given", value: support_type }, + { name: "Intended length of stay", value: intended_stay }, ] end - - def scheme_type_display - SCHEME_TYPE[scheme_type] - end - - def sensitive_display - SENSITIVE[sensitive] - end - - def registered_under_care_act_display - REGISTERED_UNDER_CARE_ACT[registered_under_care_act] - end - - def primary_client_group_display - PRIMARY_CLIENT_GROUP[primary_client_group] - end - - def secondary_client_group_display - PRIMARY_CLIENT_GROUP[secondary_client_group] - end - - def support_type_display - SUPPORT_TYPE[support_type] - end - - def intended_stay_display - INTENDED_STAY[intended_stay] - end end diff --git a/spec/helpers/tab_nav_helper_spec.rb b/spec/helpers/tab_nav_helper_spec.rb index bd57a1c5a..f1e483fd1 100644 --- a/spec/helpers/tab_nav_helper_spec.rb +++ b/spec/helpers/tab_nav_helper_spec.rb @@ -20,8 +20,8 @@ RSpec.describe TabNavHelper do end describe "#scheme_cell" do - it "returns the scheme link, name and primary user group separated by a newline character" do - expected_html = "#{scheme.service_name}\nScheme #{scheme.primary_client_group_display}" + it "returns the scheme link service name and primary user group separated by a newline character" do + expected_html = "#{scheme.service_name}\nScheme #{scheme.primary_client_group}" expect(scheme_cell(scheme)).to match(expected_html) end end diff --git a/spec/requests/schemes_controller_spec.rb b/spec/requests/schemes_controller_spec.rb index be17ec13e..0a8070442 100644 --- a/spec/requests/schemes_controller_spec.rb +++ b/spec/requests/schemes_controller_spec.rb @@ -199,17 +199,17 @@ RSpec.describe SchemesController, type: :request do expect(page).to have_content(specific_scheme.code) expect(page).to have_content(specific_scheme.service_name) expect(page).to have_content(specific_scheme.organisation.name) - expect(page).to have_content(specific_scheme.sensitive_display) + expect(page).to have_content(specific_scheme.sensitive) expect(page).to have_content(specific_scheme.code) expect(page).to have_content(specific_scheme.service_name) - expect(page).to have_content(specific_scheme.sensitive_display) - expect(page).to have_content(specific_scheme.scheme_type_display) - expect(page).to have_content(specific_scheme.registered_under_care_act_display) + expect(page).to have_content(specific_scheme.sensitive) + expect(page).to have_content(specific_scheme.scheme_type) + expect(page).to have_content(specific_scheme.registered_under_care_act) expect(page).to have_content(specific_scheme.total_units) - expect(page).to have_content(specific_scheme.primary_client_group_display) - expect(page).to have_content(specific_scheme.secondary_client_group_display) - expect(page).to have_content(specific_scheme.support_type_display) - expect(page).to have_content(specific_scheme.intended_stay_display) + expect(page).to have_content(specific_scheme.primary_client_group) + expect(page).to have_content(specific_scheme.secondary_client_group) + expect(page).to have_content(specific_scheme.support_type) + expect(page).to have_content(specific_scheme.intended_stay) end context "when coordinator attempts to see scheme belonging to a different organisation" do @@ -233,17 +233,17 @@ RSpec.describe SchemesController, type: :request do expect(page).to have_content(specific_scheme.code) expect(page).to have_content(specific_scheme.service_name) expect(page).to have_content(specific_scheme.organisation.name) - expect(page).to have_content(specific_scheme.sensitive_display) + expect(page).to have_content(specific_scheme.sensitive) expect(page).to have_content(specific_scheme.code) expect(page).to have_content(specific_scheme.service_name) - expect(page).to have_content(specific_scheme.sensitive_display) - expect(page).to have_content(specific_scheme.scheme_type_display) - expect(page).to have_content(specific_scheme.registered_under_care_act_display) + expect(page).to have_content(specific_scheme.sensitive) + expect(page).to have_content(specific_scheme.scheme_type) + expect(page).to have_content(specific_scheme.registered_under_care_act) expect(page).to have_content(specific_scheme.total_units) - expect(page).to have_content(specific_scheme.primary_client_group_display) - expect(page).to have_content(specific_scheme.secondary_client_group_display) - expect(page).to have_content(specific_scheme.support_type_display) - expect(page).to have_content(specific_scheme.intended_stay_display) + expect(page).to have_content(specific_scheme.primary_client_group) + expect(page).to have_content(specific_scheme.secondary_client_group) + expect(page).to have_content(specific_scheme.support_type) + expect(page).to have_content(specific_scheme.intended_stay) end end end