Browse Source

redirect to scheme when trying to access check answers for confirmed scheme

pull/792/head
Kat 2 years ago
parent
commit
ef9d75accc
  1. 4
      app/controllers/schemes_controller.rb
  2. 32
      spec/features/schemes_spec.rb
  3. 8
      spec/requests/locations_controller_spec.rb
  4. 46
      spec/requests/schemes_controller_spec.rb

4
app/controllers/schemes_controller.rb

@ -84,8 +84,12 @@ class SchemesController < ApplicationController
end
def check_answers
if @scheme.confirmed?
redirect_to @scheme
else
render "schemes/check_answers"
end
end
def edit_name
render "schemes/edit_name"

32
spec/features/schemes_spec.rb

@ -274,13 +274,13 @@ RSpec.describe "Schemes scheme Features" do
click_button "Save and continue"
end
it "shows the check answers page location tab" do
expect(page.current_url.split("/").last).to eq("check-answers#locations")
it "shows scheme location tab" do
expect(page.current_url.split("/").last).to eq("locations")
expect(page).to have_content(location_name)
end
it "has the correct action button text" do
expect(page).to have_button("Save")
it "does not have an action button" do
expect(page).not_to have_button("Save")
expect(page).not_to have_button("Create scheme")
end
@ -289,8 +289,8 @@ RSpec.describe "Schemes scheme Features" do
click_link("Scheme")
end
it "does not let you change details other than the name" do
assert_selector "a", text: "Change", count: 1
it "does not let you change details other than the name, confidential information and Housing stock owned by" do
assert_selector "a", text: "Change", count: 3
end
end
end
@ -460,6 +460,14 @@ RSpec.describe "Schemes scheme Features" do
fill_in_and_save_second_location
expect(page).to have_content "Check your changes before creating this scheme"
end
context "when saving a scheme" do
it "shows a confirmation banner" do
fill_in_and_save_location
click_button "Create scheme"
expect(page).to have_content("has been created.")
end
end
end
context "when viewing locations" do
@ -819,13 +827,13 @@ RSpec.describe "Schemes scheme Features" do
click_button "Save and continue"
end
it "shows the check answers page location tab" do
expect(page.current_url.split("/").last).to eq("check-answers#locations")
it "shows the scheme location tab" do
expect(page.current_url.split("/").last).to eq("locations")
expect(page).to have_content(location_name)
end
it "has the correct action button text" do
expect(page).to have_button("Save")
it "does not have an action button" do
expect(page).not_to have_button("Save")
expect(page).not_to have_button("Create scheme")
end
@ -834,8 +842,8 @@ RSpec.describe "Schemes scheme Features" do
click_link("Scheme")
end
it "does not let you change details other than the name" do
assert_selector "a", text: "Change", count: 1
it "does not let you change details other than the name, Confidential information and Housing stock owned by" do
assert_selector "a", text: "Change", count: 3
end
end
end

8
spec/requests/locations_controller_spec.rb

@ -89,7 +89,7 @@ RSpec.describe LocationsController, 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(:startdate) { Time.utc(2022, 2, 2) }
let(:params) { { location: { name: "Test", units: "5", type_of_unit: "Bungalow", add_another_location: "No", postcode: "ZZ1 1ZZ", startdate:, mobility_type: "A" } } }
@ -268,7 +268,7 @@ RSpec.describe LocationsController, 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) }
let(:params) { { location: { name: "Test", units: "5", type_of_unit: "Bungalow", add_another_location: "No", postcode: "ZZ1 1ZZ", mobility_type: "N" } } }
before do
@ -507,7 +507,7 @@ RSpec.describe LocationsController, 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!(:location) { FactoryBot.create(:location, scheme:) }
let(:startdate) { Time.utc(2021, 1, 2) }
let(:params) { { location: { name: "Test", units: "5", type_of_unit: "Bungalow", add_another_location: "No", postcode: "ZZ1 1ZZ", startdate:, page: "edit" } } }
@ -639,7 +639,7 @@ RSpec.describe LocationsController, type: :request do
context "when signed in as a support user" 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!(:location) { FactoryBot.create(:location, scheme:) }
let(:params) { { location: { name: "Test", units: "5", type_of_unit: "Bungalow", add_another_location: "No", postcode: "ZZ1 1ZZ", page: "edit" } } }

46
spec/requests/schemes_controller_spec.rb

@ -873,7 +873,7 @@ RSpec.describe SchemesController, type: :request do
context "when signed in as a support" do
let(:user) { FactoryBot.create(:user, :support) }
let(:scheme_to_update) { FactoryBot.create(:scheme, owning_organisation: user.organisation) }
let(:scheme_to_update) { FactoryBot.create(:scheme, owning_organisation: user.organisation, confirmed: nil) }
before do
allow(user).to receive(:need_two_factor_authentication?).and_return(false)
@ -1433,12 +1433,34 @@ RSpec.describe SchemesController, type: :request do
before do
sign_in user
end
context "when the scheme is not confirmed" do
before do
scheme.update!(confirmed: nil)
get "/schemes/#{scheme.id}/check-answers"
end
it "returns a template for a support" do
expect(response).to have_http_status(:ok)
expect(page).to have_content("Check your changes before creating this scheme")
assert_select "a", text: /Change/, count: 11
end
end
context "when the scheme is confirmed" do
before do
scheme.update!(confirmed: true)
get "/schemes/#{scheme.id}/check-answers"
end
it "redirects to a view scheme page" do
follow_redirect!
expect(response).to have_http_status(:ok)
expect(page).not_to have_content("Check your changes before creating this scheme")
expect(page).to have_content(scheme.service_name)
assert_select "a", text: /Change/, count: 2
end
end
context "when attempting to access check-answers scheme page for another organisation" do
@ -1460,12 +1482,34 @@ RSpec.describe SchemesController, type: :request do
before do
allow(user).to receive(:need_two_factor_authentication?).and_return(false)
sign_in user
end
context "when the scheme is not confirmed" do
before do
scheme.update!(confirmed: nil)
get "/schemes/#{scheme.id}/check-answers"
end
it "returns a template for a support" do
expect(response).to have_http_status(:ok)
expect(page).to have_content("Check your changes before creating this scheme")
assert_select "a", text: /Change/, count: 11
end
end
context "when the scheme is confirmed" do
before do
scheme.update!(confirmed: true)
get "/schemes/#{scheme.id}/check-answers"
end
it "redirects to a view scheme page" do
follow_redirect!
expect(response).to have_http_status(:ok)
expect(page).not_to have_content("Check your changes before creating this scheme")
expect(page).to have_content(scheme.service_name)
assert_select "a", text: /Change/, count: 3
end
end
end
end

Loading…
Cancel
Save