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

VideoStoreAPI - Angela and Maria - Octos #4

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

Conversation

knockknockhusthere
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. We started with two classes, Customer and Movie. We then considered a join table to connect the movie id with customer id being rented. We later on during the project decided on a Rental model instead.
Describe a set of positive and negative test cases you implemented for a model. A movie can be created with all valid fields. A movie cannot be created without a title, or with an inventory of zero or less.
Describe a set of positive and negative test cases you implemented for a controller. We check that a movie that exists will return all required fields, and we check that it yields a not_found status if the movie does not exist.
How does your API respond when bad data is sent to it? with a 404 not_found and the error
Describe one of your custom model methods and why you chose to wrap that functionality into a method. We wrote the logic for incrementing and decrementing the movies_checked_out_count inside the customer model.
Do you have any recommendations on how we could improve this project for the next cohort? Write better requirements so we know that the movies_checked_out_count was not an optional. Demo the smoketests and how to find your bugs/problems.
Link to Trello https://docs.google.com/document/d/11SUxikq4CTRo-3FCuA3QQfJmbMQdzBHVnFhHLlhydR8/edit
Link to ERD https://www.lucidchart.com/documents/edit/959e2eb3-0b26-4482-87d4-12db975ee52c/0?shared=true&

knockknockhusthere and others added 28 commits May 9, 2018 23:38
…ixed a customer controller test to include movies_checked_out_count in fields to return
@kariabancroft
Copy link

Video Store

What We're Looking For

Feature Feedback
Core Requirements
Git hygiene Used the commits - not too happy with the lopsided commits towards the end of the project though
Comprehension questions Yes
General
Business Logic in Models Yes - custom validations, increment and decrement methods. Per inline comments, you could still move some rental logic into the model.
All required endpoints return expected JSON data Yes
Requests respond with appropriate HTTP Status Code Most, missing some status: ok on success cases
Errors are reported Yes
Testing
Passes all Smoke Tests Yes
Model Tests - all relations, validations, and custom functions test positive & negative cases Yes, though there is room for improvement on the relationship tests.
Controller Tests - URI parameters and data in the request body have positive & negative cases Customer and Movies look good. Would like to see more tests for the Rentals controller on check in and check out.
Overall When creating your tests for model relationships, consider that you want to test from both sides of the relationship. Whichever test file you're in, you want to be testing the relationship from that model object. The customer and movie controller methods were easier to test, but since the rentals controller does more logic, it would be a bigger "bang for your buck" if you tested that because there is a larger opportunity for these methods to go wrong. Overall, you demonstrated your learning of this API functionality.

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

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])

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

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)

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)

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

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

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

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.

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.

2 participants