diff --git a/app/controllers/locations_controller.rb b/app/controllers/locations_controller.rb
index 621150bd7..6cd40161f 100644
--- a/app/controllers/locations_controller.rb
+++ b/app/controllers/locations_controller.rb
@@ -31,7 +31,7 @@ class LocationsController < ApplicationController
@location.deactivation_date_type = params[:location][:deactivation_date_type]
render "toggle_active", locals: { action: "deactivate" }, status: :unprocessable_entity
else
- render "toggle_active_confirm", locals: { action: "deactivate", deactivation_date: deactivation_date }
+ render "toggle_active_confirm", locals: { action: "deactivate", deactivation_date: }
end
end
end
@@ -168,12 +168,11 @@ private
flash[:notice] = "#{@location.name || @location.postcode} has been deactivated"
end
redirect_to scheme_location_path(@scheme, @location)
- return
end
def deactivation_date_errors
if params[:location][:deactivation_date].blank? && params[:location][:deactivation_date_type].blank?
- @location.errors.add(:deactivation_date_type, message: I18n.t("validations.location.deactivation_date.not_selected"))
+ @location.errors.add(:deactivation_date_type, message: I18n.t("validations.location.deactivation_date.not_selected"))
end
if params[:location][:deactivation_date_type] == "other"
@@ -183,7 +182,7 @@ private
collection_start_date = FormHandler.instance.current_collection_start_date
- if [day, month, year].any?(&:blank?)
+ if [day, month, year].any?(&:blank?)
{ day:, month:, year: }.each do |period, value|
@location.errors.add(:deactivation_date, message: I18n.t("validations.location.deactivation_date.not_entered", period: period.to_s)) if value.blank?
end
@@ -197,6 +196,7 @@ private
def deactivation_date
return if params[:location].blank?
+
collection_start_date = FormHandler.instance.current_collection_start_date
return collection_start_date if params[:location][:deactivation_date_type] == "default"
return params[:location][:deactivation_date] if params[:location][:deactivation_date_type].blank?
diff --git a/app/helpers/tag_helper.rb b/app/helpers/tag_helper.rb
index c7c5c1cbe..2ea23a86a 100644
--- a/app/helpers/tag_helper.rb
+++ b/app/helpers/tag_helper.rb
@@ -8,7 +8,7 @@ module TagHelper
completed: "Completed",
active: "Active",
deactivating_soon: "Deactivating soon",
- deactivated: "Deactivated"
+ deactivated: "Deactivated",
}.freeze
COLOUR = {
@@ -18,7 +18,7 @@ module TagHelper
completed: "green",
active: "green",
deactivating_soon: "yellow",
- deactivated: "grey"
+ deactivated: "grey",
}.freeze
def status_tag(status, classes = [])
diff --git a/app/models/location.rb b/app/models/location.rb
index e41c4b175..ab1c3620a 100644
--- a/app/models/location.rb
+++ b/app/models/location.rb
@@ -10,7 +10,7 @@ class Location < ApplicationRecord
auto_strip_attributes :name
- attr_accessor :add_another_location
+ attr_accessor :add_another_location, :deactivation_date_type
scope :search_by_postcode, ->(postcode) { where("REPLACE(postcode, ' ', '') ILIKE ?", "%#{postcode.delete(' ')}%") }
scope :search_by_name, ->(name) { where("name ILIKE ?", "%#{name}%") }
@@ -18,8 +18,6 @@ class Location < ApplicationRecord
scope :started, -> { where("startdate <= ?", Time.zone.today).or(where(startdate: nil)) }
scope :active, -> { where(confirmed: true).and(started) }
- attribute :deactivation_date_type
-
LOCAL_AUTHORITIES = {
"E07000223": "Adur",
"E07000026": "Allerdale",
diff --git a/app/views/locations/show.html.erb b/app/views/locations/show.html.erb
index 829b56942..ccc0163c2 100644
--- a/app/views/locations/show.html.erb
+++ b/app/views/locations/show.html.erb
@@ -28,5 +28,5 @@
<%= govuk_button_link_to "Deactivate this location", scheme_location_deactivate_path(scheme_id: @scheme.id, location_id: @location.id), warning: true %>
<% else %>
<%= govuk_button_link_to "Reactivate this location", scheme_location_reactivate_path(scheme_id: @scheme.id, location_id: @location.id) %>
- <% end%>
+ <% end %>
<% end %>
diff --git a/app/views/locations/toggle_active.html.erb b/app/views/locations/toggle_active.html.erb
index 90638f34c..ba3fa22e6 100644
--- a/app/views/locations/toggle_active.html.erb
+++ b/app/views/locations/toggle_active.html.erb
@@ -13,7 +13,7 @@
<% collection_start_date = FormHandler.instance.current_collection_start_date %>
<%= f.govuk_error_summary %>
- <%= f.govuk_radio_buttons_fieldset :deactivation_date,
+ <%= f.govuk_radio_buttons_fieldset :deactivation_date_type,
legend: { text: I18n.t("questions.location.deactivation.apply_from") },
caption: { text: "Deactivate #{@location.postcode}" },
hint: { text: I18n.t("hints.location.deactivation", date: collection_start_date.to_formatted_s(:govuk_date)) } do %>
diff --git a/config/locales/en.yml b/config/locales/en.yml
index bc0b0121b..3c4808696 100644
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -388,7 +388,7 @@ en:
warnings:
location:
deactivation:
- existing_logs: "It will not be possible to add logs with this scheme if their tenancy start date is on or after the date you enter. Any existing logs may be affected."
+ existing_logs: "It will not be possible to add logs with this location if their tenancy start date is on or after the date you enter. Any existing logs may be affected."
review_logs: "Your data providers will need to review these logs and answer a few questions again. We’ll email each log creator with a list of logs that need updating."
test:
diff --git a/spec/requests/locations_controller_spec.rb b/spec/requests/locations_controller_spec.rb
index 75150e692..acf1803f4 100644
--- a/spec/requests/locations_controller_spec.rb
+++ b/spec/requests/locations_controller_spec.rb
@@ -1267,7 +1267,7 @@ RSpec.describe LocationsController, type: :request do
end
context "when confirming deactivation" do
- let(:params) { { location: { deactivation_date: deactivation_date, confirm: true } } }
+ let(:params) { { location: { deactivation_date:, confirm: true } } }
it "updates existing location with valid deactivation date and renders location page" do
follow_redirect!
@@ -1289,7 +1289,7 @@ RSpec.describe LocationsController, type: :request do
context "when invalid date is entered" do
let(:params) { { location: { deactivation_date_type: "other", "deactivation_date(3i)": "10", "deactivation_date(2i)": "44", "deactivation_date(1i)": "2022" } } }
-
+
it "displays the new page with an error message" do
expect(response).to have_http_status(:unprocessable_entity)
expect(page).to have_content(I18n.t("validations.location.deactivation_date.invalid"))
@@ -1298,7 +1298,7 @@ RSpec.describe LocationsController, type: :request do
context "when the date is entered is before the beginning of current collection window" do
let(:params) { { location: { deactivation_date_type: "other", "deactivation_date(3i)": "10", "deactivation_date(2i)": "4", "deactivation_date(1i)": "2020" } } }
-
+
it "displays the new page with an error message" do
expect(response).to have_http_status(:unprocessable_entity)
expect(page).to have_content(I18n.t("validations.location.deactivation_date.out_of_range", date: "5 April 2022"))
@@ -1307,7 +1307,7 @@ RSpec.describe LocationsController, type: :request do
context "when the day is not entered" do
let(:params) { { location: { deactivation_date_type: "other", "deactivation_date(3i)": "", "deactivation_date(2i)": "2", "deactivation_date(1i)": "2022" } } }
-
+
it "displays page with an error message" do
expect(response).to have_http_status(:unprocessable_entity)
expect(page).to have_content(I18n.t("validations.location.deactivation_date.not_entered", period: "day"))
@@ -1316,7 +1316,7 @@ RSpec.describe LocationsController, type: :request do
context "when the month is not entered" do
let(:params) { { location: { deactivation_date_type: "other", "deactivation_date(3i)": "2", "deactivation_date(2i)": "", "deactivation_date(1i)": "2022" } } }
-
+
it "displays page with an error message" do
expect(response).to have_http_status(:unprocessable_entity)
expect(page).to have_content(I18n.t("validations.location.deactivation_date.not_entered", period: "month"))
@@ -1325,7 +1325,7 @@ RSpec.describe LocationsController, type: :request do
context "when the year is not entered" do
let(:params) { { location: { deactivation_date_type: "other", "deactivation_date(3i)": "2", "deactivation_date(2i)": "2", "deactivation_date(1i)": "" } } }
-
+
it "displays page with an error message" do
expect(response).to have_http_status(:unprocessable_entity)
expect(page).to have_content(I18n.t("validations.location.deactivation_date.not_entered", period: "year"))