diff --git a/app/controllers/schemes_controller.rb b/app/controllers/schemes_controller.rb
index c3bafa318..8b8f1fe1e 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? && scheme_params[:arrangement_type] != "The same organisation that owns the housing stock"
+ @scheme.errors.delete(:managing_organisation_id)
+ end
end
def confirm_secondary_page?(page)
@@ -170,14 +174,20 @@ 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 @scheme.present? && @scheme.arrangement_type_same? && required_params[:arrangement_type] != "The same organisation that owns the housing stock" && required_params[:managing_organisation_id].blank?
+ required_params[:managing_organisation_id] = nil
+ end
+
+ if required_params[:arrangement_type] == "The same organisation that owns the housing stock"
+ 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 search_term
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| "
#{value}" }.join
simple_format(list, { class: "govuk-list govuk-list--bullet" }, wrapper_tag: "ul")
else
- value = attribute[:value].is_a?(Array) ? attribute[:value].first : attribute[:value] || "None"
+ value = attribute[:value].is_a?(Array) ? attribute[:value].first : attribute[:value] || "You didn’t answer this question".html_safe
simple_format(value.to_s, { class: "govuk-body" }, wrapper_tag: "p")
end
diff --git a/app/models/scheme.rb b/app/models/scheme.rb
index 901481966..fc37a2239 100644
--- a/app/models/scheme.rb
+++ b/app/models/scheme.rb
@@ -196,4 +196,8 @@ class Scheme < ApplicationRecord
}
Scheme.intended_stays.keys.excluding("Missing").map { |key, _| OpenStruct.new(id: key, name: key.to_s.humanize, description: hints[key.to_sym]) }
end
+
+ def arrangement_type_same?
+ arrangement_type == "The same organisation that owns the housing stock"
+ end
end
diff --git a/app/views/schemes/check_answers.html.erb b/app/views/schemes/check_answers.html.erb
index 845b75560..61b56cdfd 100644
--- a/app/views/schemes/check_answers.html.erb
+++ b/app/views/schemes/check_answers.html.erb
@@ -19,16 +19,18 @@
<% end %>
<% end %>
<% end %>
+ <% if !@scheme.arrangement_type_same? %>
<% @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 %>
+ <%= 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 %>
+ <% end %>
<% end %>
<% end %>
<% @scheme.check_primary_client_attributes.each do |attr| %>
diff --git a/spec/features/form/accessible_autocomplete_spec.rb b/spec/features/form/accessible_autocomplete_spec.rb
index 1a9536d58..3a52294d1 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, arrangement_type: "The same organisation that owns the housing stock", 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..82761d43d 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
diff --git a/spec/requests/schemes_controller_spec.rb b/spec/requests/schemes_controller_spec.rb
index f0d3bfc14..7e1909aed 100644
--- a/spec/requests/schemes_controller_spec.rb
+++ b/spec/requests/schemes_controller_spec.rb
@@ -612,7 +612,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!
@@ -1043,7 +1043,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