From 761bf97dc2719002730989380899a0ab1f115fd2 Mon Sep 17 00:00:00 2001 From: Kat Date: Thu, 28 Jul 2022 14:20:10 +0100 Subject: [PATCH] Redirect to view scheme when trying to access create form pages for the scheme --- app/controllers/schemes_controller.rb | 30 ++++++-- spec/requests/schemes_controller_spec.rb | 95 +++++++++++++++++++++--- 2 files changed, 110 insertions(+), 15 deletions(-) diff --git a/app/controllers/schemes_controller.rb b/app/controllers/schemes_controller.rb index 0cbc66fc2..ec710b047 100644 --- a/app/controllers/schemes_controller.rb +++ b/app/controllers/schemes_controller.rb @@ -64,23 +64,43 @@ class SchemesController < ApplicationController end def primary_client_group - render "schemes/primary_client_group" + if @scheme.confirmed? + redirect_to @scheme + else + render "schemes/primary_client_group" + end end def confirm_secondary_client_group - render "schemes/confirm_secondary" + if @scheme.confirmed? + redirect_to @scheme + else + render "schemes/confirm_secondary" + end end def secondary_client_group - render "schemes/secondary_client_group" + if @scheme.confirmed? + redirect_to @scheme + else + render "schemes/secondary_client_group" + end end def support - render "schemes/support" + if @scheme.confirmed? + redirect_to @scheme + else + render "schemes/support" + end end def details - render "schemes/details" + if @scheme.confirmed? + redirect_to @scheme + else + render "schemes/details" + end end def check_answers diff --git a/spec/requests/schemes_controller_spec.rb b/spec/requests/schemes_controller_spec.rb index 41e6d0f58..feb23e77b 100644 --- a/spec/requests/schemes_controller_spec.rb +++ b/spec/requests/schemes_controller_spec.rb @@ -1164,7 +1164,7 @@ RSpec.describe SchemesController, type: :request do context "when signed in as a data coordinator" do let(:user) { FactoryBot.create(:user, :data_coordinator) } - let!(:scheme) { FactoryBot.create(:scheme, owning_organisation: user.organisation) } + let!(:scheme) { FactoryBot.create(:scheme, owning_organisation: user.organisation, confirmed: nil) } let!(:another_scheme) { FactoryBot.create(:scheme) } before do @@ -1191,7 +1191,7 @@ RSpec.describe SchemesController, type: :request do context "when signed in as a support user" do let(:user) { FactoryBot.create(:user, :support) } - let!(:scheme) { FactoryBot.create(:scheme) } + let!(:scheme) { FactoryBot.create(:scheme, confirmed: nil) } before do allow(user).to receive(:need_two_factor_authentication?).and_return(false) @@ -1203,6 +1203,21 @@ RSpec.describe SchemesController, type: :request do expect(response).to have_http_status(:ok) expect(page).to have_content("What client group is this scheme intended for?") end + + context "and the scheme is confirmed" do + before do + scheme.update!(confirmed: true) + get "/schemes/#{scheme.id}/primary-client-group" + end + + it "redirects to a view scheme page" do + follow_redirect! + expect(response).to have_http_status(:ok) + expect(path).to match("/schemes/#{scheme.id}") + expect(page).to have_content(scheme.service_name) + assert_select "a", text: /Change/, count: 3 + end + end end end @@ -1230,7 +1245,7 @@ RSpec.describe SchemesController, type: :request do context "when signed in as a data coordinator" do let(:user) { FactoryBot.create(:user, :data_coordinator) } - let!(:scheme) { FactoryBot.create(:scheme, owning_organisation: user.organisation) } + let!(:scheme) { FactoryBot.create(:scheme, owning_organisation: user.organisation, confirmed: nil) } let!(:another_scheme) { FactoryBot.create(:scheme) } before do @@ -1257,7 +1272,7 @@ RSpec.describe SchemesController, type: :request do context "when signed in as a support user" do let(:user) { FactoryBot.create(:user, :support) } - let!(:scheme) { FactoryBot.create(:scheme) } + let!(:scheme) { FactoryBot.create(:scheme, confirmed: nil) } before do allow(user).to receive(:need_two_factor_authentication?).and_return(false) @@ -1269,6 +1284,21 @@ RSpec.describe SchemesController, type: :request do expect(response).to have_http_status(:ok) expect(page).to have_content("Does this scheme provide for another client group?") end + + context "and the scheme is confirmed" do + before do + scheme.update!(confirmed: true) + get "/schemes/#{scheme.id}/confirm-secondary-client-group" + end + + it "redirects to a view scheme page" do + follow_redirect! + expect(response).to have_http_status(:ok) + expect(path).to match("/schemes/#{scheme.id}") + expect(page).to have_content(scheme.service_name) + assert_select "a", text: /Change/, count: 3 + end + end end end @@ -1296,7 +1326,7 @@ RSpec.describe SchemesController, type: :request do context "when signed in as a data coordinator" do let(:user) { FactoryBot.create(:user, :data_coordinator) } - let!(:scheme) { FactoryBot.create(:scheme, owning_organisation: user.organisation) } + let!(:scheme) { FactoryBot.create(:scheme, owning_organisation: user.organisation, confirmed: nil) } let!(:another_scheme) { FactoryBot.create(:scheme) } before do @@ -1323,7 +1353,7 @@ RSpec.describe SchemesController, type: :request do context "when signed in as a support user" do let(:user) { FactoryBot.create(:user, :support) } - let!(:scheme) { FactoryBot.create(:scheme) } + let!(:scheme) { FactoryBot.create(:scheme, confirmed: nil) } before do allow(user).to receive(:need_two_factor_authentication?).and_return(false) @@ -1335,6 +1365,21 @@ RSpec.describe SchemesController, type: :request do expect(response).to have_http_status(:ok) expect(page).to have_content("What is the other client group?") end + + context "and the scheme is confirmed" do + before do + scheme.update!(confirmed: true) + get "/schemes/#{scheme.id}/secondary-client-group" + end + + it "redirects to a view scheme page" do + follow_redirect! + expect(response).to have_http_status(:ok) + expect(path).to match("/schemes/#{scheme.id}") + expect(page).to have_content(scheme.service_name) + assert_select "a", text: /Change/, count: 3 + end + end end end @@ -1362,7 +1407,7 @@ RSpec.describe SchemesController, type: :request do context "when signed in as a data coordinator" do let(:user) { FactoryBot.create(:user, :data_coordinator) } - let!(:scheme) { FactoryBot.create(:scheme, owning_organisation: user.organisation) } + let!(:scheme) { FactoryBot.create(:scheme, owning_organisation: user.organisation, confirmed: nil) } let!(:another_scheme) { FactoryBot.create(:scheme) } before do @@ -1385,11 +1430,26 @@ RSpec.describe SchemesController, type: :request do expect(response).to have_http_status(:not_found) end end + + context "and the scheme is confirmed" do + before do + scheme.update!(confirmed: true) + get "/schemes/#{scheme.id}/support" + end + + it "redirects to a view scheme page" do + follow_redirect! + expect(response).to have_http_status(:ok) + expect(path).to match("/schemes/#{scheme.id}") + expect(page).to have_content(scheme.service_name) + assert_select "a", text: /Change/, count: 2 + end + end end context "when signed in as a support user" do let(:user) { FactoryBot.create(:user, :support) } - let!(:scheme) { FactoryBot.create(:scheme) } + let!(:scheme) { FactoryBot.create(:scheme, confirmed: nil) } before do allow(user).to receive(:need_two_factor_authentication?).and_return(false) @@ -1538,7 +1598,7 @@ RSpec.describe SchemesController, type: :request do context "when signed in as a data coordinator" do let(:user) { FactoryBot.create(:user, :data_coordinator) } - let!(:scheme) { FactoryBot.create(:scheme, owning_organisation: user.organisation) } + let!(:scheme) { FactoryBot.create(:scheme, owning_organisation: user.organisation, confirmed: nil) } let!(:another_scheme) { FactoryBot.create(:scheme) } before do @@ -1561,11 +1621,26 @@ RSpec.describe SchemesController, type: :request do expect(response).to have_http_status(:not_found) end end + + context "and the scheme is confirmed" do + before do + scheme.update!(confirmed: true) + get "/schemes/#{scheme.id}/details" + end + + it "redirects to a view scheme page" do + follow_redirect! + expect(response).to have_http_status(:ok) + expect(path).to match("/schemes/#{scheme.id}") + expect(page).to have_content(scheme.service_name) + assert_select "a", text: /Change/, count: 2 + end + end end context "when signed in as a support user" do let(:user) { FactoryBot.create(:user, :support) } - let!(:scheme) { FactoryBot.create(:scheme) } + let!(:scheme) { FactoryBot.create(:scheme, confirmed: nil) } before do allow(user).to receive(:need_two_factor_authentication?).and_return(false)