Browse Source

Redirect to view scheme when trying to access create form pages for the scheme

pull/792/head
Kat 2 years ago
parent
commit
761bf97dc2
  1. 30
      app/controllers/schemes_controller.rb
  2. 95
      spec/requests/schemes_controller_spec.rb

30
app/controllers/schemes_controller.rb

@ -64,23 +64,43 @@ class SchemesController < ApplicationController
end end
def primary_client_group def primary_client_group
render "schemes/primary_client_group" if @scheme.confirmed?
redirect_to @scheme
else
render "schemes/primary_client_group"
end
end end
def confirm_secondary_client_group def confirm_secondary_client_group
render "schemes/confirm_secondary" if @scheme.confirmed?
redirect_to @scheme
else
render "schemes/confirm_secondary"
end
end end
def secondary_client_group def secondary_client_group
render "schemes/secondary_client_group" if @scheme.confirmed?
redirect_to @scheme
else
render "schemes/secondary_client_group"
end
end end
def support def support
render "schemes/support" if @scheme.confirmed?
redirect_to @scheme
else
render "schemes/support"
end
end end
def details def details
render "schemes/details" if @scheme.confirmed?
redirect_to @scheme
else
render "schemes/details"
end
end end
def check_answers def check_answers

95
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 context "when signed in as a data coordinator" do
let(:user) { FactoryBot.create(:user, :data_coordinator) } 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) } let!(:another_scheme) { FactoryBot.create(:scheme) }
before do before do
@ -1191,7 +1191,7 @@ RSpec.describe SchemesController, type: :request do
context "when signed in as a support user" do context "when signed in as a support user" do
let(:user) { FactoryBot.create(:user, :support) } let(:user) { FactoryBot.create(:user, :support) }
let!(:scheme) { FactoryBot.create(:scheme) } let!(:scheme) { FactoryBot.create(:scheme, confirmed: nil) }
before do before do
allow(user).to receive(:need_two_factor_authentication?).and_return(false) 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(response).to have_http_status(:ok)
expect(page).to have_content("What client group is this scheme intended for?") expect(page).to have_content("What client group is this scheme intended for?")
end 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
end end
@ -1230,7 +1245,7 @@ RSpec.describe SchemesController, type: :request do
context "when signed in as a data coordinator" do context "when signed in as a data coordinator" do
let(:user) { FactoryBot.create(:user, :data_coordinator) } 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) } let!(:another_scheme) { FactoryBot.create(:scheme) }
before do before do
@ -1257,7 +1272,7 @@ RSpec.describe SchemesController, type: :request do
context "when signed in as a support user" do context "when signed in as a support user" do
let(:user) { FactoryBot.create(:user, :support) } let(:user) { FactoryBot.create(:user, :support) }
let!(:scheme) { FactoryBot.create(:scheme) } let!(:scheme) { FactoryBot.create(:scheme, confirmed: nil) }
before do before do
allow(user).to receive(:need_two_factor_authentication?).and_return(false) 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(response).to have_http_status(:ok)
expect(page).to have_content("Does this scheme provide for another client group?") expect(page).to have_content("Does this scheme provide for another client group?")
end 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
end end
@ -1296,7 +1326,7 @@ RSpec.describe SchemesController, type: :request do
context "when signed in as a data coordinator" do context "when signed in as a data coordinator" do
let(:user) { FactoryBot.create(:user, :data_coordinator) } 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) } let!(:another_scheme) { FactoryBot.create(:scheme) }
before do before do
@ -1323,7 +1353,7 @@ RSpec.describe SchemesController, type: :request do
context "when signed in as a support user" do context "when signed in as a support user" do
let(:user) { FactoryBot.create(:user, :support) } let(:user) { FactoryBot.create(:user, :support) }
let!(:scheme) { FactoryBot.create(:scheme) } let!(:scheme) { FactoryBot.create(:scheme, confirmed: nil) }
before do before do
allow(user).to receive(:need_two_factor_authentication?).and_return(false) 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(response).to have_http_status(:ok)
expect(page).to have_content("What is the other client group?") expect(page).to have_content("What is the other client group?")
end 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
end end
@ -1362,7 +1407,7 @@ RSpec.describe SchemesController, type: :request do
context "when signed in as a data coordinator" do context "when signed in as a data coordinator" do
let(:user) { FactoryBot.create(:user, :data_coordinator) } 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) } let!(:another_scheme) { FactoryBot.create(:scheme) }
before do before do
@ -1385,11 +1430,26 @@ RSpec.describe SchemesController, type: :request do
expect(response).to have_http_status(:not_found) expect(response).to have_http_status(:not_found)
end end
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 end
context "when signed in as a support user" do context "when signed in as a support user" do
let(:user) { FactoryBot.create(:user, :support) } let(:user) { FactoryBot.create(:user, :support) }
let!(:scheme) { FactoryBot.create(:scheme) } let!(:scheme) { FactoryBot.create(:scheme, confirmed: nil) }
before do before do
allow(user).to receive(:need_two_factor_authentication?).and_return(false) 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 context "when signed in as a data coordinator" do
let(:user) { FactoryBot.create(:user, :data_coordinator) } 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) } let!(:another_scheme) { FactoryBot.create(:scheme) }
before do before do
@ -1561,11 +1621,26 @@ RSpec.describe SchemesController, type: :request do
expect(response).to have_http_status(:not_found) expect(response).to have_http_status(:not_found)
end end
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 end
context "when signed in as a support user" do context "when signed in as a support user" do
let(:user) { FactoryBot.create(:user, :support) } let(:user) { FactoryBot.create(:user, :support) }
let!(:scheme) { FactoryBot.create(:scheme) } let!(:scheme) { FactoryBot.create(:scheme, confirmed: nil) }
before do before do
allow(user).to receive(:need_two_factor_authentication?).and_return(false) allow(user).to receive(:need_two_factor_authentication?).and_return(false)

Loading…
Cancel
Save