Browse Source

Fix data mapping for mantype (#761)

* Fix data mapping for mantype

This was mapped to a column called support services provider which was an
integer, this now maps to the arrangement type column. This should be in
line with expectations for the import/export

* remove unused stuff

* lint fixes

* changes to comparison

* fix lambda checks in view

* fix export test
pull/770/head
Dushan 2 years ago committed by GitHub
parent
commit
bc618e2ab9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 20
      app/controllers/schemes_controller.rb
  2. 17
      app/models/scheme.rb
  3. 11
      app/views/schemes/details.html.erb
  4. 10
      app/views/schemes/new.html.erb
  5. 4
      config/locales/en.yml
  6. 5
      db/migrate/20220719132350_remove_support_provider_column.rb
  7. 1
      db/schema.rb
  8. 1
      spec/factories/scheme.rb
  9. 2
      spec/fixtures/exports/supported_housing_logs.xml
  10. 25
      spec/requests/schemes_controller_spec.rb
  11. 2
      spec/services/imports/scheme_import_service_spec.rb

20
app/controllers/schemes_controller.rb

@ -30,7 +30,7 @@ class SchemesController < ApplicationController
validation_errors scheme_params validation_errors scheme_params
if @scheme.errors.empty? && @scheme.save if @scheme.errors.empty? && @scheme.save
if scheme_params[:support_services_provider].zero? if @scheme.arrangement_type_before_type_cast == "D"
redirect_to scheme_primary_client_group_path(@scheme) redirect_to scheme_primary_client_group_path(@scheme)
else else
redirect_to scheme_support_services_provider_path(@scheme) redirect_to scheme_support_services_provider_path(@scheme)
@ -100,9 +100,7 @@ private
def validation_errors(scheme_params) def validation_errors(scheme_params)
scheme_params.each_key do |key| scheme_params.each_key do |key|
if key == "support_services_provider" if scheme_params[key].to_s.empty?
@scheme.errors.add("support_services_provider_before_type_cast".to_sym) if scheme_params[key].to_s.empty?
elsif scheme_params[key].to_s.empty?
@scheme.errors.add(key.to_sym) @scheme.errors.add(key.to_sym)
end end
end end
@ -143,9 +141,9 @@ private
when "support" when "support"
new_location_path new_location_path
when "details" when "details"
if @scheme.support_services_provider_before_type_cast&.zero? if @scheme.arrangement_type_before_type_cast == "D"
scheme_primary_client_group_path(@scheme) scheme_primary_client_group_path(@scheme)
elsif @scheme.support_services_provider_before_type_cast.positive? elsif @scheme.arrangement_type.present? && @scheme.arrangement_type_before_type_cast != "D"
scheme_support_services_provider_path(@scheme) scheme_support_services_provider_path(@scheme)
else else
scheme_details_path(@scheme) scheme_details_path(@scheme)
@ -167,19 +165,17 @@ private
:primary_client_group, :primary_client_group,
:secondary_client_group, :secondary_client_group,
:support_type, :support_type,
:support_services_provider, :arrangement_type,
:support_services_provider_before_type_cast, :intended_stay)
:intended_stay).merge(support_services_provider: params[:scheme][:support_services_provider_before_type_cast])
full_params = required_params[:support_services_provider] == "0" && required_params[:owning_organisation_id].present? ? required_params.merge(managing_organisation_id: required_params[:owning_organisation_id]) : required_params full_params = required_params[:arrangement_type] == "D" && required_params[:owning_organisation_id].present? ? required_params.merge(managing_organisation_id: required_params[:owning_organisation_id]) : required_params
full_params[:sensitive] = full_params[:sensitive].to_i if full_params[:sensitive] full_params[:sensitive] = full_params[:sensitive].to_i if full_params[:sensitive]
full_params[:support_services_provider] = full_params[:support_services_provider].to_i unless full_params[:support_services_provider] && full_params[:support_services_provider].empty?
if current_user.data_coordinator? if current_user.data_coordinator?
full_params[:owning_organisation_id] = current_user.organisation_id full_params[:owning_organisation_id] = current_user.organisation_id
end end
full_params.except(:support_services_provider_before_type_cast) full_params
end end
def search_term def search_term

17
app/models/scheme.rb

@ -84,14 +84,15 @@ class Scheme < ApplicationRecord
enum intended_stay: INTENDED_STAY, _suffix: true enum intended_stay: INTENDED_STAY, _suffix: true
enum has_other_client_group: HAS_OTHER_CLIENT_GROUP, _suffix: true enum has_other_client_group: HAS_OTHER_CLIENT_GROUP, _suffix: true
SUPPORT_SERVICES_PROVIDER = { ARRANGEMENT_TYPE = {
"The same organisation that owns the housing stock": 0, "The same organisation that owns the housing stock": "D",
"Another registered housing provider": 1, "Another registered housing provider": "R",
"A registered charity or voluntary organisation": 2, "A registered charity or voluntary organisation": "V",
"Another organisation": 3, "Another organisation": "O",
"Missing": "X",
}.freeze }.freeze
enum support_services_provider: SUPPORT_SERVICES_PROVIDER enum arrangement_type: ARRANGEMENT_TYPE, _suffix: true
def id_to_display def id_to_display
"S#{id}" "S#{id}"
@ -105,7 +106,7 @@ class Scheme < ApplicationRecord
{ name: "Type of scheme", value: scheme_type }, { name: "Type of scheme", value: scheme_type },
{ name: "Registered under Care Standards Act 2000", value: registered_under_care_act }, { name: "Registered under Care Standards Act 2000", value: registered_under_care_act },
{ name: "Housing stock owned by", value: owning_organisation.name }, { name: "Housing stock owned by", value: owning_organisation.name },
{ name: "Support provided by", value: support_services_provider }, { name: "Support services provided by", value: arrangement_type },
] ]
end end
@ -148,7 +149,7 @@ class Scheme < ApplicationRecord
{ name: "Type of scheme", value: scheme_type }, { name: "Type of scheme", value: scheme_type },
{ name: "Registered under Care Standards Act 2000", value: registered_under_care_act }, { name: "Registered under Care Standards Act 2000", value: registered_under_care_act },
{ name: "Housing stock owned by", value: owning_organisation.name, edit: true }, { name: "Housing stock owned by", value: owning_organisation.name, edit: true },
{ name: "Support services provided by", value: support_services_provider }, { name: "Support services provided by", value: arrangement_type },
{ name: "Organisation providing support", value: managing_organisation&.name }, { name: "Organisation providing support", value: managing_organisation&.name },
{ name: "Primary client group", value: primary_client_group }, { name: "Primary client group", value: primary_client_group },
{ name: "Has another client group", value: has_other_client_group }, { name: "Has another client group", value: has_other_client_group },

11
app/views/schemes/details.html.erb

@ -63,14 +63,13 @@
"data-controller": %w[accessible-autocomplete conditional-filter] %> "data-controller": %w[accessible-autocomplete conditional-filter] %>
<% end %> <% end %>
<% support_services_provider_selection = Scheme.support_services_providers.map do |key, value| %> <% mantype_selection = Scheme.arrangement_types.keys.excluding("Missing").map { |key, _| OpenStruct.new(id: key, name: key.to_s.humanize) } %>
<% OpenStruct.new(id: value, name: key.to_s.humanize) %>
<% end %> <%= f.govuk_collection_radio_buttons :arrangement_type,
<%= f.govuk_collection_radio_buttons :support_services_provider_before_type_cast, mantype_selection,
support_services_provider_selection,
:id, :id,
lambda { |option| lambda { |option|
if option.id.zero? && !current_user.support? if Scheme::ARRANGEMENT_TYPE[option.id] == "D" && !current_user.support?
"Your organisation" "Your organisation"
else else
option.name option.name

10
app/views/schemes/new.html.erb

@ -65,15 +65,13 @@
"data-controller": %w[accessible-autocomplete conditional-filter] %> "data-controller": %w[accessible-autocomplete conditional-filter] %>
<% end %> <% end %>
<% support_services_provider_selection = Scheme.support_services_providers.map do |key, value| %> <% mantype_selection = Scheme.arrangement_types.keys.excluding("Missing").map { |key, _| OpenStruct.new(id: key, name: key.to_s.humanize) } %>
<% OpenStruct.new(id: value, name: key.to_s.humanize) %>
<% end %>
<%= f.govuk_collection_radio_buttons :support_services_provider_before_type_cast, <%= f.govuk_collection_radio_buttons :arrangement_type,
support_services_provider_selection, mantype_selection,
:id, :id,
lambda { |option| lambda { |option|
if option.id.zero? && !current_user.support? if Scheme::ARRANGEMENT_TYPE[option.id] == "D" && !current_user.support?
"Your organisation" "Your organisation"
else else
option.name option.name

4
config/locales/en.yml

@ -63,9 +63,7 @@ en:
invalid: "Select intended length of stay" invalid: "Select intended length of stay"
has_other_client_group: has_other_client_group:
invalid: "Select if this scheme provides for another client group" invalid: "Select if this scheme provides for another client group"
support_services_provider: arrangement_type:
invalid: "Select who provides the support services used by this scheme"
support_services_provider_before_type_cast:
invalid: "Select who provides the support services used by this scheme" invalid: "Select who provides the support services used by this scheme"
location: location:
attributes: attributes:

5
db/migrate/20220719132350_remove_support_provider_column.rb

@ -0,0 +1,5 @@
class RemoveSupportProviderColumn < ActiveRecord::Migration[7.0]
def change
remove_column :schemes, :support_services_provider, :integer
end
end

1
db/schema.rb

@ -320,7 +320,6 @@ ActiveRecord::Schema[7.0].define(version: 2022_07_20_111635) do
t.string "old_id" t.string "old_id"
t.integer "old_visible_id" t.integer "old_visible_id"
t.integer "total_units" t.integer "total_units"
t.integer "support_services_provider"
t.index ["managing_organisation_id"], name: "index_schemes_on_managing_organisation_id" t.index ["managing_organisation_id"], name: "index_schemes_on_managing_organisation_id"
t.index ["owning_organisation_id"], name: "index_schemes_on_owning_organisation_id" t.index ["owning_organisation_id"], name: "index_schemes_on_owning_organisation_id"
end end

1
spec/factories/scheme.rb

@ -5,6 +5,7 @@ FactoryBot.define do
registered_under_care_act { 1 } registered_under_care_act { 1 }
support_type { [0, 2, 3, 4, 5].sample } support_type { [0, 2, 3, 4, 5].sample }
scheme_type { 0 } scheme_type { 0 }
arrangement_type { "D" }
intended_stay { %w[M P S V X].sample } intended_stay { %w[M P S V X].sample }
primary_client_group { %w[O H M L A G F B D E I S N R Q P X].sample } primary_client_group { %w[O H M L A G F B D E I S N R Q P X].sample }
secondary_client_group { %w[O H M L A G F B D E I S N R Q P X].sample } secondary_client_group { %w[O H M L A G F B D E I S N R Q P X].sample }

2
spec/fixtures/exports/supported_housing_logs.xml vendored

@ -148,7 +148,7 @@
<cligrp1>G</cligrp1> <cligrp1>G</cligrp1>
<cligrp2>M</cligrp2> <cligrp2>M</cligrp2>
<intstay>M</intstay> <intstay>M</intstay>
<mantype/> <mantype>D</mantype>
<reghome>1</reghome> <reghome>1</reghome>
<schtype>7</schtype> <schtype>7</schtype>
<support>4</support> <support>4</support>

25
spec/requests/schemes_controller_spec.rb

@ -341,7 +341,7 @@ RSpec.describe SchemesController, type: :request do
sensitive: "1", sensitive: "1",
scheme_type: "Foyer", scheme_type: "Foyer",
registered_under_care_act: "No", registered_under_care_act: "No",
support_services_provider_before_type_cast: "0" } } arrangement_type: "D" } }
end end
before do before do
@ -378,7 +378,7 @@ RSpec.describe SchemesController, type: :request do
sensitive: "1", sensitive: "1",
scheme_type: "Foyer", scheme_type: "Foyer",
registered_under_care_act: "No", registered_under_care_act: "No",
support_services_provider_before_type_cast: "1" } } arrangement_type: "R" } }
end end
it "creates a new scheme for user organisation with valid params and renders correct page" do it "creates a new scheme for user organisation with valid params and renders correct page" do
@ -411,7 +411,7 @@ RSpec.describe SchemesController, type: :request do
{ scheme: { service_name: "", { scheme: { service_name: "",
scheme_type: "", scheme_type: "",
registered_under_care_act: "", registered_under_care_act: "",
support_services_provider_before_type_cast: "" } } arrangement_type: "" } }
end end
it "renders the same page with error message" do it "renders the same page with error message" do
@ -420,7 +420,7 @@ RSpec.describe SchemesController, type: :request do
expect(page).to have_content("Create a new supported housing scheme") expect(page).to have_content("Create a new supported housing scheme")
expect(page).to have_content(I18n.t("activerecord.errors.models.scheme.attributes.scheme_type.invalid")) expect(page).to have_content(I18n.t("activerecord.errors.models.scheme.attributes.scheme_type.invalid"))
expect(page).to have_content(I18n.t("activerecord.errors.models.scheme.attributes.registered_under_care_act.invalid")) expect(page).to have_content(I18n.t("activerecord.errors.models.scheme.attributes.registered_under_care_act.invalid"))
expect(page).to have_content(I18n.t("activerecord.errors.models.scheme.attributes.support_services_provider.invalid")) expect(page).to have_content(I18n.t("activerecord.errors.models.scheme.attributes.arrangement_type.invalid"))
expect(page).to have_content(I18n.t("activerecord.errors.models.scheme.attributes.service_name.invalid")) expect(page).to have_content(I18n.t("activerecord.errors.models.scheme.attributes.service_name.invalid"))
end end
end end
@ -435,7 +435,7 @@ RSpec.describe SchemesController, type: :request do
scheme_type: "Foyer", scheme_type: "Foyer",
registered_under_care_act: "No", registered_under_care_act: "No",
owning_organisation_id: organisation.id, owning_organisation_id: organisation.id,
support_services_provider_before_type_cast: "0" } } arrangement_type: "D" } }
end end
before do before do
@ -506,7 +506,7 @@ RSpec.describe SchemesController, type: :request do
{ scheme: { service_name: "", { scheme: { service_name: "",
scheme_type: "", scheme_type: "",
registered_under_care_act: "", registered_under_care_act: "",
support_services_provider_before_type_cast: "" } } arrangement_type: "" } }
end end
it "renders the same page with error message" do it "renders the same page with error message" do
@ -515,7 +515,7 @@ RSpec.describe SchemesController, type: :request do
expect(page).to have_content("Create a new supported housing scheme") expect(page).to have_content("Create a new supported housing scheme")
expect(page).to have_content(I18n.t("activerecord.errors.models.scheme.attributes.scheme_type.invalid")) expect(page).to have_content(I18n.t("activerecord.errors.models.scheme.attributes.scheme_type.invalid"))
expect(page).to have_content(I18n.t("activerecord.errors.models.scheme.attributes.registered_under_care_act.invalid")) expect(page).to have_content(I18n.t("activerecord.errors.models.scheme.attributes.registered_under_care_act.invalid"))
expect(page).to have_content(I18n.t("activerecord.errors.models.scheme.attributes.support_services_provider.invalid")) expect(page).to have_content(I18n.t("activerecord.errors.models.scheme.attributes.arrangement_type.invalid"))
expect(page).to have_content(I18n.t("activerecord.errors.models.scheme.attributes.service_name.invalid")) expect(page).to have_content(I18n.t("activerecord.errors.models.scheme.attributes.service_name.invalid"))
expect(page).to have_content(I18n.t("activerecord.errors.models.scheme.attributes.owning_organisation_id.invalid")) expect(page).to have_content(I18n.t("activerecord.errors.models.scheme.attributes.owning_organisation_id.invalid"))
end end
@ -576,7 +576,7 @@ RSpec.describe SchemesController, type: :request do
registered_under_care_act: "", registered_under_care_act: "",
support_type: "", support_type: "",
intended_stay: "", intended_stay: "",
support_services_provider_before_type_cast: "", arrangement_type: "",
has_other_client_group: "", has_other_client_group: "",
page: "details", page: "details",
} } } }
@ -593,7 +593,6 @@ RSpec.describe SchemesController, type: :request do
expect(page).to have_content(I18n.t("activerecord.errors.models.scheme.attributes.support_type.invalid")) expect(page).to have_content(I18n.t("activerecord.errors.models.scheme.attributes.support_type.invalid"))
expect(page).to have_content(I18n.t("activerecord.errors.models.scheme.attributes.intended_stay.invalid")) expect(page).to have_content(I18n.t("activerecord.errors.models.scheme.attributes.intended_stay.invalid"))
expect(page).to have_content(I18n.t("activerecord.errors.models.scheme.attributes.has_other_client_group.invalid")) expect(page).to have_content(I18n.t("activerecord.errors.models.scheme.attributes.has_other_client_group.invalid"))
expect(page).to have_content(I18n.t("activerecord.errors.models.scheme.attributes.support_services_provider_before_type_cast.invalid"))
end end
context "when updating from check answers page" do context "when updating from check answers page" do
@ -787,7 +786,7 @@ RSpec.describe SchemesController, type: :request do
registered_under_care_act: "No", registered_under_care_act: "No",
page: "details", page: "details",
owning_organisation_id: organisation.id, owning_organisation_id: organisation.id,
support_services_provider_before_type_cast: "0" } } arrangement_type: "D" } }
end end
it "renders confirm secondary group after successful update" do it "renders confirm secondary group after successful update" do
@ -862,7 +861,7 @@ RSpec.describe SchemesController, type: :request do
registered_under_care_act: "", registered_under_care_act: "",
support_type: "", support_type: "",
intended_stay: "", intended_stay: "",
support_services_provider_before_type_cast: "", arrangement_type: "",
has_other_client_group: "", has_other_client_group: "",
page: "details", page: "details",
} } } }
@ -880,7 +879,7 @@ RSpec.describe SchemesController, type: :request do
expect(page).to have_content(I18n.t("activerecord.errors.models.scheme.attributes.support_type.invalid")) expect(page).to have_content(I18n.t("activerecord.errors.models.scheme.attributes.support_type.invalid"))
expect(page).to have_content(I18n.t("activerecord.errors.models.scheme.attributes.intended_stay.invalid")) expect(page).to have_content(I18n.t("activerecord.errors.models.scheme.attributes.intended_stay.invalid"))
expect(page).to have_content(I18n.t("activerecord.errors.models.scheme.attributes.has_other_client_group.invalid")) expect(page).to have_content(I18n.t("activerecord.errors.models.scheme.attributes.has_other_client_group.invalid"))
expect(page).to have_content(I18n.t("activerecord.errors.models.scheme.attributes.support_services_provider_before_type_cast.invalid")) expect(page).to have_content(I18n.t("activerecord.errors.models.scheme.attributes.arrangement_type.invalid"))
end end
context "when updating from check answers page" do context "when updating from check answers page" do
@ -1044,7 +1043,7 @@ RSpec.describe SchemesController, type: :request do
scheme_type: "Foyer", scheme_type: "Foyer",
registered_under_care_act: "No", registered_under_care_act: "No",
page: "details", page: "details",
support_services_provider_before_type_cast: "0", arrangement_type: "D",
owning_organisation_id: another_organisation.id } } owning_organisation_id: another_organisation.id } }
end end

2
spec/services/imports/scheme_import_service_spec.rb

@ -48,7 +48,7 @@ RSpec.describe Imports::SchemeImportService do
expect(scheme.old_id).to eq("6d6d7618b58affe2a150a5ef2e9f4765fa6cd05d") expect(scheme.old_id).to eq("6d6d7618b58affe2a150a5ef2e9f4765fa6cd05d")
expect(scheme.old_visible_id).to eq(123) expect(scheme.old_visible_id).to eq(123)
expect(scheme.service_name).to eq("Management Group") expect(scheme.service_name).to eq("Management Group")
expect(scheme.arrangement_type).to eq("O") expect(scheme.arrangement_type).to eq("Another organisation")
end end
context "and the scheme status is not approved" do context "and the scheme status is not approved" do

Loading…
Cancel
Save