This is a codebase which provides an API that allows users to find a local Citizens Advice bureaux which serves their geographic area. It powers the Find Your Local Citizens Advice function on www.citizensadvice.org.uk.
It loads a copy of the Citizens Advice network and geographic data into a PostgreSQL database to allow for fast searching.
This project uses rbenv to manage the Ruby version the .ruby-version file.
Please make sure that's installed and configured and you will automatically
use the correct Ruby version when working with this project.
You will also need the libpq library installed (on a Mac, use Homebrew to
install it brew install libpq and then configure Bundler to use the Homebrew
version with bundle config build.pg --with-pg-config=/opt/homebrew/opt/libpq/bin/pg_config).
You can now run bundle to have a copy of your dependencies available in
your local environment.
If you would like to run commands locally, then it's worth creating a .env
file with the correct environment variables set:
cat >.env <<EOF
LOCAL_OFFICE_SEARCH_DB_HOST=localhost
LOCAL_OFFICE_SEARCH_DB_PORT=5460
LOCAL_OFFICE_SEARCH_DB_USER=local_office_search_api
LOCAL_OFFICE_SEARCH_DB_PASSWORD=develop
LOCAL_OFFICE_SEARCH_DB_NAME=local_office_search_api
LSS_DATA_BUCKET=sandbox-advicelocationpipe-pipelinebucket263ac468-19wuk9oanxght
GEO_DATA_BUCKET=uat-geo-data-postcodes-raw-eu-west-1
EOFFinally, you must now add the following to your hosts file:
127.0.0.1 local-office-search-api.test
The easiest way to start a local copy of the app is to use Docker. Run
bin/docker/start to do this.
You should then be able to visit the app at http://local-office-search-api.test:3060/.
Once you're done, bin/docker/stop ends the application!
This repo uses RSpec for testing. To quickly run all the tests:
bundle exec rake spec.
Linting is also available, and this is done using Rubocop, following
Citizens' Advice code style.
IDE integration is best for this, alternatively, you can run bundle exec rubocop.
You can also run these in Docker if there are any environmental issues
locally using bin/docker/lint and bin/docker/test.
You will need to have AWS set up and be authorised locally.
If you are logged in as ContentPlatformDeveloper you should now be able to run bin/docker/rake sync_database,
or bin/rake sync_database to load data in from the data science buckets.
The sync_database task sense checks the files have the expected columns in before loading them. Sometimes the
schema changes, and you need to alter the fixtures in spec/fixtures/ (which contain subsets of the full data)
to reflect the new schema to get failing tests you can use to fix the code.
To update the postcode files, you can use these commands (assuming you've downloaded the new file)
head -n 2 < ~/Downloads/Geo_postcodes_csv_uat.csv > spec/fixtures/postcodes/single.csv
head -n 2 < ~/Downloads/Geo_postcodes_csv_uat.csv > spec/fixtures/postcodes/with_nil_la.csv
grep 'AB11 3AG' ~/Downloads/Geo_postcodes_csv_uat.csv >> spec/fixtures/postcodes/with_nil_la.csv
This repo uses RSwag to produce Swagger API documentation from tests which have been written against an endpoint.
In order to edit the API documentation, you should write appropriate tests in
spec/requests/ folder, and once they are green, run bin/rails rswag to
update the documentation files.