-
Notifications
You must be signed in to change notification settings - Fork 26
Sopheary & Nara #10
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?
Sopheary & Nara #10
Conversation
Video StoreWhat We're Looking For
|
| if movie | ||
| render json: movie.as_json(except: [:id,:created_at, :updated_at], :methods => [:available_inventory]), status: :ok | ||
| else | ||
| render json: { "errors": ["Movie was not found"]}, status: :not_found |
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 would probably break line 10 up across multiple lines.
| movie = Movie.find_by(id: rental_params[:movie_id]) | ||
| if movie | ||
| if movie.available_inventory > 0 | ||
| rental = Rental.new(rental_params.merge(checkout_date: Date.today, due_date: Date.today + 7)) |
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.
Would it be possible to encapsulate this business logic in a model method? Something like Rental.check_out(customer_id, movie_id) might be a good interface.
|
|
||
| def movies_checked_out_count | ||
| self.rentals.where(checkin_date: nil).count | ||
| 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.
I love that you made Customer#movies_checked_out_count and Movie#available_inventory methods instead of storing them in the database. That way there's no way to forget to update these values.
| it "renders status bad request" do | ||
| get movie_path(-1) | ||
| must_respond_with :not_found | ||
| 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.
Since you send back specific JSON in the error case, it would be good to check that here as well.
| body = JSON.parse(response.body) | ||
|
|
||
| expect(body).must_be_kind_of Hash | ||
| expect(body).must_include "errors" |
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 that you verify error JSON here.
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.