Browse Source

Only direct via secondary client group page when newly required

pull/2775/head
Rachael Booth 7 months ago
parent
commit
53a63936b0
  1. 8
      app/controllers/schemes_controller.rb
  2. 7
      spec/features/schemes_spec.rb
  3. 42
      spec/requests/schemes_controller_spec.rb

8
app/controllers/schemes_controller.rb

@ -145,7 +145,7 @@ class SchemesController < ApplicationController
if @scheme.errors.empty? && @scheme.update(scheme_params)
@scheme.update!(secondary_client_group: nil) if @scheme.has_other_client_group == "No"
if scheme_params[:confirmed] == "true" || @scheme.confirmed?
if check_answers && confirm_secondary_page?(page)
if check_answers && should_direct_via_secondary_client_group_page?(page)
redirect_to scheme_secondary_client_group_path(@scheme, referrer: "check-answers")
else
@scheme.locations.update!(confirmed: true)
@ -157,7 +157,7 @@ class SchemesController < ApplicationController
redirect_to scheme_path(@scheme)
end
elsif check_answers
if confirm_secondary_page?(page)
if should_direct_via_secondary_client_group_page?(page)
redirect_to scheme_secondary_client_group_path(@scheme, referrer: "check-answers")
else
redirect_to scheme_check_answers_path(@scheme)
@ -249,8 +249,8 @@ private
end
end
def confirm_secondary_page?(page)
page == "confirm-secondary" && @scheme.has_other_client_group == "Yes"
def should_direct_via_secondary_client_group_page?(page)
page == "confirm-secondary" && @scheme.has_other_client_group == "Yes" && @scheme.secondary_client_group.nil?
end
def current_template(page)

7
spec/features/schemes_spec.rb

@ -727,13 +727,6 @@ RSpec.describe "Schemes scheme Features" do
expect(page).to have_content "Check your changes before creating this scheme"
end
it "keeps the provider answer when switching between other provider options" do
click_link("Change", href: "/schemes/#{scheme.id}/confirm-secondary-client-group?referrer=check-answers", match: :first)
choose "Yes"
click_button "Save changes"
expect(find_field("Offenders and people at risk of offending")).to be_checked
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?referrer=check-answers", match: :first)
choose "The same organisation that owns the housing stock"

42
spec/requests/schemes_controller_spec.rb

@ -1405,10 +1405,11 @@ RSpec.describe SchemesController, type: :request do
expect(scheme_to_update.reload.has_other_client_group).to eq("Yes")
end
context "when updating from check answers page with the answer YES" do
context "when updating from check answers page with the answer YES and no secondary client group set" do
let(:scheme_to_update) { create(:scheme, owning_organisation: user.organisation, confirmed: nil, secondary_client_group: nil) }
let(:params) { { scheme: { has_other_client_group: "Yes", page: "confirm-secondary", check_answers: "true" } } }
it "renders check answers page after successful update" do
it "renders secondary client group page after successful update" do
follow_redirect!
expect(response).to have_http_status(:ok)
expect(page).to have_content("What is the other client group?")
@ -1420,6 +1421,22 @@ RSpec.describe SchemesController, type: :request do
end
end
context "when updating from check answers page with the answer YES and a secondary client group set" do
let(:scheme_to_update) { create(:scheme, owning_organisation: user.organisation, confirmed: nil, secondary_client_group: "F") }
let(:params) { { scheme: { has_other_client_group: "Yes", page: "confirm-secondary", check_answers: "true" } } }
it "renders check answers page after successful update" do
follow_redirect!
expect(response).to have_http_status(:ok)
expect(page).to have_content("Check your changes before creating this scheme")
end
it "updates a scheme with valid params" do
follow_redirect!
expect(scheme_to_update.reload.has_other_client_group).to eq("Yes")
end
end
context "when updating from check answers page with the answer NO" do
let(:params) { { scheme: { has_other_client_group: "No", page: "confirm-secondary", check_answers: "true" } } }
@ -1716,10 +1733,11 @@ RSpec.describe SchemesController, type: :request do
expect(scheme_to_update.reload.has_other_client_group).to eq("Yes")
end
context "when updating from check answers page with the answer YES" do
context "when updating from check answers page with the answer YES and no existing secondary client group set" do
let(:scheme_to_update) { create(:scheme, owning_organisation: user.organisation, confirmed: nil, secondary_client_group: nil) }
let(:params) { { scheme: { has_other_client_group: "Yes", page: "confirm-secondary", check_answers: "true" } } }
it "renders check answers page after successful update" do
it "renders secondary client group page after successful update" do
follow_redirect!
expect(response).to have_http_status(:ok)
expect(page).to have_content("What is the other client group?")
@ -1731,6 +1749,22 @@ RSpec.describe SchemesController, type: :request do
end
end
context "when updating from check answers page with the answer YES and an existing secondary client group set" do
let(:scheme_to_update) { create(:scheme, owning_organisation: user.organisation, confirmed: nil, secondary_client_group: "F") }
let(:params) { { scheme: { has_other_client_group: "Yes", page: "confirm-secondary", check_answers: "true" } } }
it "renders check answers page after successful update" do
follow_redirect!
expect(response).to have_http_status(:ok)
expect(page).to have_content("Check your changes before creating this scheme")
end
it "updates a scheme with valid params" do
follow_redirect!
expect(scheme_to_update.reload.has_other_client_group).to eq("Yes")
end
end
context "when updating from check answers page with the answer NO" do
let(:params) { { scheme: { has_other_client_group: "No", page: "confirm-secondary", check_answers: "true" } } }

Loading…
Cancel
Save