VideoStoreAPI - Angela and Maria - Octos#4
VideoStoreAPI - Angela and Maria - Octos#4knockknockhusthere wants to merge 60 commits intoAda-C9:masterfrom
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.
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.
Don't forget status codes even when its the positive case
|
|
||
| class RentalsController < ApplicationController | ||
|
|
||
| def check_out |
There was a problem hiding this comment.
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.
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.
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.
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.
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.
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