-
Notifications
You must be signed in to change notification settings - Fork 26
Faiza and Rosalyn #27
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
base: master
Are you sure you want to change the base?
Conversation
Video StoreWhat We're Looking For
|
| def checkout | ||
| rental = Rental.new(rental_params) | ||
|
|
||
| rental.set_checkout_date |
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.
I like the idea of making set_checkout_date be its own method. If you were to take this even further, you could write a class method on Rental that does both in one step.
|
|
||
| def checkin | ||
| rental = Rental.find_by(movie_id: rental_params[:movie_id], customer_id: rental_params[:customer_id]) | ||
|
|
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.
I don't see that using strong params here gets you anything. It would be simpler to say:
Rental.find_by(movie_id: params[:movie_id], customer_id: params[:customer_id])Since we're not using params directly to create or update a model (as in Rental.new(params)), we don't need the filtering that strong params gives us.
| def movies_checked_out_count | ||
| currently_rented = Rental.where(customer_id: self.id, currently_checked_out: true) | ||
| return currently_rented.length | ||
| 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.
Because you have the relation on line 2, you could shorten line 14 to rentals.where(currently_checked_out: 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.
I do love that you calculate this value on the fly instead of storing it in the database. That means there's no way to forget to update the count.
| def available_inventory | ||
| checked_out_movies = Rental.where(movie_id: self.id, currently_checked_out: true) | ||
| avail_inventory = inventory - checked_out_movies.length | ||
| return avail_inventory |
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.
Similar comments to Customer#movies_checked_out_count
|
|
||
| it "returns json" do | ||
| # Arrange - Act | ||
| get customers_path |
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.
The code you've written here matches what we showed in class. However, those tests were intentionally split out as a pedagogical tool. I think you could get away with collapsing all of these into one, since there's only one behavior you're covering.
|
|
||
| get movie_path(invalid_movie_id) | ||
|
|
||
| must_respond_with :bad_request |
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.
Since your endpoint returns specific JSON in this case, it would be wise to verify that is sent correctly.
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
POST /rentals/check-inendpoint? What does the time complexity depend on? Explain your reasoning.