Simple Payments API
A simple payments API where users can create accounts, send/receive money, get money added/subtracted from their account's balance, and see sent/received transactions.
(Solution to coding challenge)
Requirements
- Ruby version
2.7.2
(manage Ruby versions with rvm or rbenv) - PostgreSQL (or just Docker if you're going to install and use the app using it (Docker))
Features:
- 💎 Versioned gems
- All gems have MAJOR and MINOR versions specified
- This way we don't automatically pull breaking changes on
bundle update
- This way we don't automatically pull breaking changes on
- All gems have MAJOR and MINOR versions specified
- 📝 Versioned API
- Semantic versioning with MAJOR and MINOR versions specified for endpoints
- PATCH is not specified because users don't need to change versions for bug fixes. They (bug fixes) can be assumed to happen in the background via ticket resolutions.
- Read more about semantic versioning here
- Semantic versioning with MAJOR and MINOR versions specified for endpoints
- 📃 OpenAPI compliant endpoints
- All API endpoints have OpenAPI specs
- UI viewable at http://localhost:3000/api-docs
- YAML file viewable at
swagger/v1.0/swagger.yaml
- If you change any specs (at
spec/requests
), make sure you runrails rswag:specs:swaggerize
after - To generate a controller spec file, run
rails generate rspec:swagger API::v1.0::MyController
(replacingMyController
with the target controller name)
- ✔️ Integration tests
- All API endpoints have integration tests
- Other data type validation and resposne code matching tests are added in
spec/requests/api/v1.0/accounts_spec.rb
and inspec/requests/api/v1.0/money_send_transactions_spec.rb
by utilizing therswag
gem test suite. - (Total number of tests: 53)
- 🐳 Dockerized
(OpenAPI UI. Available at http://localhost:3000/api-docs)
Run
Setup and run server
- Traditional/local way
rails db:create db:migrate
bundle install
rails s
- Docker way
docker-compose build
docker-compose run --rm app rake db:create db:migrate
docker-compose up
Run tests
- Traditional/local way
bundle exec rspec
- Docker way
docker-compose run --rm -e RAILS_ENV=test app rails db:migrate
docker-compose exec app rspec
Docker help:
- To run any rails commands on the docker container use
docker-compose exec app <rails command>
- Run the build (i.e,
docker-compose build
) after adding any new gems - More help (link to tutorial followed for Rails-Docker setup)
Noticeable Gems:
rswag
- For writing and generating OpenAPI specs
database_cleaner-active_record
- For cleaning up the database before, during, and after running tests
Assumptions:
- All transactions are done in a single currency