Browse Source

Update deactivates_in_a_long_time? method

pull/1701/head
Kat 3 years ago
parent
commit
57e0f965d5
  1. 2
      app/controllers/locations_controller.rb
  2. 2
      app/controllers/schemes_controller.rb
  3. 2
      app/helpers/locations_helper.rb
  4. 2
      app/helpers/schemes_helper.rb
  5. 2
      app/helpers/tag_helper.rb
  6. 4
      app/models/location.rb
  7. 4
      app/models/scheme.rb
  8. 2
      spec/views/locations/show.html.erb_spec.rb

2
app/controllers/locations_controller.rb

@ -149,7 +149,7 @@ class LocationsController < ApplicationController
def show; end def show; end
def new_deactivation def new_deactivation
@location_deactivation_period = if @location.deactivates_in_more_than_6_months? @location_deactivation_period = if @location.deactivates_in_a_long_time?
@location.open_deactivation || LocationDeactivationPeriod.new @location.open_deactivation || LocationDeactivationPeriod.new
else else
LocationDeactivationPeriod.new LocationDeactivationPeriod.new

2
app/controllers/schemes_controller.rb

@ -27,7 +27,7 @@ class SchemesController < ApplicationController
end end
def new_deactivation def new_deactivation
@scheme_deactivation_period = if @scheme.deactivates_in_more_than_6_months? @scheme_deactivation_period = if @scheme.deactivates_in_a_long_time?
@scheme.open_deactivation || SchemeDeactivationPeriod.new @scheme.open_deactivation || SchemeDeactivationPeriod.new
else else
SchemeDeactivationPeriod.new SchemeDeactivationPeriod.new

2
app/helpers/locations_helper.rb

@ -69,7 +69,7 @@ module LocationsHelper
end end
def toggle_location_link(location) def toggle_location_link(location)
return govuk_button_link_to "Deactivate this location", scheme_location_new_deactivation_path(location.scheme, location), warning: true if location.active? || location.deactivates_in_more_than_6_months? return govuk_button_link_to "Deactivate this location", scheme_location_new_deactivation_path(location.scheme, location), warning: true if location.active? || location.deactivates_in_a_long_time?
return govuk_button_link_to "Reactivate this location", scheme_location_new_reactivation_path(location.scheme, location) if location.deactivated? return govuk_button_link_to "Reactivate this location", scheme_location_new_reactivation_path(location.scheme, location) if location.deactivated?
end end

2
app/helpers/schemes_helper.rb

@ -40,7 +40,7 @@ module SchemesHelper
end end
def toggle_scheme_link(scheme) def toggle_scheme_link(scheme)
return govuk_button_link_to "Deactivate this scheme", scheme_new_deactivation_path(scheme), warning: true if scheme.active? || scheme.deactivates_in_more_than_6_months? return govuk_button_link_to "Deactivate this scheme", scheme_new_deactivation_path(scheme), warning: true if scheme.active? || scheme.deactivates_in_a_long_time?
return govuk_button_link_to "Reactivate this scheme", scheme_new_reactivation_path(scheme) if scheme.deactivated? return govuk_button_link_to "Reactivate this scheme", scheme_new_reactivation_path(scheme) if scheme.deactivated?
end end

2
app/helpers/tag_helper.rb

@ -37,7 +37,7 @@ module TagHelper
def status_tag_from_resource(resource, classes = []) def status_tag_from_resource(resource, classes = [])
status = resource.status status = resource.status
status = :active if resource.deactivates_in_more_than_6_months? status = :active if resource.deactivates_in_a_long_time?
status_tag(status, classes) status_tag(status, classes)
end end
end end

4
app/models/location.rb

@ -108,8 +108,8 @@ class Location < ApplicationRecord
status == :reactivating_soon status == :reactivating_soon
end end
def deactivates_in_more_than_6_months? def deactivates_in_a_long_time?
status == :deactivating_soon && open_deactivation.present? && open_deactivation.deactivation_date > 6.months.from_now status_at(6.months.from_now) == :deactivating_soon
end end
def validate_postcode def validate_postcode

4
app/models/scheme.rb

@ -243,7 +243,7 @@ class Scheme < ApplicationRecord
status == :deactivated status == :deactivated
end end
def deactivates_in_more_than_6_months? def deactivates_in_a_long_time?
status == :deactivating_soon && open_deactivation.present? && open_deactivation.deactivation_date > 6.months.from_now status_at(6.months.from_now) == :deactivating_soon
end end
end end

2
spec/views/locations/show.html.erb_spec.rb

@ -40,7 +40,7 @@ RSpec.describe "locations/show.html.erb" do
status: :active, status: :active,
active?: true, active?: true,
scheme:, scheme:,
deactivates_in_more_than_6_months?: false, deactivates_in_a_long_time?: false,
) )
end end

Loading…
Cancel
Save