TB-Foundation: A backend for TB Mobile App
This is the backend API for a project intended to improve tuberculosis treatment outcomes. It allows users to report their medication use and check in with providers throughout their treatment.
-
Create .env file This will provide the dockerized services with the environment variables needed to get started. Some sensible defaults are provided in .sample.env
-
Edit /etc/hosts If using a local development environment modify /etc/hosts to include a redirect for bucket to localhost. This is required to file urls consistant internally and externally on docker.
127.0.0.1 bucket
-
Spin up dockerized services
docker-compose up -d
-
Setup and seed database for rails application
docker-compose exec web bash -c 'bundle exec rake db:setup
docker-compose run --rm -e "RAILS_ENV=test" web rspec spec/requests/get_patients_spec.rb
- To skip to a specific test you can include the line number at the end (ie
:104
) - Can also run a whole "it" block if you specify that line
When working in vscode remote container mode I added an alias for easier testing rspec_test
To run the tests interactively you can run a one off container with the proper environment docker-compose run --rm -e "RAILS_ENV=test" web bash
and then run the rspec commands
Launch Rails Console
docker-compose exec web bin/rails c
Add a photo day to the first test account (for debugging)
Patient.first.add_photo_day
- Add gem to Gemfile
- run docker build -t uwcirg/tb-foundation .
- Redeploy
- An alias has been created in the docker build
create_docs
that will generate the Swagger DocumentationRAILS_ENV=test bundle exec rake rswag:specs:swaggerize PATTERN="spec/integration/\*\*/\*_spec.rb"
- These docs can be accessed from https://base-url.com/api-docs
- They will only be available in development environment
- Generating the docs does not run the tests, you can still run with the normal command above
- This is a good time saver, you can test the validity of API responses while also getting documentation out of it
Sometimes when adding gems or needing to upgrade versions, things can break with the installation of gems. If you get a message like this
Could not find rake-13.0.3 in any of the sources Run `bundle install` to install missing gems.
just run docker-compose build web