-
Notifications
You must be signed in to change notification settings - Fork 26
Kate S. and Kelly #30
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
Kes/rental tests
Add movies routes, index & show actions and tests
Controller for customers
Creates rental controller
Migrations
Checkout branch
Add movie and cutomer ids to rental
Update finding customer and movie
Revise checkin action and add tests
Add movie controller tests
Clean up merge
Video StoreWhat We're Looking For
|
| has_many :rentals | ||
|
|
||
| after_create do |movie| | ||
| movie.available_inventory = movie.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.
This available_inventory makes better sense as a method instead of as a field. That way you don't have to engage in this chicanery.
Instead I suggest putting available_inventory method and movies_checked_out_count as methods in movie.rb and customer.rb.
| it "returns JSON and the route is working" do | ||
| get customers_path, as: :json | ||
|
|
||
| expect(response.header["Content-Type"]).must_include "json" |
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 should also test the required keys.
| body.length.must_equal Movie.count | ||
| end | ||
|
|
||
| it "returns movies with exactly the required fields" do |
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.
🥇
| } | ||
| } | ||
|
|
||
| describe "checkout" do |
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 about checking out a movie with no available inventory left?
| end | ||
|
|
||
| describe "check-in" do | ||
| let(:checkin_params) { |
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 if you check in a movie that's not checked out?
| if !customer | ||
| render json: { "errors": { "customer": ["Customer not found"] } }, status: :bad_request | ||
| else | ||
| checkout_date = Date.today |
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.
Look at how much code is here... This would indicate a good case for a model method.
| rental = Rental.find_by(customer_id: rental_params[:customer_id], movie_id: rental_params[:movie_id]) | ||
|
|
||
| if rental | ||
| rental.movie.available_inventory += 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.
This business logic would look lovely in a model.
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.