Skip to content

Commit

Permalink
ER-815 Service Unavailable Page (#941)
Browse files Browse the repository at this point in the history
* add redirect to service unavailable page

* rubocop

* update specs

* update service unavailable redirect

* add maintencance? method to application config

* update spec

* rename maintenance page and update spec
  • Loading branch information
jack-coggin authored Nov 7, 2023
1 parent e517946 commit 4cc8207
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,6 @@ E2E=true

# Deployment environment
ENVIRONMENT=

# DISPLAY SERVICE_UNAVAILABLE PAGE
MAINTENANCE = true
12 changes: 11 additions & 1 deletion app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ class ApplicationController < ActionController::Base
:set_hotjar_site_id,
:prepare_cms

before_action :maintenance_page, if: :maintenance?

helper_method :current_user,
:timeout_timer,
:debug?

default_form_builder(EarlyYearsRecoveryFormBuilder)

include Tracking
Expand Down Expand Up @@ -67,6 +68,15 @@ def timeout_timer

private

# @return [Boolean]
def maintenance?
Rails.application.maintenance? && request.path != '/maintenance'
end

def maintenance_page
redirect_to static_path('maintenance')
end

def set_time_zone(&block)
Time.use_zone(ENV['TZ'], &block)
end
Expand Down
5 changes: 5 additions & 0 deletions config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,11 @@ def debug?
Types::Params::Bool[ENV.fetch('DEBUG', false)]
end

# @return [Boolean]
def maintenance?
Types::Params::Bool[ENV.fetch('MAINTENANCE', false)]
end

# @return [ActiveSupport::TimeWithZone]
def public_beta_launch_date
Time.zone.local(2023, 2, 9, 15, 0, 0)
Expand Down
38 changes: 38 additions & 0 deletions spec/system/maintenance_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
require 'rails_helper'

RSpec.shared_examples 'displays service unavailable page' do
it 'displays the service unavailable message and title' do
expect(page).to have_css('h1', text: 'Sorry, the service is unavailable')
expect(page).to have_title('Early years child development training : Sorry, the service is unavailable')
end
end

RSpec.describe 'Service Unavailable' do
before do
allow(Rails.application).to receive(:maintenance?).and_return(true)
end

context 'when the service is unavailable and user navigates to home' do
before do
visit '/'
end

it_behaves_like 'displays service unavailable page'
end

context 'when the service is unavailable and user navigates to my modules page' do
before do
visit my_modules_path
end

it_behaves_like 'displays service unavailable page'
end

context 'when the service is unavailable and user is already on the service unavailable page' do
before do
visit '/maintenance'
end

it_behaves_like 'displays service unavailable page'
end
end

0 comments on commit 4cc8207

Please sign in to comment.