-
Notifications
You must be signed in to change notification settings - Fork 25
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
Sam & Hannah -- Octos #17
base: master
Are you sure you want to change the base?
Conversation
…ventory; edited inventory validation to no longer be greater than zero
… pass postman smoke tests
…es controller tests
…idation for available inventory to be only on create
…movie, wrote tests, commented out method as it isn't working
…hod from model to controller
… that passes said tests (in that order)
…. also wrote tests
Video StoreWhat We're Looking For
|
validates :name, presence: true | ||
validates :movies_checked_out_count, presence: true, numericality: { only_integer: true } | ||
|
||
def decrement_movies_checked_out_count |
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.
Is it known that this will do nothing if there aren't any checked out?
@@ -0,0 +1,27 @@ | |||
class Movie < ApplicationRecord | |||
before_validation :set_available_inventory_default, on: :create |
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.
Nice use of the before_
action. You could also use before_create
for the same purpose.
movie = Movie.find_by(id: rental_params[:movie_id]) | ||
customer = Customer.find_by(id: rental_params[:customer_id]) | ||
|
||
if movie.nil? |
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 the customer doesn't exist?
end | ||
|
||
if rental.save | ||
movie.decrement_available_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.
It might be logical to move all of this updating logic into a rental model method. One thing to keep in mind in the future is that when an action requires many model updates, you may want to combine these into a transaction. If the rental save succeeds, then you also want to ensure that the movie and customer object updates work, otherwise you could end up in an odd state where the movie inventory is updated, but the customer's isn't.
require "test_helper" | ||
require 'pry' | ||
|
||
describe Rental 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 have a test that verifies the logic written in the before_create
block
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