-
Notifications
You must be signed in to change notification settings - Fork 26
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
Elle and Cyndi #23
base: master
Are you sure you want to change the base?
Elle and Cyndi #23
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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."} |
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 include a status code.
if !movies.empty? | ||
render json: movies.as_json(except: [:created_at, :updated_at]), status: :ok | ||
else | ||
render json: {message: "There are currently no movies."} |
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.
Status code?
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 } | ||
|
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.
No validations???
|
||
it "returns false for invalid movie data" do | ||
movie = Movie.new | ||
movie.valid?.must_equal false |
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.
No test for why it's not valid?
rental.customer.must_equal customers(:one) | ||
end | ||
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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-in
endpoint? What does the time complexity depend on? Explain your reasoning.