<% collection_start_date = FormHandler.instance.current_collection_start_date %>
<%= f.govuk_error_summary %>
- <%= 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 %>
- <%= govuk_warning_text text: I18n.t("warnings.location.deactivation.existing_logs") %>
- <%= f.govuk_radio_button :deactivation_date_type,
+ <%= f.govuk_radio_buttons_fieldset date_type_question(action),
+ legend: { text: I18n.t("questions.location.toggle_active.apply_from") },
+ caption: { text: title },
+ hint: { text: I18n.t("hints.location.toggle_active", date: collection_start_date.to_formatted_s(:govuk_date)) } do %>
+ <%= govuk_warning_text text: I18n.t("warnings.location.#{action}.existing_logs") %>
+ <%= f.govuk_radio_button date_type_question(action),
"default",
label: { text: "From the start of the current collection period (#{collection_start_date.to_formatted_s(:govuk_date)})" } %>
- <%= f.govuk_radio_button :deactivation_date_type,
+ <%= f.govuk_radio_button date_type_question(action),
"other",
label: { text: "For tenancies starting after a certain date" },
**basic_conditional_html_attributes({ "deactivation_date" => %w[other] }, "location") do %>
- <%= f.govuk_date_field :deactivation_date,
+ <%= f.govuk_date_field date_question(action),
legend: { text: "Date", size: "m" },
hint: { text: "For example, 27 3 2022" },
width: 20 %>
diff --git a/app/views/schemes/deactivate_confirm.html.erb b/app/views/schemes/deactivate_confirm.html.erb
index 45f7d4341..0cfd454c8 100644
--- a/app/views/schemes/deactivate_confirm.html.erb
+++ b/app/views/schemes/deactivate_confirm.html.erb
@@ -1,6 +1,6 @@
<% title = "Deactivate #{@scheme.service_name}" %>
<% content_for :title, title %>
-<%= form_with model: @scheme, url: scheme_deactivate_path(@scheme), method: "patch", local: true do |f| %>
+<%= form_with model: @scheme_deactivation_period, url: scheme_deactivate_path(@scheme), method: "patch", local: true do |f| %>
<% content_for :before_content do %>
<%= govuk_back_link(href: :back) %>
<% end %>
diff --git a/app/views/schemes/toggle_active.html.erb b/app/views/schemes/toggle_active.html.erb
index 11dd2f276..fbb3ebc5f 100644
--- a/app/views/schemes/toggle_active.html.erb
+++ b/app/views/schemes/toggle_active.html.erb
@@ -6,7 +6,7 @@
href: scheme_details_path(@scheme),
) %>
<% end %>
-<%= form_with model: @scheme, url: scheme_new_deactivation_path(@scheme), method: "patch", local: true do |f| %>
+<%= form_with model: @scheme_deactivation_period, url: scheme_new_deactivation_path(@scheme), method: "patch", local: true do |f| %>
<% collection_start_date = FormHandler.instance.current_collection_start_date %>
diff --git a/config/locales/en.yml b/config/locales/en.yml
index a1c18330a..f839ccf7e 100644
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -319,10 +319,14 @@ en:
out_of_range: "The date must be on or after the %{date}"
location:
- deactivation_date:
+ toggle_date:
not_selected: "Select one of the options"
invalid: "Enter a valid day, month and year"
out_of_range: "The date must be on or after the %{date}"
+ reactivation:
+ before_deactivation: "This location was deactivated on %{date}\nThe reactivation date must be on or after deactivation date"
+ deactivation:
+ during_deactivated_period: "The location is already deactivated during this date, please enter a different date"
soft_validations:
net_income:
@@ -374,7 +378,7 @@ en:
startdate: "When did the first property in this location become available under this scheme? (optional)"
add_another_location: "Do you want to add another location?"
mobility_type: "What are the mobility standards for the majority of units in this location?"
- deactivation:
+ toggle_active:
apply_from: "When should this change apply?"
scheme:
deactivation:
@@ -391,15 +395,17 @@ en:
postcode: "For example, SW1P 4DF."
name: "This is how you refer to this location within your organisation"
units: "A unit can be a bedroom in a shared house or flat, or a house with 4 bedrooms. Do not include bedrooms used for wardens, managers, volunteers or sleep-in staff."
- deactivation: "If the date is before %{date}, select ‘From the start of the current collection period’ because the previous period has now closed."
+ toggle_active: "If the date is before %{date}, select ‘From the start of the current collection period’ because the previous period has now closed."
scheme:
deactivation: "If the date is before %{date}, select ‘From the start of the current collection period’ because the previous period has now closed."
warnings:
location:
- deactivation:
+ deactivate:
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."
+ reactivate:
+ existing_logs: "You’ll be able to add logs with this location if their tenancy start date is on or after the date you enter."
scheme:
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."
diff --git a/config/routes.rb b/config/routes.rb
index f90f70534..98d7151b1 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -61,8 +61,10 @@ Rails.application.routes.draw do
get "new-deactivation", to: "locations#new_deactivation"
get "deactivate-confirm", to: "locations#deactivate_confirm"
get "reactivate", to: "locations#reactivate"
+ get "new-reactivation", to: "locations#new_reactivation"
patch "new-deactivation", to: "locations#new_deactivation"
patch "deactivate", to: "locations#deactivate"
+ patch "reactivate", to: "locations#reactivate"
end
end
diff --git a/spec/factories/location_deactivation_period.rb b/spec/factories/location_deactivation_period.rb
index 6a3ab70c3..7d2355ca2 100644
--- a/spec/factories/location_deactivation_period.rb
+++ b/spec/factories/location_deactivation_period.rb
@@ -1,5 +1,6 @@
FactoryBot.define do
factory :location_deactivation_period do
+ deactivation_date { Time.zone.local(2022, 4, 1) }
reactivation_date { nil }
end
end
diff --git a/spec/features/schemes_spec.rb b/spec/features/schemes_spec.rb
index 67660b8ad..797b718af 100644
--- a/spec/features/schemes_spec.rb
+++ b/spec/features/schemes_spec.rb
@@ -693,8 +693,10 @@ RSpec.describe "Schemes scheme Features" do
context "when I click to see individual scheme" do
let(:scheme) { schemes.first }
let!(:location) { FactoryBot.create(:location, startdate: Time.zone.local(2022, 4, 4), scheme:) }
+ let!(:deactivated_location) { FactoryBot.create(:location, startdate: Time.zone.local(2022, 4, 4), scheme:) }
before do
+ FactoryBot.create(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 6, 4), location: deactivated_location)
click_link(scheme.service_name)
end
@@ -752,6 +754,46 @@ RSpec.describe "Schemes scheme Features" do
expect(page).to have_current_path("/schemes/#{scheme.id}/locations")
end
+ context "when location is incative" do
+ context "and I click to view the location" do
+ before do
+ click_link(deactivated_location.postcode)
+ end
+
+ it "displays details about the selected location" do
+ expect(page).to have_current_path("/schemes/#{scheme.id}/locations/#{deactivated_location.id}")
+ expect(page).to have_content(deactivated_location.postcode)
+ expect(page).to have_content(deactivated_location.location_admin_district)
+ expect(page).to have_content(deactivated_location.name)
+ expect(page).to have_content(deactivated_location.units)
+ expect(page).to have_content(deactivated_location.type_of_unit)
+ expect(page).to have_content(deactivated_location.mobility_type)
+ expect(page).to have_content(deactivated_location.location_code)
+ expect(page).to have_content("Active from 4 April 2022 to 3 June 2022 Deactivated on 4 June 2022")
+ expect(page).to have_content("Deactivated")
+ end
+
+ it "allows to reactivate a location" do
+ click_link("Reactivate this location")
+ expect(page).to have_current_path("/schemes/#{scheme.id}/locations/#{deactivated_location.id}/new-reactivation")
+ expect(page).to have_content("Reactivate #{deactivated_location.name}")
+ expect(page).to have_content("You’ll be able to add logs with this location if their tenancy start date is on or after the date you enter.")
+ expect(page).to have_content("If the date is before 1 April 2022, select ‘From the start of the current collection period’ because the previous period has now closed.")
+ end
+
+ context "when I press the back button" do
+ before do
+ click_link "Back"
+ end
+
+ it "I see location details" do
+ expect(page).to have_content scheme.locations.first.id
+ expect(page).to have_current_path("/schemes/#{scheme.id}/locations")
+ end
+ end
+ end
+ end
+
context "when I click to change location name" do
before do
click_link(location.postcode)
diff --git a/spec/helpers/locations_helper_spec.rb b/spec/helpers/locations_helper_spec.rb
index e0d2abfea..bccacba3c 100644
--- a/spec/helpers/locations_helper_spec.rb
+++ b/spec/helpers/locations_helper_spec.rb
@@ -47,8 +47,94 @@ RSpec.describe LocationsHelper do
end
end
+ describe "Active periods" do
+ let(:location) { FactoryBot.create(:location, startdate: nil) }
+
+ before do
+ Timecop.freeze(2022, 10, 10)
+ end
+
+ after do
+ Timecop.unfreeze
+ end
+
+ it "returns one active period without to date" do
+ expect(active_periods(location).count).to eq(1)
+ expect(active_periods(location).first).to have_attributes(from: Time.zone.local(2022, 4, 1), to: nil)
+ end
+
+ it "ignores reactivations that were deactivated on the same day" do
+ FactoryBot.create(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 5, 5), reactivation_date: Time.zone.local(2022, 6, 4), location:)
+ FactoryBot.create(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 6, 4), location:)
+ location.reload
+
+ expect(active_periods(location).count).to eq(1)
+ expect(active_periods(location).first).to have_attributes(from: Time.zone.local(2022, 4, 1), to: Time.zone.local(2022, 5, 5))
+ end
+
+ it "returns sequential non reactivated active periods" do
+ FactoryBot.create(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 5, 5), reactivation_date: Time.zone.local(2022, 6, 4), location:)
+ FactoryBot.create(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 7, 6), location:)
+ location.reload
+
+ expect(active_periods(location).count).to eq(2)
+ expect(active_periods(location).first).to have_attributes(from: Time.zone.local(2022, 4, 1), to: Time.zone.local(2022, 5, 5))
+ expect(active_periods(location).second).to have_attributes(from: Time.zone.local(2022, 6, 4), to: Time.zone.local(2022, 7, 6))
+ end
+
+ it "returns sequential reactivated active periods" do
+ FactoryBot.create(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 5, 5), reactivation_date: Time.zone.local(2022, 6, 4), location:)
+ FactoryBot.create(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 7, 6), reactivation_date: Time.zone.local(2022, 8, 5), location:)
+ location.reload
+ expect(active_periods(location).count).to eq(3)
+ expect(active_periods(location).first).to have_attributes(from: Time.zone.local(2022, 4, 1), to: Time.zone.local(2022, 5, 5))
+ expect(active_periods(location).second).to have_attributes(from: Time.zone.local(2022, 6, 4), to: Time.zone.local(2022, 7, 6))
+ expect(active_periods(location).third).to have_attributes(from: Time.zone.local(2022, 8, 5), to: nil)
+ end
+
+ it "returns non sequential non reactivated active periods" do
+ FactoryBot.create(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 7, 6), reactivation_date: Time.zone.local(2022, 8, 5), location:)
+ FactoryBot.create(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 5, 5), reactivation_date: nil, location:)
+ location.reload
+
+ expect(active_periods(location).count).to eq(2)
+ expect(active_periods(location).first).to have_attributes(from: Time.zone.local(2022, 4, 1), to: Time.zone.local(2022, 5, 5))
+ expect(active_periods(location).second).to have_attributes(from: Time.zone.local(2022, 8, 5), to: nil)
+ end
+
+ it "returns non sequential reactivated active periods" do
+ FactoryBot.create(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 7, 6), reactivation_date: Time.zone.local(2022, 8, 5), location:)
+ FactoryBot.create(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 5, 5), reactivation_date: Time.zone.local(2022, 6, 4), location:)
+ location.reload
+ expect(active_periods(location).count).to eq(3)
+ expect(active_periods(location).first).to have_attributes(from: Time.zone.local(2022, 4, 1), to: Time.zone.local(2022, 5, 5))
+ expect(active_periods(location).second).to have_attributes(from: Time.zone.local(2022, 6, 4), to: Time.zone.local(2022, 7, 6))
+ expect(active_periods(location).third).to have_attributes(from: Time.zone.local(2022, 8, 5), to: nil)
+ end
+
+ it "returns correct active periods when reactivation happends during a deactivated period" do
+ FactoryBot.create(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 5, 5), reactivation_date: Time.zone.local(2022, 11, 11), location:)
+ FactoryBot.create(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 4, 6), reactivation_date: Time.zone.local(2022, 7, 7), location:)
+ location.reload
+
+ expect(active_periods(location).count).to eq(2)
+ expect(active_periods(location).first).to have_attributes(from: Time.zone.local(2022, 4, 1), to: Time.zone.local(2022, 4, 6))
+ expect(active_periods(location).second).to have_attributes(from: Time.zone.local(2022, 11, 11), to: nil)
+ end
+
+ it "returns correct active periods when a full deactivation period happens during another deactivation period" do
+ FactoryBot.create(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 5, 5), reactivation_date: Time.zone.local(2022, 6, 11), location:)
+ FactoryBot.create(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 4, 6), reactivation_date: Time.zone.local(2022, 7, 7), location:)
+ location.reload
+
+ expect(active_periods(location).count).to eq(2)
+ expect(active_periods(location).first).to have_attributes(from: Time.zone.local(2022, 4, 1), to: Time.zone.local(2022, 4, 6))
+ expect(active_periods(location).second).to have_attributes(from: Time.zone.local(2022, 7, 7), to: nil)
+ end
+ end
+
describe "display_location_attributes" do
- let(:location) { FactoryBot.build(:location, startdate: Time.zone.local(2022, 8, 8)) }
+ let(:location) { FactoryBot.build(:location, created_at: Time.zone.local(2022, 3, 16), startdate: Time.zone.local(2022, 4, 1)) }
it "returns correct display attributes" do
attributes = [
@@ -59,7 +145,7 @@ RSpec.describe LocationsHelper do
{ name: "Common type of unit", value: location.type_of_unit },
{ name: "Mobility type", value: location.mobility_type },
{ name: "Code", value: location.location_code },
- { name: "Availability", value: "Active from 8 August 2022" },
+ { name: "Availability", value: "Active from 1 April 2022" },
{ name: "Status", value: :active },
]
@@ -67,25 +153,110 @@ RSpec.describe LocationsHelper do
end
context "when viewing availability" do
- context "with are no deactivations" do
+ context "with no deactivations" do
it "displays created_at as availability date if startdate is not present" do
location.update!(startdate: nil)
availability_attribute = display_location_attributes(location).find { |x| x[:name] == "Availability" }[:value]
expect(availability_attribute).to eq("Active from #{location.created_at.to_formatted_s(:govuk_date)}")
end
+
+ it "displays current collection start date as availability date if created_at is later than collection start date" do
+ location.update!(startdate: nil, created_at: Time.zone.local(2022, 4, 16))
+ availability_attribute = display_location_attributes(location).find { |x| x[:name] == "Availability" }[:value]
+
+ expect(availability_attribute).to eq("Active from 1 April 2022")
+ end
end
context "with previous deactivations" do
+ context "and all reactivated deactivations" do
+ before do
+ FactoryBot.create(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 8, 10), reactivation_date: Time.zone.local(2022, 9, 1), location:)
+ FactoryBot.create(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 9, 15), reactivation_date: Time.zone.local(2022, 9, 28), location:)
+ location.reload
+ end
+
+ it "displays the timeline of availability" do
+ availability_attribute = display_location_attributes(location).find { |x| x[:name] == "Availability" }[:value]
+
+ expect(availability_attribute).to eq("Active from 1 April 2022 to 9 August 2022\nDeactivated on 10 August 2022\nActive from 1 September 2022 to 14 September 2022\nDeactivated on 15 September 2022\nActive from 28 September 2022")
+ end
+ end
+
+ context "and non reactivated deactivation" do
+ before do
+ FactoryBot.create(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 8, 10), reactivation_date: Time.zone.local(2022, 9, 1), location:)
+ FactoryBot.create(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 9, 15), reactivation_date: nil, location:)
+ location.reload
+ end
+
+ it "displays the timeline of availability" do
+ availability_attribute = display_location_attributes(location).find { |x| x[:name] == "Availability" }[:value]
+
+ expect(availability_attribute).to eq("Active from 1 April 2022 to 9 August 2022\nDeactivated on 10 August 2022\nActive from 1 September 2022 to 14 September 2022\nDeactivated on 15 September 2022")
+ end
+ end
+ end
+
+ context "with out of order deactivations" do
+ context "and all reactivated deactivations" do
+ before do
+ FactoryBot.create(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 9, 24), reactivation_date: Time.zone.local(2022, 9, 28), location:)
+ FactoryBot.create(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 6, 15), reactivation_date: Time.zone.local(2022, 6, 18), location:)
+ location.reload
+ end
+
+ it "displays the timeline of availability" do
+ availability_attribute = display_location_attributes(location).find { |x| x[:name] == "Availability" }[:value]
+
+ expect(availability_attribute).to eq("Active from 1 April 2022 to 14 June 2022\nDeactivated on 15 June 2022\nActive from 18 June 2022 to 23 September 2022\nDeactivated on 24 September 2022\nActive from 28 September 2022")
+ end
+ end
+
+ context "and one non reactivated deactivation" do
+ before do
+ FactoryBot.create(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 9, 24), reactivation_date: Time.zone.local(2022, 9, 28), location:)
+ FactoryBot.create(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 6, 15), reactivation_date: nil, location:)
+ location.reload
+ end
+
+ it "displays the timeline of availability" do
+ availability_attribute = display_location_attributes(location).find { |x| x[:name] == "Availability" }[:value]
+
+ expect(availability_attribute).to eq("Active from 1 April 2022 to 14 June 2022\nDeactivated on 15 June 2022\nActive from 28 September 2022")
+ end
+ end
+ end
+
+ context "with multiple out of order deactivations" do
+ context "and one non reactivated deactivation" do
+ before do
+ FactoryBot.create(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 9, 24), reactivation_date: Time.zone.local(2022, 9, 28), location:)
+ FactoryBot.create(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 10, 24), reactivation_date: Time.zone.local(2022, 10, 28), location:)
+ FactoryBot.create(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 6, 15), reactivation_date: nil, location:)
+ location.reload
+ end
+
+ it "displays the timeline of availability" do
+ availability_attribute = display_location_attributes(location).find { |x| x[:name] == "Availability" }[:value]
+
+ expect(availability_attribute).to eq("Active from 1 April 2022 to 14 June 2022\nDeactivated on 15 June 2022\nActive from 28 September 2022 to 23 October 2022\nDeactivated on 24 October 2022\nActive from 28 October 2022")
+ end
+ end
+ end
+
+ context "with intersecting deactivations" do
before do
- location.location_deactivation_periods << FactoryBot.create(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 8, 10), reactivation_date: Time.zone.local(2022, 9, 1))
- location.location_deactivation_periods << FactoryBot.create(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 9, 15), reactivation_date: nil)
+ FactoryBot.create(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 10, 10), reactivation_date: Time.zone.local(2022, 12, 1), location:)
+ FactoryBot.create(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 11, 11), reactivation_date: Time.zone.local(2022, 12, 11), location:)
+ location.reload
end
it "displays the timeline of availability" do
availability_attribute = display_location_attributes(location).find { |x| x[:name] == "Availability" }[:value]
- expect(availability_attribute).to eq("Active from 8 August 2022 to 9 August 2022\nDeactivated on 10 August 2022\nActive from 1 September 2022 to 14 September 2022\nDeactivated on 15 September 2022")
+ expect(availability_attribute).to eq("Active from 1 April 2022 to 9 October 2022\nDeactivated on 10 October 2022\nActive from 11 December 2022")
end
end
end
diff --git a/spec/helpers/schemes_helper_spec.rb b/spec/helpers/schemes_helper_spec.rb
index 1924a6cc5..9db3639d9 100644
--- a/spec/helpers/schemes_helper_spec.rb
+++ b/spec/helpers/schemes_helper_spec.rb
@@ -35,8 +35,9 @@ RSpec.describe SchemesHelper do
context "with previous deactivations" do
before do
- scheme.scheme_deactivation_periods << FactoryBot.create(:scheme_deactivation_period, deactivation_date: Time.zone.local(2022, 8, 10), reactivation_date: Time.zone.local(2022, 9, 1))
- scheme.scheme_deactivation_periods << FactoryBot.create(:scheme_deactivation_period, deactivation_date: Time.zone.local(2022, 9, 15), reactivation_date: nil)
+ FactoryBot.create(:scheme_deactivation_period, deactivation_date: Time.zone.local(2022, 8, 10), reactivation_date: Time.zone.local(2022, 9, 1), scheme:)
+ FactoryBot.create(:scheme_deactivation_period, deactivation_date: Time.zone.local(2022, 9, 15), reactivation_date: nil, scheme:)
+ scheme.reload
end
it "displays the timeline of availability" do
diff --git a/spec/models/location_spec.rb b/spec/models/location_spec.rb
index 01185249a..64a4855da 100644
--- a/spec/models/location_spec.rb
+++ b/spec/models/location_spec.rb
@@ -113,7 +113,7 @@ RSpec.describe Location, type: :model do
end
describe "status" do
- let(:location) { FactoryBot.build(:location) }
+ let(:location) { FactoryBot.build(:location, startdate: Time.zone.local(2022, 4, 1)) }
before do
Timecop.freeze(2022, 6, 7)
@@ -129,27 +129,34 @@ RSpec.describe Location, type: :model do
end
it "returns deactivating soon if deactivation_date is in the future" do
- location.location_deactivation_periods << FactoryBot.create(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 8, 8))
+ FactoryBot.create(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 8, 8), location:)
location.save!
expect(location.status).to eq(:deactivating_soon)
end
it "returns deactivated if deactivation_date is in the past" do
- location.location_deactivation_periods << FactoryBot.create(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 6, 6))
+ FactoryBot.create(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 6, 6), location:)
location.save!
expect(location.status).to eq(:deactivated)
end
it "returns deactivated if deactivation_date is today" do
- location.location_deactivation_periods << FactoryBot.create(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 6, 7))
+ FactoryBot.create(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 6, 7), location:)
location.save!
expect(location.status).to eq(:deactivated)
end
+
+ it "returns reactivating soon if the location has a future reactivation date" do
+ FactoryBot.create(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 6, 7), reactivation_date: Time.zone.local(2022, 6, 8), location:)
+ location.save!
+ expect(location.status).to eq(:reactivating_soon)
+ end
end
context "when there have been previous deactivations" do
before do
- location.location_deactivation_periods << FactoryBot.create(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 6, 4), reactivation_date: Time.zone.local(2022, 6, 5))
+ FactoryBot.create(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 5, 4), reactivation_date: Time.zone.local(2022, 6, 5), location:)
+ location.save!
end
it "returns active if the location has no relevant deactivation records" do
@@ -157,30 +164,36 @@ RSpec.describe Location, type: :model do
end
it "returns deactivating soon if deactivation_date is in the future" do
- location.location_deactivation_periods << FactoryBot.create(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 8, 8))
+ FactoryBot.create(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 8, 8), location:)
location.save!
expect(location.status).to eq(:deactivating_soon)
end
it "returns deactivated if deactivation_date is in the past" do
- location.location_deactivation_periods << FactoryBot.create(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 6, 6))
+ FactoryBot.create(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 6, 6), location:)
location.save!
expect(location.status).to eq(:deactivated)
end
it "returns deactivated if deactivation_date is today" do
- location.location_deactivation_periods << FactoryBot.create(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 6, 7))
+ FactoryBot.create(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 6, 7), location:)
location.save!
expect(location.status).to eq(:deactivated)
end
- end
- end
- describe "with deactivation_date (but no deactivation_date_type)" do
- let(:location) { FactoryBot.create(:location, deactivation_date: Date.new(2022, 4, 1)) }
+ it "returns reactivating soon if the location has a future reactivation date" do
+ Timecop.freeze(2022, 6, 8)
+ FactoryBot.create(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 6, 7), reactivation_date: Time.zone.local(2022, 6, 9), location:)
+ location.save!
+ expect(location.status).to eq(:reactivating_soon)
+ end
- it "is valid" do
- expect(location).to be_valid
+ it "returns if the location had a deactivation during another deactivation" do
+ Timecop.freeze(2022, 6, 4)
+ FactoryBot.create(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 5, 5), reactivation_date: Time.zone.local(2022, 6, 2), location:)
+ location.save!
+ expect(location.status).to eq(:reactivating_soon)
+ end
end
end
end
diff --git a/spec/models/scheme_spec.rb b/spec/models/scheme_spec.rb
index d95d867dc..b19e8c992 100644
--- a/spec/models/scheme_spec.rb
+++ b/spec/models/scheme_spec.rb
@@ -109,27 +109,27 @@ RSpec.describe Scheme, type: :model do
end
it "returns deactivating soon if deactivation_date is in the future" do
- scheme.scheme_deactivation_periods << FactoryBot.create(:scheme_deactivation_period, deactivation_date: Time.zone.local(2022, 8, 8))
- scheme.save!
+ FactoryBot.create(:scheme_deactivation_period, deactivation_date: Time.zone.local(2022, 8, 8), scheme:)
+ scheme.reload
expect(scheme.status).to eq(:deactivating_soon)
end
it "returns deactivated if deactivation_date is in the past" do
- scheme.scheme_deactivation_periods << FactoryBot.create(:scheme_deactivation_period, deactivation_date: Time.zone.local(2022, 6, 6))
- scheme.save!
+ FactoryBot.create(:scheme_deactivation_period, deactivation_date: Time.zone.local(2022, 6, 6), scheme:)
+ scheme.reload
expect(scheme.status).to eq(:deactivated)
end
it "returns deactivated if deactivation_date is today" do
- scheme.scheme_deactivation_periods << FactoryBot.create(:scheme_deactivation_period, deactivation_date: Time.zone.local(2022, 6, 7))
- scheme.save!
+ FactoryBot.create(:scheme_deactivation_period, deactivation_date: Time.zone.local(2022, 6, 7), scheme:)
+ scheme.reload
expect(scheme.status).to eq(:deactivated)
end
end
context "when there have been previous deactivations" do
before do
- scheme.scheme_deactivation_periods << FactoryBot.create(:scheme_deactivation_period, deactivation_date: Time.zone.local(2022, 6, 4), reactivation_date: Time.zone.local(2022, 6, 5))
+ FactoryBot.create(:scheme_deactivation_period, deactivation_date: Time.zone.local(2022, 6, 4), reactivation_date: Time.zone.local(2022, 6, 5), scheme:)
end
it "returns active if the scheme has no relevant deactivation records" do
@@ -137,30 +137,22 @@ RSpec.describe Scheme, type: :model do
end
it "returns deactivating soon if deactivation_date is in the future" do
- scheme.scheme_deactivation_periods << FactoryBot.create(:scheme_deactivation_period, deactivation_date: Time.zone.local(2022, 8, 8))
- scheme.save!
+ FactoryBot.create(:scheme_deactivation_period, deactivation_date: Time.zone.local(2022, 8, 8), scheme:)
+ scheme.reload
expect(scheme.status).to eq(:deactivating_soon)
end
it "returns deactivated if deactivation_date is in the past" do
- scheme.scheme_deactivation_periods << FactoryBot.create(:scheme_deactivation_period, deactivation_date: Time.zone.local(2022, 6, 6))
- scheme.save!
+ FactoryBot.create(:scheme_deactivation_period, deactivation_date: Time.zone.local(2022, 6, 6), scheme:)
+ scheme.reload
expect(scheme.status).to eq(:deactivated)
end
it "returns deactivated if deactivation_date is today" do
- scheme.scheme_deactivation_periods << FactoryBot.create(:scheme_deactivation_period, deactivation_date: Time.zone.local(2022, 6, 7))
- scheme.save!
+ FactoryBot.create(:scheme_deactivation_period, deactivation_date: Time.zone.local(2022, 6, 7), scheme:)
+ scheme.reload
expect(scheme.status).to eq(:deactivated)
end
end
end
-
- describe "with deactivation_date (but no deactivation_date_type)" do
- let(:scheme) { FactoryBot.create(:scheme, deactivation_date: Date.new(2022, 4, 1)) }
-
- it "is valid" do
- expect(scheme).to be_valid
- end
- end
end
diff --git a/spec/requests/locations_controller_spec.rb b/spec/requests/locations_controller_spec.rb
index 605c357b7..237149f7d 100644
--- a/spec/requests/locations_controller_spec.rb
+++ b/spec/requests/locations_controller_spec.rb
@@ -1238,14 +1238,17 @@ RSpec.describe LocationsController, type: :request do
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!(:location) { FactoryBot.create(:location, scheme:, startdate: nil, created_at: Time.zone.local(2022, 4, 1)) }
let(:deactivation_date) { Time.utc(2022, 10, 10) }
let!(:lettings_log) { FactoryBot.create(:lettings_log, :sh, location:, scheme:, startdate:, owning_organisation: user.organisation) }
let(:startdate) { Time.utc(2022, 10, 11) }
+ let(:add_deactivations) { nil }
before do
Timecop.freeze(Time.utc(2022, 10, 10))
sign_in user
+ add_deactivations
+ location.save!
patch "/schemes/#{scheme.id}/locations/#{location.id}/new-deactivation", params:
end
@@ -1254,7 +1257,7 @@ RSpec.describe LocationsController, type: :request do
end
context "with default date" do
- let(:params) { { location: { deactivation_date_type: "default", deactivation_date: } } }
+ let(:params) { { location_deactivation_period: { deactivation_date_type: "default", deactivation_date: } } }
it "redirects to the confirmation page" do
follow_redirect!
@@ -1264,7 +1267,7 @@ RSpec.describe LocationsController, type: :request do
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" } } }
+ 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
follow_redirect!
@@ -1274,7 +1277,7 @@ RSpec.describe LocationsController, type: :request do
end
context "when confirming deactivation" do
- let(:params) { { location: { deactivation_date:, confirm: true, deactivation_date_type: "other" } } }
+ let(:params) { { deactivation_date:, confirm: true, deactivation_date_type: "other" } }
before do
Timecop.freeze(Time.utc(2022, 10, 10))
@@ -1319,56 +1322,67 @@ RSpec.describe LocationsController, type: :request do
end
context "when the date is not selected" do
- let(:params) { { location: { "deactivation_date": "" } } }
+ let(:params) { { location_deactivation_period: { "deactivation_date": "" } } }
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.not_selected"))
+ expect(page).to have_content(I18n.t("validations.location.toggle_date.not_selected"))
end
end
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" } } }
+ let(:params) { { location_deactivation_period: { 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"))
+ expect(page).to have_content(I18n.t("validations.location.toggle_date.invalid"))
end
end
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" } } }
+ let(:params) { { location_deactivation_period: { 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: "1 April 2022"))
+ expect(page).to have_content(I18n.t("validations.location.toggle_date.out_of_range", date: "1 April 2022"))
end
end
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" } } }
+ let(:params) { { location_deactivation_period: { 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.invalid"))
+ expect(page).to have_content(I18n.t("validations.location.toggle_date.invalid"))
end
end
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" } } }
+ let(:params) { { location_deactivation_period: { 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.invalid"))
+ expect(page).to have_content(I18n.t("validations.location.toggle_date.invalid"))
end
end
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)": "" } } }
+ let(:params) { { location_deactivation_period: { 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.toggle_date.invalid"))
+ end
+ end
+
+ context "when deactivation date is during a deactivated period" do
+ let(:deactivation_date) { Time.zone.local(2022, 10, 10) }
+ let(:params) { { location_deactivation_period: { deactivation_date_type: "other", "deactivation_date(3i)": "8", "deactivation_date(2i)": "9", "deactivation_date(1i)": "2022" } } }
+ let(:add_deactivations) { FactoryBot.create(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 5, 5), reactivation_date: Time.zone.local(2022, 10, 12), location:) }
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.invalid"))
+ expect(page).to have_content(I18n.t("validations.location.deactivation.during_deactivated_period"))
end
end
end
@@ -1399,7 +1413,7 @@ RSpec.describe LocationsController, type: :request do
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!(:location) { FactoryBot.create(:location, scheme:, startdate: nil) }
let(:add_deactivations) { location.location_deactivation_periods << location_deactivation_period }
before do
@@ -1424,20 +1438,184 @@ RSpec.describe LocationsController, type: :request do
end
context "with deactivated location" do
- let(:location_deactivation_period) { FactoryBot.create(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 10, 9)) }
+ let(:location_deactivation_period) { FactoryBot.create(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 10, 9), location:) }
it "renders reactivate this location" do
expect(response).to have_http_status(:ok)
- expect(page).to have_link("Reactivate this location", href: "/schemes/#{scheme.id}/locations/#{location.id}/reactivate")
+ expect(page).to have_link("Reactivate this location", href: "/schemes/#{scheme.id}/locations/#{location.id}/new-reactivation")
end
end
context "with location that's deactivating soon" do
- let(:location_deactivation_period) { FactoryBot.create(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 10, 12)) }
+ let(:location_deactivation_period) { FactoryBot.create(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 10, 12), location:) }
+
+ it "renders reactivate this location" do
+ expect(response).to have_http_status(:ok)
+ expect(page).to have_link("Reactivate this location", href: "/schemes/#{scheme.id}/locations/#{location.id}/new-reactivation")
+ end
+ end
+
+ context "with location that's reactivating soon" do
+ let(:location_deactivation_period) { FactoryBot.create(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 4, 12), reactivation_date: Time.zone.local(2022, 10, 12), location:) }
it "renders reactivate this location" do
expect(response).to have_http_status(:ok)
- expect(page).to have_link("Reactivate this location", href: "/schemes/#{scheme.id}/locations/#{location.id}/reactivate")
+ expect(page).to have_link("Deactivate this location", href: "/schemes/#{scheme.id}/locations/#{location.id}/new-deactivation")
+ 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:, startdate: nil) }
+ let(:deactivation_date) { Time.zone.local(2022, 4, 1) }
+ let(:startdate) { Time.utc(2022, 10, 11) }
+
+ before do
+ Timecop.freeze(Time.utc(2022, 10, 10))
+ sign_in user
+ FactoryBot.create(:location_deactivation_period, deactivation_date:, location:)
+ 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_deactivation_period: { reactivation_date_type: "default" } } }
+
+ 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
+
+ it "updates existing location deactivations with valid reactivation date" do
+ follow_redirect!
+ location.reload
+ expect(location.location_deactivation_periods.count).to eq(1)
+ expect(location.location_deactivation_periods.first.reactivation_date).to eq(Time.zone.local(2022, 4, 1))
+ end
+ end
+
+ context "with other date" do
+ let(:params) { { location_deactivation_period: { reactivation_date_type: "other", "reactivation_date(3i)": "10", "reactivation_date(2i)": "10", "reactivation_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
+
+ it "updates existing location deactivations with valid reactivation date" do
+ follow_redirect!
+ location.reload
+ expect(location.location_deactivation_periods.count).to eq(1)
+ expect(location.location_deactivation_periods.first.reactivation_date).to eq(Time.zone.local(2022, 10, 10))
+ end
+ end
+
+ context "with other future date" do
+ let(:params) { { location_deactivation_period: { reactivation_date_type: "other", "reactivation_date(3i)": "14", "reactivation_date(2i)": "12", "reactivation_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} will reactivate on 14 December 2022")
+ end
+ end
+
+ context "when the date is not selected" do
+ let(:params) { { location_deactivation_period: { "reactivation_date": "" } } }
+
+ 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.toggle_date.not_selected"))
+ end
+ end
+
+ context "when invalid date is entered" do
+ let(:params) { { location_deactivation_period: { reactivation_date_type: "other", "reactivation_date(3i)": "10", "reactivation_date(2i)": "44", "reactivation_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.toggle_date.invalid"))
+ end
+ end
+
+ context "when the date is entered is before the beginning of current collection window" do
+ let(:params) { { location_deactivation_period: { reactivation_date_type: "other", "reactivation_date(3i)": "10", "reactivation_date(2i)": "4", "reactivation_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.toggle_date.out_of_range", date: "1 April 2022"))
+ end
+ end
+
+ context "when the day is not entered" do
+ let(:params) { { location_deactivation_period: { reactivation_date_type: "other", "reactivation_date(3i)": "", "reactivation_date(2i)": "2", "reactivation_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.toggle_date.invalid"))
+ end
+ end
+
+ context "when the month is not entered" do
+ let(:params) { { location_deactivation_period: { reactivation_date_type: "other", "reactivation_date(3i)": "2", "reactivation_date(2i)": "", "reactivation_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.toggle_date.invalid"))
+ end
+ end
+
+ context "when the year is not entered" do
+ let(:params) { { location_deactivation_period: { reactivation_date_type: "other", "reactivation_date(3i)": "2", "reactivation_date(2i)": "2", "reactivation_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.toggle_date.invalid"))
+ end
+ end
+
+ context "when the reactivation date is before deactivation date" do
+ let(:deactivation_date) { Time.zone.local(2022, 10, 10) }
+ let(:params) { { location_deactivation_period: { reactivation_date_type: "other", "reactivation_date(3i)": "8", "reactivation_date(2i)": "9", "reactivation_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.reactivation.before_deactivation", date: "10 October 2022"))
end
end
end
diff --git a/spec/requests/schemes_controller_spec.rb b/spec/requests/schemes_controller_spec.rb
index 59d044050..0c3b47f1a 100644
--- a/spec/requests/schemes_controller_spec.rb
+++ b/spec/requests/schemes_controller_spec.rb
@@ -270,7 +270,7 @@ RSpec.describe SchemesController, type: :request do
end
context "with deactivated scheme" do
- let(:scheme_deactivation_period) { FactoryBot.create(:scheme_deactivation_period, deactivation_date: Time.zone.local(2022, 10, 9)) }
+ let(:scheme_deactivation_period) { FactoryBot.create(:scheme_deactivation_period, deactivation_date: Time.zone.local(2022, 10, 9), scheme:) }
it "renders reactivate this scheme" do
expect(response).to have_http_status(:ok)
@@ -279,7 +279,7 @@ RSpec.describe SchemesController, type: :request do
end
context "with scheme that's deactivating soon" do
- let(:scheme_deactivation_period) { FactoryBot.create(:scheme_deactivation_period, deactivation_date: Time.zone.local(2022, 10, 12)) }
+ let(:scheme_deactivation_period) { FactoryBot.create(:scheme_deactivation_period, deactivation_date: Time.zone.local(2022, 10, 12), scheme:) }
it "renders reactivate this scheme" do
expect(response).to have_http_status(:ok)
@@ -1785,7 +1785,7 @@ RSpec.describe SchemesController, type: :request do
end
context "with default date" do
- let(:params) { { scheme: { deactivation_date_type: "default", deactivation_date: } } }
+ let(:params) { { scheme_deactivation_period: { deactivation_date_type: "default", deactivation_date: } } }
it "redirects to the confirmation page" do
follow_redirect!
@@ -1795,7 +1795,7 @@ RSpec.describe SchemesController, type: :request do
end
context "with other date" do
- let(:params) { { scheme: { 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
follow_redirect!
@@ -1805,7 +1805,7 @@ RSpec.describe SchemesController, type: :request do
end
context "when confirming deactivation" do
- let(:params) { { scheme: { deactivation_date:, confirm: true, deactivation_date_type: "other" } } }
+ let(:params) { { deactivation_date:, confirm: true, deactivation_date_type: "other" } }
before do
Timecop.freeze(Time.utc(2022, 10, 10))
@@ -1851,7 +1851,7 @@ RSpec.describe SchemesController, type: :request do
end
context "when the date is not selected" do
- let(:params) { { scheme: { "deactivation_date": "" } } }
+ let(:params) { { scheme_deactivation_period: { "deactivation_date": "" } } }
it "displays the new page with an error message" do
expect(response).to have_http_status(:unprocessable_entity)
@@ -1860,7 +1860,7 @@ RSpec.describe SchemesController, type: :request do
end
context "when invalid date is entered" do
- let(:params) { { scheme: { deactivation_date_type: "other", "deactivation_date(3i)": "10", "deactivation_date(2i)": "44", "deactivation_date(1i)": "2022" } } }
+ let(:params) { { scheme_deactivation_period: { 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)
@@ -1869,7 +1869,7 @@ RSpec.describe SchemesController, type: :request do
end
context "when the date is entered is before the beginning of current collection window" do
- let(:params) { { scheme: { deactivation_date_type: "other", "deactivation_date(3i)": "10", "deactivation_date(2i)": "4", "deactivation_date(1i)": "2020" } } }
+ let(:params) { { scheme_deactivation_period: { 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)
@@ -1878,7 +1878,7 @@ RSpec.describe SchemesController, type: :request do
end
context "when the day is not entered" do
- let(:params) { { scheme: { deactivation_date_type: "other", "deactivation_date(3i)": "", "deactivation_date(2i)": "2", "deactivation_date(1i)": "2022" } } }
+ let(:params) { { scheme_deactivation_period: { 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)
@@ -1887,7 +1887,7 @@ RSpec.describe SchemesController, type: :request do
end
context "when the month is not entered" do
- let(:params) { { scheme: { deactivation_date_type: "other", "deactivation_date(3i)": "2", "deactivation_date(2i)": "", "deactivation_date(1i)": "2022" } } }
+ let(:params) { { scheme_deactivation_period: { 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)
@@ -1896,7 +1896,7 @@ RSpec.describe SchemesController, type: :request do
end
context "when the year is not entered" do
- let(:params) { { scheme: { deactivation_date_type: "other", "deactivation_date(3i)": "2", "deactivation_date(2i)": "2", "deactivation_date(1i)": "" } } }
+ let(:params) { { scheme_deactivation_period: { 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)