diff --git a/app/controllers/schemes_controller.rb b/app/controllers/schemes_controller.rb index 9c5e4dcc5..aa9da0ea7 100644 --- a/app/controllers/schemes_controller.rb +++ b/app/controllers/schemes_controller.rb @@ -9,7 +9,7 @@ class SchemesController < ApplicationController def index flash[:notice] = "#{Scheme.find(params[:scheme_id].to_i).service_name} has been created." if params[:scheme_id] redirect_to schemes_organisation_path(current_user.organisation) unless current_user.support? - all_schemes = Scheme.all + all_schemes = Scheme.all.order("service_name ASC") @pagy, @schemes = pagy(filtered_collection(all_schemes, search_term)) @searched = search_term.presence @@ -26,8 +26,15 @@ class SchemesController < ApplicationController def create @scheme = Scheme.new(scheme_params) - if @scheme.save - render "schemes/primary_client_group" + + validation_errors scheme_params + + if @scheme.errors.empty? && @scheme.save + if scheme_params[:support_services_provider].zero? + redirect_to scheme_primary_client_group_path(@scheme) + else + redirect_to scheme_support_services_provider_path(@scheme) + end else @scheme.errors.add(:owning_organisation_id, message: @scheme.errors[:organisation]) @scheme.errors.delete(:owning_organisation) @@ -39,7 +46,9 @@ class SchemesController < ApplicationController check_answers = params[:scheme][:check_answers] page = params[:scheme][:page] - if @scheme.update(scheme_params) + validation_errors scheme_params + + if @scheme.errors.empty? && @scheme.update(scheme_params) if check_answers if confirm_secondary_page? page redirect_to scheme_secondary_client_group_path(@scheme, check_answers: "true") @@ -51,7 +60,7 @@ class SchemesController < ApplicationController redirect_to next_page_path params[:scheme][:page] end else - render request.current_url, status: :unprocessable_entity + render current_template(page), status: :unprocessable_entity end end @@ -83,14 +92,48 @@ class SchemesController < ApplicationController render "schemes/edit_name" end + def support_services_provider + render "schemes/support_services_provider" + end + private + def validation_errors(scheme_params) + scheme_params.each_key do |key| + if key == "support_services_provider" + @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) + end + end + end + def confirm_secondary_page?(page) page == "confirm-secondary" && @scheme.has_other_client_group == "Yes" end + def current_template(page) + if page.include?("primary") + "schemes/primary_client_group" + elsif page.include?("support-services-provider") + "schemes/support_services_provider" + elsif page.include?("confirm") + "schemes/confirm_secondary" + elsif page.include?("secondary-client") + "schemes/secondary_client_group" + elsif page.include?("support") + "schemes/support" + elsif page.include?("details") + "schemes/details" + elsif page.include?("edit") + "schemes/edit_name" + end + end + def next_page_path(page) case page + when "support-services-provider" + scheme_primary_client_group_path(@scheme) when "primary-client-group" scheme_confirm_secondary_client_group_path(@scheme) when "confirm-secondary" @@ -100,7 +143,13 @@ private when "support" new_location_path when "details" - scheme_primary_client_group_path(@scheme) + if @scheme.support_services_provider_before_type_cast&.zero? + scheme_primary_client_group_path(@scheme) + elsif @scheme.support_services_provider_before_type_cast.positive? + scheme_support_services_provider_path(@scheme) + else + scheme_details_path(@scheme) + end when "edit-name" scheme_path(@scheme) end @@ -118,13 +167,19 @@ private :primary_client_group, :secondary_client_group, :support_type, - :intended_stay) + :support_services_provider, + :support_services_provider_before_type_cast, + :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[: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? - required_params[:sensitive] = required_params[:sensitive].to_i if required_params[:sensitive] if current_user.data_coordinator? - required_params[:owning_organisation_id] = current_user.organisation_id + full_params[:owning_organisation_id] = current_user.organisation_id end - required_params + full_params.except(:support_services_provider_before_type_cast) end def search_term diff --git a/app/models/location.rb b/app/models/location.rb index a44640889..0d5bf1a76 100644 --- a/app/models/location.rb +++ b/app/models/location.rb @@ -1,5 +1,6 @@ class Location < ApplicationRecord validate :validate_postcode + validates :units, :type_of_unit, presence: true belongs_to :scheme before_save :infer_la!, if: :postcode_changed? @@ -24,12 +25,12 @@ class Location < ApplicationRecord enum mobility_type: MOBILITY_TYPE TYPE_OF_UNIT = { + "Bungalow": 6, "Self-contained flat or bedsit": 1, "Self-contained flat or bedsit with common facilities": 2, + "Self-contained house": 7, "Shared flat": 3, "Shared house or hostel": 4, - "Bungalow": 6, - "Self-contained house": 7, }.freeze enum type_of_unit: TYPE_OF_UNIT diff --git a/app/models/scheme.rb b/app/models/scheme.rb index bdd9671ed..cbe10af1d 100644 --- a/app/models/scheme.rb +++ b/app/models/scheme.rb @@ -17,39 +17,37 @@ class Scheme < ApplicationRecord enum sensitive: SENSITIVE, _suffix: true REGISTERED_UNDER_CARE_ACT = { - "No": 1, "Yes – registered care home providing nursing care": 4, "Yes – registered care home providing personal care": 3, "Yes – part registered as a care home": 2, + "No": 1, }.freeze enum registered_under_care_act: REGISTERED_UNDER_CARE_ACT SCHEME_TYPE = { - "Missing": 0, - "Foyer": 4, "Direct Access Hostel": 5, - "Other Supported Housing": 6, + "Foyer": 4, "Housing for older people": 7, + "Other Supported Housing": 6, + "Missing": 0, }.freeze enum scheme_type: SCHEME_TYPE, _suffix: true SUPPORT_TYPE = { "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, + "Low level": 2, + "Medium level": 3, + "High level": 4, + "Nursing care in a care home": 5, }.freeze enum support_type: SUPPORT_TYPE, _suffix: true PRIMARY_CLIENT_GROUP = { "Homeless families with support needs": "O", - "Offenders & people at risk of offending": "H", + "Offenders and 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", @@ -71,10 +69,10 @@ class Scheme < ApplicationRecord enum secondary_client_group: PRIMARY_CLIENT_GROUP, _suffix: true INTENDED_STAY = { + "Very short stay": "V", + "Short stay": "S", "Medium stay": "M", "Permanent": "P", - "Short stay": "S", - "Very short stay": "V", "Missing": "X", }.freeze @@ -86,6 +84,15 @@ class Scheme < ApplicationRecord enum intended_stay: INTENDED_STAY, _suffix: true enum has_other_client_group: HAS_OTHER_CLIENT_GROUP, _suffix: true + SUPPORT_SERVICES_PROVIDER = { + "The same organisation that owns the housing stock": 0, + "Another registered housing provider": 1, + "A registered charity or voluntary organisation": 2, + "Another organisation": 3, + }.freeze + + enum support_services_provider: SUPPORT_SERVICES_PROVIDER + def id_to_display "S#{id}" end @@ -95,10 +102,16 @@ class Scheme < ApplicationRecord { name: "Service code", value: id_to_display }, { name: "Name", value: service_name }, { name: "Confidential information", value: sensitive }, - { name: "Housing stock owned by", value: owning_organisation.name }, - { name: "Managed by", value: managing_organisation&.name }, { name: "Type of scheme", value: scheme_type }, { name: "Registered under Care Standards Act 2000", value: registered_under_care_act }, + { name: "Housing stock owned by", value: owning_organisation.name }, + { name: "Support provided by", value: support_services_provider }, + ] + end + + def check_support_services_provider_attributes + [ + { name: "Organisation providing support", value: managing_organisation&.name }, ] end @@ -129,14 +142,16 @@ class Scheme < ApplicationRecord def display_attributes [ - { name: "Service code", value: id_to_display }, + { name: "Scheme code", value: id_to_display }, { name: "Name", value: service_name, edit: true }, { name: "Confidential information", value: sensitive, edit: true }, - { name: "Housing stock owned by", value: owning_organisation.name, edit: true }, - { name: "Managed by", value: managing_organisation&.name }, { name: "Type of scheme", value: scheme_type }, { name: "Registered under Care Standards Act 2000", value: registered_under_care_act }, + { name: "Housing stock owned by", value: owning_organisation.name, edit: true }, + { name: "Support services provided by", value: support_services_provider }, + { name: "Organisation providing support", value: managing_organisation&.name }, { name: "Primary client group", value: primary_client_group }, + { name: "Has another client group", value: has_other_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 }, @@ -154,4 +169,30 @@ class Scheme < ApplicationRecord def hint [primary_client_group, secondary_client_group].filter(&:present?).join(", ") end + + def care_acts_options_with_hints + hints = { "Yes – part registered as a care home": "A proportion of units are registered as being a care home." } + + Scheme.registered_under_care_acts.keys.map { |key, _| OpenStruct.new(id: key, name: key.to_s.humanize, description: hints[key.to_sym]) } + end + + def support_level_options_with_hints + hints = { + "Low level": "Staff visiting once a week, fortnightly or less.", + "Medium level": "Staff on site daily or making frequent visits with some out-of-hours cover.", + "High level": "Intensive level of staffing provided on a 24-hour basis.", + } + Scheme.support_types.keys.excluding("Missing").map { |key, _| OpenStruct.new(id: key, name: key.to_s.humanize, description: hints[key.to_sym]) } + end + + def intended_length_of_stay_options_with_hints + hints = { + "Very short stay": "Up to one month.", + "Short stay": "Up to one year.", + "Medium stay": "More than one year but with an expectation to move on.", + "Permanent": "Provides a home for life with no requirement for the tenant to move.", + + } + Scheme.intended_stays.keys.excluding("Missing").map { |key, _| OpenStruct.new(id: key, name: key.to_s.humanize, description: hints[key.to_sym]) } + end end diff --git a/app/views/schemes/check_answers.html.erb b/app/views/schemes/check_answers.html.erb index eb9fe5ef3..ef3bd16ed 100644 --- a/app/views/schemes/check_answers.html.erb +++ b/app/views/schemes/check_answers.html.erb @@ -1,5 +1,4 @@ <% content_for :title, "Check your answers before creating this scheme" %> - <%= render partial: "organisations/headings", locals: { main: "Check your changes before creating this scheme", sub: @scheme.service_name } %>
@@ -18,6 +17,16 @@ ) %> <% end %> <% end %> + <% @scheme.check_support_services_provider_attributes.each do |attr| %> + <%= summary_list.row do |row| %> + <% row.key { attr[:name].to_s } %> + <% row.value { details_html(attr) } %> + <% row.action( + text: "Change", + href: scheme_support_services_provider_path(scheme_id: @scheme.id, check_answers: true), + ) %> + <% end %> + <% end %> <% @scheme.check_primary_client_attributes.each do |attr| %> <%= summary_list.row do |row| %> <% row.key { attr[:name].to_s } %> diff --git a/app/views/schemes/details.html.erb b/app/views/schemes/details.html.erb index 4ae640208..dd05c4a00 100644 --- a/app/views/schemes/details.html.erb +++ b/app/views/schemes/details.html.erb @@ -2,9 +2,9 @@ <% content_for :before_content do %> <%= govuk_back_link( - text: "Back", - href: :back, - ) %> + text: "Back", + href: :back, + ) %> <% end %> <%= render partial: "organisations/headings", locals: { main: "Create a new supported housing scheme", sub: nil } %> @@ -15,11 +15,11 @@ <%= f.govuk_error_summary %> <%= f.govuk_text_field :service_name, - label: { text: "Scheme name", size: "m" }, - hint: { text: "This is how you refer to this supported housing scheme within your organisation. For example, the name could relate to the address or location. You’ll be able to see the client group when selecting it." } %> + label: { text: "Scheme name", size: "m" }, + hint: { text: "This is how you refer to this supported housing scheme within your organisation. For example, the name could relate to the address or location. You’ll be able to see the client group when selecting it." } %> <%= f.govuk_check_boxes_fieldset :sensitive, - legend: nil do %> + legend: nil do %> <%= f.govuk_check_box :sensitive, 1, 0, @@ -28,17 +28,31 @@ label: { text: "This scheme contains confidential information" } %> <% end %> - <% null_option = [OpenStruct.new(id: "", name: "Select an option")] %> - <% organisations = Organisation.all.map { |org| OpenStruct.new(id: org.id, name: org.name) } %> - <% managing_org_answer_options = null_option + organisations %> + <% if current_user.data_coordinator? %> + <%= f.hidden_field :owning_organisation_id, value: current_user.organisation.id %> + <% end %> + + <% scheme_types_selection = Scheme.scheme_types.keys.excluding("Missing").map { |key, _| OpenStruct.new(id: key, name: key.to_s.humanize) } %> + + <%= f.govuk_collection_radio_buttons :scheme_type, + scheme_types_selection, + :id, + :name, + legend: { text: "What is this type of scheme?", size: "m" } %> + + <% care_acts_options_hints = { "Yes – part registered as a care home": "A proportion of units are registered as being a care home." } %> + + <% care_acts_options_with_hints = Scheme.registered_under_care_acts.keys.map { |key, _| OpenStruct.new(id: key, name: key.to_s.humanize, description: care_acts_options_hints[key.to_sym]) } %> + + <%= f.govuk_collection_radio_buttons :registered_under_care_act, + care_acts_options_with_hints, + :id, + :name, + :description, + legend: { text: "Is this scheme registered under the Care Standards Act 2000?", size: "m" }, + bold_labels: false %> - <%= f.govuk_collection_select :managing_organisation_id, - managing_org_answer_options, - :id, - :name, - label: { text: "Which organisation manages this scheme?", size: "m" }, - options: { required: true }, - "data-controller": %w[accessible-autocomplete conditional-filter] %> + <% organisations = Organisation.all.map { |org| OpenStruct.new(id: org.id, name: org.name) } %> <% if current_user.support? %> <%= f.govuk_collection_select :owning_organisation_id, @@ -49,29 +63,24 @@ "data-controller": %w[accessible-autocomplete conditional-filter] %> <% end %> - <% if current_user.data_coordinator? %> - <%= f.hidden_field :owning_organisation_id, value: current_user.organisation.id %> + <% support_services_provider_selection = Scheme.support_services_providers.map do |key, value| %> + <% OpenStruct.new(id: value, name: key.to_s.humanize) %> <% end %> - - <% scheme_types_selection = Scheme.scheme_types.keys.excluding("Missing").map { |key, _| OpenStruct.new(id: key, name: key.to_s.humanize) } %> - - <%= f.govuk_collection_radio_buttons :scheme_type, - scheme_types_selection, - :id, - :name, - legend: { text: "What is this type of scheme?", size: "m" } %> - - <% care_acts_selection = Scheme.registered_under_care_acts.keys.reverse.map { |key, _| OpenStruct.new(id: key, name: key.to_s.humanize) } %> - - <%= f.govuk_collection_radio_buttons :registered_under_care_act, - care_acts_selection, - :id, - :name, - legend: { text: "Is this scheme registered under the Care Standards Act 2000?", size: "m" } %> + <%= f.govuk_collection_radio_buttons :support_services_provider_before_type_cast, + support_services_provider_selection, + :id, + lambda { |option| + if option.id.zero? && !current_user.support? + "Your organisation" + else + option.name + end + }, + legend: { text: "Who provides the support services used by this scheme?", size: "m" } %> <%= f.hidden_field :page, value: "details" %> <% if request.query_parameters["check_answers"] %> - <%= f.hidden_field :check_answers, value: "true" %> + <%= f.hidden_field :check_answers, value: "true" %> <% end %> <%= f.govuk_submit "Save and continue" %>
diff --git a/app/views/schemes/edit_name.html.erb b/app/views/schemes/edit_name.html.erb index 876e73a25..8ce38c9d6 100644 --- a/app/views/schemes/edit_name.html.erb +++ b/app/views/schemes/edit_name.html.erb @@ -29,6 +29,7 @@ <% end %> <% organisations = Organisation.all.map { |org| OpenStruct.new(id: org.id, name: org.name) } %> + <% if current_user.support? %> <%= f.govuk_collection_select :owning_organisation_id, organisations, @@ -40,6 +41,10 @@ <%= f.hidden_field :page, value: "edit-name" %> + <% if request.query_parameters["check_answers"] %> + <%= f.hidden_field :check_answers, value: "true" %> + <% end %> + <%= f.govuk_submit "Save changes" %> diff --git a/app/views/schemes/new.html.erb b/app/views/schemes/new.html.erb index 297af9cef..9a2a3c6d4 100644 --- a/app/views/schemes/new.html.erb +++ b/app/views/schemes/new.html.erb @@ -2,9 +2,9 @@ <% content_for :before_content do %> <%= govuk_back_link( - text: "Back", - href: "javascript:history.go(-1);", - ) %> + text: "Back", + href: "javascript:history.go(-1);", + ) %> <% end %> <%= form_for(@scheme, as: :scheme, method: :post) do |f| %> @@ -17,8 +17,8 @@ <%= f.govuk_text_field :service_name, - label: { text: "Scheme name", size: "m" }, - hint: { text: "This is how you refer to this supported housing scheme within your organisation. For example, the name could relate to the address or location. You’ll be able to see the client group when selecting it." } %> + label: { text: "Scheme name", size: "m" }, + hint: { text: "This is how you refer to this supported housing scheme within your organisation. For example, the name could relate to the address or location. You’ll be able to see the client group when selecting it." } %> <%= f.govuk_check_boxes_fieldset :sensitive, legend: nil do %> @@ -33,12 +33,29 @@ <% organisations = Organisation.all.map { |org| OpenStruct.new(id: org.id, name: org.name) } %> <% answer_options = null_option + organisations %> - <%= f.govuk_collection_select :managing_organisation_id, - answer_options, - :id, - :name, - label: { text: "Which organisation manages this scheme?", size: "m" }, - "data-controller": %w[accessible-autocomplete conditional-filter] %> + <% if current_user.data_coordinator? %> + <%= f.hidden_field :owning_organisation_id, value: current_user.organisation.id %> + <% end %> + + <% scheme_types_selection = Scheme.scheme_types.keys.excluding("Missing").map { |key, _| OpenStruct.new(id: key, name: key.to_s.humanize) } %> + <%= f.govuk_collection_radio_buttons :scheme_type, + scheme_types_selection, + :id, + :name, + legend: { text: "What is this type of scheme?", size: "m" } %> + + <% care_acts_options_hints = { "Yes – part registered as a care home": "A proportion of units are registered as being a care home." } %> + + <% care_acts_options_with_hints = Scheme.registered_under_care_acts.keys.map { |key, _| OpenStruct.new(id: key, name: key.to_s.humanize, description: care_acts_options_hints[key.to_sym]) } %> + + <%= f.govuk_collection_radio_buttons :registered_under_care_act, + care_acts_options_with_hints, + :id, + :name, + :description, + legend: { text: "Is this scheme registered under the Care Standards Act 2000?", size: "m" }, + bold_labels: false %> + <% if current_user.support? %> <%= f.govuk_collection_select :owning_organisation_id, answer_options, @@ -48,23 +65,21 @@ "data-controller": %w[accessible-autocomplete conditional-filter] %> <% end %> - <% if current_user.data_coordinator? %> - <%= f.hidden_field :owning_organisation_id, value: current_user.organisation.id %> + <% support_services_provider_selection = Scheme.support_services_providers.map do |key, value| %> + <% OpenStruct.new(id: value, name: key.to_s.humanize) %> <% end %> - <% scheme_types_selection = Scheme.scheme_types.keys.excluding("Missing").map { |key, _| OpenStruct.new(id: key, name: key.to_s.humanize) } %> - <%= f.govuk_collection_radio_buttons :scheme_type, - scheme_types_selection, - :id, - :name, - legend: { text: "What is this type of scheme?", size: "m" } %> - - <% care_acts_selection = Scheme.registered_under_care_acts.keys.reverse.map { |key, _| OpenStruct.new(id: key, name: key.to_s.humanize) } %> - <%= f.govuk_collection_radio_buttons :registered_under_care_act, - care_acts_selection, - :id, - :name, - legend: { text: "Is this scheme registered under the Care Standards Act 2000?", size: "m" } %> + <%= f.govuk_collection_radio_buttons :support_services_provider_before_type_cast, + support_services_provider_selection, + :id, + lambda { |option| + if option.id.zero? && !current_user.support? + "Your organisation" + else + option.name + end + }, + legend: { text: "Who provides the support services used by this scheme?", size: "m" } %> <%= f.govuk_submit "Save and continue" %> diff --git a/app/views/schemes/primary_client_group.html.erb b/app/views/schemes/primary_client_group.html.erb index 893eaff59..2b1407b1a 100644 --- a/app/views/schemes/primary_client_group.html.erb +++ b/app/views/schemes/primary_client_group.html.erb @@ -1,9 +1,17 @@ <% content_for :title, "What client group is this scheme intended for?" %> +<% if request.referer&.include?("new") || request.referer&.include?("details") %> + <% back_button_path = scheme_details_path(@scheme) %> +<% elsif request.referer&.include?("provider") %> + <% back_button_path = scheme_support_services_provider_path(@scheme) %> +<% elsif request.query_parameters["check_answers"] %> + <% back_button_path = scheme_check_answers_path(@scheme) %> +<% end %> + <% content_for :before_content do %> <%= govuk_back_link( text: "Back", - href: request.query_parameters["check_answers"] ? "/schemes/#{@scheme.id}/check-answers" : "/schemes/#{@scheme.id}/details", + href: back_button_path, ) %> <% end %> @@ -14,7 +22,7 @@
<%= f.govuk_error_summary %> - <% primary_client_group_selection = Scheme.primary_client_groups.keys.excluding("Missing").map { |key, _| OpenStruct.new(id: key, name: key.to_s.humanize) } %> + <% primary_client_group_selection = Scheme.primary_client_groups.keys.excluding("Missing").map { |key, _| OpenStruct.new(id: key, name: key) } %> <%= f.govuk_collection_radio_buttons :primary_client_group, primary_client_group_selection, :id, @@ -25,6 +33,9 @@ <% if request.query_parameters["check_answers"] == "true" %> <%= f.hidden_field :check_answers, value: "true" %> <% end %> + <% if request.query_parameters["select_managing_org"] == "true" %> + <%= f.hidden_field :check_answers, value: "true" %> + <% end %> <%= f.govuk_submit "Save and continue" %>
diff --git a/app/views/schemes/secondary_client_group.html.erb b/app/views/schemes/secondary_client_group.html.erb index eb88881c4..5ef5b1a1a 100644 --- a/app/views/schemes/secondary_client_group.html.erb +++ b/app/views/schemes/secondary_client_group.html.erb @@ -14,7 +14,7 @@
<%= f.govuk_error_summary %> - <% secondary_client_group_selection = Scheme.secondary_client_groups.keys.excluding("Missing").map { |key, _| OpenStruct.new(id: key, name: key.to_s.humanize) } %> + <% secondary_client_group_selection = Scheme.secondary_client_groups.keys.excluding("Missing").map { |key, _| OpenStruct.new(id: key, name: key) } %> <%= f.govuk_collection_radio_buttons :secondary_client_group, secondary_client_group_selection, :id, diff --git a/app/views/schemes/support.html.erb b/app/views/schemes/support.html.erb index b4482bf66..dd2758cfd 100644 --- a/app/views/schemes/support.html.erb +++ b/app/views/schemes/support.html.erb @@ -14,19 +14,29 @@
<%= f.govuk_error_summary %> - <% support_type_selection = Scheme.support_types.keys.excluding("Missing").map { |key, _| OpenStruct.new(id: key, name: key.to_s.humanize) } %> + <% support_level_options_hints = { "Low level": "Staff visiting once a week, fortnightly or less.", "Medium level": "Staff on site daily or making frequent visits with some out-of-hours cover.", "High level": "Intensive level of staffing provided on a 24-hour basis." } %> + + <% support_level_options_with_hints = Scheme.support_types.keys.excluding("Missing").map { |key, _| OpenStruct.new(id: key, name: key.to_s.humanize, description: support_level_options_hints[key.to_sym]) } %> + <%= f.govuk_collection_radio_buttons :support_type, - support_type_selection, - :id, - :name, - legend: { text: "Level of support given", size: "m" } %> + support_level_options_with_hints, + :id, + :name, + :description, + legend: { text: "Level of support given", size: "m" }, + bold_labels: false %> + + <% intended_length_of_stay_options_hints = { "Very short stay": "Up to one month.", "Short stay": "Up to one year.", "Medium stay": "More than one year but with an expectation to move on.", "Permanent": "Provides a home for life with no requirement for the tenant to move." } %> + + <% intended_length_of_stay_options_with_hints = Scheme.intended_stays.keys.excluding("Missing").map { |key, _| OpenStruct.new(id: key, name: key.to_s.humanize, description: intended_length_of_stay_options_hints[key.to_sym]) } %> - <% intended_stay_selection = Scheme.intended_stays.keys.excluding("Missing").map { |key, _| OpenStruct.new(id: key, name: key.to_s.humanize) } %> <%= f.govuk_collection_radio_buttons :intended_stay, - intended_stay_selection, - :id, - :name, - legend: { text: "Intended length of stay", size: "m" } %> + intended_length_of_stay_options_with_hints, + :id, + :name, + :description, + legend: { text: "Intended length of stay", size: "m" }, + bold_labels: false %> <%= f.hidden_field :page, value: "support" %> diff --git a/app/views/schemes/support_services_provider.html.erb b/app/views/schemes/support_services_provider.html.erb new file mode 100644 index 000000000..5a1dae620 --- /dev/null +++ b/app/views/schemes/support_services_provider.html.erb @@ -0,0 +1,36 @@ +<% content_for :title, "Which organisation provides the support services used by this scheme?" %> + +<% content_for :before_content do %> + <%= govuk_back_link( + text: "Back", + href: request.query_parameters["check_answers"] ? "/schemes/#{@scheme.id}/check-answers" : "/schemes/#{@scheme.id}/details", + ) %> +<% end %> + +<%= render partial: "organisations/headings", locals: { main: "Which organisation provides the support services used by this scheme?", sub: nil } %> + +<%= form_for(@scheme, method: :patch) do |f| %> +
+
+ <%= f.govuk_error_summary %> + + <% null_option = [OpenStruct.new(id: "", name: "Select an option")] %> + <% organisations = Organisation.all.map { |org| OpenStruct.new(id: org.id, name: org.name) } %> + <% managing_org_answer_options = null_option + organisations %> + + <%= f.govuk_collection_select :managing_organisation_id, + managing_org_answer_options, + :id, + :name, + label: { text: "Which organisation manages this scheme?", size: "m" }, + options: { required: true }, + "data-controller": %w[accessible-autocomplete conditional-filter] %> + + <%= f.hidden_field :page, value: "support-services-provider" %> + <% if request.query_parameters["check_answers"] %> + <%= f.hidden_field :check_answers, value: "true" %> + <% end %> + <%= f.govuk_submit "Save and continue" %> +
+
+<% end %> diff --git a/app/views/users/new.html.erb b/app/views/users/new.html.erb index 2b3db667e..1965da4a2 100644 --- a/app/views/users/new.html.erb +++ b/app/views/users/new.html.erb @@ -15,7 +15,7 @@ <%= f.govuk_text_field :name, autocomplete: "name", - label: { text: "Name (optional)", size: "m" } %> + label: { text: "Location name (optional)", size: "m" } %> <%= f.govuk_email_field :email, label: { text: "Email address", size: "m" }, diff --git a/config/locales/en.yml b/config/locales/en.yml index 6b5ad6412..76709ba83 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -44,8 +44,35 @@ en: scheme: attributes: owning_organisation_id: - required: "Enter the existing organisation’s name" invalid: "Enter the existing organisation’s name" + managing_organisation_id: + invalid: "Enter the existing organisation’s name" + service_name: + invalid: "Enter the scheme’s name" + scheme_type: + invalid: "Select the scheme’s type" + registered_under_care_act: + invalid: "Select if this scheme is registered under the Care Standards Act 2000" + primary_client_group: + invalid: "Select what client group is this scheme intended for" + secondary_client_group: + invalid: "Select what is the other client group" + support_type: + invalid: "Select level of support given" + intended_stay: + invalid: "Select intended length of stay" + has_other_client_group: + invalid: "Select if this scheme provides for another client group" + support_services_provider: + 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" + location: + attributes: + units: + blank: "Enter total number of units at this location" + type_of_unit: + blank: "Select the most common type of unit at this location" validations: organisation: diff --git a/config/routes.rb b/config/routes.rb index de42be41a..dc6588142 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -43,6 +43,7 @@ Rails.application.routes.draw do get "details", to: "schemes#details" get "check-answers", to: "schemes#check_answers" get "edit-name", to: "schemes#edit_name" + get "support-services-provider", to: "schemes#support_services_provider" member do resources :locations do diff --git a/db/migrate/20220711134558_add_support_services_provider_to_schemes.rb b/db/migrate/20220711134558_add_support_services_provider_to_schemes.rb new file mode 100644 index 000000000..e2c7de937 --- /dev/null +++ b/db/migrate/20220711134558_add_support_services_provider_to_schemes.rb @@ -0,0 +1,5 @@ +class AddSupportServicesProviderToSchemes < ActiveRecord::Migration[7.0] + def change + add_column :schemes, :support_services_provider, :integer + end +end diff --git a/db/schema.rb b/db/schema.rb index 7654de950..096056489 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -257,7 +257,7 @@ ActiveRecord::Schema[7.0].define(version: 2022_07_15_133937) do create_table "logs_exports", force: :cascade do |t| t.datetime "created_at", default: -> { "CURRENT_TIMESTAMP" } - t.datetime "started_at", precision: nil, null: false + t.datetime "started_at", null: false t.integer "base_number", default: 1, null: false t.integer "increment_number", default: 1, null: false t.boolean "empty_export", default: false, null: false @@ -321,6 +321,7 @@ ActiveRecord::Schema[7.0].define(version: 2022_07_15_133937) do t.string "old_id" t.integer "old_visible_id" t.integer "total_units" + t.integer "support_services_provider" t.index ["managing_organisation_id"], name: "index_schemes_on_managing_organisation_id" t.index ["owning_organisation_id"], name: "index_schemes_on_owning_organisation_id" end diff --git a/db/seeds.rb b/db/seeds.rb index 3ac0aa7d5..03a61cf59 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -73,8 +73,8 @@ unless Rails.env.test? scheme1 = Scheme.create!( service_name: "Beulahside Care", sensitive: 0, - registered_under_care_act: 0, - support_type: 1, + registered_under_care_act: 1, + support_type: 2, scheme_type: 4, intended_stay: "M", primary_client_group: "O", @@ -87,7 +87,7 @@ unless Rails.env.test? service_name: "Abdullahview Point", sensitive: 0, registered_under_care_act: 1, - support_type: 1, + support_type: 2, scheme_type: 5, intended_stay: "S", primary_client_group: "D", @@ -115,9 +115,9 @@ unless Rails.env.test? postcode: "CU193AA", name: "Rectory Road", type_of_unit: 4, + units: 1, type_of_building: "Purpose built", - county: "Mid Sussex", - wheelchair_adaptation: 0, + wheelchair_adaptation: 2, ) Location.create!( @@ -126,8 +126,8 @@ unless Rails.env.test? postcode: "DM250DC", name: "Smithy Lane", type_of_unit: 1, + units: 1, type_of_building: "Converted from previous residential or non-residential property", - county: "Fife", wheelchair_adaptation: 1, ) @@ -137,8 +137,8 @@ unless Rails.env.test? postcode: "YX130WP", name: "Smithy Lane", type_of_unit: 2, + units: 1, type_of_building: "Converted from previous residential or non-residential property", - county: "Rochford", wheelchair_adaptation: 1, ) end diff --git a/spec/factories/location.rb b/spec/factories/location.rb index daef3d2ce..934f6d1be 100644 --- a/spec/factories/location.rb +++ b/spec/factories/location.rb @@ -3,6 +3,7 @@ FactoryBot.define do postcode { Faker::Address.postcode.delete(" ") } name { Faker::Address.street_name } type_of_unit { [1, 2, 3, 4, 6, 7].sample } + units { [1, 2, 3, 4, 6, 7].sample } type_of_building { "Purpose built" } mobility_type { %w[A M N W X].sample } wheelchair_adaptation { 2 } diff --git a/spec/factories/scheme.rb b/spec/factories/scheme.rb index ecd83a930..c27b8a576 100644 --- a/spec/factories/scheme.rb +++ b/spec/factories/scheme.rb @@ -3,7 +3,7 @@ FactoryBot.define do service_name { Faker::Name.name } sensitive { Faker::Number.within(range: 0..1) } registered_under_care_act { 1 } - support_type { Faker::Number.within(range: 0..6) } + support_type { [0, 2, 3, 4, 5].sample } scheme_type { 0 } 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 } diff --git a/spec/features/schemes_spec.rb b/spec/features/schemes_spec.rb index 9230ab143..049916ce5 100644 --- a/spec/features/schemes_spec.rb +++ b/spec/features/schemes_spec.rb @@ -240,9 +240,9 @@ RSpec.describe "Schemes scheme Features" do expect(page).to have_content "Scheme name" expect(page).to have_content "This scheme contains confidential information" expect(page).to have_content "Which organisation owns the housing stock for this scheme?" - expect(page).to have_content "Which organisation manages this scheme?" expect(page).to have_content "What is this type of scheme?" expect(page).to have_content "Is this scheme registered under the Care Standards Act 2000?" + expect(page).to have_content "Who provides the support services used by this scheme?" end context "when I fill in scheme details and I press save I see primary client group section" do @@ -253,8 +253,8 @@ RSpec.describe "Schemes scheme Features" do check "This scheme contains confidential information" choose "Direct access hostel" choose "Yes – registered care home providing nursing care" - select organisation.name, from: "scheme-managing-organisation-id-field" select organisation.name, from: "scheme-owning-organisation-id-field" + choose "The same organisation that owns the housing stock" click_button "Save and continue" end @@ -271,8 +271,8 @@ RSpec.describe "Schemes scheme Features" do expect(page).to have_current_path("/schemes/#{scheme.id}/details") expect(page).to have_content "Scheme name" expect(page).to have_content "This scheme contains confidential information" - expect(page).to have_content "Which organisation manages this scheme" expect(page).to have_content "What is this type of scheme?" + expect(page).to have_content "Who provides the support services used by this scheme?" expect(page).to have_content "Is this scheme registered under the Care Standards Act 2000?" end @@ -370,7 +370,7 @@ RSpec.describe "Schemes scheme Features" do context "when I select the support answers" do before do - choose "Floating support" + choose "Low level" choose "Very short stay" click_button "Save and continue" end @@ -479,7 +479,7 @@ RSpec.describe "Schemes scheme Features" do context "when changing answers" do it "displays change links" do - assert_selector "a", text: "Change", count: 12 + assert_selector "a", text: "Change", count: 13 end context "when changing details" do @@ -491,13 +491,10 @@ RSpec.describe "Schemes scheme Features" do expect(page).to have_current_path("/schemes/#{scheme.id}/details?check_answers=true") fill_in "Scheme name", with: "Example" - choose "Direct access hostel" - choose "Yes – registered care home providing nursing care" click_button "Save and continue" expect(page).to have_current_path("/schemes/#{scheme.id}/check-answers") expect(page).to have_content "Example" - expect(page).to have_content "Yes – registered care home providing nursing care" end context "when I press the back button" do @@ -511,150 +508,317 @@ RSpec.describe "Schemes scheme Features" do end end end + end - context "when changing primary client group" do - before do - click_link("Change", href: "/schemes/#{scheme.id}/primary-client-group?check_answers=true") - end + context "and I select to create a scheme" do + before do + click_link "Create scheme" + end - it "allows changing primary-client-group question" do - expect(page).to have_current_path("/schemes/#{scheme.id}/primary-client-group?check_answers=true") + it "adds scheme to the list of schemes" do + expect(page).to have_content "Supported housing schemes" + expect(page).to have_content scheme.id_to_display + expect(page).to have_content scheme.service_name + expect(page).to have_content scheme.owning_organisation.name + expect(page).to have_content "#{scheme.owning_organisation.name} has been created." + end + end + end + end + end + end + end + end - choose "Older people with support needs" - click_button "Save and continue" + context "when I fill in scheme details indicating that supported services provided by a different organisation and I press save I see primary client group section" do + let(:scheme) { Scheme.first } + let!(:another_organisation) { FactoryBot.create(:organisation, name: "Another Org") } - expect(page).to have_current_path("/schemes/#{scheme.id}/check-answers") - expect(page).to have_content "Older people with support needs" - end + before do + fill_in "Scheme name", with: "FooBar" + check "This scheme contains confidential information" + choose "Direct access hostel" + choose "Yes – registered care home providing nursing care" + select organisation.name, from: "scheme-owning-organisation-id-field" + choose "Another registered housing provider" + click_button "Save and continue" + end - context "when I press the back button" do - before do - click_link "Back" - end + it "lets me fill in the managing organisation details" do + expect(page).to have_content "Which organisation provides the support services used by this scheme?" + end - it "lets me select the support answers" do - expect(page).to have_current_path("/schemes/#{scheme.id}/check-answers") - expect(page).to have_content "Check your changes before creating this scheme" - end - end - end + context "when I press the back button" do + before do + click_link "Back" + end - context "when changing confirm secondary group answer" do - before do - click_link("Change", href: "/schemes/#{scheme.id}/confirm-secondary-client-group?check_answers=true") - end + it "lets me fill in the scheme details" do + expect(page).to have_current_path("/schemes/#{scheme.id}/details") + expect(page).to have_content "Scheme name" + expect(page).to have_content "This scheme contains confidential information" + expect(page).to have_content "What is this type of scheme?" + expect(page).to have_content "Who provides the support services used by this scheme?" + expect(page).to have_content "Is this scheme registered under the Care Standards Act 2000?" + end - it "allows changing confirm-secondary-client-group question to yes" do - expect(page).to have_current_path("/schemes/#{scheme.id}/confirm-secondary-client-group?check_answers=true") + context "when we amend scheme details" do + it "returns to the primary client group question" do + click_button "Save and continue" + expect(page).to have_current_path("/schemes/#{scheme.id}/support-services-provider") + end + end + end - choose "Yes" - click_button "Save and continue" + context "when I select organisation providing support for scheme" do + before do + select another_organisation.name, from: "scheme-managing-organisation-id-field" + click_button "Save and continue" + end - expect(page).to have_current_path("/schemes/#{scheme.id}/secondary-client-group?check_answers=true") + it "lets me select the primary client group" do + expect(page).to have_content "What client group is this scheme intended for?" + end - choose "People at risk of domestic violence" - click_button "Save and continue" + context "when I select primary client group details" do + before do + choose "Homeless families with support needs" + click_button "Save and continue" + end - expect(page).to have_current_path("/schemes/#{scheme.id}/check-answers") - expect(page).to have_content "People at risk of domestic violence" - end + it "lets me confirm if I want to select secondary group details" do + expect(page).to have_content "Does this scheme provide for another client group?" + end - context "when I press the back button" do - before do - click_link "Back" - end + context "when I press the back button" do + before do + click_link "Back" + end - it "lets me select the support answers" do - expect(page).to have_current_path("/schemes/#{scheme.id}/check-answers") - expect(page).to have_content "Check your changes before creating this scheme" - end - end + it "lets me select the primary client group" do + expect(page).to have_current_path("/schemes/#{scheme.id}/primary-client-group") + expect(page).to have_content "What client group is this scheme intended for?" + end + + context "when we amend primary client group" do + it "returns to the confirm secondary client group question" do + click_button "Save and continue" + expect(page).to have_current_path("/schemes/#{scheme.id}/confirm-secondary-client-group") + end + end + end + + context "when I confirm the secondary group" do + before do + choose "Yes" + click_button "Save and continue" + end + + it "lets me select secondary client group" do + expect(page).to have_content "What is the other client group?" + end + + context "when I press the back button" do + before do + click_link "Back" + end + + it "lets me confirm the secondary group" do + expect(page).to have_current_path("/schemes/#{scheme.id}/confirm-secondary-client-group") + expect(page).to have_content "Does this scheme provide for another client group?" + end + + context "when we amend confirm secondary client" do + it "returns to the secondary client group question" do + click_button "Save and continue" + expect(page).to have_current_path("/schemes/#{scheme.id}/secondary-client-group") + end + end + end + + context "when I select the secondary group" do + before do + choose "Homeless families with support needs" + click_button "Save and continue" + end + + it "lets me select level of support" do + expect(page).to have_content "What support does this scheme provide?" + end + + context "when I press the back button" do + before do + click_link "Back" + end + + it "lets me select the secondary group" do + expect(page).to have_current_path("/schemes/#{scheme.id}/secondary-client-group") + expect(page).to have_content "What is the other client group?" + end + + context "when we amend secondary client" do + it "returns to the support question" do + click_button "Save and continue" + expect(page).to have_current_path("/schemes/#{scheme.id}/support") end + end + end - context "when allows changing confirm-secondary-client-group question to no" do - before do - click_link("Change", href: "/schemes/#{scheme.id}/confirm-secondary-client-group?check_answers=true") - end + context "when I select the support answers" do + before do + choose "Low level" + choose "Very short stay" + click_button "Save and continue" + end - it "allows changing confirm-secondary-client-group question to no" do - expect(page).to have_current_path("/schemes/#{scheme.id}/confirm-secondary-client-group?check_answers=true") + it "lets me add location" do + expect(page).to have_content "Add a location to this scheme" + end - choose "No" - click_button "Save and continue" + context "when I press the back button" do + before do + click_link "Back" + end - expect(page).to have_current_path("/schemes/#{scheme.id}/check-answers") - expect(page).not_to have_content "Secondary client group" + it "lets me select the secondary group" do + expect(page).to have_current_path("/schemes/#{scheme.id}/support") + expect(page).to have_content "What support does this scheme provide?" + end + + context "when I amend support" do + it "returns to the add location page" do + click_button "Save and continue" + expect(page).to have_current_path("/schemes/#{scheme.id}/locations/new") end end + end - context "when changing secondary-client-group question" do + context "when I add location to the scheme" do + before do + fill_in "Postcode", with: "SW1P 4DF" + fill_in "Location name (optional)", with: "Some name" + fill_in "Total number of units at this location", with: 1 + choose "Self-contained house" + choose "location-wheelchair-adaptation-no-field" + choose "location-add-another-location-no-field" + click_button "Save and continue" + end + + it "lets me check my answers" do + expect(page).to have_content "Check your changes before creating this scheme" + end + + context "when I select to view locations" do before do - click_link("Change", href: "/schemes/#{scheme.id}/secondary-client-group?check_answers=true") + click_link "Locations" end - it "allows changing secondary-client-group question" do - expect(page).to have_current_path("/schemes/#{scheme.id}/secondary-client-group?check_answers=true") + it "displays information about locations" do + expect(page).to have_content "Locations" + expect(page).to have_content "#{scheme.locations.count} location" + end - choose "People at risk of domestic violence" + it "displays information about newly created location" do + expect(page).to have_content "SW1P4DF" + expect(page).to have_content "Some name" + expect(page).to have_content "Self-contained house" + end + end + + context "and I select to add another location a scheme" do + before do + click_link "Add a location" + fill_in "Postcode", with: "XX1 1XX" + fill_in "Location name (optional)", with: "Other name" + fill_in "Total number of units at this location", with: 2 + choose "Self-contained house" + choose "location-wheelchair-adaptation-no-field" + choose "location-add-another-location-no-field" click_button "Save and continue" + end - expect(page).to have_current_path("/schemes/#{scheme.id}/check-answers") - expect(page).to have_content "People at risk of domestic violence" + it "lets me check my answers" do + expect(page).to have_content "Check your changes before creating this scheme" end - context "when I press the back button" do + context "when I select to view locations" do before do - click_link "Back" + click_link "Locations" end - it "lets me select the support answers" do - expect(page).to have_current_path("/schemes/#{scheme.id}/check-answers") - expect(page).to have_content "Check your changes before creating this scheme" + it "displays information about another location" do + expect(page).to have_content "Locations" + expect(page).to have_content "#{scheme.locations.count} location" + end + + it "displays information about newly created location" do + expect(page).to have_content "XX11XX" + expect(page).to have_content "Other name" + expect(page).to have_content "Self-contained house" + end + + context "when changing location details" do + before do + click_link "XX11XX" + fill_in "Postcode", with: "ZZ1 1ZZ" + click_button "Save and continue" + end + + it "displays changed location" do + expect(page).to have_content "Locations" + expect(page).to have_content "#{scheme.locations.count} location" + expect(page).to have_content "ZZ11ZZ" + end end end end - context "when changing support questions" do - before do - click_link("Change", href: "/schemes/#{scheme.id}/support?check_answers=true", match: :first) + context "when changing answers" do + it "displays change links" do + assert_selector "a", text: "Change", count: 13 end - it "allows changing support questions" do - expect(page).to have_current_path("/schemes/#{scheme.id}/support?check_answers=true") + context "when changing details" do + before do + click_link("Change", href: "/schemes/#{scheme.id}/details?check_answers=true", match: :first) + end - choose "Resettlement support" - choose "Medium stay" - click_button "Save and continue" + it "allows changing details questions" do + expect(page).to have_current_path("/schemes/#{scheme.id}/details?check_answers=true") - expect(page).to have_current_path("/schemes/#{scheme.id}/locations/new") - expect(page).to have_content "Add a location to this scheme" - end + fill_in "Scheme name", with: "Example" + click_button "Save and continue" - context "when I press the back button" do - before do - click_link "Back" + expect(page).to have_current_path("/schemes/#{scheme.id}/check-answers") + expect(page).to have_content "Example" end - it "lets me select the support answers" do - expect(page).to have_current_path("/schemes/#{scheme.id}/check-answers") - expect(page).to have_content "Check your changes before creating this scheme" + context "when I press the back button" do + before do + click_link "Back" + end + + it "lets me select the support answers" do + expect(page).to have_current_path("/schemes/#{scheme.id}/check-answers") + expect(page).to have_content "Check your changes before creating this scheme" + end end end end - end - context "and I select to create a scheme" do - before do - click_link "Create scheme" - end + context "and I select to create a scheme" do + before do + click_link "Create scheme" + end - it "adds scheme to the list of schemes" do - expect(page).to have_content "Supported housing schemes" - expect(page).to have_content scheme.id_to_display - expect(page).to have_content scheme.service_name - expect(page).to have_content scheme.owning_organisation.name - expect(page).to have_content scheme.managing_organisation.name - expect(page).to have_content "#{scheme.owning_organisation.name} has been created." + it "adds scheme to the list of schemes" do + expect(page).to have_content "Supported housing schemes" + expect(page).to have_content scheme.id_to_display + expect(page).to have_content scheme.service_name + expect(page).to have_content scheme.owning_organisation.name + expect(page).to have_content scheme.managing_organisation.name + expect(page).to have_content "#{scheme.owning_organisation.name} has been created." + end end end end diff --git a/spec/models/location_spec.rb b/spec/models/location_spec.rb index ae78df6c5..e5feaec24 100644 --- a/spec/models/location_spec.rb +++ b/spec/models/location_spec.rb @@ -35,4 +35,24 @@ RSpec.describe Location, type: :model do .to raise_error(ActiveRecord::RecordInvalid, "Validation failed: Postcode Enter a postcode in the correct format, for example AA1 1AA") end end + + describe "#units" do + let(:location) { FactoryBot.build(:location) } + + it "does add an error when the postcode is invalid" do + location.units = nil + expect { location.save! } + .to raise_error(ActiveRecord::RecordInvalid, "Validation failed: Units Enter total number of units at this location") + end + end + + describe "#type_of_unit" do + let(:location) { FactoryBot.build(:location) } + + it "does add an error when the postcode is invalid" do + location.type_of_unit = nil + expect { location.save! } + .to raise_error(ActiveRecord::RecordInvalid, "Validation failed: Type of unit Select the most common type of unit at this location") + end + end end diff --git a/spec/requests/locations_controller_spec.rb b/spec/requests/locations_controller_spec.rb index 0f770ddb3..2148f350d 100644 --- a/spec/requests/locations_controller_spec.rb +++ b/spec/requests/locations_controller_spec.rb @@ -133,15 +133,6 @@ RSpec.describe LocationsController, type: :request do end end - context "when required postcode param is missing" do - let(:params) { { location: { name: "Test", units: "5", type_of_unit: "Bungalow", wheelchair_adaptation: "No", add_another_location: "No" } } } - - it "displays the new page with an error message" do - expect(response).to have_http_status(:unprocessable_entity) - expect(page).to have_content(I18n.t("validations.postcode")) - end - end - context "when do you want to add another location is selected as yes" do let(:params) { { location: { name: "Test", units: "5", type_of_unit: "Bungalow", wheelchair_adaptation: "No", add_another_location: "Yes", postcode: "ZZ1 1ZZ" } } } @@ -198,6 +189,17 @@ RSpec.describe LocationsController, type: :request do expect(Location.last.wheelchair_adaptation).to eq("No") end end + + context "when required param are missing" do + let(:params) { { location: { postcode: "", name: "Test", units: "", type_of_unit: "", wheelchair_adaptation: "No", add_another_location: "No" } } } + + it "displays the new page with an error message" do + expect(response).to have_http_status(:unprocessable_entity) + expect(page).to have_content(I18n.t("validations.postcode")) + expect(page).to have_content(I18n.t("activerecord.errors.models.location.attributes.units.blank")) + expect(page).to have_content(I18n.t("activerecord.errors.models.location.attributes.type_of_unit.blank")) + end + end end context "when signed in as a support user" do @@ -297,6 +299,17 @@ RSpec.describe LocationsController, type: :request do expect(Location.last.wheelchair_adaptation).to eq("No") end end + + context "when required param are missing" do + let(:params) { { location: { postcode: "", name: "Test", units: "", type_of_unit: "", wheelchair_adaptation: "No", add_another_location: "No" } } } + + it "displays the new page with an error message" do + expect(response).to have_http_status(:unprocessable_entity) + expect(page).to have_content(I18n.t("validations.postcode")) + expect(page).to have_content(I18n.t("activerecord.errors.models.location.attributes.units.blank")) + expect(page).to have_content(I18n.t("activerecord.errors.models.location.attributes.type_of_unit.blank")) + end + end end end @@ -511,6 +524,17 @@ RSpec.describe LocationsController, type: :request do expect(Location.last.wheelchair_adaptation).to eq("No") end end + + context "when required param are missing" do + let(:params) { { location: { postcode: "", name: "Test", units: "", type_of_unit: "", wheelchair_adaptation: "No", add_another_location: "No" } } } + + it "displays the new page with an error message" do + expect(response).to have_http_status(:unprocessable_entity) + expect(page).to have_content(I18n.t("validations.postcode")) + expect(page).to have_content(I18n.t("activerecord.errors.models.location.attributes.units.blank")) + expect(page).to have_content(I18n.t("activerecord.errors.models.location.attributes.type_of_unit.blank")) + end + end end context "when signed in as a support user" do @@ -620,6 +644,17 @@ RSpec.describe LocationsController, type: :request do expect(Location.last.wheelchair_adaptation).to eq("No") end end + + context "when required param are missing" do + let(:params) { { location: { postcode: "", name: "Test", units: "", type_of_unit: "", wheelchair_adaptation: "No", add_another_location: "No" } } } + + it "displays the new page with an error message" do + expect(response).to have_http_status(:unprocessable_entity) + expect(page).to have_content(I18n.t("validations.postcode")) + expect(page).to have_content(I18n.t("activerecord.errors.models.location.attributes.units.blank")) + expect(page).to have_content(I18n.t("activerecord.errors.models.location.attributes.type_of_unit.blank")) + end + end end end diff --git a/spec/requests/schemes_controller_spec.rb b/spec/requests/schemes_controller_spec.rb index 2d92c7385..a2dc3e584 100644 --- a/spec/requests/schemes_controller_spec.rb +++ b/spec/requests/schemes_controller_spec.rb @@ -336,7 +336,13 @@ RSpec.describe SchemesController, type: :request do context "when signed in as a data coordinator" do let(:user) { FactoryBot.create(:user, :data_coordinator) } - let(:params) { { scheme: { service_name: "testy", sensitive: "1", scheme_type: "Foyer", registered_under_care_act: "No" } } } + let(:params) do + { scheme: { service_name: "testy", + sensitive: "1", + scheme_type: "Foyer", + registered_under_care_act: "No", + support_services_provider_before_type_cast: "0" } } + end before do sign_in user @@ -344,6 +350,7 @@ RSpec.describe SchemesController, type: :request do it "creates a new scheme for user organisation with valid params and renders correct page" do expect { post "/schemes", params: }.to change(Scheme, :count).by(1) + follow_redirect! expect(response).to have_http_status(:ok) expect(page).to have_content("What client group is this scheme intended for?") end @@ -364,12 +371,72 @@ RSpec.describe SchemesController, type: :request do expect(Scheme.last.intended_stay).to eq(nil) expect(Scheme.last.id_to_display).to match(/S*/) end + + context "when support services provider is selected" do + let(:params) do + { scheme: { service_name: "testy", + sensitive: "1", + scheme_type: "Foyer", + registered_under_care_act: "No", + support_services_provider_before_type_cast: "1" } } + end + + it "creates a new scheme for user organisation with valid params and renders correct page" do + expect { post "/schemes", params: }.to change(Scheme, :count).by(1) + follow_redirect! + expect(response).to have_http_status(:ok) + expect(page).to have_content("Which organisation provides the support services used by this scheme?") + end + + it "creates a new scheme for user organisation with valid params" do + post "/schemes", params: params + + expect(Scheme.last.owning_organisation_id).to eq(user.organisation_id) + expect(Scheme.last.service_name).to eq("testy") + expect(Scheme.last.scheme_type).to eq("Foyer") + expect(Scheme.last.sensitive).to eq("Yes") + expect(Scheme.last.registered_under_care_act).to eq("No") + expect(Scheme.last.id).not_to eq(nil) + expect(Scheme.last.has_other_client_group).to eq(nil) + expect(Scheme.last.primary_client_group).to eq(nil) + expect(Scheme.last.secondary_client_group).to eq(nil) + expect(Scheme.last.support_type).to eq(nil) + expect(Scheme.last.intended_stay).to eq(nil) + expect(Scheme.last.id_to_display).to match(/S*/) + end + end + + context "when missing required scheme params" do + let(:params) do + { scheme: { service_name: "", + scheme_type: "", + registered_under_care_act: "", + support_services_provider_before_type_cast: "" } } + end + + it "renders the same page with error message" do + post "/schemes", params: params + expect(response).to have_http_status(:unprocessable_entity) + 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.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.service_name.invalid")) + end + end end context "when signed in as a support user" do let(:organisation) { FactoryBot.create(:organisation) } let(:user) { FactoryBot.create(:user, :support) } - let(:params) { { scheme: { service_name: "testy", sensitive: "1", scheme_type: "Foyer", registered_under_care_act: "No", owning_organisation_id: organisation.id } } } + let(:params) do + { scheme: { service_name: "testy", + sensitive: "1", + scheme_type: "Foyer", + registered_under_care_act: "No", + owning_organisation_id: organisation.id, + support_services_provider_before_type_cast: "0" } } + end before do allow(user).to receive(:need_two_factor_authentication?).and_return(false) @@ -378,6 +445,7 @@ RSpec.describe SchemesController, type: :request do it "creates a new scheme for user organisation with valid params and renders correct page" do expect { post "/schemes", params: }.to change(Scheme, :count).by(1) + follow_redirect! expect(response).to have_http_status(:ok) expect(page).to have_content("What client group is this scheme intended for?") end @@ -399,13 +467,67 @@ RSpec.describe SchemesController, type: :request do expect(Scheme.last.id_to_display).to match(/S*/) end + context "when support services provider is selected" do + let(:params) do + { scheme: { service_name: "testy", + sensitive: "1", + scheme_type: "Foyer", + registered_under_care_act: "No", + owning_organisation_id: organisation.id, + support_services_provider_before_type_cast: "1" } } + end + + it "creates a new scheme for user organisation with valid params and renders correct page" do + expect { post "/schemes", params: }.to change(Scheme, :count).by(1) + follow_redirect! + expect(response).to have_http_status(:ok) + expect(page).to have_content("Which organisation provides the support services used by this scheme?") + end + + it "creates a new scheme for user organisation with valid params" do + post "/schemes", params: params + expect(Scheme.last.owning_organisation_id).to eq(organisation.id) + expect(Scheme.last.service_name).to eq("testy") + expect(Scheme.last.scheme_type).to eq("Foyer") + expect(Scheme.last.sensitive).to eq("Yes") + expect(Scheme.last.registered_under_care_act).to eq("No") + expect(Scheme.last.id).not_to eq(nil) + expect(Scheme.last.has_other_client_group).to eq(nil) + expect(Scheme.last.primary_client_group).to eq(nil) + expect(Scheme.last.secondary_client_group).to eq(nil) + expect(Scheme.last.support_type).to eq(nil) + expect(Scheme.last.intended_stay).to eq(nil) + expect(Scheme.last.id_to_display).to match(/S*/) + end + end + + context "when missing required scheme params" do + let(:params) do + { scheme: { service_name: "", + scheme_type: "", + registered_under_care_act: "", + support_services_provider_before_type_cast: "" } } + end + + it "renders the same page with error message" do + post "/schemes", params: params + expect(response).to have_http_status(:unprocessable_entity) + 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.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.service_name.invalid")) + expect(page).to have_content(I18n.t("activerecord.errors.models.scheme.attributes.owning_organisation_id.invalid")) + end + end + context "when required organisation id param is missing" do let(:params) { { "scheme" => { "service_name" => "qweqwer", "sensitive" => "Yes", "owning_organisation_id" => "", "scheme_type" => "Foyer", "registered_under_care_act" => "Yes – part registered as a care home" } } } it "displays the new page with an error message" do post "/schemes", params: params expect(response).to have_http_status(:unprocessable_entity) - expect(page).to have_content(I18n.t("activerecord.errors.models.scheme.attributes.owning_organisation_id.required")) + expect(page).to have_content(I18n.t("activerecord.errors.models.scheme.attributes.owning_organisation_id.invalid")) end end end @@ -442,6 +564,84 @@ RSpec.describe SchemesController, type: :request do patch "/schemes/#{scheme_to_update.id}", params: end + context "when params are missing" do + let(:params) do + { scheme: { + service_name: "", + managing_organisation_id: "", + owning_organisation_id: "", + primary_client_group: "", + secondary_client_group: "", + scheme_type: "", + registered_under_care_act: "", + support_type: "", + intended_stay: "", + support_services_provider_before_type_cast: "", + has_other_client_group: "", + page: "details", + } } + end + + it "renders primary client group after successful update" do + expect(response).to have_http_status(:unprocessable_entity) + expect(page).to have_content("Create a new supported housing scheme") + 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.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.primary_client_group.invalid")) + expect(page).to have_content(I18n.t("activerecord.errors.models.scheme.attributes.secondary_client_group.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.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 + + context "when updating from check answers page" do + let(:params) { { scheme: { primary_client_group: "Homeless families with support needs", page: "primary-client-group", check_answers: "true" } } } + + it "renders check answers page after successful update" do + follow_redirect! + expect(response).to have_http_status(:ok) + expect(page).to have_content("Check your changes before creating this scheme") + end + + it "updates a scheme with valid params" do + follow_redirect! + expect(scheme_to_update.reload.primary_client_group).to eq("Homeless families with support needs") + end + end + end + + context "when updating support services provider" do + let(:params) { { scheme: { managing_organisation_id: organisation.id, page: "support-services-provider" } } } + + it "renders primary client group after successful update" do + follow_redirect! + expect(response).to have_http_status(:ok) + expect(page).to have_content("What client group is this scheme intended for?") + end + + it "updates a scheme with valid params" do + follow_redirect! + expect(scheme_to_update.reload.managing_organisation_id).to eq(organisation.id) + end + + context "when updating from check answers page" do + let(:params) { { scheme: { primary_client_group: "Homeless families with support needs", page: "primary-client-group", check_answers: "true" } } } + + it "renders check answers page after successful update" do + follow_redirect! + expect(response).to have_http_status(:ok) + expect(page).to have_content("Check your changes before creating this scheme") + end + + it "updates a scheme with valid params" do + follow_redirect! + expect(scheme_to_update.reload.primary_client_group).to eq("Homeless families with support needs") + end + end + end + context "when updating primary client group" do let(:params) { { scheme: { primary_client_group: "Homeless families with support needs", page: "primary-client-group" } } } @@ -548,7 +748,7 @@ RSpec.describe SchemesController, type: :request do end context "when updating support" do - let(:params) { { scheme: { intended_stay: "Medium stay", support_type: "Resettlement support", page: "support" } } } + let(:params) { { scheme: { intended_stay: "Medium stay", support_type: "Low level", page: "support" } } } it "renders add location to this scheme successful update" do follow_redirect! @@ -559,11 +759,11 @@ RSpec.describe SchemesController, type: :request do it "updates a scheme with valid params" do follow_redirect! expect(scheme_to_update.reload.intended_stay).to eq("Medium stay") - expect(scheme_to_update.reload.support_type).to eq("Resettlement support") + expect(scheme_to_update.reload.support_type).to eq("Low level") end context "when updating from check answers page" do - let(:params) { { scheme: { intended_stay: "Medium stay", support_type: "Resettlement support", page: "support", check_answers: "true" } } } + let(:params) { { scheme: { intended_stay: "Medium stay", support_type: "Low level", page: "support", check_answers: "true" } } } it "renders check answers page after successful update" do follow_redirect! @@ -574,13 +774,21 @@ RSpec.describe SchemesController, type: :request do it "updates a scheme with valid params" do follow_redirect! expect(scheme_to_update.reload.intended_stay).to eq("Medium stay") - expect(scheme_to_update.reload.support_type).to eq("Resettlement support") + expect(scheme_to_update.reload.support_type).to eq("Low level") end end end context "when updating details" do - let(:params) { { scheme: { service_name: "testy", sensitive: "1", scheme_type: "Foyer", registered_under_care_act: "No", page: "details" } } } + let(:params) do + { scheme: { service_name: "testy", + sensitive: "1", + scheme_type: "Foyer", + registered_under_care_act: "No", + page: "details", + owning_organisation_id: organisation.id, + support_services_provider_before_type_cast: "0" } } + end it "renders confirm secondary group after successful update" do follow_redirect! @@ -642,6 +850,55 @@ RSpec.describe SchemesController, type: :request do patch "/schemes/#{scheme_to_update.id}", params: end + context "when params are missing" do + let(:params) do + { scheme: { + service_name: "", + managing_organisation_id: "", + owning_organisation_id: "", + primary_client_group: "", + secondary_client_group: "", + scheme_type: "", + registered_under_care_act: "", + support_type: "", + intended_stay: "", + support_services_provider_before_type_cast: "", + has_other_client_group: "", + page: "details", + } } + end + + it "renders primary client group after successful update" do + expect(response).to have_http_status(:unprocessable_entity) + expect(page).to have_content("Create a new supported housing scheme") + 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.service_name.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.primary_client_group.invalid")) + expect(page).to have_content(I18n.t("activerecord.errors.models.scheme.attributes.secondary_client_group.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.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 + + context "when updating from check answers page" do + let(:params) { { scheme: { primary_client_group: "Homeless families with support needs", page: "primary-client-group", check_answers: "true" } } } + + it "renders check answers page after successful update" do + follow_redirect! + expect(response).to have_http_status(:ok) + expect(page).to have_content("Check your changes before creating this scheme") + end + + it "updates a scheme with valid params" do + follow_redirect! + expect(scheme_to_update.reload.primary_client_group).to eq("Homeless families with support needs") + end + end + end + context "when updating primary client group" do let(:params) { { scheme: { primary_client_group: "Homeless families with support needs", page: "primary-client-group" } } } @@ -748,7 +1005,7 @@ RSpec.describe SchemesController, type: :request do end context "when updating support" do - let(:params) { { scheme: { intended_stay: "Medium stay", support_type: "Resettlement support", page: "support" } } } + let(:params) { { scheme: { intended_stay: "Medium stay", support_type: "Low level", page: "support" } } } it "renders confirm secondary group after successful update" do follow_redirect! @@ -759,11 +1016,11 @@ RSpec.describe SchemesController, type: :request do it "updates a scheme with valid params" do follow_redirect! expect(scheme_to_update.reload.intended_stay).to eq("Medium stay") - expect(scheme_to_update.reload.support_type).to eq("Resettlement support") + expect(scheme_to_update.reload.support_type).to eq("Low level") end context "when updating from check answers page" do - let(:params) { { scheme: { intended_stay: "Medium stay", support_type: "Resettlement support", page: "support", check_answers: "true" } } } + let(:params) { { scheme: { intended_stay: "Medium stay", support_type: "Low level", page: "support", check_answers: "true" } } } it "renders check answers page after successful update" do follow_redirect! @@ -774,7 +1031,7 @@ RSpec.describe SchemesController, type: :request do it "updates a scheme with valid params" do follow_redirect! expect(scheme_to_update.reload.intended_stay).to eq("Medium stay") - expect(scheme_to_update.reload.support_type).to eq("Resettlement support") + expect(scheme_to_update.reload.support_type).to eq("Low level") end end end @@ -787,8 +1044,8 @@ RSpec.describe SchemesController, type: :request do scheme_type: "Foyer", registered_under_care_act: "No", page: "details", - owning_organisation_id: another_organisation.id, - managing_organisation_id: another_organisation.id } } + support_services_provider_before_type_cast: "0", + owning_organisation_id: another_organisation.id } } end it "renders confirm secondary group after successful update" do diff --git a/spec/services/imports/scheme_location_import_service_spec.rb b/spec/services/imports/scheme_location_import_service_spec.rb index 199424f54..a7c13aaca 100644 --- a/spec/services/imports/scheme_location_import_service_spec.rb +++ b/spec/services/imports/scheme_location_import_service_spec.rb @@ -81,8 +81,8 @@ RSpec.describe Imports::SchemeLocationImportService do old_scheme = Scheme.find(scheme.id) new_scheme = location.scheme - expect(old_scheme.service_name).to eq("Management Group - Low levels of support") - expect(new_scheme.service_name).to eq("Management Group - Medium levels of support") + expect(old_scheme.service_name).to eq("Management Group - Low level") + expect(new_scheme.service_name).to eq("Management Group - Medium level") end end @@ -146,7 +146,7 @@ RSpec.describe Imports::SchemeLocationImportService do location = location_service.create_scheme_location(location_xml) expect(location.scheme.scheme_type).to eq("Housing for older people") expect(location.scheme.registered_under_care_act).to eq("No") - expect(location.scheme.support_type).to eq("Low levels of support") + expect(location.scheme.support_type).to eq("Low level") expect(location.scheme.intended_stay).to eq("Permanent") expect(location.scheme.primary_client_group).to eq("Older people with support needs") expect(location.scheme.secondary_client_group).to be_nil