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

Sam & Hannah -- Octos #17

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

Conversation

samanthaberk
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 knew that movies would have customers and vice versa, but through rentals from the seed data, so we decided to make rentals act like a join table. Based off of the API descriptions, we knew it would be more than a join table, so we used a has_many :through relationship.
Describe a set of positive and negative test cases you implemented for a model. For decrement_movies_count we tested that the customer_movie_count would decrease by 1. For the negative case, we tested that it would not decrease if movie_count was already at 0.
Describe a set of positive and negative test cases you implemented for a controller. On the movies controller, for the show action, we tested in a positive case that it would return the json for a specific movie that exists, and that it would return errors when the movie doesn't exist.
How does your API respond when bad data is sent to it? We send back clear error messages describing what is wrong.
Describe one of your custom model methods and why you chose to wrap that functionality into a method. We chose to wrap increment_available_inventory for the Movie class in a method so we could easily call it in the controller for the update method when a movie is checked in.
Do you have any recommendations on how we could improve this project for the next cohort? It took us some experimenting to understand how to run all tests in Postman. Based on our in-class intro, it seemed like we would need to add data in params which took up time. More guidance on this would have been helpful.
Link to Trello https://trello.com/b/vDg4DddI/videostoreapi
Link to ERD https://www.lucidchart.com/documents/edit/084a5e22-5692-4a76-9356-3cac1845eebf/0

samanthaberk and others added 30 commits May 7, 2018 14:41
…ventory; edited inventory validation to no longer be greater than zero
samanthaberk and others added 24 commits May 8, 2018 10:38
…idation for available inventory to be only on create
…movie, wrote tests, commented out method as it isn't working
@kariabancroft
Copy link

Video Store

What We're Looking For

Feature Feedback
Core Requirements
Git hygiene Good
Comprehension questions Yes
General
Business Logic in Models Yes - did a good job setting and updating some necessary fields
All required endpoints return expected JSON data Yes
Requests respond with appropriate HTTP Status Code Yes
Errors are reported Yes
Testing
Passes all Smoke Tests Yes
Model Tests - all relations, validations, and custom functions test positive & negative cases Yes, good
Controller Tests - URI parameters and data in the request body have positive & negative cases Yes, nice job with tests for rental on inventory as well as bad movie and customer ids
Overall You did a nice job with this. The main logic that I thought could be consolidated was some of the inventory and status updates on all of the objects related to checking in and checking out a rental. This would simplify the controller actions and ensure that this logic is always grouped together.

validates :name, presence: true
validates :movies_checked_out_count, presence: true, numericality: { only_integer: true }

def decrement_movies_checked_out_count

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

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?

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

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

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

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.

3 participants