Browse Source

reset managing org for sheme

pull/775/head
Kat 3 years ago
parent
commit
a3916152a1
  1. 18
      app/controllers/schemes_controller.rb
  2. 2
      app/helpers/details_table_helper.rb
  3. 4
      app/models/scheme.rb
  4. 20
      app/views/schemes/check_answers.html.erb
  5. 4
      spec/features/form/accessible_autocomplete_spec.rb
  6. 23
      spec/features/schemes_spec.rb
  7. 4
      spec/requests/schemes_controller_spec.rb

18
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

2
app/helpers/details_table_helper.rb

@ -4,7 +4,7 @@ module DetailsTableHelper
list = attribute[:value].map { |value| "<li>#{value}</li>" }.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] || "<span class=\"app-!-colour-muted\">You didn’t answer this question</span>".html_safe
simple_format(value.to_s, { class: "govuk-body" }, wrapper_tag: "p")
end

4
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

20
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| %>

4
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

23
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

4
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

Loading…
Cancel
Save