Parliament::Utils
parliament-utils, created by the Parliamentary Digital Service, holds all reusable application configuration, test set up and generic helper methods. It is intended to be used across all applications making up the UK Parliament's website.
NOTE: This gem is in active development and is likely to change at short notice. It is not recommended that you use this in any production environment.
Requirements
parliament-utils requires the following:
- Ruby - click here for the exact version
- Bundler
Installation
Within your application, add this line to your application's Gemfile
:
gem 'parliament-utils'
Once you add the gem to your Gemfile
run:
bundle install
Usage
Follow installation instructions below to integrate the parliament-utils gem into an existing application
Now all application configuration, test set up and helper methods should be available within your application.
Instructions
The following steps can be followed to include this gem in your application:
Gemfile
- Add
gem 'parliament-utils'
to Gemfile, belowparliament-grom-decorators
- Ensure latest version of
pugin
gem version tbc
config
- Delete
config/initializers
folder - Delete
config/puma.rb
file - Add
require 'parliament/utils'
toconfig/application.rb
file, belowrequire 'pugin'
spec/spec_helper
- Remove all contents from
spec/spec_helper
spec/rails_helper
- Remove VCR and RSpec configuration blocks
- Remove the following code, if it exists
`require 'parliament/ntriple'`
`require 'vcr'`
Dir[Rails.root.join('spec/support/**/*.rb')].each { |f| require f }
- Add the following code:
require 'parliament/utils/test_helpers'
RSpec.configure do |config|
Parliament::Utils::TestHelpers.included_modules.each do |m|
m.load_rspec_config(config)
end
end
spec/helpers
- Delete
flag_helper_spec.rb
file, if it exists
spec/controllers/concerns
- Delete
postcode_helper_spec.rb
file, if it exists
app/controllers/concerns
- Delete
format_helper.rb
,houses_helper.rb
,parliament_helper.rb
,postcode_helper.rb
,request_helper.rb
,v_card_helper.rb
files, if they exist
app/controllers/application_controller
- Remove the following references to Helpers, if they exist
require 'houses_helper'
require 'request_helper'
require 'parliament_helper'
require 'format_helper'
require 'v_card_helper'
include HousesHelper
include RequestHelper
include ParliamentHelper
include FormatHelper
include VCardHelper
- Add
require 'parliament/utils'
- Add the following
include
statements to theApplicationController
class (ResourceHelper and VCardHelper may not be required in all apps)
include ResourceHelper
include Parliament::Utils::Helpers::ApplicationHelper
include Parliament::Utils::Helpers::VCardHelper
- Remove
data_check
,data_url
,build_request
,populate_alternates
methods, if they exist
app/helpers
- Delete
application_helper.rb
,flag_helper.rb
files, if they exist
Referencing new gem modules
- Find all instances of the Helpers mentioned below (in entire project) and replace/use as required:
Replace `ApplicationHelper` with `Parliament::Utils::Helpers::ApplicationHelper`
Replace `FlagHelper` with `Parliament::Utils::Helpers::FlagHelper`
Replace `FormatHelper` with `Parliament::Utils::Helpers::FormatHelper`
Replace `HousesHelper` with `Parliament::Utils::Helpers::HousesHelper`
Replace `ParliamentHelper` with `Parliament::Utils::Helpers::ParliamentHelper`
Replace `PostcodeHelper` with `Parliament::Utils::Helpers::PostcodeHelper`
Replace `RequestHelper` with `Parliament::Utils::Helpers::RequestHelper`
Replace `VCardHelper` with `Parliament::Utils::Helpers::VCardHelper`
Getting Started with Development
To clone the repository and set up the dependencies, run the following:
git clone https://github.com/ukparliament/parliament-utils.git
cd parliament-utils
bundle install
Running Tests
We use Rspec as our testing framework and tests can be run using:
bundle exec rake
Contributing
- Fork the repository
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Ensure your changes are tested using Rspec
- Create a new Pull Request
License
parliament-utils is licensed under the Open Parliament Licence.