AC's Video Rental API #21
AC's Video Rental API #21acgillette wants to merge 29 commits intoAda-C7:masterfrom acgillette:master
Conversation
…e to class method
Video StoreWhat We're Looking For
|
Erin007
left a comment
There was a problem hiding this comment.
Wahoo! Nice work - especially flying solo. Just a few things to think about. Please let me know if you have any follow up questions or would like me to take a closer look at something. -Erin
| render status: :bad_request, json: { error: "Not enough inventory" } | ||
| elsif rental.save | ||
| render status: :ok, json: { id: rental.id } | ||
| rental.customer.movies_checked_out_count += 1 |
There was a problem hiding this comment.
If the rental is processed, the customer.movies_checked_out_count increments up one, which makes sense. Does the movie.available_inventory also need to decrease by one?
| validates :address, presence: true | ||
| validates :city, presence: true | ||
| validates :state, presence: true | ||
| validates :postal_code, presence: true |
There was a problem hiding this comment.
You could consider validating whether the data you're getting for these fields is consistent with what's expected. For example, is the postal code 6 digits? Big picture, you want to always validate that what is required exists, and if it exists, that the format (data type, length, etc) is what you want it to be.
| validates :title, presence: true, uniqueness: true | ||
| validates :overview, presence: true | ||
| validates :release_date, presence: true | ||
| validates :inventory, presence: true, numericality: { greater_than: -1, only_integer: true } |
There was a problem hiding this comment.
yeah! like, here where you check that the inventory is an integer or that movie names are unique. That's what I was thinking in my previous comment 🙂
| Rails.application.routes.draw do | ||
|
|
||
| get '/movies', to: 'movies#index', as: 'movies' | ||
| get '/movies/:title', to: 'movies#show', as: 'movie' |
There was a problem hiding this comment.
It's totally great as is, just know that you will more often than not (in my -admittedly limited - experience) see :id in the routes for show. There's a little Rails magic you can tap into if you use the convention of /model/:id in routes. If you're curious to Google or you come across something like resources :movies in a routes file, it's generating all of the routes for you and will format the show method with the id in the route.
| @@ -0,0 +1,22 @@ | |||
| # Be sure to restart your server when you modify this file. | |||
There was a problem hiding this comment.
Shhhhh. These are secrets. They shouldn't float around out in the open. Pop this file in your gitignore.
| @@ -0,0 +1,4 @@ | |||
| class AddRelationships < ActiveRecord::Migration[5.0] | |||
| def change | |||
There was a problem hiding this comment.
What's going on with this empty change method in this migration? Seems like you could delete this migration if it's not doing anything...
|
|
||
| create_table "movies", force: :cascade do |t| | ||
| t.string "title" | ||
| t.string "overview" |
There was a problem hiding this comment.
How long is the overview? I ask because I wonder if you want t.text rather than t.string.
There was a problem hiding this comment.
Nevermind, I re-read the instructions, but something to consider in the future.
| r = JSON.parse(response.body) | ||
| r.length.must_equal Customer.count | ||
| end | ||
| end |
There was a problem hiding this comment.
You could also spot check that the json data you're getting back is consistent with what you would expect for customers. Do the objects returned, for example, have telephone numbers etc?
| customers(:no_code).valid?.must_equal false | ||
| customers(:no_phone).valid?.must_equal false | ||
| customers(:no_credit).valid?.must_equal false | ||
| end |
There was a problem hiding this comment.
You'll want to test any of your relationships in these model tests, too. Like has_many etc
|
|
||
| it "must be valid" do | ||
| value(rental).must_be :valid? | ||
| end |
There was a problem hiding this comment.
what happens if you test an invalid rental?
Video Store API
Congratulations! You're submitting your assignment!
If you didn't get to the functionality the question is asking about, reply with what you would have done if you had completed it.
Comprehension Questions