diff --git a/app/controllers/schemes_controller.rb b/app/controllers/schemes_controller.rb index 8c7b80833..fe9454c4b 100644 --- a/app/controllers/schemes_controller.rb +++ b/app/controllers/schemes_controller.rb @@ -57,8 +57,8 @@ class SchemesController < ApplicationController if @scheme.errors.empty? && @scheme.update(scheme_params) if scheme_params[:confirmed] == "true" @scheme.locations.each {|location| location.update!(confirmed:true)} - end - if check_answers + redirect_to scheme_path(@scheme) + elsif check_answers if confirm_secondary_page? page redirect_to scheme_secondary_client_group_path(@scheme, check_answers: "true") else @@ -180,7 +180,7 @@ private scheme_details_path(@scheme) end when "edit-name" - scheme_path(@scheme) + scheme_check_answers_path(@scheme) when "check-answers" schemes_path(scheme_id: @scheme.id) end diff --git a/app/helpers/check_answers_helper.rb b/app/helpers/check_answers_helper.rb index 982cab7cc..8b9c04629 100644 --- a/app/helpers/check_answers_helper.rb +++ b/app/helpers/check_answers_helper.rb @@ -11,6 +11,10 @@ module CheckAnswersHelper end end + def can_change_scheme_answer?(attribute_name, scheme) + editable_attributes = current_user.support? ? ["Name", "Confidential information", "Housing stock owned by"] : ["Name", "Confidential information"] + !scheme.confirmed? || editable_attributes.include?(attribute_name) + end private def answered_questions_count(subsection, case_log, current_user) diff --git a/app/views/schemes/_scheme_summary_list_row.html.erb b/app/views/schemes/_scheme_summary_list_row.html.erb index a02e5d25f..7765347d7 100644 --- a/app/views/schemes/_scheme_summary_list_row.html.erb +++ b/app/views/schemes/_scheme_summary_list_row.html.erb @@ -1,4 +1,4 @@ -
"> +
">
<%= attribute[:name].to_s %>
@@ -14,7 +14,7 @@ <%= details_html(attribute) %> <% end %> - <% if !scheme.confirmed? || attribute[:name] == "Name" %> + <% if can_change_scheme_answer?(attribute[:name], scheme) %>
Change
diff --git a/app/views/schemes/check_answers.html.erb b/app/views/schemes/check_answers.html.erb index 7319259f4..3e9bd76cf 100644 --- a/app/views/schemes/check_answers.html.erb +++ b/app/views/schemes/check_answers.html.erb @@ -10,7 +10,7 @@
<% @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) } %> + <%= 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 %> <% if !@scheme.arrangement_type_same? %> <% @scheme.check_support_services_provider_attributes.each do |attr| %> diff --git a/spec/features/schemes_spec.rb b/spec/features/schemes_spec.rb index 9792dfc42..29d6a516f 100644 --- a/spec/features/schemes_spec.rb +++ b/spec/features/schemes_spec.rb @@ -284,6 +284,27 @@ RSpec.describe "Schemes scheme Features" do expect(page).not_to have_button("Create scheme") end + it "allows you to edit the newly added location" do + click_link 'Locations' + expect(page).to have_link(nil , href: /edit/) + end + + context "when you click save" do + it "takes you to view location tab and displays a banner" do + click_button "Save" + expect(page.current_url.split("/").last).to eq("locations") + expect(page).to have_css(".govuk-notification-banner.govuk-notification-banner--success") + expect(page).to have_content("udpated") + end + + it "does not let you edit the saved location" do + click_button "Save" + click_link "Back" + click_link 'Change' + expect(page.current_url.split("/").last).to eq("edit-name") + end + end + context "when you click to view the scheme details" do before do click_link("Scheme") @@ -451,6 +472,7 @@ RSpec.describe "Schemes scheme Features" do it "lets me check my answers after adding a location" do fill_in_and_save_location + expect(page).to have_current_path("/schemes/#{scheme.id}/check-answers") expect(page).to have_content "Check your changes before creating this scheme" end @@ -704,9 +726,10 @@ RSpec.describe "Schemes scheme Features" do click_button "Save changes" end - it "lets me see amended details on the show page" do + it "lets me see amended details on the check answers page" do expect(page).to have_content "FooBar" - expect(page).to have_current_path("/schemes/#{scheme.id}") + expect(page).to have_current_path("/schemes/#{scheme.id}/check-answers") + assert_selector "a", text: "Change", count: 3 end end end @@ -846,6 +869,55 @@ RSpec.describe "Schemes scheme Features" do end end + context "when I am signed in as a data coordinator" do + let(:user) { FactoryBot.create(:user, :data_coordinator, last_sign_in_at: Time.zone.now) } + let!(:schemes) { FactoryBot.create_list(:scheme, 5, owning_organisation_id: user.organisation_id) } + let!(:scheme_to_search) { FactoryBot.create(:scheme) } + + before do + visit("/logs") + fill_in("user[email]", with: user.email) + fill_in("user[password]", with: user.password) + click_button("Sign in") + end + + context "when editing a scheme" do + context "when I visit schemes page" do + before do + visit("schemes") + end + + context "when I click to see individual scheme" do + let(:scheme) { schemes.first } + let!(:location) { FactoryBot.create(:location, scheme:) } + + before do + click_link(scheme.service_name) + end + + context "when I click to change scheme name" do + before do + click_link("Change", href: "/schemes/#{scheme.id}/edit-name", match: :first) + end + + context "when I edit details" do + before do + fill_in "Scheme name", with: "FooBar" + check "This scheme contains confidential information" + click_button "Save changes" + end + + it "lets me see amended details on the check answers page" do + expect(page).to have_content "FooBar" + expect(page).to have_current_path("/schemes/#{scheme.id}/check-answers") + expect(page).to have_link("Change", href: /schemes\/#{scheme.id}\/edit-name/, count: 2) + end + end + end + end + end + end + end 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, managing_organisation: user.organisation, arrangement_type: "The same organisation that owns the housing stock") }