-
Notifications
You must be signed in to change notification settings - Fork 19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
AC's Video Rental API #21
base: master
Are you sure you want to change the base?
Conversation
…e to class method
Video StoreWhat We're Looking For
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can a customer have negative credit?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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