diff --git a/app/controllers/schemes_controller.rb b/app/controllers/schemes_controller.rb index dadca8adc..64da2edc4 100644 --- a/app/controllers/schemes_controller.rb +++ b/app/controllers/schemes_controller.rb @@ -26,8 +26,9 @@ class SchemesController < ApplicationController def create @scheme = Scheme.new(scheme_params) + if @scheme.save - if @scheme.support_services_provider.eql?"The same organisation that owns the housing stock" + if scheme_params[:support_services_provider] == "The same organisation that owns the housing stock" redirect_to scheme_primary_client_group_path(@scheme) else redirect_to scheme_support_services_provider_path(@scheme) @@ -135,7 +136,11 @@ private when "support" new_location_path when "details" - scheme_support_services_provider_path(@scheme) + if @scheme.support_services_provider.eql?"The same organisation that owns the housing stock" + scheme_primary_client_group_path(@scheme) + else + scheme_support_services_provider_path(@scheme) + end when "edit-name" scheme_path(@scheme) end @@ -156,11 +161,15 @@ private :support_services_provider, :intended_stay) - required_params[:sensitive] = required_params[:sensitive].to_i if required_params[:sensitive] + same_org_providing_support = required_params[:support_services_provider] == "The same organisation that owns the housing stock" + + full_params = same_org_providing_support ? 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] if current_user.data_coordinator? - required_params[:owning_organisation_id] = current_user.organisation_id + full_params[:owning_organisation_id] = current_user.organisation_id end - required_params + full_params end def search_term diff --git a/app/views/schemes/check_answers.html.erb b/app/views/schemes/check_answers.html.erb index abebf91fb..f297b5209 100644 --- a/app/views/schemes/check_answers.html.erb +++ b/app/views/schemes/check_answers.html.erb @@ -13,7 +13,7 @@ <%= summary_list.row do |row| %> <% row.key { attr[:name].eql?("Registered under Care Standards Act 2000") ? "Registered under Care Standards Act 2000" : attr[:name].to_s.humanize } %> <% row.value { details_html(attr) } %> - <% row.action(text: "Change", href: scheme_edit_name_path(scheme_id: @scheme.id)) if attr[:edit] %> + <% row.action(text: "Change", href: scheme_edit_name_path(scheme_id: @scheme.id, check_answers: true)) if attr[:edit] %> <% end %> <% end %> <% end %> diff --git a/app/views/schemes/edit_name.html.erb b/app/views/schemes/edit_name.html.erb index 876e73a25..8fd713580 100644 --- a/app/views/schemes/edit_name.html.erb +++ b/app/views/schemes/edit_name.html.erb @@ -40,6 +40,10 @@ <%= 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" %> diff --git a/spec/features/schemes_spec.rb b/spec/features/schemes_spec.rb index ddac2aabb..0b36e92c6 100644 --- a/spec/features/schemes_spec.rb +++ b/spec/features/schemes_spec.rb @@ -271,7 +271,6 @@ RSpec.describe "Schemes scheme Features" do expect(page).to have_current_path("/schemes/#{scheme.id}/details") expect(page).to have_content "Scheme name" 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 "Who provides the support services used by this scheme?" expect(page).to have_content "Is this scheme registered under the Care Standards Act 2000?" @@ -480,155 +479,22 @@ RSpec.describe "Schemes scheme Features" do context "when changing answers" do it "displays change links" do - assert_selector "a", text: "Change", count: 12 + assert_selector "a", text: "Change", count: 3 end context "when changing details" do before do - click_link("Change", href: "/schemes/#{scheme.id}/details?check_answers=true", match: :first) + click_link("Change", href: "/schemes/#{scheme.id}/edit-name?check_answers=true", match: :first) end it "allows changing details questions" do - expect(page).to have_current_path("/schemes/#{scheme.id}/details?check_answers=true") + expect(page).to have_current_path("/schemes/#{scheme.id}/edit-name?check_answers=true") 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 changes" expect(page).to have_current_path("/schemes/#{scheme.id}/check-answers") expect(page).to have_content "Example" - expect(page).to have_content "Yes – registered care home providing nursing care" - end - - context "when I press the back button" do - before do - 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 - - context "when changing primary client group" do - before do - click_link("Change", href: "/schemes/#{scheme.id}/primary-client-group?check_answers=true") - end - - it "allows changing primary-client-group question" do - expect(page).to have_current_path("/schemes/#{scheme.id}/primary-client-group?check_answers=true") - - choose "Older people with support needs" - click_button "Save and continue" - - expect(page).to have_current_path("/schemes/#{scheme.id}/check-answers") - expect(page).to have_content "Older people with support needs" - end - - context "when I press the back button" do - before do - 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 - - context "when changing confirm secondary group answer" do - before do - click_link("Change", href: "/schemes/#{scheme.id}/confirm-secondary-client-group?check_answers=true") - end - - it "allows changing confirm-secondary-client-group question to yes" do - expect(page).to have_current_path("/schemes/#{scheme.id}/confirm-secondary-client-group?check_answers=true") - - choose "Yes" - click_button "Save and continue" - - expect(page).to have_current_path("/schemes/#{scheme.id}/secondary-client-group?check_answers=true") - - choose "People at risk of domestic violence" - click_button "Save and continue" - - expect(page).to have_current_path("/schemes/#{scheme.id}/check-answers") - expect(page).to have_content "People at risk of domestic violence" - end - - context "when I press the back button" do - before do - 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 - - context "when allows changing confirm-secondary-client-group question to no" do - before do - click_link("Change", href: "/schemes/#{scheme.id}/confirm-secondary-client-group?check_answers=true") - end - - it "allows changing confirm-secondary-client-group question to no" do - expect(page).to have_current_path("/schemes/#{scheme.id}/confirm-secondary-client-group?check_answers=true") - - choose "No" - click_button "Save and continue" - - expect(page).to have_current_path("/schemes/#{scheme.id}/check-answers") - expect(page).not_to have_content "Secondary client group" - end - end - - context "when changing secondary-client-group question" do - before do - click_link("Change", href: "/schemes/#{scheme.id}/secondary-client-group?check_answers=true") - end - - it "allows changing secondary-client-group question" do - expect(page).to have_current_path("/schemes/#{scheme.id}/secondary-client-group?check_answers=true") - - choose "People at risk of domestic violence" - click_button "Save and continue" - - expect(page).to have_current_path("/schemes/#{scheme.id}/check-answers") - expect(page).to have_content "People at risk of domestic violence" - end - - context "when I press the back button" do - before do - 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 - - context "when changing support questions" do - before do - click_link("Change", href: "/schemes/#{scheme.id}/support?check_answers=true", match: :first) - end - - it "allows changing support questions" do - expect(page).to have_current_path("/schemes/#{scheme.id}/support?check_answers=true") - - choose "Resettlement support" - choose "Medium stay" - click_button "Save and continue" - - expect(page).to have_current_path("/schemes/#{scheme.id}/locations/new") - expect(page).to have_content "Add a location to this scheme" end context "when I press the back button" do @@ -667,6 +533,7 @@ RSpec.describe "Schemes scheme Features" do 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 let(:scheme) { Scheme.first } + let!(:another_organisation) { FactoryBot.create(:organisation, name: "Another Org") } before do fill_in "Scheme name", with: "FooBar" @@ -699,47 +566,29 @@ RSpec.describe "Schemes scheme Features" do context "when we amend scheme details" do it "returns to the primary client group question" do click_button "Save and continue" - expect(page).to have_current_path("/schemes/#{scheme.id}/primary-client-group") + expect(page).to have_current_path("/schemes/#{scheme.id}/support-services-provider") end end end - context "when I select primary client group details" do + context "when I select organisation providing support for scheme" do before do - choose "Homeless families with support needs" + select another_organisation.name, from: "scheme-managing-organisation-id-field" click_button "Save and continue" end - it "lets me confirm if I want to select secondary group details" do - expect(page).to have_content "Does this scheme provide for another client group?" - end - - context "when I press the back button" do - before do - click_link "Back" - end - - it "lets me select the primary client group" do - expect(page).to have_current_path("/schemes/#{scheme.id}/primary-client-group") - expect(page).to have_content "What client group is this scheme intended for?" - 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 + it "lets me select the primary client group" do + expect(page).to have_content "What client group is this scheme intended for?" end - context "when I confirm the secondary group" do + context "when I select primary client group details" do before do - choose "Yes" + choose "Homeless families with support needs" 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?" + it "lets me confirm if I want to select secondary group details" do + expect(page).to have_content "Does this scheme provide for another client group?" end context "when I press the back button" do @@ -747,27 +596,27 @@ RSpec.describe "Schemes scheme Features" 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?" + it "lets me select the primary client group" do + expect(page).to have_current_path("/schemes/#{scheme.id}/primary-client-group") + expect(page).to have_content "What client group is this scheme intended for?" end - context "when we amend confirm secondary client" do - it "returns to the secondary client group question" do + 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}/secondary-client-group") + expect(page).to have_current_path("/schemes/#{scheme.id}/confirm-secondary-client-group") end end end - context "when I select the secondary group" do + context "when I confirm the secondary group" do before do - choose "Homeless families with support needs" + choose "Yes" 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?" + 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 @@ -775,28 +624,27 @@ RSpec.describe "Schemes scheme Features" 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?" + 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 secondary client" do - it "returns to the support question" do + 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}/support") + expect(page).to have_current_path("/schemes/#{scheme.id}/secondary-client-group") end end end - context "when I select the support answers" do + context "when I select the secondary group" do before do - choose "Floating support" - choose "Very short stay" + choose "Homeless families with support needs" click_button "Save and continue" end - it "lets me add location" do - expect(page).to have_content "Add a location to this scheme" + 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 @@ -805,19 +653,19 @@ RSpec.describe "Schemes scheme Features" do end it "lets me select the secondary group" do - expect(page).to have_current_path("/schemes/#{scheme.id}/support") - expect(page).to have_content "What support does this scheme provide?" + 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 I amend support" do - it "returns to the add location page" do + 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}/locations/new") + expect(page).to have_current_path("/schemes/#{scheme.id}/support") end end end - context "when I add location to the scheme" do + context "when I select the support answers" do before do fill_in "Postcode", with: "SW1P 4DF" fill_in "Location name (optional)", with: "Some name" @@ -825,36 +673,39 @@ RSpec.describe "Schemes scheme Features" do choose "Self-contained house" choose "location-wheelchair-adaptation-no-field" choose "location-add-another-location-no-field" + choose "Floating support" + choose "Very short stay" 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" + it "lets me add location" do + expect(page).to have_content "Add a location to this scheme" end - context "when I select to view locations" do + context "when I press the back button" do before do - click_link "Locations" + click_link "Back" end - it "displays information about locations" do - expect(page).to have_content "Locations" - expect(page).to have_content "#{scheme.locations.count} location" + it "lets me select the secondary group" do + expect(page).to have_current_path("/schemes/#{scheme.id}/support") + expect(page).to have_content "What support does this scheme provide?" end - 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" + 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 - context "and I select to add another location a scheme" do + context "when I add location to the 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 + fill_in "Postcode", with: "SW1P 4DF" + fill_in "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" @@ -870,211 +721,112 @@ RSpec.describe "Schemes scheme Features" do click_link "Locations" end - it "displays information about another location" do + it "displays information about locations" do expect(page).to have_content "Locations" 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 "SW1P4DF" + expect(page).to have_content "Some 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 - context "when changing answers" do - it "displays change links" do - assert_selector "a", text: "Change", count: 12 - end - - context "when changing details" do + context "and I select to add another location a scheme" do before do - click_link("Change", href: "/schemes/#{scheme.id}/details?check_answers=true", match: :first) - end - - it "allows changing details questions" do - expect(page).to have_current_path("/schemes/#{scheme.id}/details?check_answers=true") - - fill_in "Scheme name", with: "Example" - choose "Direct access hostel" - choose "Yes – registered care home providing nursing care" + click_link "Add a location" + fill_in "Postcode", with: "XX1 1XX" + fill_in "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" + end - expect(page).to have_current_path("/schemes/#{scheme.id}/check-answers") - expect(page).to have_content "Example" - expect(page).to have_content "Yes – registered care home providing nursing care" + it "lets me check my answers" do + expect(page).to have_content "Check your changes before creating this scheme" end - context "when I press the back button" do + context "when I select to view locations" do before do - click_link "Back" + click_link "Locations" 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" + it "displays information about another location" do + expect(page).to have_content "Locations" + expect(page).to have_content "#{scheme.locations.count} location" end - end - end - - context "when changing primary client group" do - before do - click_link("Change", href: "/schemes/#{scheme.id}/primary-client-group?check_answers=true") - end - - it "allows changing primary-client-group question" do - expect(page).to have_current_path("/schemes/#{scheme.id}/primary-client-group?check_answers=true") - - choose "Older people with support needs" - click_button "Save and continue" - expect(page).to have_current_path("/schemes/#{scheme.id}/check-answers") - expect(page).to have_content "Older people with support needs" - end - - context "when I press the back button" do - before do - click_link "Back" + 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 - 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" + 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 - context "when changing confirm secondary group answer" do - before do - click_link("Change", href: "/schemes/#{scheme.id}/confirm-secondary-client-group?check_answers=true") - end - - it "allows changing confirm-secondary-client-group question to yes" do - expect(page).to have_current_path("/schemes/#{scheme.id}/confirm-secondary-client-group?check_answers=true") - - choose "Yes" - click_button "Save and continue" - - expect(page).to have_current_path("/schemes/#{scheme.id}/secondary-client-group?check_answers=true") - - choose "People at risk of domestic violence" - click_button "Save and continue" - - expect(page).to have_current_path("/schemes/#{scheme.id}/check-answers") - expect(page).to have_content "People at risk of domestic violence" + context "when changing answers" do + it "displays change links" do + assert_selector "a", text: "Change", count: 3 end - context "when I press the back button" do + context "when changing details" do before do - click_link "Back" + click_link("Change", href: "/schemes/#{scheme.id}/edit-name?check_answers=true", match: :first) 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 + it "allows changing details questions" do + expect(page).to have_current_path("/schemes/#{scheme.id}/edit-name?check_answers=true") - context "when allows changing confirm-secondary-client-group question to no" do - before do - click_link("Change", href: "/schemes/#{scheme.id}/confirm-secondary-client-group?check_answers=true") - end - - it "allows changing confirm-secondary-client-group question to no" do - expect(page).to have_current_path("/schemes/#{scheme.id}/confirm-secondary-client-group?check_answers=true") - - choose "No" - click_button "Save and continue" - - expect(page).to have_current_path("/schemes/#{scheme.id}/check-answers") - expect(page).not_to have_content "Secondary client group" - end - end - - context "when changing secondary-client-group question" do - before do - click_link("Change", href: "/schemes/#{scheme.id}/secondary-client-group?check_answers=true") - end - - it "allows changing secondary-client-group question" do - expect(page).to have_current_path("/schemes/#{scheme.id}/secondary-client-group?check_answers=true") - - choose "People at risk of domestic violence" - click_button "Save and continue" + fill_in "Scheme name", with: "Example" + click_button "Save changes" - expect(page).to have_current_path("/schemes/#{scheme.id}/check-answers") - expect(page).to have_content "People at risk of domestic violence" - end - - context "when I press the back button" do - before do - click_link "Back" + expect(page).to have_current_path("/schemes/#{scheme.id}/check-answers") + expect(page).to have_content "Example" 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" + context "when I press the back button" do + before do + 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 - context "when changing support questions" do + context "and I select to create a scheme" do before do - click_link("Change", href: "/schemes/#{scheme.id}/support?check_answers=true", match: :first) + click_link "Create scheme" end - it "allows changing support questions" do - expect(page).to have_current_path("/schemes/#{scheme.id}/support?check_answers=true") - - choose "Resettlement support" - choose "Medium stay" - click_button "Save and continue" - - expect(page).to have_current_path("/schemes/#{scheme.id}/locations/new") - expect(page).to have_content "Add a location to this scheme" + it "adds scheme to the list of schemes" do + 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.managing_organisation.name + expect(page).to have_content "#{scheme.owning_organisation.name} has been created." end - - context "when I press the back button" do - before do - 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 - - context "and I select to create a scheme" do - before do - click_link "Create scheme" - end - - it "adds scheme to the list of schemes" do - 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.managing_organisation.name - expect(page).to have_content "#{scheme.owning_organisation.name} has been created." end end end