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.
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.
You should also test the required keys.
| body.length.must_equal Movie.count | ||
| end | ||
|
|
||
| it "returns movies with exactly the required fields" do |
| } | ||
| } | ||
|
|
||
| describe "checkout" do |
There was a problem hiding this comment.
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.
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.
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.
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.