Skip to content

Rails 6 API implementation of a customer to vehicle association with testing.

Notifications You must be signed in to change notification settings

emmahyde/customer-vehicles

Repository files navigation

customer-vehicles

Docker Test Build Run Coverage GitHub Page Snyk Vulnerabilities Github Repo Size

How-To

Asciinema Walkthrough

asciicast

Requirements

You will need:

  • git
  • docker-compose & docker

Setup

  1. git clone [email protected]:emmahyde/customer-vehicles.git
  2. cd customer-vehicles
  3. docker-compose build
  4. docker-compose run web rails db:setup

Run Tests

Follow above instructions and then execute:

docker-compose run web rspec

Run Server

Follow Setup instructions and then execute:

docker-compose up -d

The server is now running on localhost:3000.

API Documentation

Load the schema in your local Postman app,

Or view it on a static site.

Next Steps

There are some clear opportunities for improvement here.

  • The Vehicle association makes DB queries that could be removed if a cache layer was implemented, or we could eager-load the associations in.
  • More sort options for Customers, sort options at all for Vehicles.
  • Expand the primary-vehicle functionality: right now the primary Vehicle is only ever set the first time a Vehicle is created for a Customer. The intention here is to leave it very easily extendable, and the best way to do that is to support an association right off the bat, making some progress towards decoupling Customers and Vehicles.
    • Add more fine-grain control around the response to the client, for instance, listing all Vehicles associated with a Customer. Since this API does support a 1:many relationship here, this would be very simple. The reason the primary functionality was added was in order to implement the initial requirement of sort Customers on vehicle_type (where some Vehicle must be the "default"), but implementing these two concepts as separate models leaves the door open to extendability down the line.
  • Better deletion practices: As of right now we could end up with bad data since we are not explicitly deleting Vehicle associations upon destroying the parent Customer.
  • It isn't necessarily DRY, it could be better abstracted, but for ease of digestion I wanted to leave it pretty friendly.
  • Further awareness of edge cases and coverage on error handling, but as of right now it has 98.26% test coverage.

See code coverage report at https://emmahyde.github.io/customer-vehicles.

╰─❯ docker-compose run web rspec
Creating outdoorsy_web_run ... done
..............................

Finished in 3.22 seconds (files took 1.87 seconds to load)
30 examples, 0 failures

Coverage report generated for RSpec to /app/coverage. 395 / 402 LOC (98.26%) covered.

Screen Shot 2021-08-13 at 1 57 40 PM

About

Rails 6 API implementation of a customer to vehicle association with testing.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages