Browse Source

Deactivation does not affect logs (#1018)

* Update affected logs count and skip the confirmation page if no logs are affected for locations

* Update affected logs count and skip the confirmation page if no logs are affected for schemes

* refactor
CLDC-1672-scheme-reactivation-review-app
kosiakkatrina 2 years ago committed by GitHub
parent
commit
3a60c4cd02
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 9
      app/controllers/locations_controller.rb
  2. 9
      app/controllers/schemes_controller.rb
  3. 2
      app/views/locations/deactivate_confirm.html.erb
  4. 2
      app/views/schemes/deactivate_confirm.html.erb
  5. 50
      spec/requests/locations_controller_spec.rb
  6. 52
      spec/requests/schemes_controller_spec.rb

9
app/controllers/locations_controller.rb

@ -38,8 +38,13 @@ class LocationsController < ApplicationController
end end
def deactivate_confirm def deactivate_confirm
@deactivation_date = params[:deactivation_date] @affected_logs = @location.lettings_logs.filter_by_before_startdate(params[:deactivation_date])
@deactivation_date_type = params[:deactivation_date_type] if @affected_logs.count.zero?
deactivate
else
@deactivation_date = params[:deactivation_date]
@deactivation_date_type = params[:deactivation_date_type]
end
end end
def deactivate def deactivate

9
app/controllers/schemes_controller.rb

@ -39,8 +39,13 @@ class SchemesController < ApplicationController
end end
def deactivate_confirm def deactivate_confirm
@deactivation_date = params[:deactivation_date] @affected_logs = @scheme.lettings_logs.filter_by_before_startdate(params[:deactivation_date])
@deactivation_date_type = params[:deactivation_date_type] if @affected_logs.count.zero?
deactivate
else
@deactivation_date = params[:deactivation_date]
@deactivation_date_type = params[:deactivation_date_type]
end
end end
def deactivate def deactivate

2
app/views/locations/deactivate_confirm.html.erb

@ -4,7 +4,7 @@
<% end %> <% end %>
<h1 class="govuk-heading-l"> <h1 class="govuk-heading-l">
<span class="govuk-caption-l"><%= @location.postcode %></span> <span class="govuk-caption-l"><%= @location.postcode %></span>
This change will affect <%= @location.lettings_logs.count %> logs This change will affect <%= @affected_logs.count %> logs
</h1> </h1>
<%= govuk_warning_text text: I18n.t("warnings.location.deactivate.review_logs") %> <%= govuk_warning_text text: I18n.t("warnings.location.deactivate.review_logs") %>
<%= f.hidden_field :confirm, value: true %> <%= f.hidden_field :confirm, value: true %>

2
app/views/schemes/deactivate_confirm.html.erb

@ -4,7 +4,7 @@
<% end %> <% end %>
<h1 class="govuk-heading-l"> <h1 class="govuk-heading-l">
<span class="govuk-caption-l"><%= @scheme.service_name %></span> <span class="govuk-caption-l"><%= @scheme.service_name %></span>
This change will affect <%= @scheme.lettings_logs.count %> logs This change will affect <%= @affected_logs.count %> logs
</h1> </h1>
<%= govuk_warning_text text: I18n.t("warnings.scheme.deactivate.review_logs") %> <%= govuk_warning_text text: I18n.t("warnings.scheme.deactivate.review_logs") %>
<%= f.hidden_field :confirm, value: true %> <%= f.hidden_field :confirm, value: true %>

50
spec/requests/locations_controller_spec.rb

@ -1243,11 +1243,13 @@ RSpec.describe LocationsController, type: :request do
let!(:lettings_log) { FactoryBot.create(:lettings_log, :sh, location:, scheme:, startdate:, owning_organisation: user.organisation) } let!(:lettings_log) { FactoryBot.create(:lettings_log, :sh, location:, scheme:, startdate:, owning_organisation: user.organisation) }
let(:startdate) { Time.utc(2022, 10, 11) } let(:startdate) { Time.utc(2022, 10, 11) }
let(:add_deactivations) { nil } let(:add_deactivations) { nil }
let(:setup_locations) { nil }
before do before do
Timecop.freeze(Time.utc(2022, 10, 10)) Timecop.freeze(Time.utc(2022, 10, 10))
sign_in user sign_in user
add_deactivations add_deactivations
setup_locations
location.save! location.save!
patch "/schemes/#{scheme.id}/locations/#{location.id}/new-deactivation", params: patch "/schemes/#{scheme.id}/locations/#{location.id}/new-deactivation", params:
end end
@ -1259,20 +1261,52 @@ RSpec.describe LocationsController, type: :request do
context "with default date" do context "with default date" do
let(:params) { { location_deactivation_period: { deactivation_date_type: "default", deactivation_date: } } } let(:params) { { location_deactivation_period: { deactivation_date_type: "default", deactivation_date: } } }
it "redirects to the confirmation page" do context "and affected logs" do
follow_redirect! it "redirects to the confirmation page" do
expect(response).to have_http_status(:ok) follow_redirect!
expect(page).to have_content("This change will affect #{location.lettings_logs.count} logs") expect(response).to have_http_status(:ok)
expect(page).to have_content("This change will affect 1 logs")
end
end
context "and no affected logs" do
let(:setup_locations) { location.lettings_logs.update(location: nil) }
it "redirects to the location page and updates the deactivation period" do
follow_redirect!
follow_redirect!
expect(response).to have_http_status(:ok)
expect(page).to have_css(".govuk-notification-banner.govuk-notification-banner--success")
location.reload
expect(location.location_deactivation_periods.count).to eq(1)
expect(location.location_deactivation_periods.first.deactivation_date).to eq(Time.zone.local(2022, 4, 1))
end
end end
end end
context "with other date" do context "with other date" do
let(:params) { { location_deactivation_period: { deactivation_date_type: "other", "deactivation_date(3i)": "10", "deactivation_date(2i)": "10", "deactivation_date(1i)": "2022" } } } let(:params) { { location_deactivation_period: { deactivation_date_type: "other", "deactivation_date(3i)": "10", "deactivation_date(2i)": "10", "deactivation_date(1i)": "2022" } } }
it "redirects to the confirmation page" do context "and afected logs" do
follow_redirect! it "redirects to the confirmation page" do
expect(response).to have_http_status(:ok) follow_redirect!
expect(page).to have_content("This change will affect #{location.lettings_logs.count} logs") expect(response).to have_http_status(:ok)
expect(page).to have_content("This change will affect #{location.lettings_logs.count} logs")
end
end
context "and no affected logs" do
let(:setup_locations) { location.lettings_logs.update(location: nil) }
it "redirects to the location page and updates the deactivation period" do
follow_redirect!
follow_redirect!
expect(response).to have_http_status(:ok)
expect(page).to have_css(".govuk-notification-banner.govuk-notification-banner--success")
location.reload
expect(location.location_deactivation_periods.count).to eq(1)
expect(location.location_deactivation_periods.first.deactivation_date).to eq(Time.zone.local(2022, 10, 10))
end
end end
end end

52
spec/requests/schemes_controller_spec.rb

@ -1772,10 +1772,12 @@ RSpec.describe SchemesController, type: :request do
let(:deactivation_date) { Time.utc(2022, 10, 10) } let(:deactivation_date) { Time.utc(2022, 10, 10) }
let!(:lettings_log) { FactoryBot.create(:lettings_log, :sh, location:, scheme:, startdate:, owning_organisation: user.organisation) } let!(:lettings_log) { FactoryBot.create(:lettings_log, :sh, location:, scheme:, startdate:, owning_organisation: user.organisation) }
let(:startdate) { Time.utc(2022, 10, 11) } let(:startdate) { Time.utc(2022, 10, 11) }
let(:setup_schemes) { nil }
before do before do
Timecop.freeze(Time.utc(2022, 10, 10)) Timecop.freeze(Time.utc(2022, 10, 10))
sign_in user sign_in user
setup_schemes
patch "/schemes/#{scheme.id}/new-deactivation", params: patch "/schemes/#{scheme.id}/new-deactivation", params:
end end
@ -1786,20 +1788,54 @@ RSpec.describe SchemesController, type: :request do
context "with default date" do context "with default date" do
let(:params) { { scheme_deactivation_period: { deactivation_date_type: "default", deactivation_date: } } } let(:params) { { scheme_deactivation_period: { deactivation_date_type: "default", deactivation_date: } } }
it "redirects to the confirmation page" do context "and affected logs" do
follow_redirect! it "redirects to the confirmation page" do
expect(response).to have_http_status(:ok) follow_redirect!
expect(page).to have_content("This change will affect #{scheme.lettings_logs.count} logs") expect(response).to have_http_status(:ok)
expect(page).to have_content("This change will affect #{scheme.lettings_logs.count} logs")
end
end
context "and no affected logs" do
let(:setup_schemes) { scheme.lettings_logs.update(scheme: nil) }
it "redirects to the location page and updates the deactivation period" do
follow_redirect!
follow_redirect!
follow_redirect!
expect(response).to have_http_status(:ok)
expect(page).to have_css(".govuk-notification-banner.govuk-notification-banner--success")
scheme.reload
expect(scheme.scheme_deactivation_periods.count).to eq(1)
expect(scheme.scheme_deactivation_periods.first.deactivation_date).to eq(Time.zone.local(2022, 4, 1))
end
end end
end end
context "with other date" do context "with other date" do
let(:params) { { scheme_deactivation_period: { deactivation_date_type: "other", "deactivation_date(3i)": "10", "deactivation_date(2i)": "10", "deactivation_date(1i)": "2022" } } } let(:params) { { scheme_deactivation_period: { deactivation_date_type: "other", "deactivation_date(3i)": "10", "deactivation_date(2i)": "10", "deactivation_date(1i)": "2022" } } }
it "redirects to the confirmation page" do context "and affected logs" do
follow_redirect! it "redirects to the confirmation page" do
expect(response).to have_http_status(:ok) follow_redirect!
expect(page).to have_content("This change will affect #{scheme.lettings_logs.count} logs") expect(response).to have_http_status(:ok)
expect(page).to have_content("This change will affect #{scheme.lettings_logs.count} logs")
end
end
context "and no affected logs" do
let(:setup_schemes) { scheme.lettings_logs.update(scheme: nil) }
it "redirects to the location page and updates the deactivation period" do
follow_redirect!
follow_redirect!
follow_redirect!
expect(response).to have_http_status(:ok)
expect(page).to have_css(".govuk-notification-banner.govuk-notification-banner--success")
scheme.reload
expect(scheme.scheme_deactivation_periods.count).to eq(1)
expect(scheme.scheme_deactivation_periods.first.deactivation_date).to eq(Time.zone.local(2022, 10, 10))
end
end end
end end

Loading…
Cancel
Save