Browse Source

Display banners and redirect to check answers after editing location name

pull/797/head
Kat 3 years ago
parent
commit
1074311cfa
  1. 2
      app/controllers/locations_controller.rb
  2. 9
      app/controllers/schemes_controller.rb
  3. 1
      app/helpers/check_answers_helper.rb
  4. 34
      spec/features/schemes_spec.rb
  5. 20
      spec/requests/schemes_controller_spec.rb

2
app/controllers/locations_controller.rb

@ -56,7 +56,7 @@ class LocationsController < ApplicationController
when "edit"
location_params[:add_another_location] == "Yes" ? redirect_to(new_location_path(@location.scheme)) : redirect_to(scheme_check_answers_path(@scheme, anchor: "locations"))
when "edit-name"
redirect_to(locations_path(@scheme))
redirect_to(scheme_check_answers_path(@scheme, anchor: "locations"))
end
else
render :edit, status: :unprocessable_entity

9
app/controllers/schemes_controller.rb

@ -7,7 +7,6 @@ class SchemesController < ApplicationController
before_action :authenticate_scope!
def index
flash[:notice] = "#{Scheme.find(params[:scheme_id].to_i).service_name} has been created." if params[:scheme_id]
redirect_to schemes_organisation_path(current_user.organisation) unless current_user.support?
all_schemes = Scheme.all.order("service_name ASC")
@ -52,11 +51,17 @@ class SchemesController < ApplicationController
check_answers = params[:scheme][:check_answers]
page = params[:scheme][:page]
scheme_previously_confirmed = @scheme.confirmed?
validation_errors scheme_params
if @scheme.errors.empty? && @scheme.update(scheme_params)
if scheme_params[:confirmed] == "true"
@scheme.locations.each {|location| location.update!(confirmed:true)}
@scheme.locations.each { |location| location.update!(confirmed: true) }
flash[:notice] = if scheme_previously_confirmed
"#{@scheme.service_name} has been updated."
else
"#{@scheme.service_name} has been created."
end
redirect_to scheme_path(@scheme)
elsif check_answers
if confirm_secondary_page? page

1
app/helpers/check_answers_helper.rb

@ -23,6 +23,7 @@ module CheckAnswersHelper
"/schemes/#{scheme.id}/locations/#{location.id}/edit"
end
end
private
def answered_questions_count(subsection, case_log, current_user)

34
spec/features/schemes_spec.rb

@ -285,16 +285,20 @@ RSpec.describe "Schemes scheme Features" do
end
it "allows you to edit the newly added location" do
click_link 'Locations'
expect(page).to have_link(nil , href: /edit/)
click_link "Locations"
expect(page).to have_link(nil, href: /edit/)
end
context "when you click save" do
xit "takes you to view location tab and displays a banner" do
xit "takes you to view location tab" do
click_button "Save"
expect(page.current_url.split("/").last).to eq("locations")
end
it "displays a updated banner" do
click_button "Save"
expect(page).to have_css(".govuk-notification-banner.govuk-notification-banner--success")
expect(page).to have_content("updated")
expect(page).to have_content("has been updated")
end
it "does not let you edit the saved location" do
@ -584,11 +588,12 @@ RSpec.describe "Schemes scheme Features" do
end
it "adds scheme to the list of schemes" do
expect(page).to have_content "#{scheme.service_name} has been created."
click_link "Schemes"
expect(page).to have_content "Supported housing schemes"
expect(page).to have_content scheme.id_to_display
expect(page).to have_content scheme.service_name
expect(page).to have_content scheme.owning_organisation.name
expect(page).to have_content "#{scheme.service_name} has been created."
end
end
@ -732,6 +737,13 @@ RSpec.describe "Schemes scheme Features" do
expect(page).to have_current_path("/schemes/#{scheme.id}/check-answers")
assert_selector "a", text: "Change", count: 3
end
it "lets me save the scheme" do
click_button "Save"
expect(page).to have_current_path("/schemes/#{scheme.id}")
expect(page).to have_css(".govuk-notification-banner.govuk-notification-banner--success")
expect(page).to have_content("has been updated")
end
end
end
@ -772,10 +784,10 @@ RSpec.describe "Schemes scheme Features" do
click_button "Save and continue"
end
it "returns to locations page and shows the new name" do
it "returns to locations check your answers page and shows the new name" do
expect(page).to have_content location.id
expect(page).to have_content "NewName"
expect(page).to have_current_path("/schemes/#{scheme.id}/locations")
expect(page.current_url.split("/").last).to eq("check-answers#locations")
end
end
end
@ -858,8 +870,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
@ -873,7 +885,6 @@ RSpec.describe "Schemes scheme Features" do
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")
@ -890,9 +901,9 @@ RSpec.describe "Schemes scheme Features" do
context "when I click to see individual scheme" do
let(:scheme) { schemes.first }
let!(:location) { FactoryBot.create(:location, scheme:) }
before do
FactoryBot.create(:location, scheme:)
click_link(scheme.service_name)
end
@ -919,6 +930,7 @@ RSpec.describe "Schemes scheme Features" do
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") }

20
spec/requests/schemes_controller_spec.rb

@ -37,14 +37,6 @@ RSpec.describe SchemesController, type: :request do
get "/schemes"
end
context "when params scheme_id is present" do
it "shows a success banner" do
get "/schemes", params: { scheme_id: schemes.first.id }
follow_redirect!
expect(page).to have_css(".govuk-notification-banner.govuk-notification-banner--success")
end
end
it "redirects to the organisation schemes path" do
follow_redirect!
expect(path).to match("/organisations/#{user.organisation.id}/schemes")
@ -93,13 +85,6 @@ RSpec.describe SchemesController, type: :request do
expect(CGI.unescape_html(response.body)).to match("<strong>#{schemes.count}</strong> total schemes")
end
context "when params scheme_id is present" do
it "shows a success banner" do
get "/schemes", params: { scheme_id: schemes.first.id }
expect(page).to have_css(".govuk-notification-banner.govuk-notification-banner--success")
end
end
context "when paginating over 20 results" do
let(:total_schemes_count) { Scheme.count }
@ -885,9 +870,10 @@ 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, confirmed: nil) }
let!(:location) { FactoryBot.create(:location, scheme: scheme_to_update )}
# let!(:location) { FactoryBot.create(:location, scheme: scheme_to_update) }
before do
FactoryBot.create(:location, scheme: scheme_to_update)
allow(user).to receive(:need_two_factor_authentication?).and_return(false)
sign_in user
patch "/schemes/#{scheme_to_update.id}", params:
@ -945,7 +931,7 @@ RSpec.describe SchemesController, type: :request do
let(:params) { { scheme: { page: "check-answers", confirmed: "true" } } }
it "marks the scheme as confirmed" do
expect(scheme_to_update.reload.confirmed?).to eq(true)
expect(scheme_to_update.reload.confirmed?).to eq(true)
end
it "marks all the scheme locations as confirmed" do

Loading…
Cancel
Save