Browse Source

Add reactivate ocation button and path

pull/981/head
Kat 4 years ago
parent
commit
e0c53ad606
  1. 4
      app/controllers/locations_controller.rb
  2. 6
      app/views/locations/show.html.erb
  3. 2
      app/views/locations/toggle_active.html.erb
  4. 1
      config/routes.rb
  5. 64
      spec/requests/locations_controller_spec.rb

4
app/controllers/locations_controller.rb

@ -39,6 +39,10 @@ class LocationsController < ApplicationController
end
end
def reactivate
render "toggle_active", locals: { action: "reactivate" }
end
def create
if date_params_missing?(location_params) || valid_date_params?(location_params)
@location = Location.new(location_params)

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

@ -24,5 +24,9 @@
</div>
</div>
<% if FeatureToggle.location_toggle_enabled? %>
<%= govuk_button_link_to "Deactivate this location", scheme_location_deactivate_path(scheme_id: @scheme.id, location_id: @location.id), warning: true %>
<% if @location.status == :active %>
<%= 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 %>

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

@ -1,4 +1,4 @@
<% title = "Deactivate #{@location.postcode}" %>
<% title = "#{action.humanize} #{@location.postcode}" %>
<% content_for :title, title %>
<% content_for :before_content do %>

1
config/routes.rb

@ -54,6 +54,7 @@ Rails.application.routes.draw do
get "edit-name", to: "locations#edit_name"
get "edit-local-authority", to: "locations#edit_local_authority"
get "deactivate", to: "locations#deactivate"
get "reactivate", to: "locations#reactivate"
patch "deactivate", to: "locations#deactivate"
end
end

64
spec/requests/locations_controller_spec.rb

@ -1345,4 +1345,68 @@ RSpec.describe LocationsController, type: :request do
end
end
end
describe "#show" do
context "when not signed in" do
it "redirects to the sign in page" do
get "/schemes/1/locations/1"
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
get "/schemes/1/locations/1"
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:) }
before do
Timecop.freeze(Time.utc(2022, 10, 10))
sign_in user
location.deactivation_date = deactivation_date
location.save!
get "/schemes/#{scheme.id}/locations/#{location.id}"
end
context "with active location" do
let(:deactivation_date) { nil }
it "renders deactivate this location" do
expect(response).to have_http_status(:ok)
expect(page).to have_link("Deactivate this location", href: "/schemes/#{scheme.id}/locations/#{location.id}/deactivate")
end
end
context "with deactivated location" do
let(:deactivation_date) { Time.utc(2022, 10, 9) }
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")
end
end
context "with location that's deactivating soon" do
let(:deactivation_date) { Time.utc(2022, 10, 12) }
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")
end
end
end
end
end

Loading…
Cancel
Save