A tradeline on a credit report represents an account, such as a credit card or car loan.
In the codebase, the following exists:
- The
Tradeline
model, which can be used to store tradelines in the database. - A
Tradeline
controller, which serves both theindex
andshow
routes for tradelines. - Basic
rspec
tests on the controller with atradeline
FactoryBot.
Add in the ability to create deposits for a specific tradeline using a JSON API call. You should store the deposit date (this is most likely a future date), and amount. Expose the outstanding balance for a given tradeline in the JSON output for TradelinesController#show
, and TradelinesController#index
. The oustanding balance should be calculated as the amount
minus all of the deposit amounts.
In addition:
- A deposit should not be able to be created that exceeds the outstanding balance of a tradeline.
- You should return validation errors if a deposit cannot be created.
- Expose endpoints for seeing all deposits for a given tradeline, as well as seeing an individual deposit.
Feel free to add any gems to the Gemfile
, and touch any of the existing code. For example, if you prefer to use PostgreSQL or MySQL over the included SQLite, or a serializer of your choice, please go ahead. This is not required, but you can be as creative as you want.
This exercise is purely API based, and will not have any frontend components. Please do not spend more than 3 hours on this.
The exercise requires Ruby 3.3.0. Simply clone the repo, and run bundle
to get started. This will install Rails 7.1.2, and the other specified gems.
Please do not fork the repo; if forked accidentally, please delete the fork. For review, either of the following methods for submission are preferred:
- Cloning the repository and then uploading it under your Github account for review.
- Zipping up the directory.
- Create Deposit model
- generate model & run migration
- set up associations with Tradeline
- create index, show, and create routes (see Routes section)
- serializer?
- Add outstanding balance to Tradeline responses
- add serializer?
- Add validation for deposit amount with error handling
- for amount > outstanding balance
- for date in the past
- jsonapi-serializer for response formatting
- shoulda-matchers for testing relationships.. and validations?
-
Tradelines
- GET /tradelines
- include outstanding balance
- GET /tradelines/:id
- include outstanding balance
- GET /tradelines
-
Deposits
- GET /tradelines/:tradeline_id/deposits
- GET /tradelines/:tradeline_id/deposits/:id
- POST /tradelines/:tradeline_id/deposits
- request includes date and amount
- happy path: returns deposit with id, date, amount, and tradeline_id
- error path: returns error message
- When setting up Tradeline and Deposit associations, I cannot run test for models
- Errors state pending migrations (screenshot)
- What I tried:
- 'rails db:migrate' shows no pending migrations
- 'rails db:migrate:status' shows all migrations are up
- checked in Rails console, and the tables exist
- 'rails db:reset' but same error as running test occurs
- Problem and Solution:
- I was set up a migration for the Deposit model, but I created a reference to "account", not "tradeline".
- I ran 'rails db:rollback' to remove the migration, and then created a new migration with the correct reference.
- When creating a custom validation for the deposit amount, test fails
- Inital custom validation is commented out in the Deposit model
- Test Error: ArgumentError:You need to supply at least one validation
- What I tried/Solution:
- use validate numericality of :amount, less_than_or_equal_to: :maximum_balance
- Add sad path testing and error handling (more 404s) for all requests
- Refactor calidation for deposit amount
- Try to figure out custom validation for deposit amount (as mentioned above)
- Or validate inside the controller
- This would prevent needing to call on the tradeline to check the outstanding balance inside of the Deposit model.
- Creating controller tests following Afra's example