Browse Source

CLDC-3019 Allow scheme editing for support users (#2084)

* Allow scheme editing for support users

* Allow editing locations

* refactor attribute list

* Add inset text

* Redirect change back to scheme path

* Reset secondary client group
pull/2100/head
kosiakkatrina 1 year ago committed by GitHub
parent
commit
5ac969703a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 8
      app/controllers/locations_controller.rb
  2. 26
      app/controllers/schemes_controller.rb
  3. 3
      app/helpers/check_answers_helper.rb
  4. 34
      app/helpers/schemes_helper.rb
  5. 43
      app/models/scheme.rb
  6. 3
      app/views/locations/mobility_standards.html.erb
  7. 3
      app/views/locations/postcode.html.erb
  8. 4
      app/views/locations/show.html.erb
  9. 3
      app/views/locations/type_of_unit.html.erb
  10. 3
      app/views/locations/units.html.erb
  11. 4
      app/views/schemes/_scheme_summary_list_row.html.erb
  12. 20
      app/views/schemes/check_answers.html.erb
  13. 6
      app/views/schemes/confirm_secondary.html.erb
  14. 11
      app/views/schemes/details.html.erb
  15. 1
      app/views/schemes/edit_name.html.erb
  16. 11
      app/views/schemes/primary_client_group.html.erb
  17. 6
      app/views/schemes/secondary_client_group.html.erb
  18. 38
      app/views/schemes/show.html.erb
  19. 8
      app/views/schemes/support.html.erb
  20. 3
      spec/factories/scheme.rb
  21. 53
      spec/features/schemes_spec.rb
  22. 228
      spec/helpers/schemes_helper_spec.rb
  23. 21
      spec/requests/schemes_controller_spec.rb

8
app/controllers/locations_controller.rb

@ -40,6 +40,8 @@ class LocationsController < ApplicationController
redirect_to scheme_location_local_authority_path(@scheme, @location, route: params[:route], referrer: params[:referrer])
elsif return_to_check_your_answers?
redirect_to scheme_location_check_answers_path(@scheme, @location, route: params[:route])
elsif params[:referrer] == "details"
redirect_to scheme_location_path(@scheme, @location)
else
redirect_to scheme_location_name_path(@scheme, @location, route: params[:route])
end
@ -88,6 +90,8 @@ class LocationsController < ApplicationController
if @location.save(context: :units)
if return_to_check_your_answers?
redirect_to scheme_location_check_answers_path(@scheme, @location, route: params[:route])
elsif params[:referrer] == "details"
redirect_to scheme_location_path(@scheme, @location)
else
redirect_to scheme_location_type_of_unit_path(@scheme, @location, route: params[:route])
end
@ -103,6 +107,8 @@ class LocationsController < ApplicationController
if @location.save(context: :type_of_unit)
if return_to_check_your_answers?
redirect_to scheme_location_check_answers_path(@scheme, @location, route: params[:route])
elsif params[:referrer] == "details"
redirect_to scheme_location_path(@scheme, @location)
else
redirect_to scheme_location_mobility_standards_path(@scheme, @location, route: params[:route])
end
@ -118,6 +124,8 @@ class LocationsController < ApplicationController
if @location.save(context: :mobility_type)
if return_to_check_your_answers?
redirect_to scheme_location_check_answers_path(@scheme, @location, route: params[:route])
elsif params[:referrer] == "details"
redirect_to scheme_location_path(@scheme, @location)
else
redirect_to scheme_location_availability_path(@scheme, @location, route: params[:route])
end

26
app/controllers/schemes_controller.rb

@ -136,19 +136,23 @@ class SchemesController < ApplicationController
validation_errors scheme_params
if @scheme.errors.empty? && @scheme.update(scheme_params)
if scheme_params[:confirmed] == "true"
@scheme.locations.update!(confirmed: true)
flash[:notice] = if scheme_previously_confirmed
"#{@scheme.service_name} has been updated."
else
"#{@scheme.service_name} has been created. It does not require helpdesk approval."
end
redirect_to scheme_path(@scheme)
@scheme.update!(secondary_client_group: nil) if @scheme.has_other_client_group == "No"
if scheme_params[:confirmed] == "true" || @scheme.confirmed?
if check_answers && confirm_secondary_page?(page)
redirect_to scheme_secondary_client_group_path(@scheme, check_answers: "true")
else
@scheme.locations.update!(confirmed: true)
flash[:notice] = if scheme_previously_confirmed
"#{@scheme.service_name} has been updated."
else
"#{@scheme.service_name} has been created. It does not require helpdesk approval."
end
redirect_to scheme_path(@scheme)
end
elsif check_answers
if confirm_secondary_page? page
if confirm_secondary_page?(page)
redirect_to scheme_secondary_client_group_path(@scheme, check_answers: "true")
else
@scheme.update!(secondary_client_group: nil) if @scheme.has_other_client_group == "No"
redirect_to scheme_check_answers_path(@scheme)
end
else
@ -310,7 +314,7 @@ private
end
def redirect_if_scheme_confirmed
redirect_to @scheme if @scheme.confirmed?
redirect_to @scheme if @scheme.confirmed? && !current_user.support?
end
def deactivate_success_notice

3
app/helpers/check_answers_helper.rb

@ -12,7 +12,8 @@ module CheckAnswersHelper
end
def can_change_scheme_answer?(attribute_name, scheme)
return false unless current_user.support? || current_user.data_coordinator?
return true if current_user.support?
return false unless current_user.data_coordinator?
editable_attributes = ["Name", "Confidential information", "Housing stock owned by"]

34
app/helpers/schemes_helper.rb

@ -1,23 +1,4 @@
module SchemesHelper
def display_scheme_attributes(scheme)
[
{ name: "Scheme code", value: scheme.id_to_display },
{ name: "Name", value: scheme.service_name, edit: true },
{ name: "Status", value: status_tag_from_resource(scheme) },
{ name: "Confidential information", value: scheme.sensitive, edit: true },
{ name: "Type of scheme", value: scheme.scheme_type },
{ name: "Registered under Care Standards Act 2000", value: scheme.registered_under_care_act },
{ name: "Housing stock owned by", value: scheme.owning_organisation.name, edit: true },
{ name: "Support services provided by", value: scheme.arrangement_type },
{ name: "Primary client group", value: scheme.primary_client_group },
{ name: "Has another client group", value: scheme.has_other_client_group },
scheme.has_other_client_group == "Yes" ? { name: "Secondary client group", value: scheme.secondary_client_group } : nil,
{ name: "Level of support given", value: scheme.support_type },
{ name: "Intended length of stay", value: scheme.intended_stay },
{ name: "Availability", value: scheme_availability(scheme) },
].compact
end
def scheme_availability(scheme)
availability = ""
scheme_active_periods(scheme).each do |period|
@ -76,6 +57,21 @@ module SchemesHelper
schemes_csv_download_organisation_path(organisation, search:, download_type:)
end
def change_answer_link(scheme, question_id, user)
case question_id
when "service_name", "sensitive", "scheme_type", "registered_under_care_act", "owning_organisation_id", "arrangement_type"
user.support? || !scheme.confirmed? ? scheme_details_path(scheme, check_answers: true) : scheme_edit_name_path(scheme)
when "primary_client_group"
scheme_primary_client_group_path(scheme, check_answers: true)
when "has_other_client_group"
scheme_confirm_secondary_client_group_path(scheme, check_answers: true)
when "secondary_client_group"
scheme_secondary_client_group_path(scheme, check_answers: true)
when "support_type", "intended_stay"
scheme_support_path(scheme, check_answers: true)
end
end
private
ActivePeriod = Struct.new(:from, :to)

43
app/models/scheme.rb

@ -187,37 +187,18 @@ class Scheme < ApplicationRecord
def check_details_attributes
[
{ name: "Scheme code", value: id_to_display, id: "id" },
{ name: "Name", value: service_name, id: "service_name" },
{ name: "Confidential information", value: sensitive, id: "sensitive" },
{ name: "Type of scheme", value: scheme_type, id: "scheme_type" },
{ name: "Registered under Care Standards Act 2000", value: registered_under_care_act, id: "registered_under_care_act" },
{ name: "Housing stock owned by", value: owning_organisation.name, id: "owning_organisation_id" },
{ name: "Support services provided by", value: arrangement_type, id: "arrangement_type" },
]
end
def check_primary_client_attributes
[
{ name: "Primary client group", value: primary_client_group, id: "primary_client_group" },
]
end
def check_secondary_client_confirmation_attributes
[
{ name: "Has another client group", value: has_other_client_group, id: "has_other_client_group" },
]
end
def check_secondary_client_attributes
[
{ name: "Secondary client group", value: secondary_client_group, id: "secondary_client_group" },
]
end
def check_support_attributes
[
{ name: "Level of support given", value: support_type, id: "support_type" },
{ name: "Intended length of stay", value: intended_stay, id: "intended_stay" },
{ name: "Name", value: service_name, id: "service_name", edit: true },
{ name: "Status", value: status, id: "status" },
{ name: "Confidential information", value: sensitive, id: "sensitive", edit: true },
{ name: "Type of scheme", value: scheme_type, id: "scheme_type", edit: true },
{ name: "Registered under Care Standards Act 2000", value: registered_under_care_act, id: "registered_under_care_act", edit: true },
{ name: "Housing stock owned by", value: owning_organisation.name, id: "owning_organisation_id", edit: true },
{ name: "Support services provided by", value: arrangement_type, id: "arrangement_type", edit: true },
{ name: "Primary client group", value: primary_client_group, id: "primary_client_group", edit: true },
{ name: "Has another client group", value: has_other_client_group, id: "has_other_client_group", edit: true },
{ name: "Secondary client group", value: secondary_client_group, id: "secondary_client_group", edit: true },
{ name: "Level of support given", value: support_type, id: "support_type", edit: true },
{ name: "Intended length of stay", value: intended_stay, id: "intended_stay", edit: true },
]
end

3
app/views/locations/mobility_standards.html.erb

@ -24,6 +24,9 @@
<% if params[:referrer] == "check_answers" %>
<%= f.govuk_submit "Save changes" %>
<%= govuk_link_to "Cancel", scheme_location_check_answers_path(@scheme, @location, route: params[:route]), secondary: true %>
<% elsif params[:referrer] == "details" %>
<%= f.govuk_submit "Save changes" %>
<%= govuk_link_to "Cancel", scheme_location_path(@scheme, @location), secondary: true %>
<% else %>
<%= f.govuk_submit "Save and continue" %>
<%= govuk_link_to "Skip for now", scheme_location_availability_path(@scheme, @location), secondary: true %>

3
app/views/locations/postcode.html.erb

@ -26,6 +26,9 @@
<% if params[:referrer] == "check_answers" %>
<%= f.govuk_submit "Save changes" %>
<%= govuk_link_to "Cancel", scheme_location_check_answers_path(@scheme, @location, route: params[:route]), secondary: true %>
<% elsif params[:referrer] == "details" %>
<%= f.govuk_submit "Save changes" %>
<%= govuk_link_to "Cancel", scheme_location_path(@scheme, @location), secondary: true %>
<% else %>
<%= f.govuk_submit "Save and continue" %>
<%= govuk_link_to "Skip for now", scheme_location_name_path(@scheme, @location), secondary: true %>

4
app/views/locations/show.html.erb

@ -19,7 +19,11 @@
<% row.key { attr[:name] } %>
<% row.value { attr[:attribute].eql?("status") ? status_tag_from_resource(@location) : details_html(attr) } %>
<% if LocationPolicy.new(current_user, @location).update? %>
<% row.action(text: "Change", href: scheme_location_postcode_path(@scheme, @location, referrer: "details")) if attr[:attribute] == "postcode" && current_user.support? %>
<% row.action(text: "Change", href: scheme_location_name_path(@scheme, @location, referrer: "details")) if attr[:attribute] == "name" %>
<% row.action(text: "Change", href: scheme_location_units_path(@scheme, @location, referrer: "details")) if attr[:attribute] == "units" && current_user.support? %>
<% row.action(text: "Change", href: scheme_location_type_of_unit_path(@scheme, @location, referrer: "details")) if attr[:attribute] == "type_of_unit" && current_user.support? %>
<% row.action(text: "Change", href: scheme_location_mobility_standards_path(@scheme, @location, referrer: "details")) if attr[:attribute] == "mobility_standards" && current_user.support? %>
<% end %>
<% end %>
<% end %>

3
app/views/locations/type_of_unit.html.erb

@ -23,6 +23,9 @@
<% if params[:referrer] == "check_answers" %>
<%= f.govuk_submit "Save changes" %>
<%= govuk_link_to "Cancel", scheme_location_check_answers_path(@scheme, @location, route: params[:route]), secondary: true %>
<% elsif params[:referrer] == "details" %>
<%= f.govuk_submit "Save changes" %>
<%= govuk_link_to "Cancel", scheme_location_path(@scheme, @location), secondary: true %>
<% else %>
<%= f.govuk_submit "Save and continue" %>
<%= govuk_link_to "Skip for now", scheme_location_mobility_standards_path(@scheme, @location), secondary: true %>

3
app/views/locations/units.html.erb

@ -23,6 +23,9 @@
<% if params[:referrer] == "check_answers" %>
<%= f.govuk_submit "Save changes" %>
<%= govuk_link_to "Cancel", scheme_location_check_answers_path(@scheme, @location, route: params[:route]), secondary: true %>
<% elsif params[:referrer] == "details" %>
<%= f.govuk_submit "Save changes" %>
<%= govuk_link_to "Cancel", scheme_location_path(@scheme, @location), secondary: true %>
<% else %>
<%= f.govuk_submit "Save and continue" %>
<%= govuk_link_to "Skip for now", scheme_location_type_of_unit_path(@scheme, @location), secondary: true %>

4
app/views/schemes/_scheme_summary_list_row.html.erb

@ -1,4 +1,4 @@
<div class="<%= "govuk-summary-list__row #{scheme.confirmed? && !can_change_scheme_answer?(attribute[:name], @scheme) ? 'govuk-summary-list__row--no-actions' : ''}" %>">
<div class="<%= "govuk-summary-list__row #{scheme.confirmed? && !can_change_scheme_answer?(attribute[:name], @scheme) && !attribute[:edit] ? 'govuk-summary-list__row--no-actions' : ''}" %>">
<dt class="govuk-summary-list__key">
<%= attribute[:name].to_s %>
</dt>
@ -15,7 +15,7 @@
</dd>
<% end %>
<% if can_change_scheme_answer?(attribute[:name], scheme) %>
<% if can_change_scheme_answer?(attribute[:name], scheme) && attribute[:edit] %>
<dd class="govuk-summary-list__actions">
<a class="govuk-link" href="<%= change_link %>">Change</a>
</dd>

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

@ -9,26 +9,10 @@
<h2 class="govuk-visually-hidden">Scheme</h2>
<dl class="govuk-summary-list">
<% @scheme.check_details_attributes.each do |attr| %>
<%= render partial: "scheme_summary_list_row", locals: { scheme: @scheme, attribute: attr, change_link: @scheme.confirmed? ? scheme_edit_name_path(@scheme) : scheme_details_path(@scheme, check_answers: true) } %>
<% end %>
<% @scheme.check_primary_client_attributes.each do |attr| %>
<%= render partial: "scheme_summary_list_row", locals: { scheme: @scheme, attribute: attr, change_link: scheme_primary_client_group_path(@scheme, check_answers: true) } %>
<% end %>
<% @scheme.check_secondary_client_confirmation_attributes.each do |attr| %>
<%= render partial: "scheme_summary_list_row", locals: { scheme: @scheme, attribute: attr, change_link: scheme_confirm_secondary_client_group_path(@scheme, check_answers: true) } %>
<% end %>
<% if @scheme.has_other_client_group == "Yes" %>
<% @scheme.check_secondary_client_attributes.each do |attr| %>
<%= render partial: "scheme_summary_list_row", locals: { scheme: @scheme, attribute: attr, change_link: scheme_secondary_client_group_path(@scheme, check_answers: true) } %>
<% if attr[:name] != "Status" && (attr[:id] != "secondary_client_group" || @scheme.has_other_client_group == "Yes") %>
<%= render partial: "scheme_summary_list_row", locals: { scheme: @scheme, attribute: attr, change_link: change_answer_link(@scheme, attr[:id], current_user) } %>
<% end %>
<% end %>
<% @scheme.check_support_attributes.each do |attr| %>
<%= render partial: "scheme_summary_list_row", locals: { scheme: @scheme, attribute: attr, change_link: scheme_support_path(@scheme, check_answers: true) } %>
<% end %>
</dl>
<% end %>
<% end %>

6
app/views/schemes/confirm_secondary.html.erb

@ -7,6 +7,7 @@
<% end %>
<%= render partial: "organisations/headings", locals: { main: "Does this scheme provide for another client group?", sub: @scheme.service_name } %>
<%= govuk_inset_text(text: "Only update a scheme if you’re fixing an error. If the scheme is changing, create a new scheme.") if @scheme.confirmed? %>
<%= form_for(@scheme, method: :patch) do |f| %>
<div class="govuk-grid-row">
@ -23,9 +24,10 @@
<%= f.hidden_field :page, value: "confirm-secondary" %>
<% if request.query_parameters["check_answers"] == "true" %>
<%= f.hidden_field :check_answers, value: "true" %>
<%= f.govuk_submit "Save changes" %>
<% else %>
<%= f.govuk_submit "Save and continue" %>
<% end %>
<%= f.govuk_submit "Save and continue" %>
</div>
</div>
<% end %>

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

@ -9,7 +9,12 @@
<div class="govuk-grid-column-two-thirds">
<%= f.govuk_error_summary %>
<%= render partial: "organisations/headings", locals: { main: "Create a new supported housing scheme", sub: nil } %>
<% if @scheme.id.present? %>
<%= render partial: "organisations/headings", locals: { main: "Scheme details", sub: @scheme.service_name } %>
<% else %>
<%= render partial: "organisations/headings", locals: { main: "Create a new supported housing scheme", sub: nil } %>
<% end %>
<%= govuk_inset_text(text: "Only update a scheme if you’re fixing an error. If the scheme is changing, create a new scheme.") if @scheme.confirmed? %>
<%= f.govuk_text_field :service_name,
label: { text: "Scheme name", size: "m" },
@ -72,8 +77,10 @@
<%= f.hidden_field :page, value: "details" %>
<% if request.query_parameters["check_answers"] %>
<%= f.hidden_field :check_answers, value: "true" %>
<%= f.govuk_submit "Save changes" %>
<% else %>
<%= f.govuk_submit "Save and continue" %>
<% end %>
<%= f.govuk_submit "Save and continue" %>
</div>
</div>
<% end %>

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

@ -10,6 +10,7 @@
<%= f.govuk_error_summary %>
<%= render partial: "organisations/headings", locals: { main: "Scheme details", sub: @scheme.service_name } %>
<%= govuk_inset_text(text: "Only update a scheme if you’re fixing an error. If the scheme is changing, create a new scheme.") if @scheme.confirmed? %>
<%= f.govuk_text_field :service_name,
label: { text: "Scheme name", size: "m" },

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

@ -16,6 +16,7 @@
<%= f.govuk_error_summary %>
<%= render partial: "organisations/headings", locals: { main: "What client group is this scheme intended for?", sub: @scheme.service_name } %>
<%= govuk_inset_text(text: "Only update a scheme if you’re fixing an error. If the scheme is changing, create a new scheme.") if @scheme.confirmed? %>
<% 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,
@ -25,14 +26,16 @@
legend: nil %>
<%= f.hidden_field :page, value: "primary-client-group" %>
<% 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" %>
<% if request.query_parameters["check_answers"] == "true" %>
<%= f.hidden_field :check_answers, value: "true" %>
<%= f.govuk_submit "Save changes" %>
<% else %>
<%= f.govuk_submit "Save and continue" %>
<% end %>
</div>
</div>
<% end %>

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

@ -12,6 +12,7 @@
<%= f.govuk_error_summary %>
<%= render partial: "organisations/headings", locals: { main: "What is the other client group?", sub: @scheme.service_name } %>
<%= govuk_inset_text(text: "Only update a scheme if you’re fixing an error. If the scheme is changing, create a new scheme.") if @scheme.confirmed? %>
<% secondary_client_group_selection = Scheme.secondary_client_groups.keys.excluding("Missing", @scheme.primary_client_group).map { |key, _| OpenStruct.new(id: key, name: key) } %>
<%= f.govuk_collection_radio_buttons :secondary_client_group,
@ -23,9 +24,10 @@
<%= f.hidden_field :page, value: "secondary-client-group" %>
<% if request.query_parameters["check_answers"] == "true" %>
<%= f.hidden_field :check_answers, value: "true" %>
<%= f.govuk_submit "Save changes" %>
<% else %>
<%= f.govuk_submit "Save and continue" %>
<% end %>
<%= f.govuk_submit "Save and continue" %>
</div>
</div>
<% end %>

38
app/views/schemes/show.html.erb

@ -19,24 +19,30 @@
<%= render SubNavigationComponent.new(items: scheme_items(request.path, @scheme.id)) %>
<h2 class="govuk-visually-hidden">Scheme</h2>
<%= govuk_inset_text(text: edit_scheme_text(@scheme, current_user)) %>
<%= govuk_summary_list do |summary_list| %>
<% display_scheme_attributes(@scheme).each do |attr| %>
<%= summary_list.row do |row| %>
<% row.key { attr[:name] } %>
<% row.value do %>
<%= details_html(attr) %>
<% if attr[:name] == "Status" && @scheme.confirmed? && @scheme.locations.confirmed.none? && LocationPolicy.new(current_user, @scheme.locations.new).create? %>
<span class="app-!-colour-muted">Complete this scheme by adding a location using the <%= govuk_link_to("‘locations’ tab", scheme_locations_path(@scheme)) %>.</span>
<% end %>
<% end %>
<% if SchemePolicy.new(current_user, @scheme).update? %>
<% row.action(text: "Change", href: scheme_edit_name_path(scheme_id: @scheme.id)) if attr[:edit] %>
<% end %>
<dl class="govuk-summary-list">
<% @scheme.check_details_attributes.each do |attr| %>
<% if attr[:name] == "Status" %>
<div class="govuk-summary-list__row govuk-summary-list__row--no-actions">
<dt class="govuk-summary-list__key">Status</dt>
<dd class="govuk-summary-list__value">
<%= details_html({ name: "Status", value: status_tag_from_resource(@scheme), id: "status" }) %>
<% if @scheme.confirmed? && @scheme.locations.confirmed.none? && LocationPolicy.new(current_user, @scheme.locations.new).create? %>
<span class="app-!-colour-muted">Complete this scheme by adding a location using the <%= govuk_link_to("‘locations’ tab", scheme_locations_path(@scheme)) %>.</span>
<% end %>
</dd>
</div>
<% elsif attr[:id] != "secondary_client_group" || @scheme.has_other_client_group == "Yes" %>
<%= render partial: "scheme_summary_list_row", locals: { scheme: @scheme, attribute: attr, change_link: change_answer_link(@scheme, attr[:id], current_user) } %>
<% end %>
<% end %>
<% end %>
<div class="govuk-summary-list__row govuk-summary-list__row--no-actions">
<dt class="govuk-summary-list__key">Availability</dt>
<dd class="govuk-summary-list__value">
<%= details_html({ name: "Availability", value: scheme_availability(@scheme), id: "availability" }) %>
</dd>
</div>
</dl>
</div>
</div>

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

@ -12,6 +12,7 @@
<%= f.govuk_error_summary %>
<%= render partial: "organisations/headings", locals: { main: "What support does this scheme provide?", sub: @scheme.service_name } %>
<%= govuk_inset_text(text: "Only update a scheme if you’re fixing an error. If the scheme is changing, create a new scheme.") if @scheme.confirmed? %>
<% 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." } %>
@ -37,7 +38,12 @@
<%= f.hidden_field :page, value: "support" %>
<%= f.govuk_submit "Save and continue" %>
<% if request.query_parameters["check_answers"] == "true" %>
<%= f.hidden_field :check_answers, value: "true" %>
<%= f.govuk_submit "Save changes" %>
<% else %>
<%= f.govuk_submit "Save and continue" %>
<% end %>
</div>
</div>
<% end %>

3
spec/factories/scheme.rb

@ -4,7 +4,7 @@ FactoryBot.define do
sensitive { Faker::Number.within(range: 0..1) }
registered_under_care_act { 1 }
support_type { [0, 2, 3, 4, 5].sample }
scheme_type { 0 }
scheme_type { 4 }
arrangement_type { "D" }
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 }
@ -13,6 +13,7 @@ FactoryBot.define do
owning_organisation { FactoryBot.create(:organisation) }
confirmed { true }
created_at { Time.zone.local(2021, 4, 1) }
total_units { 2 }
trait :export do
sensitive { 1 }
registered_under_care_act { 1 }

53
spec/features/schemes_spec.rb

@ -377,9 +377,9 @@ RSpec.describe "Schemes scheme Features" do
expect(page).to have_content("has been added")
end
it "does not let you edit the saved location" do
it "lets you edit the saved location" do
click_link "AA1 2AA"
expect(page).not_to have_link(nil, href: /postcode/)
expect(page).to have_link("Change", href: /postcode/)
end
end
@ -390,7 +390,7 @@ RSpec.describe "Schemes scheme Features" do
end
it "does not let you change details other than the name, confidential information and housing stock owner" do
assert_selector "a", text: "Change", count: 3
assert_selector "a", text: "Change", count: 11
end
end
end
@ -607,7 +607,7 @@ RSpec.describe "Schemes scheme Features" do
it "displays changed location" do
click_link "AA1 2AA"
click_link "Change"
click_link("Change", href: "/schemes/#{scheme.id}/locations/#{location.id}/name?referrer=details", match: :first)
fill_in with: "new name"
click_button "Save changes"
expect(page).to have_content "AA1 2AA"
@ -621,7 +621,7 @@ RSpec.describe "Schemes scheme Features" do
end
it "displays change links" do
assert_selector "a", text: "Change", count: 11
assert_selector "a", text: "Change", count: 10
end
it "allows changing details questions" do
@ -629,7 +629,7 @@ 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"
click_button "Save and continue"
click_button "Save changes"
expect(page).to have_current_path("/schemes/#{scheme.id}/check-answers")
expect(page).to have_content "Example"
@ -645,7 +645,7 @@ RSpec.describe "Schemes scheme Features" do
it "indicates if the scheme is not complete" do
click_link("Change", href: "/schemes/#{scheme.id}/confirm-secondary-client-group?check_answers=true", match: :first)
choose "Yes"
click_button "Save and continue"
click_button "Save changes"
visit("/schemes/#{scheme.id}/check-answers")
expect(page).to have_content("You didn’t answer this question")
end
@ -687,7 +687,7 @@ RSpec.describe "Schemes scheme Features" do
end
it "displays change links" do
assert_selector "a", text: "Change", count: 12
assert_selector "a", text: "Change", count: 11
end
it "allows changing details questions" do
@ -695,7 +695,7 @@ 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"
click_button "Save and continue"
click_button "Save changes"
expect(page).to have_current_path("/schemes/#{scheme.id}/check-answers")
expect(page).to have_content "Example"
@ -711,14 +711,14 @@ RSpec.describe "Schemes scheme Features" do
it "keeps the provider answer when switching between other provider options" do
click_link("Change", href: "/schemes/#{scheme.id}/confirm-secondary-client-group?check_answers=true", match: :first)
choose "Yes"
click_button "Save and continue"
click_button "Save changes"
expect(find_field("Offenders and people at risk of offending")).to be_checked
end
it "does not display the answer if it's changed to the same support provider" do
click_link("Change", href: "/schemes/#{scheme.id}/details?check_answers=true", match: :first)
choose "The same organisation that owns the housing stock"
click_button "Save and continue"
click_button "Save changes"
expect(page).not_to have_content("Organisation providing support")
end
end
@ -766,11 +766,11 @@ RSpec.describe "Schemes scheme Features" do
context "when I click to change scheme name" do
before do
click_link("Change", href: "/schemes/#{scheme.id}/edit-name", match: :first)
click_link("Change", href: "/schemes/#{scheme.id}/details?check_answers=true", match: :first)
end
it "shows available fields to edit" do
expect(page).to have_current_path("/schemes/#{scheme.id}/edit-name")
expect(page).to have_current_path("/schemes/#{scheme.id}/details?check_answers=true")
expect(page).to have_content "Scheme details"
end
@ -781,15 +781,10 @@ RSpec.describe "Schemes scheme Features" do
click_button "Save changes"
end
it "lets me see amended details on the check answers page" do
it "lets me see amended details on the details page" do
expect(page).to have_content "FooBar"
expect(page).to have_current_path("/schemes/#{scheme.id}/check-answers")
assert_selector "a", text: "Change", count: 3
end
it "lets me save the scheme" do
click_button "Save"
expect(page).to have_current_path("/schemes/#{scheme.id}")
assert_selector "a", text: "Change", count: 11
expect(page).to have_css(".govuk-notification-banner.govuk-notification-banner--success")
expect(page).to have_content("has been updated")
end
@ -864,10 +859,10 @@ RSpec.describe "Schemes scheme Features" do
expect(page).to have_content("Active")
end
it "only allows to edit the location name" do
assert_selector "a", text: "Change", count: 1
it "only allows to edit the location name, postcode, unit, unit type and mobility standards" do
assert_selector "a", text: "Change", count: 5
click_link("Change")
click_link("Change", href: "/schemes/#{scheme.id}/locations/#{location.id}/name?referrer=details", match: :first)
expect(page).to have_content "What is the name of this location?"
end
@ -889,7 +884,7 @@ RSpec.describe "Schemes scheme Features" do
context "and I change the location name" do
before do
click_link("Change")
click_link("Change", href: "/schemes/#{scheme.id}/locations/#{location.id}/name?referrer=details", match: :first)
end
it "returns to locations check your answers page and shows the new name" do
@ -1008,9 +1003,9 @@ RSpec.describe "Schemes scheme Features" do
expect(page).to have_content("has been added")
end
it "does not let you edit the saved location" do
it "lets you edit the saved location" do
click_link "AA1 2AA"
expect(page).not_to have_link(nil, href: /postcode/)
expect(page).to have_link("Change", href: /postcode/)
end
end
@ -1021,7 +1016,7 @@ RSpec.describe "Schemes scheme Features" do
end
it "does not let you change details other than the name, confidential information and housing stock owner" do
assert_selector "a", text: "Change", count: 3
assert_selector "a", text: "Change", count: 11
end
end
end
@ -1069,9 +1064,9 @@ RSpec.describe "Schemes scheme Features" do
click_button "Save changes"
end
it "lets me see amended details on the check answers page" do
it "lets me see amended details on the details page" do
expect(page).to have_content "FooBar"
expect(page).to have_current_path("/schemes/#{scheme.id}/check-answers")
expect(page).to have_current_path("/schemes/#{scheme.id}")
expect(page).to have_link("Change", href: /schemes\/#{scheme.id}\/edit-name/, count: 3)
end
end

228
spec/helpers/schemes_helper_spec.rb

@ -88,234 +88,6 @@ RSpec.describe SchemesHelper do
end
include TagHelper
describe "display_scheme_attributes" do
let(:owning_organisation) { FactoryBot.create(:organisation, name: "Acme LTD Owning") }
let(:managing_organisation) { FactoryBot.create(:organisation, name: "Acme LTD Managing") }
let!(:scheme) do
FactoryBot.create(:scheme,
service_name: "Test service_name",
sensitive: 0,
scheme_type: 7,
registered_under_care_act: 3,
owning_organisation:,
arrangement_type: "V",
primary_client_group: "S",
has_other_client_group: 1,
secondary_client_group: "I",
support_type: 4,
intended_stay: "P",
created_at: Time.zone.local(2022, 4, 1))
end
let!(:scheme_where_managing_organisation_is_owning_organisation) { FactoryBot.create(:scheme, arrangement_type: "D") }
let(:support_user) { FactoryBot.create(:user, :support) }
let(:coordinator_user) { FactoryBot.create(:user, :data_coordinator) }
context "when scheme has no locations" do
it "returns correct display attributes" do
attributes = [
{ name: "Scheme code", value: "S#{scheme.id}" },
{ name: "Name", value: "Test service_name", edit: true },
{ name: "Status", value: status_tag(:incomplete) },
{ name: "Confidential information", value: "No", edit: true },
{ name: "Type of scheme", value: "Housing for older people" },
{ name: "Registered under Care Standards Act 2000", value: "Yes – registered care home providing personal care" },
{ name: "Housing stock owned by", value: "Acme LTD Owning", edit: true },
{ name: "Support services provided by", value: "A registered charity or voluntary organisation" },
{ name: "Primary client group", value: "Rough sleepers" },
{ name: "Has another client group", value: "Yes" },
{ name: "Secondary client group", value: "Refugees (permanent)" },
{ name: "Level of support given", value: "High level" },
{ name: "Intended length of stay", value: "Permanent" },
{ name: "Availability", value: "Active from 1 April 2021" },
]
expect(display_scheme_attributes(scheme)).to eq(attributes)
end
end
context "when scheme has a location" do
before do
FactoryBot.create(:location, scheme:)
end
it "returns correct display attributes" do
attributes = [
{ name: "Scheme code", value: "S#{scheme.id}" },
{ name: "Name", value: "Test service_name", edit: true },
{ name: "Status", value: status_tag(:active) },
{ name: "Confidential information", value: "No", edit: true },
{ name: "Type of scheme", value: "Housing for older people" },
{ name: "Registered under Care Standards Act 2000", value: "Yes – registered care home providing personal care" },
{ name: "Housing stock owned by", value: "Acme LTD Owning", edit: true },
{ name: "Support services provided by", value: "A registered charity or voluntary organisation" },
{ name: "Primary client group", value: "Rough sleepers" },
{ name: "Has another client group", value: "Yes" },
{ name: "Secondary client group", value: "Refugees (permanent)" },
{ name: "Level of support given", value: "High level" },
{ name: "Intended length of stay", value: "Permanent" },
{ name: "Availability", value: "Active from 1 April 2021" },
]
expect(display_scheme_attributes(scheme)).to eq(attributes)
end
context "when the managing organisation is the owning organisation" do
it "doesn't show the organisation providing support" do
attributes = display_scheme_attributes(scheme_where_managing_organisation_is_owning_organisation).find { |x| x[:name] == "Organisation providing support" }
expect(attributes).to be_nil
end
end
context "when viewing availability" do
context "with no deactivations" do
it "displays current collection start date as availability date if created_at is later than collection start date" do
scheme.update!(created_at: Time.zone.local(2022, 4, 16))
availability_attribute = display_scheme_attributes(scheme).find { |x| x[:name] == "Availability" }[:value]
expect(availability_attribute).to eq("Active from 1 April 2021")
end
end
context "with previous deactivations" do
context "and all reactivated deactivations" do
before do
Timecop.freeze(Time.zone.local(2023, 11, 10))
FactoryBot.create(:scheme_deactivation_period, deactivation_date: Time.zone.local(2022, 8, 10), reactivation_date: Time.zone.local(2022, 9, 1), scheme:)
FactoryBot.create(:scheme_deactivation_period, deactivation_date: Time.zone.local(2022, 9, 15), reactivation_date: Time.zone.local(2022, 9, 28), scheme:)
Timecop.return
scheme.reload
end
it "displays the timeline of availability" do
availability_attribute = display_scheme_attributes(scheme).find { |x| x[:name] == "Availability" }[:value]
expect(availability_attribute).to eq("Active from 1 April 2021 to 9 August 2022\nDeactivated on 10 August 2022\nActive from 1 September 2022 to 14 September 2022\nDeactivated on 15 September 2022\nActive from 28 September 2022")
end
end
context "and non reactivated deactivation" do
before do
Timecop.freeze(Time.zone.local(2023, 11, 10))
FactoryBot.create(:scheme_deactivation_period, deactivation_date: Time.zone.local(2022, 8, 10), reactivation_date: Time.zone.local(2022, 9, 1), scheme:)
FactoryBot.create(:scheme_deactivation_period, deactivation_date: Time.zone.local(2022, 9, 15), reactivation_date: nil, scheme:)
Timecop.return
scheme.reload
end
it "displays the timeline of availability" do
availability_attribute = display_scheme_attributes(scheme).find { |x| x[:name] == "Availability" }[:value]
expect(availability_attribute).to eq("Active from 1 April 2021 to 9 August 2022\nDeactivated on 10 August 2022\nActive from 1 September 2022 to 14 September 2022\nDeactivated on 15 September 2022")
end
end
end
context "with out of order deactivations" do
context "and all reactivated deactivations" do
before do
Timecop.freeze(Time.zone.local(2023, 11, 10))
FactoryBot.create(:scheme_deactivation_period, deactivation_date: Time.zone.local(2022, 9, 24), reactivation_date: Time.zone.local(2022, 9, 28), scheme:)
FactoryBot.create(:scheme_deactivation_period, deactivation_date: Time.zone.local(2022, 6, 15), reactivation_date: Time.zone.local(2022, 6, 18), scheme:)
Timecop.return
scheme.reload
end
it "displays the timeline of availability" do
availability_attribute = display_scheme_attributes(scheme).find { |x| x[:name] == "Availability" }[:value]
expect(availability_attribute).to eq("Active from 1 April 2021 to 14 June 2022\nDeactivated on 15 June 2022\nActive from 18 June 2022 to 23 September 2022\nDeactivated on 24 September 2022\nActive from 28 September 2022")
end
end
context "and one non reactivated deactivation" do
before do
Timecop.freeze(Time.zone.local(2023, 11, 10))
FactoryBot.create(:scheme_deactivation_period, deactivation_date: Time.zone.local(2022, 9, 24), reactivation_date: Time.zone.local(2022, 9, 28), scheme:)
FactoryBot.create(:scheme_deactivation_period, deactivation_date: Time.zone.local(2022, 6, 15), reactivation_date: nil, scheme:)
Timecop.return
scheme.reload
end
it "displays the timeline of availability" do
availability_attribute = display_scheme_attributes(scheme).find { |x| x[:name] == "Availability" }[:value]
expect(availability_attribute).to eq("Active from 1 April 2021 to 14 June 2022\nDeactivated on 15 June 2022\nActive from 28 September 2022")
end
end
end
context "with multiple out of order deactivations" do
context "and one non reactivated deactivation" do
before do
Timecop.freeze(Time.zone.local(2023, 11, 10))
FactoryBot.create(:scheme_deactivation_period, deactivation_date: Time.zone.local(2022, 9, 24), reactivation_date: Time.zone.local(2022, 9, 28), scheme:)
FactoryBot.create(:scheme_deactivation_period, deactivation_date: Time.zone.local(2022, 10, 24), reactivation_date: Time.zone.local(2022, 10, 28), scheme:)
FactoryBot.create(:scheme_deactivation_period, deactivation_date: Time.zone.local(2022, 6, 15), reactivation_date: nil, scheme:)
Timecop.return
scheme.reload
end
it "displays the timeline of availability" do
availability_attribute = display_scheme_attributes(scheme).find { |x| x[:name] == "Availability" }[:value]
expect(availability_attribute).to eq("Active from 1 April 2021 to 14 June 2022\nDeactivated on 15 June 2022\nActive from 28 September 2022 to 23 October 2022\nDeactivated on 24 October 2022\nActive from 28 October 2022")
end
end
end
context "with intersecting deactivations" do
before do
Timecop.freeze(Time.zone.local(2023, 11, 10))
FactoryBot.create(:scheme_deactivation_period, deactivation_date: Time.zone.local(2022, 10, 10), reactivation_date: Time.zone.local(2022, 12, 1), scheme:)
FactoryBot.create(:scheme_deactivation_period, deactivation_date: Time.zone.local(2022, 11, 11), reactivation_date: Time.zone.local(2022, 12, 11), scheme:)
Timecop.return
scheme.reload
end
it "displays the timeline of availability" do
availability_attribute = display_scheme_attributes(scheme).find { |x| x[:name] == "Availability" }[:value]
expect(availability_attribute).to eq("Active from 1 April 2021 to 9 October 2022\nDeactivated on 10 October 2022\nActive from 11 December 2022")
end
end
end
end
context "when scheme has no secondary client group" do
before do
scheme.update!(has_other_client_group: 0)
end
it "returns correct display attributes" do
attributes = [
{ name: "Scheme code", value: "S#{scheme.id}" },
{ name: "Name", value: "Test service_name", edit: true },
{ name: "Status", value: status_tag(:incomplete) },
{ name: "Confidential information", value: "No", edit: true },
{ name: "Type of scheme", value: "Housing for older people" },
{ name: "Registered under Care Standards Act 2000", value: "Yes – registered care home providing personal care" },
{ name: "Housing stock owned by", value: "Acme LTD Owning", edit: true },
{ name: "Support services provided by", value: "A registered charity or voluntary organisation" },
{ name: "Primary client group", value: "Rough sleepers" },
{ name: "Has another client group", value: "No" },
{ name: "Level of support given", value: "High level" },
{ name: "Intended length of stay", value: "Permanent" },
{ name: "Availability", value: "Active from 1 April 2021" },
]
expect(display_scheme_attributes(scheme)).to eq(attributes)
end
end
context "when scheme was merged from another organisation" do
before do
FactoryBot.create(:location, scheme:)
scheme.startdate = Time.zone.local(2023, 1, 5)
end
it "returns correct availability" do
expect(display_scheme_attributes(scheme)).to include({ name: "Availability", value: "Active from 5 January 2023" })
end
end
end
describe "edit_scheme_text" do
let(:parent_organisation) { FactoryBot.create(:organisation, name: "Parent") }
let(:child_organisation) { FactoryBot.create(:organisation, name: "Child") }

21
spec/requests/schemes_controller_spec.rb

@ -1832,12 +1832,9 @@ RSpec.describe SchemesController, type: :request do
get "/schemes/#{scheme.id}/primary-client-group"
end
it "redirects to a view scheme page" do
follow_redirect!
it "allows editing the primary client group" do
expect(response).to have_http_status(:ok)
expect(path).to match("/schemes/#{scheme.id}")
expect(page).to have_content(scheme.service_name)
assert_select "a", text: /Change/, count: 3
expect(path).to match("/schemes/#{scheme.id}/primary-client-group")
end
end
end
@ -1912,12 +1909,9 @@ RSpec.describe SchemesController, type: :request do
get "/schemes/#{scheme.id}/confirm-secondary-client-group"
end
it "redirects to a view scheme page" do
follow_redirect!
it "allows updating secondary client group" do
expect(response).to have_http_status(:ok)
expect(path).to match("/schemes/#{scheme.id}")
expect(page).to have_content(scheme.service_name)
assert_select "a", text: /Change/, count: 3
expect(path).to match("/schemes/#{scheme.id}/confirm-secondary-client-group")
end
end
end
@ -1992,12 +1986,9 @@ RSpec.describe SchemesController, type: :request do
get "/schemes/#{scheme.id}/secondary-client-group"
end
it "redirects to a view scheme page" do
follow_redirect!
it "allows editing secondary client group" do
expect(response).to have_http_status(:ok)
expect(path).to match("/schemes/#{scheme.id}")
expect(page).to have_content(scheme.service_name)
assert_select "a", text: /Change/, count: 3
expect(path).to match("/schemes/#{scheme.id}/secondary-client-group")
end
end

Loading…
Cancel
Save