Skip to content
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

Cara/Brandy/Jamila Octos C9 #15

Open
wants to merge 80 commits into
base: master
Choose a base branch
from
Open

Conversation

Jcornick21
Copy link

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

Question Answer
Explain how you came up with the design of your ERD, based on the seed data.
Describe a set of positive and negative test cases you implemented for a model. That customer is invalid without a name and valid with a name.
Describe a set of positive and negative test cases you implemented for a controller. for positive we said it created a new movie for a negative case we should have written that it does not create a new movie with invalid data
How does your API respond when bad data is sent to it? it gives errors
Describe one of your custom model methods and why you chose to wrap that functionality into a method. We put a method called check_dependencies in the Rental model. The method returns an error message if the params are inappropriate and nil if it's okay to proceed. We wrapped this in a method because the if/else block is doing one specific thing that is tangential to the controller action.
Do you have any recommendations on how we could improve this project for the next cohort?
Link to Trello https://trello.com/b/vs3R6hQT/movies
Link to ERD https://files.slack.com/files-pri/T840SSYLR-FAKT425RB/img_20180507_135518.jpg

@droberts-sea
Copy link

Video Store

What We're Looking For

Feature Feedback
Core Requirements
Git hygiene yes
Comprehension questions These answers could be a little more in-depth. "It gives errors" -> in what format? What about status codes?
General
Business Logic in Models yes - great work moving logic to the Rental model
All required endpoints return expected JSON data yes
Requests respond with appropriate HTTP Status Code mostly - see MoviesController
Errors are reported mostly
Testing
Passes all Smoke Tests yes
Model Tests - all relations, validations, and custom functions test positive & negative cases no
Controller Tests - URI parameters and data in the request body have positive & negative cases yes - excellent work, especially on the RentalsController
Overall Good work overall! I've left some inline comments, but other than the missing model tests I'm quite happy with this submission. Keep up the hard work!

def show
@customer = Customer.find_by(id: cust_params[:id])
if @customer.nil?
render json: {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While this works, you don't typically use strong params for URL parameters.

def create
@movie = Movie.new(movie_params)
@movie.save!
render :create, status: :ok

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using bang (!) methods works great for the console or scripts like the seed file, but in your actual controller actions you should be calling the non-bang version and checking the result. As-is, this will produce an exception rather than a helpful error message, which is not a good user experience.

Something like this would be more appropriate:

@movie = Movie.new(movie_params)
if @movie.save
  render :create, status: :ok
else
  render json: { errors: @movie.errors.messages }, status: :bad_request
end

if @movie.nil?
render json: {
errors: {
id: ["No movie with ID #{movie_params[:id]}"]

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a good example of well-done error handling.

customer_id = check_params[:customer_id]
movie_id = check_params[:movie_id]

find_customer_and_movie(customer_id, movie_id)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the idea of moving the shared logic to find the customer and the movie into a helper method. Why not take it a step further and make it a controller filter?


if @rental.save

Rental.process_checkout(@customer, @movie)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This dance of checking the dependencies, creating the rentals, and then updating the dependent models is pretty complicated - it might make sense to encapsulate the whole thing in a model method. One thing that might help is using a transaction - go look this up!

def self.check_dependencies(customer, movie)
if customer.nil?
return {
customer_id: ["No such customer"]

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the customer and movie are about to be associated with an instance of Rental, it might make sense to make this an instance method.


it "Creates a new movie" do
# this is taking the count before and after
before_count = Movie.count

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if you send bad data?

describe Rental do

describe "relations" do
it "must respond to customer" do

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You've done such a good job of encapsulating your logic in the model! One of the big advantages of that is that you can test the logic in isolation here, but you're not doing that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants