Browse Source

only display toggle scheme/location for active and deactivted schemes

pull/1060/head
Kat 4 years ago
parent
commit
563ae26919
  1. 5
      app/helpers/locations_helper.rb
  2. 5
      app/helpers/schemes_helper.rb
  3. 4
      app/models/location.rb
  4. 4
      app/models/scheme.rb
  5. 6
      app/views/locations/show.html.erb
  6. 6
      app/views/schemes/show.html.erb
  7. 10
      spec/requests/locations_controller_spec.rb
  8. 5
      spec/requests/schemes_controller_spec.rb

5
app/helpers/locations_helper.rb

@ -53,6 +53,11 @@ module LocationsHelper
availability.strip availability.strip
end end
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?
return govuk_button_link_to "Reactivate this location", scheme_location_new_reactivation_path(location.scheme, location) if location.deactivated?
end
private private
ActivePeriod = Struct.new(:from, :to) ActivePeriod = Struct.new(:from, :to)

5
app/helpers/schemes_helper.rb

@ -42,6 +42,11 @@ module SchemesHelper
availability.strip availability.strip
end end
def toggle_scheme_link(scheme)
return govuk_button_link_to "Deactivate this scheme", scheme_new_deactivation_path(scheme), warning: true if scheme.active?
return govuk_button_link_to "Reactivate this scheme", scheme_new_reactivation_path(scheme) if scheme.deactivated?
end
private private
ActivePeriod = Struct.new(:from, :to) ActivePeriod = Struct.new(:from, :to)

4
app/models/location.rb

@ -398,6 +398,10 @@ class Location < ApplicationRecord
status == :active status == :active
end end
def deactivated?
status == :deactivated
end
def reactivating_soon? def reactivating_soon?
status == :reactivating_soon status == :reactivating_soon
end end

4
app/models/scheme.rb

@ -241,4 +241,8 @@ class Scheme < ApplicationRecord
def reactivating_soon? def reactivating_soon?
status == :reactivating_soon status == :reactivating_soon
end end
def deactivated?
status == :deactivated
end
end end

6
app/views/locations/show.html.erb

@ -24,9 +24,5 @@
</div> </div>
</div> </div>
<% if FeatureToggle.location_toggle_enabled? %> <% if FeatureToggle.location_toggle_enabled? %>
<% if @location.active? || @location.reactivating_soon? %> <%= toggle_location_link(@location) %>
<%= govuk_button_link_to "Deactivate this location", scheme_location_new_deactivation_path(@scheme, @location), warning: true %>
<% else %>
<%= govuk_button_link_to "Reactivate this location", scheme_location_new_reactivation_path(@scheme, @location) %>
<% end %>
<% end %> <% end %>

6
app/views/schemes/show.html.erb

@ -34,9 +34,5 @@
<% end %> <% end %>
<% if FeatureToggle.scheme_toggle_enabled? %> <% if FeatureToggle.scheme_toggle_enabled? %>
<% if @scheme.active? || @scheme.reactivating_soon? %> <%= toggle_scheme_link(@scheme) %>
<%= govuk_button_link_to "Deactivate this scheme", scheme_new_deactivation_path(@scheme), warning: true %>
<% else %>
<%= govuk_button_link_to "Reactivate this scheme", scheme_new_reactivation_path(@scheme) %>
<% end %>
<% end %> <% end %>

10
spec/requests/locations_controller_spec.rb

@ -1519,18 +1519,20 @@ RSpec.describe LocationsController, type: :request do
context "with location that's deactivating soon" do 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), location:) } let(:location_deactivation_period) { FactoryBot.create(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 10, 12), location:) }
it "renders reactivate this location" do it "does not render toggle location link" do
expect(response).to have_http_status(:ok) expect(response).to have_http_status(:ok)
expect(page).to have_link("Reactivate this location", href: "/schemes/#{scheme.id}/locations/#{location.id}/new-reactivation") expect(page).not_to have_link("Reactivate this location")
expect(page).not_to have_link("Deactivate this location")
end end
end end
context "with location that's reactivating soon" do 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:) } 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 it "does not render toggle location link" do
expect(response).to have_http_status(:ok) expect(response).to have_http_status(:ok)
expect(page).to have_link("Deactivate this location", href: "/schemes/#{scheme.id}/locations/#{location.id}/new-deactivation") expect(page).not_to have_link("Reactivate this location")
expect(page).not_to have_link("Deactivate this location")
end end
end end
end end

5
spec/requests/schemes_controller_spec.rb

@ -292,9 +292,10 @@ RSpec.describe SchemesController, type: :request do
context "with scheme that's deactivating soon" do 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), scheme:) } let(:scheme_deactivation_period) { FactoryBot.create(:scheme_deactivation_period, deactivation_date: Time.zone.local(2022, 10, 12), scheme:) }
it "renders reactivate this scheme" do it "does not render toggle scheme link" do
expect(response).to have_http_status(:ok) expect(response).to have_http_status(:ok)
expect(page).to have_link("Reactivate this scheme", href: "/schemes/#{scheme.id}/new-reactivation") expect(page).not_to have_link("Reactivate this scheme")
expect(page).not_to have_link("Deactivate this scheme")
end end
end end
end end

Loading…
Cancel
Save