diff --git a/app/controllers/schemes_controller.rb b/app/controllers/schemes_controller.rb
index c3bafa318..2bae8ae94 100644
--- a/app/controllers/schemes_controller.rb
+++ b/app/controllers/schemes_controller.rb
@@ -103,6 +103,10 @@ private
@scheme.errors.add(key.to_sym)
end
end
+
+ if @scheme.arrangement_type_same? && arrangement_type_value(scheme_params[:arrangement_type]) != "D"
+ @scheme.errors.delete(:managing_organisation_id)
+ end
end
def confirm_secondary_page?(page)
@@ -124,6 +128,8 @@ private
"schemes/details"
elsif page.include?("edit")
"schemes/edit_name"
+ elsif page.include?("check-answers")
+ "schemes/check_answers"
end
end
@@ -170,14 +176,32 @@ private
:intended_stay,
:confirmed)
- full_params = required_params[:arrangement_type] == "D" && required_params[:owning_organisation_id].present? ? required_params.merge(managing_organisation_id: required_params[:owning_organisation_id]) : required_params
+ if arrangement_type_changed_to_different_org?(required_params)
+ required_params[:managing_organisation_id] = nil
+ end
+
+ if arrangement_type_set_to_same_org?(required_params)
+ required_params[:managing_organisation_id] = required_params[:owning_organisation_id] || @scheme.owning_organisation_id
+ end
- full_params[:sensitive] = full_params[:sensitive].to_i if full_params[:sensitive]
+ required_params[:sensitive] = required_params[:sensitive].to_i if required_params[:sensitive]
if current_user.data_coordinator?
- full_params[:owning_organisation_id] = current_user.organisation_id
+ required_params[:owning_organisation_id] = current_user.organisation_id
end
- full_params
+ required_params
+ end
+
+ def arrangement_type_set_to_same_org?(required_params)
+ arrangement_type_value(required_params[:arrangement_type]) == "D" || (required_params[:arrangement_type].blank? && @scheme.present? && @scheme.arrangement_type_same?)
+ end
+
+ def arrangement_type_changed_to_different_org?(required_params)
+ @scheme.present? && @scheme.arrangement_type_same? && arrangement_type_value(required_params[:arrangement_type]) != "D" && required_params[:managing_organisation_id].blank?
+ end
+
+ def arrangement_type_value(key)
+ key.present? ? Scheme::ARRANGEMENT_TYPE[key.to_sym] : nil
end
def search_term
diff --git a/app/frontend/styles/_errors.scss b/app/frontend/styles/_errors.scss
new file mode 100644
index 000000000..5883fd416
--- /dev/null
+++ b/app/frontend/styles/_errors.scss
@@ -0,0 +1,4 @@
+.app-summary-list__value--error {
+ border-left: $govuk-border-width solid $govuk-error-colour;
+ padding-left: govuk-spacing(3);
+}
diff --git a/app/frontend/styles/application.scss b/app/frontend/styles/application.scss
index dd4dc3b97..4b26044d1 100644
--- a/app/frontend/styles/application.scss
+++ b/app/frontend/styles/application.scss
@@ -40,6 +40,7 @@ $govuk-breakpoints: (
@import "primary-navigation";
@import "search";
@import "sub-navigation";
+@import "errors";
// App utilities
.app-\!-colour-muted {
diff --git a/app/helpers/details_table_helper.rb b/app/helpers/details_table_helper.rb
index c39bf75d7..9d7c16f22 100644
--- a/app/helpers/details_table_helper.rb
+++ b/app/helpers/details_table_helper.rb
@@ -4,7 +4,7 @@ module DetailsTableHelper
list = attribute[:value].map { |value| "
-
- <%= govuk_tabs(title: "Check your answers before creating this scheme") do |component| %>
- <% component.tab(label: "Scheme") do %>
- <%= govuk_summary_list do |summary_list| %>
- <% @scheme.check_details_attributes.each do |attr| %>
- <% next if current_user.data_coordinator? && attr[:name] == ("owned by") %>
- <%= summary_list.row do |row| %>
- <% row.key { attr[:name].to_s } %>
- <% row.value { details_html(attr) } %>
- <% unless @scheme.confirmed? && attr[:name] != "Name" %>
- <% row.action(
- text: "Change",
- href: scheme_details_path(@scheme, check_answers: true),
- ) %>
- <% end %>
+<%= form_for(@scheme, as: :scheme, method: :patch) do |f| %>
+
+
+ <%= f.govuk_error_summary %>
+ <%= govuk_tabs(title: "Check your answers before creating this scheme") do |component| %>
+ <% component.tab(label: "Scheme") do %>
+
+ <% @scheme.check_details_attributes.each do |attr| %>
+ <% next if current_user.data_coordinator? && attr[:name] == ("owned by") %>
+ <%= render partial: "scheme_summary_list_row", locals: { scheme: @scheme, attribute: attr, change_link: scheme_details_path(@scheme, check_answers: true) } %>
<% 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) } %>
- <% unless @scheme.confirmed? %>
- <% row.action(
- text: "Change",
- href: scheme_support_services_provider_path(@scheme, check_answers: true),
- ) %>
- <% end %>
+ <% if !@scheme.arrangement_type_same? %>
+ <% @scheme.check_support_services_provider_attributes.each do |attr| %>
+ <%= render partial: "scheme_summary_list_row", locals: { scheme: @scheme, attribute: attr, change_link: scheme_support_services_provider_path(@scheme, check_answers: true) } %>
+ <% end %>
<% end %>
- <% end %>
- <% @scheme.check_primary_client_attributes.each do |attr| %>
- <%= summary_list.row do |row| %>
- <% row.key { attr[:name].to_s } %>
- <% row.value { details_html(attr) } %>
- <% unless @scheme.confirmed? %>
- <% row.action(
- text: "Change",
- href: scheme_primary_client_group_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 %>
- <% end %>
- <% @scheme.check_secondary_client_confirmation_attributes.each do |attr| %>
- <%= summary_list.row do |row| %>
- <% row.key { attr[:name].to_s } %>
- <% row.value { details_html(attr) } %>
- <% unless @scheme.confirmed? %>
- <% row.action(
- text: "Change",
- href: scheme_confirm_secondary_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 %>
- <% end %>
- <% if @scheme.has_other_client_group == "Yes" %>
- <% @scheme.check_secondary_client_attributes.each do |attr| %>
- <%= summary_list.row do |row| %>
- <% row.key { attr[:name].to_s } %>
- <% row.value { details_html(attr) } %>
- <% unless @scheme.confirmed? %>
- <% row.action(
- text: "Change",
- href: scheme_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) } %>
<% end %>
<% end %>
- <% end %>
- <% @scheme.check_support_attributes.each do |attr| %>
- <%= summary_list.row do |row| %>
- <% row.key { attr[:name].to_s } %>
- <% row.value { details_html(attr) } %>
- <% unless @scheme.confirmed? %>
- <% row.action(
- text: "Change",
- href: scheme_support_path(@scheme, check_answers: true),
- ) %>
- <% 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 %>
- <% end %>
+
<% end %>
- <% end %>
- <% component.tab(label: "Locations") do %>
- <%= govuk_table do |table| %>
- <%= table.caption(classes: %w[govuk-!-font-size-19 govuk-!-font-weight-regular]) do |caption| %>
-
<%= @scheme.locations.count %> <%= @scheme.locations.count.eql?(1) ? "location" : "locations" %>
- <% end %>
- <%= table.head do |head| %>
- <%= head.row do |row| %>
- <% row.cell(header: true, text: "Code", html_attributes: {
- scope: "col",
- }) %>
- <% row.cell(header: true, text: "Postcode", html_attributes: {
- scope: "col",
- }) %>
- <% row.cell(header: true, text: "Units", html_attributes: {
- scope: "col",
- }) %>
- <% row.cell(header: true, text: "Common unit type", html_attributes: {
- scope: "col",
- }) %>
- <% row.cell(header: true, text: "Mobility type", html_attributes: {
- scope: "col",
- }) %>
- <% row.cell(header: true, text: "Local authority", html_attributes: {
- scope: "col",
- }) %>
+ <% component.tab(label: "Locations") do %>
+ <%= govuk_table do |table| %>
+ <%= table.caption(classes: %w[govuk-!-font-size-19 govuk-!-font-weight-regular]) do |caption| %>
+
<%= @scheme.locations.count %> <%= @scheme.locations.count.eql?(1) ? "location" : "locations" %>
<% end %>
- <% end %>
- <% @scheme.locations.each do |location| %>
- <%= table.body do |body| %>
- <%= body.row do |row| %>
- <% row.cell(text: location.id) %>
- <% row.cell(text: simple_format(location_cell(location, "/schemes/#{@scheme.id}/locations/#{location.id}/edit"), { class: "govuk-!-font-weight-bold" }, wrapper_tag: "div")) %>
- <% row.cell(text: location.units) %>
- <% row.cell(text: simple_format("
#{location.type_of_unit}")) %>
- <% row.cell(text: location.mobility_type) %>
- <% row.cell(text: location.location_admin_district) %>
- <% end %>
+ <%= table.head do |head| %>
+ <%= head.row do |row| %>
+ <% row.cell(header: true, text: "Code", html_attributes: {
+ scope: "col",
+ }) %>
+ <% row.cell(header: true, text: "Postcode", html_attributes: {
+ scope: "col",
+ }) %>
+ <% row.cell(header: true, text: "Units", html_attributes: {
+ scope: "col",
+ }) %>
+ <% row.cell(header: true, text: "Common unit type", html_attributes: {
+ scope: "col",
+ }) %>
+ <% row.cell(header: true, text: "Mobility type", html_attributes: {
+ scope: "col",
+ }) %>
+ <% row.cell(header: true, text: "Local authority", html_attributes: {
+ scope: "col",
+ }) %>
+ <% end %>
+ <% end %>
+ <% @scheme.locations.each do |location| %>
+ <%= table.body do |body| %>
+ <%= body.row do |row| %>
+ <% row.cell(text: location.id) %>
+ <% row.cell(text: simple_format(location_cell(location, "/schemes/#{@scheme.id}/locations/#{location.id}/edit"), { class: "govuk-!-font-weight-bold" }, wrapper_tag: "div")) %>
+ <% row.cell(text: location.units) %>
+ <% row.cell(text: simple_format("
#{location.type_of_unit}")) %>
+ <% row.cell(text: location.mobility_type) %>
+ <% row.cell(text: location.location_admin_district) %>
+ <% end %>
+ <% end %>
<% end %>
<% end %>
+ <%= govuk_button_link_to "Add a location", new_location_path(id: @scheme.id), secondary: true %>
<% end %>
- <%= govuk_button_link_to "Add a location", new_location_path(id: @scheme.id), secondary: true %>
<% end %>
- <% end %>
+
-
-
-<%= form_for(@scheme, as: :scheme, method: :patch) do |f| %>
<%= f.hidden_field :page, value: "check-answers" %>
<%= f.hidden_field :confirmed, value: "true" %>
<% button_label = @scheme.confirmed? ? "Save" : "Create scheme" %>
diff --git a/config/locales/en.yml b/config/locales/en.yml
index 6564d8e7c..14af424b8 100644
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -65,6 +65,8 @@ en:
invalid: "Select if this scheme provides for another client group"
arrangement_type:
invalid: "Select who provides the support services used by this scheme"
+ base:
+ invalid: "You must answer all the required questions for this scheme"
location:
attributes:
startdate:
diff --git a/spec/factories/scheme.rb b/spec/factories/scheme.rb
index ab3342fea..4a85f2036 100644
--- a/spec/factories/scheme.rb
+++ b/spec/factories/scheme.rb
@@ -10,6 +10,7 @@ FactoryBot.define do
primary_client_group { %w[O H M L A G F B D E I S N R Q P X].sample }
secondary_client_group { %w[O H M L A G F B D E I S N R Q P X].sample }
owning_organisation { FactoryBot.create(:organisation) }
+ managing_organisation { FactoryBot.create(:organisation) }
confirmed { true }
created_at { Time.zone.now }
trait :export do
diff --git a/spec/features/form/accessible_autocomplete_spec.rb b/spec/features/form/accessible_autocomplete_spec.rb
index 1a9536d58..929556f09 100644
--- a/spec/features/form/accessible_autocomplete_spec.rb
+++ b/spec/features/form/accessible_autocomplete_spec.rb
@@ -60,7 +60,7 @@ RSpec.describe "Accessible Automcomplete" do
end
context "when searching schemes" do
- let(:scheme) { FactoryBot.create(:scheme, owning_organisation_id: case_log.created_by.organisation_id, primary_client_group: "Q", secondary_client_group: "P") }
+ let(:scheme) { FactoryBot.create(:scheme, owning_organisation_id: case_log.created_by.organisation_id, managing_organisation_id: case_log.created_by.organisation_id, primary_client_group: "Q", secondary_client_group: "P") }
before do
FactoryBot.create(:location, scheme:, postcode: "W6 0ST")
@@ -76,7 +76,7 @@ RSpec.describe "Accessible Automcomplete" do
it "displays appended text next to the options", js: true do
find("#case-log-scheme-id-field").click.native.send_keys("w", "6", :down, :enter)
- expect(find(".autocomplete__option__append", visible: :hidden, text: scheme.service_name)).to be_present
+ expect(find(".autocomplete__option", visible: :hidden, text: scheme.service_name)).to be_present
expect(find("span", visible: :hidden, text: "2 locations")).to be_present
end
diff --git a/spec/features/schemes_spec.rb b/spec/features/schemes_spec.rb
index ae8ed5aba..f1b8aafde 100644
--- a/spec/features/schemes_spec.rb
+++ b/spec/features/schemes_spec.rb
@@ -519,7 +519,7 @@ RSpec.describe "Schemes scheme Features" do
end
it "displays change links" do
- assert_selector "a", text: "Change", count: 13
+ assert_selector "a", text: "Change", count: 12
end
it "allows changing details questions" do
@@ -539,6 +539,13 @@ RSpec.describe "Schemes scheme Features" 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
+
+ it "indicates if the scheme is not complete" do
+ click_link("Change", href: "/schemes/#{scheme.id}/details?check_answers=true", match: :first)
+ choose "Another registered housing provider"
+ click_button "Save and continue"
+ expect(page).to have_content("You didn’t answer this question")
+ end
end
context "when selecting 'create a scheme'" do
@@ -623,6 +630,20 @@ RSpec.describe "Schemes scheme Features" 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
+
+ it "keeps the provider answer when swithing between other provider options" do
+ click_link("Change", href: "/schemes/#{scheme.id}/details?check_answers=true", match: :first)
+ choose "Another organisation"
+ click_button "Save and continue"
+ expect(page).to have_content(another_organisation.name)
+ 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"
+ expect(page).not_to have_content("Organisation providing support")
+ end
end
end
end
@@ -822,7 +843,7 @@ RSpec.describe "Schemes scheme Features" do
context "when selecting a scheme" do
let!(:user) { FactoryBot.create(:user, :data_coordinator, last_sign_in_at: Time.zone.now) }
- let!(:schemes) { FactoryBot.create_list(:scheme, 5, owning_organisation: user.organisation) }
+ let!(:schemes) { FactoryBot.create_list(:scheme, 5, owning_organisation: user.organisation, managing_organisation: user.organisation, arrangement_type: "The same organisation that owns the housing stock") }
let(:location) { FactoryBot.create(:location, scheme: schemes[2]) }
let!(:case_log) { FactoryBot.create(:case_log, created_by: user, needstype: 2) }
@@ -865,5 +886,11 @@ RSpec.describe "Schemes scheme Features" do
visit("/logs/#{case_log.id}/scheme")
expect(find("#case-log-scheme-id-field").all("option").count).to eq(4)
end
+
+ it "does display the schemes that are not completed" do
+ schemes[2].update!(confirmed: false)
+ visit("/logs/#{case_log.id}/scheme")
+ expect(find("#case-log-scheme-id-field").all("option").count).to eq(3)
+ end
end
end
diff --git a/spec/models/form/setup/questions/scheme_id_spec.rb b/spec/models/form/setup/questions/scheme_id_spec.rb
index b855161e7..12dc01fb1 100644
--- a/spec/models/form/setup/questions/scheme_id_spec.rb
+++ b/spec/models/form/setup/questions/scheme_id_spec.rb
@@ -43,7 +43,7 @@ RSpec.describe Form::Setup::Questions::SchemeId, type: :model do
let(:organisation) { FactoryBot.create(:organisation) }
let(:organisation_2) { FactoryBot.create(:organisation) }
let(:user) { FactoryBot.create(:user, organisation:) }
- let(:scheme) { FactoryBot.create(:scheme, owning_organisation: organisation) }
+ let(:scheme) { FactoryBot.create(:scheme, owning_organisation: organisation, managing_organisation: organisation) }
let(:case_log) { FactoryBot.create(:case_log, created_by: user, needstype: 2) }
before do
diff --git a/spec/requests/form_controller_spec.rb b/spec/requests/form_controller_spec.rb
index d6b4a5a30..7bad7b0a3 100644
--- a/spec/requests/form_controller_spec.rb
+++ b/spec/requests/form_controller_spec.rb
@@ -110,7 +110,8 @@ RSpec.describe FormController, type: :request do
end
before do
- FactoryBot.create_list(:location, 5)
+ locations = FactoryBot.create_list(:location, 5)
+ locations.each { |location| location.scheme.update!(arrangement_type: "The same organisation that owns the housing stock", managing_organisation_id: location.scheme.owning_organisation_id) }
end
it "returns an unfiltered list of schemes" do
diff --git a/spec/requests/schemes_controller_spec.rb b/spec/requests/schemes_controller_spec.rb
index f0d3bfc14..1b5a187fd 100644
--- a/spec/requests/schemes_controller_spec.rb
+++ b/spec/requests/schemes_controller_spec.rb
@@ -557,13 +557,22 @@ RSpec.describe SchemesController, type: :request do
context "when signed in as a data coordinator" do
let(:user) { FactoryBot.create(:user, :data_coordinator) }
- let(:scheme_to_update) { FactoryBot.create(:scheme, owning_organisation: user.organisation) }
+ let(:scheme_to_update) { FactoryBot.create(:scheme, owning_organisation: user.organisation, confirmed: nil) }
before do
sign_in user
patch "/schemes/#{scheme_to_update.id}", params:
end
+ context "when confirming unfinished scheme" do
+ let(:params) { { scheme: { owning_organisation_id: user.organisation.id, arrangement_type: "V", confirmed: true, page: "check-answers" } } }
+
+ it "does not allow the scheme to be confirmed" do
+ expect(response).to have_http_status(:unprocessable_entity)
+ expect(page).to have_content(I18n.t("activerecord.errors.models.scheme.attributes.base.invalid"))
+ end
+ end
+
context "when params are missing" do
let(:params) do
{ scheme: {
@@ -612,7 +621,7 @@ RSpec.describe SchemesController, type: :request do
end
context "when updating support services provider" do
- let(:params) { { scheme: { managing_organisation_id: organisation.id, page: "support-services-provider" } } }
+ let(:params) { { scheme: { arrangement_type: "Another organisation", managing_organisation_id: organisation.id, page: "support-services-provider" } } }
it "renders primary client group after successful update" do
follow_redirect!
@@ -786,6 +795,7 @@ RSpec.describe SchemesController, type: :request do
registered_under_care_act: "No",
page: "details",
owning_organisation_id: organisation.id,
+ managing_organisation_id: organisation.id,
arrangement_type: "D" } }
end
@@ -1043,7 +1053,7 @@ RSpec.describe SchemesController, type: :request do
scheme_type: "Foyer",
registered_under_care_act: "No",
page: "details",
- arrangement_type: "D",
+ arrangement_type: "The same organisation that owns the housing stock",
owning_organisation_id: another_organisation.id } }
end
@@ -1078,6 +1088,7 @@ RSpec.describe SchemesController, type: :request do
expect(scheme_to_update.reload.scheme_type).to eq("Foyer")
expect(scheme_to_update.reload.sensitive).to eq("Yes")
expect(scheme_to_update.reload.registered_under_care_act).to eq("No")
+ expect(scheme_to_update.reload.managing_organisation_id).to eq(scheme_to_update.owning_organisation_id)
end
end
end