Browse Source

CLDC-1348 basic validation for scheme and location + front update (#730)

* validation error messages for scheme

* WIP for validations

* fixed redirects for a correct page

* expecting link to a new question

* added support_services_provider

* WIP for support_services_provider

* WIP for support_services_provider - works concenptually

* WIP passing feature tests

* WIP passing feature tests

* WIP validations

* passing tests and working functionality

* location validations

* fixed after rebasing

* fixed edit name

* fixed after rebasing

* tests for missing params

* tests for validations

* tests for validations locaion

* tests for validation of all params for scheme

* tests for location validations

* What is this type of scheme? - Order options alphabetically:

* Care Standards Act 2000? - Order options as follows, add missing hint text for third option

* further styling

* last UI changes

* lmoved back button logic to the view

* select options in the view

* missing validation for manaing org

* fixed check answers page

* wip

* small change

* fixed

* fixed check answers page ui

* fixed updating

* fixed tests

* fixed layout

* final touches

* rebase

* rubocop

* correct condition

* old test
pull/751/head
J G 2 years ago committed by GitHub
parent
commit
9d384d6b50
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 75
      app/controllers/schemes_controller.rb
  2. 5
      app/models/location.rb
  3. 77
      app/models/scheme.rb
  4. 11
      app/views/schemes/check_answers.html.erb
  5. 79
      app/views/schemes/details.html.erb
  6. 5
      app/views/schemes/edit_name.html.erb
  7. 67
      app/views/schemes/new.html.erb
  8. 15
      app/views/schemes/primary_client_group.html.erb
  9. 2
      app/views/schemes/secondary_client_group.html.erb
  10. 30
      app/views/schemes/support.html.erb
  11. 36
      app/views/schemes/support_services_provider.html.erb
  12. 2
      app/views/users/new.html.erb
  13. 29
      config/locales/en.yml
  14. 1
      config/routes.rb
  15. 5
      db/migrate/20220711134558_add_support_services_provider_to_schemes.rb
  16. 3
      db/schema.rb
  17. 14
      db/seeds.rb
  18. 1
      spec/factories/location.rb
  19. 2
      spec/factories/scheme.rb
  20. 370
      spec/features/schemes_spec.rb
  21. 20
      spec/models/location_spec.rb
  22. 53
      spec/requests/locations_controller_spec.rb
  23. 285
      spec/requests/schemes_controller_spec.rb
  24. 6
      spec/services/imports/scheme_location_import_service_spec.rb

75
app/controllers/schemes_controller.rb

@ -9,7 +9,7 @@ class SchemesController < ApplicationController
def index def index
flash[:notice] = "#{Scheme.find(params[:scheme_id].to_i).service_name} has been created." if params[:scheme_id] 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? 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)) @pagy, @schemes = pagy(filtered_collection(all_schemes, search_term))
@searched = search_term.presence @searched = search_term.presence
@ -26,8 +26,15 @@ class SchemesController < ApplicationController
def create def create
@scheme = Scheme.new(scheme_params) @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 else
@scheme.errors.add(:owning_organisation_id, message: @scheme.errors[:organisation]) @scheme.errors.add(:owning_organisation_id, message: @scheme.errors[:organisation])
@scheme.errors.delete(:owning_organisation) @scheme.errors.delete(:owning_organisation)
@ -39,7 +46,9 @@ class SchemesController < ApplicationController
check_answers = params[:scheme][:check_answers] check_answers = params[:scheme][:check_answers]
page = params[:scheme][:page] 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 check_answers
if confirm_secondary_page? page if confirm_secondary_page? page
redirect_to scheme_secondary_client_group_path(@scheme, check_answers: "true") 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] redirect_to next_page_path params[:scheme][:page]
end end
else else
render request.current_url, status: :unprocessable_entity render current_template(page), status: :unprocessable_entity
end end
end end
@ -83,14 +92,48 @@ class SchemesController < ApplicationController
render "schemes/edit_name" render "schemes/edit_name"
end end
def support_services_provider
render "schemes/support_services_provider"
end
private 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) def confirm_secondary_page?(page)
page == "confirm-secondary" && @scheme.has_other_client_group == "Yes" page == "confirm-secondary" && @scheme.has_other_client_group == "Yes"
end 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) def next_page_path(page)
case page case page
when "support-services-provider"
scheme_primary_client_group_path(@scheme)
when "primary-client-group" when "primary-client-group"
scheme_confirm_secondary_client_group_path(@scheme) scheme_confirm_secondary_client_group_path(@scheme)
when "confirm-secondary" when "confirm-secondary"
@ -100,7 +143,13 @@ private
when "support" when "support"
new_location_path new_location_path
when "details" 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" when "edit-name"
scheme_path(@scheme) scheme_path(@scheme)
end end
@ -118,13 +167,19 @@ private
:primary_client_group, :primary_client_group,
:secondary_client_group, :secondary_client_group,
:support_type, :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? if current_user.data_coordinator?
required_params[:owning_organisation_id] = current_user.organisation_id full_params[:owning_organisation_id] = current_user.organisation_id
end end
required_params full_params.except(:support_services_provider_before_type_cast)
end end
def search_term def search_term

5
app/models/location.rb

@ -1,5 +1,6 @@
class Location < ApplicationRecord class Location < ApplicationRecord
validate :validate_postcode validate :validate_postcode
validates :units, :type_of_unit, presence: true
belongs_to :scheme belongs_to :scheme
before_save :infer_la!, if: :postcode_changed? before_save :infer_la!, if: :postcode_changed?
@ -24,12 +25,12 @@ class Location < ApplicationRecord
enum mobility_type: MOBILITY_TYPE enum mobility_type: MOBILITY_TYPE
TYPE_OF_UNIT = { TYPE_OF_UNIT = {
"Bungalow": 6,
"Self-contained flat or bedsit": 1, "Self-contained flat or bedsit": 1,
"Self-contained flat or bedsit with common facilities": 2, "Self-contained flat or bedsit with common facilities": 2,
"Self-contained house": 7,
"Shared flat": 3, "Shared flat": 3,
"Shared house or hostel": 4, "Shared house or hostel": 4,
"Bungalow": 6,
"Self-contained house": 7,
}.freeze }.freeze
enum type_of_unit: TYPE_OF_UNIT enum type_of_unit: TYPE_OF_UNIT

77
app/models/scheme.rb

@ -17,39 +17,37 @@ class Scheme < ApplicationRecord
enum sensitive: SENSITIVE, _suffix: true enum sensitive: SENSITIVE, _suffix: true
REGISTERED_UNDER_CARE_ACT = { REGISTERED_UNDER_CARE_ACT = {
"No": 1,
"Yes – registered care home providing nursing care": 4, "Yes – registered care home providing nursing care": 4,
"Yes – registered care home providing personal care": 3, "Yes – registered care home providing personal care": 3,
"Yes – part registered as a care home": 2, "Yes – part registered as a care home": 2,
"No": 1,
}.freeze }.freeze
enum registered_under_care_act: REGISTERED_UNDER_CARE_ACT enum registered_under_care_act: REGISTERED_UNDER_CARE_ACT
SCHEME_TYPE = { SCHEME_TYPE = {
"Missing": 0,
"Foyer": 4,
"Direct Access Hostel": 5, "Direct Access Hostel": 5,
"Other Supported Housing": 6, "Foyer": 4,
"Housing for older people": 7, "Housing for older people": 7,
"Other Supported Housing": 6,
"Missing": 0,
}.freeze }.freeze
enum scheme_type: SCHEME_TYPE, _suffix: true enum scheme_type: SCHEME_TYPE, _suffix: true
SUPPORT_TYPE = { SUPPORT_TYPE = {
"Missing": 0, "Missing": 0,
"Resettlement support": 1, "Low level": 2,
"Low levels of support": 2, "Medium level": 3,
"Medium levels of support": 3, "High level": 4,
"High levels of care and support": 4, "Nursing care in a care home": 5,
"Nursing care services to a care home": 5,
"Floating Support": 6,
}.freeze }.freeze
enum support_type: SUPPORT_TYPE, _suffix: true enum support_type: SUPPORT_TYPE, _suffix: true
PRIMARY_CLIENT_GROUP = { PRIMARY_CLIENT_GROUP = {
"Homeless families with support needs": "O", "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", "Older people with support needs": "M",
"People at risk of domestic violence": "L", "People at risk of domestic violence": "L",
"People with a physical or sensory disability": "A", "People with a physical or sensory disability": "A",
@ -71,10 +69,10 @@ class Scheme < ApplicationRecord
enum secondary_client_group: PRIMARY_CLIENT_GROUP, _suffix: true enum secondary_client_group: PRIMARY_CLIENT_GROUP, _suffix: true
INTENDED_STAY = { INTENDED_STAY = {
"Very short stay": "V",
"Short stay": "S",
"Medium stay": "M", "Medium stay": "M",
"Permanent": "P", "Permanent": "P",
"Short stay": "S",
"Very short stay": "V",
"Missing": "X", "Missing": "X",
}.freeze }.freeze
@ -86,6 +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 = {
"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 def id_to_display
"S#{id}" "S#{id}"
end end
@ -95,10 +102,16 @@ class Scheme < ApplicationRecord
{ name: "Service code", value: id_to_display }, { name: "Service code", value: id_to_display },
{ name: "Name", value: service_name }, { name: "Name", value: service_name },
{ name: "Confidential information", value: sensitive }, { 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: "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: "Support provided by", value: support_services_provider },
]
end
def check_support_services_provider_attributes
[
{ name: "Organisation providing support", value: managing_organisation&.name },
] ]
end end
@ -129,14 +142,16 @@ class Scheme < ApplicationRecord
def display_attributes 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: "Name", value: service_name, edit: true },
{ name: "Confidential information", value: sensitive, 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: "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: "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: "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: "Secondary client group", value: secondary_client_group },
{ name: "Level of support given", value: support_type }, { name: "Level of support given", value: support_type },
{ name: "Intended length of stay", value: intended_stay }, { name: "Intended length of stay", value: intended_stay },
@ -154,4 +169,30 @@ class Scheme < ApplicationRecord
def hint def hint
[primary_client_group, secondary_client_group].filter(&:present?).join(", ") [primary_client_group, secondary_client_group].filter(&:present?).join(", ")
end 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 end

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

@ -1,5 +1,4 @@
<% content_for :title, "Check your answers before creating this scheme" %> <% 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 } %> <%= render partial: "organisations/headings", locals: { main: "Check your changes before creating this scheme", sub: @scheme.service_name } %>
<div class="govuk-grid-row"> <div class="govuk-grid-row">
@ -18,6 +17,16 @@
) %> ) %>
<% end %> <% end %>
<% 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| %> <% @scheme.check_primary_client_attributes.each do |attr| %>
<%= summary_list.row do |row| %> <%= summary_list.row do |row| %>
<% row.key { attr[:name].to_s } %> <% row.key { attr[:name].to_s } %>

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

@ -2,9 +2,9 @@
<% content_for :before_content do %> <% content_for :before_content do %>
<%= govuk_back_link( <%= govuk_back_link(
text: "Back", text: "Back",
href: :back, href: :back,
) %> ) %>
<% end %> <% end %>
<%= render partial: "organisations/headings", locals: { main: "Create a new supported housing scheme", sub: nil } %> <%= render partial: "organisations/headings", locals: { main: "Create a new supported housing scheme", sub: nil } %>
@ -15,11 +15,11 @@
<%= f.govuk_error_summary %> <%= f.govuk_error_summary %>
<%= f.govuk_text_field :service_name, <%= f.govuk_text_field :service_name,
label: { text: "Scheme name", size: "m" }, 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." } %> 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, <%= f.govuk_check_boxes_fieldset :sensitive,
legend: nil do %> legend: nil do %>
<%= f.govuk_check_box :sensitive, <%= f.govuk_check_box :sensitive,
1, 1,
0, 0,
@ -28,17 +28,31 @@
label: { text: "This scheme contains confidential information" } %> label: { text: "This scheme contains confidential information" } %>
<% end %> <% end %>
<% null_option = [OpenStruct.new(id: "", name: "Select an option")] %> <% if current_user.data_coordinator? %>
<% organisations = Organisation.all.map { |org| OpenStruct.new(id: org.id, name: org.name) } %> <%= f.hidden_field :owning_organisation_id, value: current_user.organisation.id %>
<% managing_org_answer_options = null_option + organisations %> <% 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, <% organisations = Organisation.all.map { |org| OpenStruct.new(id: org.id, name: org.name) } %>
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] %>
<% if current_user.support? %> <% if current_user.support? %>
<%= f.govuk_collection_select :owning_organisation_id, <%= f.govuk_collection_select :owning_organisation_id,
@ -49,29 +63,24 @@
"data-controller": %w[accessible-autocomplete conditional-filter] %> "data-controller": %w[accessible-autocomplete conditional-filter] %>
<% end %> <% end %>
<% if current_user.data_coordinator? %> <% support_services_provider_selection = Scheme.support_services_providers.map do |key, value| %>
<%= f.hidden_field :owning_organisation_id, value: current_user.organisation.id %> <% OpenStruct.new(id: value, name: key.to_s.humanize) %>
<% end %> <% end %>
<%= f.govuk_collection_radio_buttons :support_services_provider_before_type_cast,
<% scheme_types_selection = Scheme.scheme_types.keys.excluding("Missing").map { |key, _| OpenStruct.new(id: key, name: key.to_s.humanize) } %> support_services_provider_selection,
:id,
<%= f.govuk_collection_radio_buttons :scheme_type, lambda { |option|
scheme_types_selection, if option.id.zero? && !current_user.support?
:id, "Your organisation"
:name, else
legend: { text: "What is this type of scheme?", size: "m" } %> option.name
end
<% care_acts_selection = Scheme.registered_under_care_acts.keys.reverse.map { |key, _| OpenStruct.new(id: key, name: key.to_s.humanize) } %> },
legend: { text: "Who provides the support services used by this scheme?", size: "m" } %>
<%= 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.hidden_field :page, value: "details" %> <%= f.hidden_field :page, value: "details" %>
<% if request.query_parameters["check_answers"] %> <% if request.query_parameters["check_answers"] %>
<%= f.hidden_field :check_answers, value: "true" %> <%= f.hidden_field :check_answers, value: "true" %>
<% end %> <% end %>
<%= f.govuk_submit "Save and continue" %> <%= f.govuk_submit "Save and continue" %>
</div> </div>

5
app/views/schemes/edit_name.html.erb

@ -29,6 +29,7 @@
<% end %> <% end %>
<% organisations = Organisation.all.map { |org| OpenStruct.new(id: org.id, name: org.name) } %> <% organisations = Organisation.all.map { |org| OpenStruct.new(id: org.id, name: org.name) } %>
<% if current_user.support? %> <% if current_user.support? %>
<%= f.govuk_collection_select :owning_organisation_id, <%= f.govuk_collection_select :owning_organisation_id,
organisations, organisations,
@ -40,6 +41,10 @@
<%= f.hidden_field :page, value: "edit-name" %> <%= 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" %> <%= f.govuk_submit "Save changes" %>
</div> </div>
</div> </div>

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

@ -2,9 +2,9 @@
<% content_for :before_content do %> <% content_for :before_content do %>
<%= govuk_back_link( <%= govuk_back_link(
text: "Back", text: "Back",
href: "javascript:history.go(-1);", href: "javascript:history.go(-1);",
) %> ) %>
<% end %> <% end %>
<%= form_for(@scheme, as: :scheme, method: :post) do |f| %> <%= form_for(@scheme, as: :scheme, method: :post) do |f| %>
@ -17,8 +17,8 @@
</h1> </h1>
<%= f.govuk_text_field :service_name, <%= f.govuk_text_field :service_name,
label: { text: "Scheme name", size: "m" }, 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." } %> 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, <%= f.govuk_check_boxes_fieldset :sensitive,
legend: nil do %> legend: nil do %>
@ -33,12 +33,29 @@
<% organisations = Organisation.all.map { |org| OpenStruct.new(id: org.id, name: org.name) } %> <% organisations = Organisation.all.map { |org| OpenStruct.new(id: org.id, name: org.name) } %>
<% answer_options = null_option + organisations %> <% answer_options = null_option + organisations %>
<%= f.govuk_collection_select :managing_organisation_id, <% if current_user.data_coordinator? %>
answer_options, <%= f.hidden_field :owning_organisation_id, value: current_user.organisation.id %>
:id, <% end %>
:name,
label: { text: "Which organisation manages this scheme?", size: "m" }, <% scheme_types_selection = Scheme.scheme_types.keys.excluding("Missing").map { |key, _| OpenStruct.new(id: key, name: key.to_s.humanize) } %>
"data-controller": %w[accessible-autocomplete conditional-filter] %> <%= 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? %> <% if current_user.support? %>
<%= f.govuk_collection_select :owning_organisation_id, <%= f.govuk_collection_select :owning_organisation_id,
answer_options, answer_options,
@ -48,23 +65,21 @@
"data-controller": %w[accessible-autocomplete conditional-filter] %> "data-controller": %w[accessible-autocomplete conditional-filter] %>
<% end %> <% end %>
<% if current_user.data_coordinator? %> <% support_services_provider_selection = Scheme.support_services_providers.map do |key, value| %>
<%= f.hidden_field :owning_organisation_id, value: current_user.organisation.id %> <% OpenStruct.new(id: value, name: key.to_s.humanize) %>
<% end %> <% 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 :support_services_provider_before_type_cast,
<%= f.govuk_collection_radio_buttons :scheme_type, support_services_provider_selection,
scheme_types_selection, :id,
:id, lambda { |option|
:name, if option.id.zero? && !current_user.support?
legend: { text: "What is this type of scheme?", size: "m" } %> "Your organisation"
else
<% care_acts_selection = Scheme.registered_under_care_acts.keys.reverse.map { |key, _| OpenStruct.new(id: key, name: key.to_s.humanize) } %> option.name
<%= f.govuk_collection_radio_buttons :registered_under_care_act, end
care_acts_selection, },
:id, legend: { text: "Who provides the support services used by this scheme?", size: "m" } %>
:name,
legend: { text: "Is this scheme registered under the Care Standards Act 2000?", size: "m" } %>
<%= f.govuk_submit "Save and continue" %> <%= f.govuk_submit "Save and continue" %>
</div> </div>

15
app/views/schemes/primary_client_group.html.erb

@ -1,9 +1,17 @@
<% content_for :title, "What client group is this scheme intended for?" %> <% 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 %> <% content_for :before_content do %>
<%= govuk_back_link( <%= govuk_back_link(
text: "Back", text: "Back",
href: request.query_parameters["check_answers"] ? "/schemes/#{@scheme.id}/check-answers" : "/schemes/#{@scheme.id}/details", href: back_button_path,
) %> ) %>
<% end %> <% end %>
@ -14,7 +22,7 @@
<div class="govuk-grid-column-two-thirds"> <div class="govuk-grid-column-two-thirds">
<%= f.govuk_error_summary %> <%= 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, <%= f.govuk_collection_radio_buttons :primary_client_group,
primary_client_group_selection, primary_client_group_selection,
:id, :id,
@ -25,6 +33,9 @@
<% if request.query_parameters["check_answers"] == "true" %> <% if request.query_parameters["check_answers"] == "true" %>
<%= f.hidden_field :check_answers, value: "true" %> <%= f.hidden_field :check_answers, value: "true" %>
<% end %> <% end %>
<% if request.query_parameters["select_managing_org"] == "true" %>
<%= f.hidden_field :check_answers, value: "true" %>
<% end %>
<%= f.govuk_submit "Save and continue" %> <%= f.govuk_submit "Save and continue" %>
</div> </div>

2
app/views/schemes/secondary_client_group.html.erb

@ -14,7 +14,7 @@
<div class="govuk-grid-column-two-thirds"> <div class="govuk-grid-column-two-thirds">
<%= f.govuk_error_summary %> <%= 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, <%= f.govuk_collection_radio_buttons :secondary_client_group,
secondary_client_group_selection, secondary_client_group_selection,
:id, :id,

30
app/views/schemes/support.html.erb

@ -14,19 +14,29 @@
<div class="govuk-grid-column-two-thirds"> <div class="govuk-grid-column-two-thirds">
<%= f.govuk_error_summary %> <%= 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, <%= f.govuk_collection_radio_buttons :support_type,
support_type_selection, support_level_options_with_hints,
:id, :id,
:name, :name,
legend: { text: "Level of support given", size: "m" } %> :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, <%= f.govuk_collection_radio_buttons :intended_stay,
intended_stay_selection, intended_length_of_stay_options_with_hints,
:id, :id,
:name, :name,
legend: { text: "Intended length of stay", size: "m" } %> :description,
legend: { text: "Intended length of stay", size: "m" },
bold_labels: false %>
<%= f.hidden_field :page, value: "support" %> <%= f.hidden_field :page, value: "support" %>

36
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| %>
<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds">
<%= 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" %>
</div>
</div>
<% end %>

2
app/views/users/new.html.erb

@ -15,7 +15,7 @@
<%= f.govuk_text_field :name, <%= f.govuk_text_field :name,
autocomplete: "name", autocomplete: "name",
label: { text: "Name (optional)", size: "m" } %> label: { text: "Location name (optional)", size: "m" } %>
<%= f.govuk_email_field :email, <%= f.govuk_email_field :email,
label: { text: "Email address", size: "m" }, label: { text: "Email address", size: "m" },

29
config/locales/en.yml

@ -44,8 +44,35 @@ en:
scheme: scheme:
attributes: attributes:
owning_organisation_id: owning_organisation_id:
required: "Enter the existing organisation’s name"
invalid: "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: validations:
organisation: organisation:

1
config/routes.rb

@ -43,6 +43,7 @@ Rails.application.routes.draw do
get "details", to: "schemes#details" get "details", to: "schemes#details"
get "check-answers", to: "schemes#check_answers" get "check-answers", to: "schemes#check_answers"
get "edit-name", to: "schemes#edit_name" get "edit-name", to: "schemes#edit_name"
get "support-services-provider", to: "schemes#support_services_provider"
member do member do
resources :locations do resources :locations do

5
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

3
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| create_table "logs_exports", force: :cascade do |t|
t.datetime "created_at", default: -> { "CURRENT_TIMESTAMP" } 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 "base_number", default: 1, null: false
t.integer "increment_number", default: 1, null: false t.integer "increment_number", default: 1, null: false
t.boolean "empty_export", default: false, 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.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

14
db/seeds.rb

@ -73,8 +73,8 @@ unless Rails.env.test?
scheme1 = Scheme.create!( scheme1 = Scheme.create!(
service_name: "Beulahside Care", service_name: "Beulahside Care",
sensitive: 0, sensitive: 0,
registered_under_care_act: 0, registered_under_care_act: 1,
support_type: 1, support_type: 2,
scheme_type: 4, scheme_type: 4,
intended_stay: "M", intended_stay: "M",
primary_client_group: "O", primary_client_group: "O",
@ -87,7 +87,7 @@ unless Rails.env.test?
service_name: "Abdullahview Point", service_name: "Abdullahview Point",
sensitive: 0, sensitive: 0,
registered_under_care_act: 1, registered_under_care_act: 1,
support_type: 1, support_type: 2,
scheme_type: 5, scheme_type: 5,
intended_stay: "S", intended_stay: "S",
primary_client_group: "D", primary_client_group: "D",
@ -115,9 +115,9 @@ unless Rails.env.test?
postcode: "CU193AA", postcode: "CU193AA",
name: "Rectory Road", name: "Rectory Road",
type_of_unit: 4, type_of_unit: 4,
units: 1,
type_of_building: "Purpose built", type_of_building: "Purpose built",
county: "Mid Sussex", wheelchair_adaptation: 2,
wheelchair_adaptation: 0,
) )
Location.create!( Location.create!(
@ -126,8 +126,8 @@ unless Rails.env.test?
postcode: "DM250DC", postcode: "DM250DC",
name: "Smithy Lane", name: "Smithy Lane",
type_of_unit: 1, type_of_unit: 1,
units: 1,
type_of_building: "Converted from previous residential or non-residential property", type_of_building: "Converted from previous residential or non-residential property",
county: "Fife",
wheelchair_adaptation: 1, wheelchair_adaptation: 1,
) )
@ -137,8 +137,8 @@ unless Rails.env.test?
postcode: "YX130WP", postcode: "YX130WP",
name: "Smithy Lane", name: "Smithy Lane",
type_of_unit: 2, type_of_unit: 2,
units: 1,
type_of_building: "Converted from previous residential or non-residential property", type_of_building: "Converted from previous residential or non-residential property",
county: "Rochford",
wheelchair_adaptation: 1, wheelchair_adaptation: 1,
) )
end end

1
spec/factories/location.rb

@ -3,6 +3,7 @@ FactoryBot.define do
postcode { Faker::Address.postcode.delete(" ") } postcode { Faker::Address.postcode.delete(" ") }
name { Faker::Address.street_name } name { Faker::Address.street_name }
type_of_unit { [1, 2, 3, 4, 6, 7].sample } type_of_unit { [1, 2, 3, 4, 6, 7].sample }
units { [1, 2, 3, 4, 6, 7].sample }
type_of_building { "Purpose built" } type_of_building { "Purpose built" }
mobility_type { %w[A M N W X].sample } mobility_type { %w[A M N W X].sample }
wheelchair_adaptation { 2 } wheelchair_adaptation { 2 }

2
spec/factories/scheme.rb

@ -3,7 +3,7 @@ FactoryBot.define do
service_name { Faker::Name.name } service_name { Faker::Name.name }
sensitive { Faker::Number.within(range: 0..1) } sensitive { Faker::Number.within(range: 0..1) }
registered_under_care_act { 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 } scheme_type { 0 }
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 }

370
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 "Scheme name"
expect(page).to have_content "This scheme contains confidential information" 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 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 "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 "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 end
context "when I fill in scheme details and I press save I see primary client group section" do 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" check "This scheme contains confidential information"
choose "Direct access hostel" choose "Direct access hostel"
choose "Yes – registered care home providing nursing care" 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" select organisation.name, from: "scheme-owning-organisation-id-field"
choose "The same organisation that owns the housing stock"
click_button "Save and continue" click_button "Save and continue"
end 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_current_path("/schemes/#{scheme.id}/details")
expect(page).to have_content "Scheme name" expect(page).to have_content "Scheme name"
expect(page).to have_content "This scheme contains confidential information" 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 "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?" expect(page).to have_content "Is this scheme registered under the Care Standards Act 2000?"
end end
@ -370,7 +370,7 @@ RSpec.describe "Schemes scheme Features" do
context "when I select the support answers" do context "when I select the support answers" do
before do before do
choose "Floating support" choose "Low level"
choose "Very short stay" choose "Very short stay"
click_button "Save and continue" click_button "Save and continue"
end end
@ -479,7 +479,7 @@ RSpec.describe "Schemes scheme Features" do
context "when changing answers" do context "when changing answers" do
it "displays change links" do it "displays change links" do
assert_selector "a", text: "Change", count: 12 assert_selector "a", text: "Change", count: 13
end end
context "when changing details" do 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") expect(page).to have_current_path("/schemes/#{scheme.id}/details?check_answers=true")
fill_in "Scheme name", with: "Example" fill_in "Scheme name", with: "Example"
choose "Direct access hostel"
choose "Yes – registered care home providing nursing care"
click_button "Save and continue" click_button "Save and continue"
expect(page).to have_current_path("/schemes/#{scheme.id}/check-answers") expect(page).to have_current_path("/schemes/#{scheme.id}/check-answers")
expect(page).to have_content "Example" expect(page).to have_content "Example"
expect(page).to have_content "Yes – registered care home providing nursing care"
end end
context "when I press the back button" do context "when I press the back button" do
@ -511,150 +508,317 @@ RSpec.describe "Schemes scheme Features" do
end end
end end
end end
end
context "when changing primary client group" do context "and I select to create a scheme" do
before do before do
click_link("Change", href: "/schemes/#{scheme.id}/primary-client-group?check_answers=true") click_link "Create scheme"
end end
it "allows changing primary-client-group question" do it "adds scheme to the list of schemes" do
expect(page).to have_current_path("/schemes/#{scheme.id}/primary-client-group?check_answers=true") 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" 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
click_button "Save and continue" let(:scheme) { Scheme.first }
let!(:another_organisation) { FactoryBot.create(:organisation, name: "Another Org") }
expect(page).to have_current_path("/schemes/#{scheme.id}/check-answers") before do
expect(page).to have_content "Older people with support needs" fill_in "Scheme name", with: "FooBar"
end 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 it "lets me fill in the managing organisation details" do
before do expect(page).to have_content "Which organisation provides the support services used by this scheme?"
click_link "Back" end
end
it "lets me select the support answers" do context "when I press the back button" do
expect(page).to have_current_path("/schemes/#{scheme.id}/check-answers") before do
expect(page).to have_content "Check your changes before creating this scheme" click_link "Back"
end end
end
end
context "when changing confirm secondary group answer" do it "lets me fill in the scheme details" do
before do expect(page).to have_current_path("/schemes/#{scheme.id}/details")
click_link("Change", href: "/schemes/#{scheme.id}/confirm-secondary-client-group?check_answers=true") expect(page).to have_content "Scheme name"
end 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 context "when we amend scheme details" do
expect(page).to have_current_path("/schemes/#{scheme.id}/confirm-secondary-client-group?check_answers=true") 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" context "when I select organisation providing support for scheme" do
click_button "Save and continue" 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" context "when I select primary client group details" do
click_button "Save and continue" 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") it "lets me confirm if I want to select secondary group details" do
expect(page).to have_content "People at risk of domestic violence" expect(page).to have_content "Does this scheme provide for another client group?"
end end
context "when I press the back button" do context "when I press the back button" do
before do before do
click_link "Back" click_link "Back"
end end
it "lets me select the support answers" do it "lets me select the primary client group" do
expect(page).to have_current_path("/schemes/#{scheme.id}/check-answers") expect(page).to have_current_path("/schemes/#{scheme.id}/primary-client-group")
expect(page).to have_content "Check your changes before creating this scheme" expect(page).to have_content "What client group is this scheme intended for?"
end end
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
end
context "when allows changing confirm-secondary-client-group question to no" do context "when I select the support answers" do
before do before do
click_link("Change", href: "/schemes/#{scheme.id}/confirm-secondary-client-group?check_answers=true") choose "Low level"
end choose "Very short stay"
click_button "Save and continue"
end
it "allows changing confirm-secondary-client-group question to no" do it "lets me add location" do
expect(page).to have_current_path("/schemes/#{scheme.id}/confirm-secondary-client-group?check_answers=true") expect(page).to have_content "Add a location to this scheme"
end
choose "No" context "when I press the back button" do
click_button "Save and continue" before do
click_link "Back"
end
expect(page).to have_current_path("/schemes/#{scheme.id}/check-answers") it "lets me select the secondary group" do
expect(page).not_to have_content "Secondary client group" 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 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 before do
click_link("Change", href: "/schemes/#{scheme.id}/secondary-client-group?check_answers=true") click_link "Locations"
end end
it "allows changing secondary-client-group question" do it "displays information about locations" do
expect(page).to have_current_path("/schemes/#{scheme.id}/secondary-client-group?check_answers=true") 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" click_button "Save and continue"
end
expect(page).to have_current_path("/schemes/#{scheme.id}/check-answers") it "lets me check my answers" do
expect(page).to have_content "People at risk of domestic violence" expect(page).to have_content "Check your changes before creating this scheme"
end end
context "when I press the back button" do context "when I select to view locations" do
before do before do
click_link "Back" click_link "Locations"
end end
it "lets me select the support answers" do it "displays information about another location" do
expect(page).to have_current_path("/schemes/#{scheme.id}/check-answers") expect(page).to have_content "Locations"
expect(page).to have_content "Check your changes before creating this scheme" 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 end
end end
context "when changing support questions" do context "when changing answers" do
before do it "displays change links" do
click_link("Change", href: "/schemes/#{scheme.id}/support?check_answers=true", match: :first) assert_selector "a", text: "Change", count: 13
end end
it "allows changing support questions" do context "when changing details" do
expect(page).to have_current_path("/schemes/#{scheme.id}/support?check_answers=true") before do
click_link("Change", href: "/schemes/#{scheme.id}/details?check_answers=true", match: :first)
end
choose "Resettlement support" it "allows changing details questions" do
choose "Medium stay" expect(page).to have_current_path("/schemes/#{scheme.id}/details?check_answers=true")
click_button "Save and continue"
expect(page).to have_current_path("/schemes/#{scheme.id}/locations/new") fill_in "Scheme name", with: "Example"
expect(page).to have_content "Add a location to this scheme" click_button "Save and continue"
end
context "when I press the back button" do expect(page).to have_current_path("/schemes/#{scheme.id}/check-answers")
before do expect(page).to have_content "Example"
click_link "Back"
end end
it "lets me select the support answers" do context "when I press the back button" do
expect(page).to have_current_path("/schemes/#{scheme.id}/check-answers") before do
expect(page).to have_content "Check your changes before creating this scheme" 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
end end
end
context "and I select to create a scheme" do context "and I select to create a scheme" do
before do before do
click_link "Create scheme" click_link "Create scheme"
end end
it "adds scheme to the list of schemes" do it "adds scheme to the list of schemes" do
expect(page).to have_content "Supported housing schemes" expect(page).to have_content "Supported housing schemes"
expect(page).to have_content scheme.id_to_display expect(page).to have_content scheme.id_to_display
expect(page).to have_content scheme.service_name 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
expect(page).to have_content scheme.managing_organisation.name expect(page).to have_content scheme.managing_organisation.name
expect(page).to have_content "#{scheme.owning_organisation.name} has been created." expect(page).to have_content "#{scheme.owning_organisation.name} has been created."
end
end end
end end
end end

20
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") .to raise_error(ActiveRecord::RecordInvalid, "Validation failed: Postcode Enter a postcode in the correct format, for example AA1 1AA")
end end
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 end

53
spec/requests/locations_controller_spec.rb

@ -133,15 +133,6 @@ RSpec.describe LocationsController, type: :request do
end end
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 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" } } } 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") expect(Location.last.wheelchair_adaptation).to eq("No")
end end
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
context "when signed in as a support user" do 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") expect(Location.last.wheelchair_adaptation).to eq("No")
end end
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
end end
@ -511,6 +524,17 @@ RSpec.describe LocationsController, type: :request do
expect(Location.last.wheelchair_adaptation).to eq("No") expect(Location.last.wheelchair_adaptation).to eq("No")
end end
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
context "when signed in as a support user" do 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") expect(Location.last.wheelchair_adaptation).to eq("No")
end end
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
end end

285
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 context "when signed in as a data coordinator" do
let(:user) { FactoryBot.create(:user, :data_coordinator) } 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 before do
sign_in user 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 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) expect { post "/schemes", params: }.to change(Scheme, :count).by(1)
follow_redirect!
expect(response).to have_http_status(:ok) expect(response).to have_http_status(:ok)
expect(page).to have_content("What client group is this scheme intended for?") expect(page).to have_content("What client group is this scheme intended for?")
end end
@ -364,12 +371,72 @@ RSpec.describe SchemesController, type: :request do
expect(Scheme.last.intended_stay).to eq(nil) expect(Scheme.last.intended_stay).to eq(nil)
expect(Scheme.last.id_to_display).to match(/S*/) expect(Scheme.last.id_to_display).to match(/S*/)
end 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 end
context "when signed in as a support user" do context "when signed in as a support user" do
let(:organisation) { FactoryBot.create(:organisation) } let(:organisation) { FactoryBot.create(:organisation) }
let(:user) { FactoryBot.create(:user, :support) } 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 before do
allow(user).to receive(:need_two_factor_authentication?).and_return(false) 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 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) expect { post "/schemes", params: }.to change(Scheme, :count).by(1)
follow_redirect!
expect(response).to have_http_status(:ok) expect(response).to have_http_status(:ok)
expect(page).to have_content("What client group is this scheme intended for?") expect(page).to have_content("What client group is this scheme intended for?")
end end
@ -399,13 +467,67 @@ RSpec.describe SchemesController, type: :request do
expect(Scheme.last.id_to_display).to match(/S*/) expect(Scheme.last.id_to_display).to match(/S*/)
end 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 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" } } } 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 it "displays the new page with an error message" do
post "/schemes", params: params post "/schemes", params: params
expect(response).to have_http_status(:unprocessable_entity) 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 end
end end
@ -442,6 +564,84 @@ RSpec.describe SchemesController, type: :request do
patch "/schemes/#{scheme_to_update.id}", params: patch "/schemes/#{scheme_to_update.id}", params:
end 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 context "when updating primary client group" do
let(:params) { { scheme: { primary_client_group: "Homeless families with support needs", page: "primary-client-group" } } } 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 end
context "when updating support" do 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 it "renders add location to this scheme successful update" do
follow_redirect! follow_redirect!
@ -559,11 +759,11 @@ RSpec.describe SchemesController, type: :request do
it "updates a scheme with valid params" do it "updates a scheme with valid params" do
follow_redirect! follow_redirect!
expect(scheme_to_update.reload.intended_stay).to eq("Medium stay") 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
context "when updating from check answers page" do 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 it "renders check answers page after successful update" do
follow_redirect! follow_redirect!
@ -574,13 +774,21 @@ RSpec.describe SchemesController, type: :request do
it "updates a scheme with valid params" do it "updates a scheme with valid params" do
follow_redirect! follow_redirect!
expect(scheme_to_update.reload.intended_stay).to eq("Medium stay") 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 end
end end
context "when updating details" do 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 it "renders confirm secondary group after successful update" do
follow_redirect! follow_redirect!
@ -642,6 +850,55 @@ RSpec.describe SchemesController, type: :request do
patch "/schemes/#{scheme_to_update.id}", params: patch "/schemes/#{scheme_to_update.id}", params:
end 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 context "when updating primary client group" do
let(:params) { { scheme: { primary_client_group: "Homeless families with support needs", page: "primary-client-group" } } } 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 end
context "when updating support" do 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 it "renders confirm secondary group after successful update" do
follow_redirect! follow_redirect!
@ -759,11 +1016,11 @@ RSpec.describe SchemesController, type: :request do
it "updates a scheme with valid params" do it "updates a scheme with valid params" do
follow_redirect! follow_redirect!
expect(scheme_to_update.reload.intended_stay).to eq("Medium stay") 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
context "when updating from check answers page" do 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 it "renders check answers page after successful update" do
follow_redirect! follow_redirect!
@ -774,7 +1031,7 @@ RSpec.describe SchemesController, type: :request do
it "updates a scheme with valid params" do it "updates a scheme with valid params" do
follow_redirect! follow_redirect!
expect(scheme_to_update.reload.intended_stay).to eq("Medium stay") 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 end
end end
@ -787,8 +1044,8 @@ 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",
owning_organisation_id: another_organisation.id, support_services_provider_before_type_cast: "0",
managing_organisation_id: another_organisation.id } } owning_organisation_id: another_organisation.id } }
end end
it "renders confirm secondary group after successful update" do it "renders confirm secondary group after successful update" do

6
spec/services/imports/scheme_location_import_service_spec.rb

@ -81,8 +81,8 @@ RSpec.describe Imports::SchemeLocationImportService do
old_scheme = Scheme.find(scheme.id) old_scheme = Scheme.find(scheme.id)
new_scheme = location.scheme new_scheme = location.scheme
expect(old_scheme.service_name).to eq("Management Group - Low levels of support") expect(old_scheme.service_name).to eq("Management Group - Low level")
expect(new_scheme.service_name).to eq("Management Group - Medium levels of support") expect(new_scheme.service_name).to eq("Management Group - Medium level")
end end
end end
@ -146,7 +146,7 @@ RSpec.describe Imports::SchemeLocationImportService do
location = location_service.create_scheme_location(location_xml) location = location_service.create_scheme_location(location_xml)
expect(location.scheme.scheme_type).to eq("Housing for older people") expect(location.scheme.scheme_type).to eq("Housing for older people")
expect(location.scheme.registered_under_care_act).to eq("No") 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.intended_stay).to eq("Permanent")
expect(location.scheme.primary_client_group).to eq("Older people with support needs") expect(location.scheme.primary_client_group).to eq("Older people with support needs")
expect(location.scheme.secondary_client_group).to be_nil expect(location.scheme.secondary_client_group).to be_nil

Loading…
Cancel
Save