Browse Source

Update toggle-active views and render them correctly

pull/981/head
Kat 4 years ago
parent
commit
276e26ecf8
  1. 12
      app/controllers/locations_controller.rb
  2. 3
      app/views/locations/toggle_active.html.erb
  3. 17
      app/views/locations/toggle_active_confirm.html.erb
  4. 1
      config/routes.rb
  5. 55
      spec/requests/locations_controller_spec.rb

12
app/controllers/locations_controller.rb

@ -21,7 +21,15 @@ class LocationsController < ApplicationController
def show; end
def deactivate
render "toggle_active", locals: { action: "deactivate" }
if params[:deactivation_date].blank?
render "toggle_active", locals: { action: "deactivate" }
elsif (params[:confirm])
# update the deactivation_date
# update the logs
# redirect to location page
else
render "toggle_active_confirm", locals: {action: "deactivate", deactivation_date: params[:deactivation_date]}
end
end
def create
@ -128,7 +136,7 @@ private
end
def authenticate_action!
if %w[new edit update create index edit_name edit_local_authority].include?(action_name) && !((current_user.organisation == @scheme&.owning_organisation) || current_user.support?)
if %w[new edit update create index edit_name edit_local_authority deactivate].include?(action_name) && !((current_user.organisation == @scheme&.owning_organisation) || current_user.support?)
render_not_found and return
end
end

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

@ -9,10 +9,9 @@
<% end %>
<%= form_for(@location, method: :patch, url: location_deactivate_path(@location)) do |f| %>
<%= form_with url: location_deactivate_path(@location), method: "patch", local: true do |f| %>
<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds">
<%= f.govuk_error_summary %>
<%= f.govuk_radio_buttons_fieldset :deactivation_date,
legend: { text: "When should this change apply?"},
caption: { text: "Deactivate #{@location.postcode}"},

17
app/views/locations/toggle_active_confirm.html.erb

@ -0,0 +1,17 @@
<%= form_with url: location_deactivate_path(@location), method: "patch", local: true do |f| %>
<% content_for :before_content do %>
<%= govuk_back_link(href: :back) %>
<% end %>
<h1 class="govuk-heading-l">
<span class="govuk-caption-l"><%= @scheme.service_name %></span>
<%= "This change will affect SOME logs" %>
</h1>
<%= govuk_warning_text text: "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." %>
<%= f.hidden_field :confirm, :value => true %>
<%= f.hidden_field :deactivation_date, :value => deactivation_date %>
<div class="govuk-button-group">
<%= f.govuk_submit "Deactivate this scheme" %>
<%= govuk_button_link_to "Cancel", location_path, html: { method: :get }, secondary: true %>
</div>
<% end %>

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"
patch "deactivate", to: "locations#deactivate"
end
end

55
spec/requests/locations_controller_spec.rb

@ -1212,4 +1212,59 @@ RSpec.describe LocationsController, type: :request do
end
end
end
describe "#deactivate" do
context "when not signed in" do
it "redirects to the sign in page" do
patch "/schemes/1/locations/1/deactivate"
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/deactivate"
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:) }
let(:startdate) { Time.utc(2021, 1, 2) }
let(:deactivation_date) { Time.new(2022, 10, 10) }
before do
Timecop.freeze(Time.utc(2022, 10, 10))
sign_in user
patch "/schemes/#{scheme.id}/locations/#{location.id}/deactivate", params:
end
context "default date" do
let(:params) { { deactivation_date: deactivation_date } }
it "renders the confirmation page" do
expect(response).to have_http_status(:ok)
expect(page).to have_content("This change will affect SOME logs")
end
end
context "other date" do
let(:params) { { deactivation_date: "other", "deactivation_date(3i)": "10", "deactivation_date(2i)": "10", "deactivation_date(1i)": "2022"} }
it "renders the confirmation page" do
expect(response).to have_http_status(:ok)
expect(page).to have_content("This change will affect SOME logs")
end
end
end
end
end

Loading…
Cancel
Save