A gem to hold shared code which other GOV.UK apps use to implement accounts-related functionality.
Add this line to your application's Gemfile:
gem 'govuk_personalisation'
And then execute:
$ bundle install
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 headerset_account_session_header
- replace the current session value, and set the response header the CDN uses to update the user's cookielogout!
- 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.
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
The gem is available as open source under the terms of the MIT License.