Browse Source

display successful reactivation banner for default date

pull/1007/head
Kat 4 years ago
parent
commit
a475ace85b
  1. 7
      app/controllers/locations_controller.rb
  2. 2
      app/helpers/toggle_active_location_helper.rb
  3. 2
      config/routes.rb
  4. 69
      spec/requests/locations_controller_spec.rb

7
app/controllers/locations_controller.rb

@ -54,7 +54,8 @@ class LocationsController < ApplicationController
end end
def reactivate def reactivate
render "toggle_active", locals: { action: "reactivate" } flash[:notice] = reactivate_success_notice
redirect_to scheme_location_path(@scheme, @location)
end end
def create def create
@ -193,6 +194,10 @@ private
end end
end end
def reactivate_success_notice
"#{@location.name} has been reactivated"
end
def update_affected_logs def update_affected_logs
@location.lettings_logs.filter_by_before_startdate(deactivation_date.to_time).update!(location: nil, scheme: nil) @location.lettings_logs.filter_by_before_startdate(deactivation_date.to_time).update!(location: nil, scheme: nil)
end end

2
app/helpers/toggle_active_location_helper.rb

@ -3,7 +3,7 @@ module ToggleActiveLocationHelper
if action == "deactivate" if action == "deactivate"
scheme_location_new_deactivation_path(scheme_id:, location_id:) scheme_location_new_deactivation_path(scheme_id:, location_id:)
else else
scheme_location_new_reactivation_path(scheme_id:, location_id:) scheme_location_reactivate_path(scheme_id:, location_id:)
end end
end end

2
config/routes.rb

@ -64,7 +64,7 @@ Rails.application.routes.draw do
get "new-reactivation", to: "locations#new_reactivation" get "new-reactivation", to: "locations#new_reactivation"
patch "new-deactivation", to: "locations#new_deactivation" patch "new-deactivation", to: "locations#new_deactivation"
patch "deactivate", to: "locations#deactivate" patch "deactivate", to: "locations#deactivate"
patch "new-reactivation", to: "locations#new_reactivation" patch "reactivate", to: "locations#reactivate"
end end
end end

69
spec/requests/locations_controller_spec.rb

@ -1442,4 +1442,73 @@ RSpec.describe LocationsController, type: :request do
end end
end end
end end
describe "#reactivate" do
context "when not signed in" do
it "redirects to the sign in page" do
patch "/schemes/1/locations/1/reactivate"
expect(response).to redirect_to("/account/sign-in")
end
end
context "when signed in as a data provider" do
let(:user) { FactoryBot.create(:user) }
before do
sign_in user
patch "/schemes/1/locations/1/reactivate"
end
it "returns 401 unauthorized" do
request
expect(response).to have_http_status(:unauthorized)
end
end
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!(:location) { FactoryBot.create(:location, scheme:) }
let(:deactivation_date) { Time.utc(2022, 10, 10) }
let(:reactivation_date) { Time.utc(2022, 10, 12) }
let!(:lettings_log) { FactoryBot.create(:lettings_log, :sh, location:, scheme:, startdate:, owning_organisation: user.organisation) }
let(:startdate) { Time.utc(2022, 10, 11) }
before do
Timecop.freeze(Time.utc(2022, 10, 10))
sign_in user
location.location_deactivation_periods << FactoryBot.create(:location_deactivation_period, deactivation_date:)
location.save!
patch "/schemes/#{scheme.id}/locations/#{location.id}/reactivate", params:
end
after do
Timecop.unfreeze
end
context "with default date" do
let(:params) { { location: { reactivation_date_type: "default", reactivation_date: } } }
it "redirects to the location page and displays a success banner" do
expect(response).to redirect_to("/schemes/#{scheme.id}/locations/#{location.id}")
follow_redirect!
expect(response).to have_http_status(:ok)
expect(page).to have_css(".govuk-notification-banner.govuk-notification-banner--success")
expect(page).to have_content("#{location.name} has been reactivated")
end
end
context "with other date" do
let(:params) { { location: { deactivation_date_type: "other", "deactivation_date(3i)": "10", "deactivation_date(2i)": "10", "deactivation_date(1i)": "2022" } } }
it "redirects to the location page and displays a success banner" do
expect(response).to redirect_to("/schemes/#{scheme.id}/locations/#{location.id}")
follow_redirect!
expect(page).to have_css(".govuk-notification-banner.govuk-notification-banner--success")
expect(page).to have_content("#{location.name} has been reactivated")
end
end
end
end
end end

Loading…
Cancel
Save