-
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
VideoStoreAPI - Angela and Maria - Octos #4
base: master
Are you sure you want to change the base?
Conversation
…ing inventory of movies
…d to handle setting available_inventory
…tionality, added inventory validation
…ixed a customer controller test to include movies_checked_out_count in fields to return
Video StoreWhat We're Looking For
|
validates :movies_checked_out_count, numericality: { only_integer: true, greater_than_or_equal_to: 0 } | ||
|
||
after_initialize do |customer| | ||
self.movies_checked_out_count ||= 0 |
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 could also use a database default value to set this
} | ||
}, status: :not_found | ||
else | ||
render json: @movie.as_json(only: [:id, :title, :overview, :release_date, :inventory, :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.
Don't forget status codes even when its the positive case
|
||
class RentalsController < ApplicationController | ||
|
||
def check_out |
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 would make sense to move some of this logic from the controller into the model. You could have a single Rental model method that would complete all of these actions: update the dates and take care of updating the movie and customer inventory.
#set available_inventory to inventory in movie controller? | ||
|
||
if rental.save | ||
movie = Movie.find_by(id: rental.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.
The rental should already have a method to retrieve the movie without going through the overall Rental
object. You should simply be able to use render.movie
movie.dec_avail_inventory | ||
movie.save | ||
|
||
customer = Customer.find_by(id: rental.customer_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.
Same comment re: the method on the rental relationships to retrieve this object
let(:ava) {customers(:ava)} | ||
|
||
describe 'relations' do | ||
it 'checks that a customer already exists' 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 don't really need a test for this - this is somewhat just testing that fixtures work which isn't part of your code
movie = Movie.first | ||
customer = Customer.first | ||
rental = Rental.new(movie_id: movie.id, customer_id: customer.id) | ||
rental.customer_id.must_equal customer.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.
By going from the rental to the customer, you're really testing this code on the rental side. In this customer model test, you should be testing the customer.rental
object instead.
it "connects customer and rental customer_id" do | ||
movie = Movie.first | ||
rental = Rental.new(movie_id: movie.id, customer_id: @customer.id) | ||
rental.movie_id.must_equal 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.
Again, note how checking the movie properties through the rental object, but you should be able to check the rental object through the movie instead.
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