Conversation
…ler tests to be finished.
…te and checkout date in the checkout action.
…s available inventory to model method in rental
Video StoreWhat We're Looking For
|
| end | ||
|
|
||
| def self.return(customer_id, movie_id) | ||
| rental = Rental.find_by(customer_id: customer_id, movie_id: movie_id) |
There was a problem hiding this comment.
How do you know the customer only had one checked out?
| belongs_to :movie, dependent: :delete | ||
| belongs_to :customer, dependent: :delete | ||
|
|
||
| def checkout_update_customer_movie(customer, movie) |
There was a problem hiding this comment.
The number checked out and available inventory sound like methods instead of data fields to me. I could see they getting out of sync especially if other apps impacted the same database.
| if !customers.empty? | ||
| render json: customers.as_json(except: [:created_at, :updated_at]), status: :ok | ||
| else | ||
| render json: {message: "There are currently no customers."} |
| if !movies.empty? | ||
| render json: movies.as_json(except: [:created_at, :updated_at]), status: :ok | ||
| else | ||
| render json: {message: "There are currently no movies."} |
| def checkout | ||
| movie = Movie.find_by(id: params[:movie_id]) | ||
| if movie == nil | ||
| render json: { error: "Movie was not found in database or no movie id was provided." }, status: :no_content |
There was a problem hiding this comment.
Status: no_content is usually for when the app has no content to return to the user, not when the operation fails. Instead I suggest, :bad_request.
|
|
||
| describe Customer do | ||
| let(:customer) { Customer.new } | ||
|
|
|
|
||
| it "returns false for invalid movie data" do | ||
| movie = Movie.new | ||
| movie.valid?.must_equal false |
| rental.customer.must_equal customers(:one) | ||
| end | ||
| end | ||
|
|
There was a problem hiding this comment.
For these methods, what about testing checkouts when the inventory isn't available?
What about checking in a movie that's never been checked out, or was already checked in?
| get customers_path | ||
| body = JSON.parse(response.body) | ||
| body.each do |customer| | ||
| customer.keys.must_equal keys |
There was a problem hiding this comment.
If you don't care about the order, I'd suggest that you sort the keys before comparing them.
| must_respond_with :success | ||
| end | ||
|
|
||
| it "will return bad request if given invalid data" do |
There was a problem hiding this comment.
You should also try this with invalid customer_id
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.