The project is in a healthy, maintained state
A gem to hold shared code which other GOV.UK apps will use to implement accounts-related functionality.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

Runtime

>= 6, < 9
>= 1.9.0
 Project Readme

GOV.UK Personalisation

A gem to hold shared code which other GOV.UK apps use to implement accounts-related functionality.

Installation

Add this line to your application's Gemfile:

gem 'govuk_personalisation'

And then execute:

$ bundle install

Usage

Rails concern

Include the concern into a controller:

include GovukPersonalisation::AccountConcern

And it will add before_action methods to:

  • fetch the account session identifier from the request headers, making it available as account_session_header
  • set a Vary response header, to ensure responses for different users are cached differently by the CDN

The following functions are available:

  • logged_in? - check if there is an account session header
  • set_account_session_header - replace the current session value, and set the response header the CDN uses to update the user's cookie
  • logout! - clear the session value, and set the response header the CDN uses to remove the user's cookie

When run in development mode (RAILS_ENV=development), a cookie on dev.gov.uk is used instead of custom headers.

Test helpers

There are test helpers for both request and feature specs to log the user in. Include the relevant helper:

include GovukPersonalisation::TestHelpers::Requests

or

include GovukPersonalisation::TestHelpers::Features

And then log the user in:

before do
  mock_logged_in_session
end

If you need a specific session identifier, for example to match against it in WebMock stubs or with the gds-api-adapters test helpers, you can pass it as an argument:

before do
  mock_logged_in_session("your-session-identifier-goes-here")
end

License

The gem is available as open source under the terms of the MIT License.