Skip to content

Commit

Permalink
use feature flag in application_helper links
Browse files Browse the repository at this point in the history
  • Loading branch information
jack-coggin committed Dec 4, 2023
1 parent 93923c3 commit 948fa98
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 31 deletions.
18 changes: 14 additions & 4 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ def navigation
header.with_navigation_item(text: 'Home', href: root_path, classes: %w[dfe-header__navigation-item])
if user_signed_in?
header.with_action_link(text: 'My Account', href: user_path, options: { inverse: true })
header.with_action_link(text: 'Sign out', href: logout_uri.to_s, options: { id: 'sign-out-desktop', data: { turbo_method: :get }, inverse: true })
header.with_action_link(text: 'Sign out', href: logout_path, options: { id: 'sign-out-desktop', data: { turbo_method: :get }, inverse: true })
header.with_navigation_item(text: 'My modules', href: my_modules_path, classes: %w[dfe-header__navigation-item])
header.with_navigation_item(text: 'Learning log', href: user_notes_path, classes: %w[dfe-header__navigation-items]) if current_user.course_started?
header.with_navigation_item(text: 'My account', href: user_path, classes: %w[dfe-header__navigation-item dfe-header-f-mob])
header.with_navigation_item(text: 'Sign out', href: logout_uri.to_s, options: { data: { turbo_method: :get } }, classes: %w[dfe-header__navigation-item dfe-header-f-mob], html_attributes: { id: 'sign-out-f-mob' })
header.with_navigation_item(text: 'Sign out', href: logout_path, options: { data: { turbo_method: :get } }, classes: %w[dfe-header__navigation-item dfe-header-f-mob], html_attributes: { id: 'sign-out-f-mob' })
else
header.with_action_link(text: 'Sign in', href: gov_one_info_path, options: { inverse: true })
header.with_navigation_item(text: 'Sign in', href: gov_one_info_path, classes: %w[dfe-header__navigation-item dfe-header-f-mob])
header.with_action_link(text: 'Sign in', href: login_path, options: { inverse: true })
header.with_navigation_item(text: 'Sign in', href: login_path, classes: %w[dfe-header__navigation-item dfe-header-f-mob])
end
end
end
Expand Down Expand Up @@ -59,4 +59,14 @@ def html_title(*parts)
def calculate_module_state
CalculateModuleState.new(user: current_user).call
end

# @return [String]
def login_path
Rails.application.gov_one_login? ? gov_one_info_path : new_user_session_path
end

# @return [String]
def logout_path
Rails.application.gov_one_login? ? logout_uri.to_s : destroy_user_session_path
end
end
36 changes: 25 additions & 11 deletions app/views/gov_one/show.html.slim
Original file line number Diff line number Diff line change
@@ -1,14 +1,28 @@
= render 'learning/cms_debug'

- content_for :page_title do
= html_title t('gov_one_info.title')
= html_title t('home.title')

- content_for :hero do
.govuk-grid-row class='govuk-!-padding-top-9'
.govuk-grid-column-three-quarters
h1.dfe-heading-xl class='govuk-!-margin-bottom-4'
= t('gov_one_info.hero_header')
p.govuk-body-l = t('gov_one_info.hero_body')


.govuk-grid-row
.govuk-grid-column-full
. class='govuk-!-margin-bottom-5'
= m('gov_one_info.body')
hr

= login_button

.govuk-grid-row
.govuk-grid-column-one-half
= m('gov_one_info.body')

- if current_user
= logout_button
- else
= login_button

.govuk-grid-column-three-quarters class='govuk-!-margin-top-4 govuk-!-margin-bottom-9'
details.govuk-details data-module='govuk-details'
summary.govuk-details__summary
span.govuk-details__summary-text
= t('gov_one_info.details_summary')
.govuk-details__text
= t('gov_one_info.details_text')
5 changes: 5 additions & 0 deletions config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,11 @@ def maintenance?
Types::Params::Bool[ENV.fetch('MAINTENANCE', false)]
end

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

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

RSpec.describe 'Gov One Info' do
context 'with an unauthenticated visitor' do
before do
visit '/gov-one/info'
end
before do
allow(Rails.application).to receive(:gov_one_login?).and_return(false)
visit '/gov-one/info'
end

context 'with an unauthenticated visitor' do
it 'displays the correct content' do
expect(page).to have_css('h1', text: 'How to access this training course')
expect(page).to have_css('p', text: 'This service uses GOV.UK One Login which is managed by the Government Digital Service.')
Expand All @@ -23,7 +24,6 @@
include_context 'with user'

it 'redirects to the my modules page' do
visit '/gov-one/info'
expect(page).to have_current_path('/my-modules')
end
end
Expand Down
22 changes: 11 additions & 11 deletions spec/system/whats_new_page_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,19 @@
end

describe 'with subsequent logins' do
before do
click_on 'sign-out-desktop'
before do
click_on 'sign-out-desktop'

visit '/users/sign-in'
fill_in 'Email address', with: user.email
fill_in 'Password', with: user.password
click_button 'Sign in'
end
visit '/users/sign-in'
fill_in 'Email address', with: user.email
fill_in 'Password', with: user.password
click_button 'Sign in'
end

it 'does not appear' do
expect(page).not_to have_current_path '/whats-new'
expect(page).to have_current_path '/my-modules'
end
it 'does not appear' do
expect(page).not_to have_current_path '/whats-new'
expect(page).to have_current_path '/my-modules'
end
end
end
end

0 comments on commit 948fa98

Please sign in to comment.