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. 3
      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" when "edit"
location_params[:add_another_location] == "Yes" ? redirect_to(new_location_path(@location.scheme)) : redirect_to(scheme_check_answers_path(@scheme, anchor: "locations")) 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" when "edit-name"
redirect_to(locations_path(@scheme)) redirect_to(scheme_check_answers_path(@scheme, anchor: "locations"))
end end
else else
render :edit, status: :unprocessable_entity render :edit, status: :unprocessable_entity

9
app/controllers/schemes_controller.rb

@ -7,7 +7,6 @@ class SchemesController < ApplicationController
before_action :authenticate_scope! before_action :authenticate_scope!
def index 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? redirect_to schemes_organisation_path(current_user.organisation) unless current_user.support?
all_schemes = Scheme.all.order("service_name ASC") all_schemes = Scheme.all.order("service_name ASC")
@ -52,11 +51,17 @@ class SchemesController < ApplicationController
check_answers = params[:scheme][:check_answers] check_answers = params[:scheme][:check_answers]
page = params[:scheme][:page] page = params[:scheme][:page]
scheme_previously_confirmed = @scheme.confirmed?
validation_errors scheme_params validation_errors scheme_params
if @scheme.errors.empty? && @scheme.update(scheme_params) if @scheme.errors.empty? && @scheme.update(scheme_params)
if scheme_params[:confirmed] == "true" 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) redirect_to scheme_path(@scheme)
elsif check_answers elsif check_answers
if confirm_secondary_page? page if confirm_secondary_page? page

3
app/helpers/check_answers_helper.rb

@ -13,7 +13,7 @@ module CheckAnswersHelper
def can_change_scheme_answer?(attribute_name, scheme) def can_change_scheme_answer?(attribute_name, scheme)
editable_attributes = current_user.support? ? ["Name", "Confidential information", "Housing stock owned by"] : ["Name", "Confidential information"] editable_attributes = current_user.support? ? ["Name", "Confidential information", "Housing stock owned by"] : ["Name", "Confidential information"]
!scheme.confirmed? || editable_attributes.include?(attribute_name) !scheme.confirmed? || editable_attributes.include?(attribute_name)
end end
def get_location_change_link_href(scheme, location) def get_location_change_link_href(scheme, location)
@ -23,6 +23,7 @@ module CheckAnswersHelper
"/schemes/#{scheme.id}/locations/#{location.id}/edit" "/schemes/#{scheme.id}/locations/#{location.id}/edit"
end end
end end
private private
def answered_questions_count(subsection, case_log, current_user) 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 end
it "allows you to edit the newly added location" do it "allows you to edit the newly added location" do
click_link 'Locations' click_link "Locations"
expect(page).to have_link(nil , href: /edit/) expect(page).to have_link(nil, href: /edit/)
end end
context "when you click save" do 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" click_button "Save"
expect(page.current_url.split("/").last).to eq("locations") 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_css(".govuk-notification-banner.govuk-notification-banner--success")
expect(page).to have_content("updated") expect(page).to have_content("has been updated")
end end
it "does not let you edit the saved location" do it "does not let you edit the saved location" do
@ -584,11 +588,12 @@ RSpec.describe "Schemes scheme Features" do
end end
it "adds scheme to the list of schemes" do 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 "Supported housing schemes"
expect(page).to have_content scheme.id_to_display expect(page).to have_content scheme.id_to_display
expect(page).to have_content scheme.service_name expect(page).to have_content scheme.service_name
expect(page).to have_content scheme.owning_organisation.name expect(page).to have_content scheme.owning_organisation.name
expect(page).to have_content "#{scheme.service_name} has been created."
end end
end end
@ -732,6 +737,13 @@ RSpec.describe "Schemes scheme Features" do
expect(page).to have_current_path("/schemes/#{scheme.id}/check-answers") expect(page).to have_current_path("/schemes/#{scheme.id}/check-answers")
assert_selector "a", text: "Change", count: 3 assert_selector "a", text: "Change", count: 3
end 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
end end
@ -772,10 +784,10 @@ RSpec.describe "Schemes scheme Features" do
click_button "Save and continue" click_button "Save and continue"
end 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 location.id
expect(page).to have_content "NewName" 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 end
end end
@ -858,8 +870,8 @@ RSpec.describe "Schemes scheme Features" do
click_link("Scheme") click_link("Scheme")
end end
it "does not let you change details other than the name" do 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: 1 assert_selector "a", text: "Change", count: 3
end end
end end
end end
@ -873,7 +885,6 @@ RSpec.describe "Schemes scheme Features" do
context "when I am signed in as a data coordinator" 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(: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!(:schemes) { FactoryBot.create_list(:scheme, 5, owning_organisation_id: user.organisation_id) }
let!(:scheme_to_search) { FactoryBot.create(:scheme) }
before do before do
visit("/logs") visit("/logs")
@ -890,9 +901,9 @@ RSpec.describe "Schemes scheme Features" do
context "when I click to see individual scheme" do context "when I click to see individual scheme" do
let(:scheme) { schemes.first } let(:scheme) { schemes.first }
let!(:location) { FactoryBot.create(:location, scheme:) }
before do before do
FactoryBot.create(:location, scheme:)
click_link(scheme.service_name) click_link(scheme.service_name)
end end
@ -919,6 +930,7 @@ RSpec.describe "Schemes scheme Features" do
end end
end end
end end
context "when selecting a scheme" do context "when selecting a scheme" do
let!(:user) { FactoryBot.create(:user, :data_coordinator, last_sign_in_at: Time.zone.now) } 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") } 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" get "/schemes"
end 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 it "redirects to the organisation schemes path" do
follow_redirect! follow_redirect!
expect(path).to match("/organisations/#{user.organisation.id}/schemes") 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") expect(CGI.unescape_html(response.body)).to match("<strong>#{schemes.count}</strong> total schemes")
end 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 context "when paginating over 20 results" do
let(:total_schemes_count) { Scheme.count } let(:total_schemes_count) { Scheme.count }
@ -885,9 +870,10 @@ RSpec.describe SchemesController, type: :request do
context "when signed in as a support" do context "when signed in as a support" do
let(:user) { FactoryBot.create(:user, :support) } let(:user) { FactoryBot.create(:user, :support) }
let(:scheme_to_update) { FactoryBot.create(:scheme, owning_organisation: user.organisation, confirmed: nil) } 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 before do
FactoryBot.create(:location, scheme: scheme_to_update)
allow(user).to receive(:need_two_factor_authentication?).and_return(false) allow(user).to receive(:need_two_factor_authentication?).and_return(false)
sign_in user sign_in user
patch "/schemes/#{scheme_to_update.id}", params: 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" } } } let(:params) { { scheme: { page: "check-answers", confirmed: "true" } } }
it "marks the scheme as confirmed" do 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 end
it "marks all the scheme locations as confirmed" do it "marks all the scheme locations as confirmed" do

Loading…
Cancel
Save