Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add feature toggle for Downtime edit page #2033

Merged
merged 1 commit into from
Jan 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion app/controllers/downtimes_controller.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
class DowntimesController < ApplicationController
before_action :require_govuk_editor
before_action :load_edition
before_action :process_params, only: %i[create]
before_action :process_params, only: %i[create update]

def new
@downtime = Downtime.new(artefact: @edition.artefact)
Expand All @@ -18,6 +18,26 @@ def create
end
end

def edit
@downtime = Downtime.for(@edition.artefact)
end

def update
@downtime = Downtime.for(@edition.artefact)

if params["commit"] == "Cancel downtime"
DowntimeRemover.destroy_immediately(@downtime)
flash[:success] = "#{edition_link} downtime message cancelled".html_safe
redirect_to downtimes_path
elsif @downtime.update(downtime_params)
DowntimeScheduler.schedule_publish_and_expiry(@downtime)
flash[:success] = "#{edition_link} downtime message re-scheduled (from #{view_context.downtime_datetime(@downtime)})".html_safe
redirect_to downtimes_path
else
render :edit
end
end

private

def downtime_params
Expand Down
19 changes: 19 additions & 0 deletions app/views/downtimes/edit.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<% content_for :page_title, 'Re-schedule downtime message' %>

<ul class="breadcrumb">
<li class="crumb"><%= link_to 'Downtime', downtimes_path %></li>
<li class="active"><%= @downtime.artefact.name %></li>
</ul>

<div class="page-title">
<h1>
<span class="small"><%= @downtime.artefact.name %></span>
Re-schedule downtime message
</h1>
</div>

<%= form_for @downtime, url: edition_downtime_path(@edition), html: { class: 'form well remove-top-margin', 'data-module': 'downtime-message' } do |f| %>
<%= render 'form', f: f %>
<%= f.submit 'Re-schedule downtime message', class: 'js-submit btn btn-success' %>
<%= f.submit 'Cancel downtime', class: 'add-left-margin btn btn-danger' %>
<% end %>
4 changes: 4 additions & 0 deletions config/features.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,8 @@
feature :design_system_downtime_new,
default: false,
description: "A transition of the add downtime page to use the GOV.UK Design System"

feature :design_system_downtime_edit,
default: false,
description: "A transition of the edit downtime page to the GOV.UK Design System"
end
3 changes: 3 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@
constraints FeatureConstraint.new("design_system_downtime_new") do
resource :downtime, only: %i[new create]
end
constraints FeatureConstraint.new("design_system_downtime_edit") do
resource :downtime, only: %i[edit update]
end
resource :downtime, only: %i[new create edit update destroy], controller: "legacy_downtimes"
end

Expand Down
45 changes: 45 additions & 0 deletions test/functional/downtimes_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,51 @@ class DowntimesControllerTest < ActionController::TestCase
end
end

context "#edit" do
should "render the page ok" do
create_downtime
get :edit, params: { edition_id: edition.id }
assert_response :ok
end
end

context "#update" do
context "cancelling scheduled downtime" do
should "invoke the DowntimeRemover" do
DowntimeRemover.expects(:destroy_immediately).with(downtime)
put :update, params: { edition_id: edition.id, downtime: downtime_params, commit: "Cancel downtime" }
end

should "redirect to the downtime index" do
DowntimeRemover.stubs(:destroy_immediately)
put :update, params: { edition_id: edition.id, downtime: downtime_params, commit: "Cancel downtime" }
assert_redirected_to controller: "legacy_downtimes", action: "index"
end
end

context "rescheduling planned downtime" do
should "schedule the changes for publication and expiration" do
DowntimeScheduler.expects(:schedule_publish_and_expiry).with(downtime)
put :update, params: { edition_id: edition.id, downtime: downtime_params, commit: "Re-schedule downtime message" }
end

should "redirect to the downtime index" do
create_downtime
DowntimeScheduler.stubs(:schedule_publish_and_expiry)
put :update, params: { edition_id: edition.id, downtime: downtime_params, commit: "Re-schedule downtime message" }
assert_redirected_to controller: "legacy_downtimes", action: "index"
end
end

context "with invalid form data" do
should "rerender the page" do
create_downtime
put :update, params: { edition_id: edition.id, downtime: invalid_params, commit: "Re-schedule downtime message" }
assert_template :edit
end
end
end

def edition
@edition ||= FactoryBot.create(:transaction_edition)
end
Expand Down
9 changes: 9 additions & 0 deletions test/integration/routes_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,13 @@ class RoutesTest < ActionDispatch::IntegrationTest

assert_routing("/reports", controller: "legacy_reports", action: "index")
end

should "route to legacy reports controller when 'design_system_downtime_edit' toggle is enabled" do
test_strategy = Flipflop::FeatureSet.current.test!
test_strategy.switch!(:design_system_downtime_edit, true)
edition = FactoryBot.create(:edition)
edition_id = edition.id.to_s

assert_routing("/editions/#{edition_id}/downtime/edit", controller: "downtimes", action: "edit", edition_id:)
end
end
Loading