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

Ann and Regan's Fine Fine Video Store API #3

Open
wants to merge 61 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
0433510
Initial setup
pancake-batfish May 9, 2017
541278f
Generate customer, movie and rental models
pancake-batfish May 9, 2017
f28cc23
Add sketched-out routes to routes file
pancake-batfish May 9, 2017
25f84c6
added customer yml fixtures
gofarann May 9, 2017
4e9d845
Stub in tests for movie model
pancake-batfish May 9, 2017
253a37f
added tests to customer model
gofarann May 9, 2017
6ff5942
First movie validations tests
pancake-batfish May 9, 2017
2c6ea17
Add presence validations for title and inventory
pancake-batfish May 9, 2017
3f7ea24
customer model test
gofarann May 9, 2017
73f1289
Add tests and validations for uniqueness
pancake-batfish May 9, 2017
b485b74
Add inventory tests and validations for movie
pancake-batfish May 9, 2017
a4b7449
Add test for relation of movie to rental
pancake-batfish May 9, 2017
e9fd684
all model test validations passed thus far
gofarann May 9, 2017
bc3edac
merge conflicts
gofarann May 9, 2017
e7482be
Stub in rental model tests
pancake-batfish May 9, 2017
21d1345
Merge branch 'rental_tests'
pancake-batfish May 9, 2017
8c3bfc2
Add test to require associated movie for rental
pancake-batfish May 9, 2017
7daf8f7
Add chronic gem and defaults for rental model
pancake-batfish May 9, 2017
e9ef964
added rental model tests
gofarann May 9, 2017
4432ab3
merge deconflicted
gofarann May 9, 2017
95c9159
Generate rentals and customers controllers
pancake-batfish May 9, 2017
c79bf6c
Uncomment first routes
pancake-batfish May 9, 2017
f23cd92
added movie index controller method and tests
gofarann May 9, 2017
5244c59
Add tests and controller action for customer index
pancake-batfish May 10, 2017
2641f41
Add custom method to customers and return value in json for customer …
pancake-batfish May 10, 2017
55f2513
Merge branch 'customer_index'
pancake-batfish May 10, 2017
0df9bad
Rename constant in tests to avoid conflict
pancake-batfish May 10, 2017
cc59455
added test stubs for checkout method
gofarann May 10, 2017
eab2a5e
First test movie show
pancake-batfish May 10, 2017
4a16b11
Additional tests and action for movie show
pancake-batfish May 10, 2017
a8c2d9c
Add negative test for movie show
pancake-batfish May 10, 2017
94d9e28
Complete movie show tests
pancake-batfish May 10, 2017
a8d152b
Stub in tests for checkin
pancake-batfish May 10, 2017
184273b
First rental update test
pancake-batfish May 10, 2017
bc286bb
rental controller tests
gofarann May 10, 2017
ad93c60
Start to build out update method
pancake-batfish May 10, 2017
6342b68
more checkout tests
gofarann May 10, 2017
9589853
Add tests and logic for invalid customer id or movie title
pancake-batfish May 11, 2017
579c021
Complete checkin tests
pancake-batfish May 11, 2017
208b099
Add seed for rental
pancake-batfish May 11, 2017
2a4149a
more rental checkout contorller testing
gofarann May 11, 2017
88234c8
Merge pull request #1 from pancake-batfish/checkin
gofarann May 11, 2017
5b04d87
Merge branch 'master' into rental_post_checkout
pancake-batfish May 11, 2017
ffe2e2d
Merge pull request #2 from pancake-batfish/rental_post_checkout
pancake-batfish May 11, 2017
670d719
added decrease inventory logic
gofarann May 11, 2017
38c070c
Stub in tests for customers sort
pancake-batfish May 11, 2017
779f024
WIP sort tests
pancake-batfish May 11, 2017
24c9aae
Add movies checked out count method
pancake-batfish May 12, 2017
be2894f
added overdue controller tests
gofarann May 12, 2017
4105087
Add test and logic to increase movie inventory on checkin
pancake-batfish May 12, 2017
3268737
Revise tests and methods to use available_inventory rather than inven…
pancake-batfish May 12, 2017
6be0e6a
Merge branch 'optional_parameters'
pancake-batfish May 12, 2017
e8fb922
making changes in overdue method
gofarann May 12, 2017
6aea9c7
resolved overdue method errors
gofarann May 12, 2017
d9f0a4a
resolved merge conflicts
gofarann May 12, 2017
05d9189
Merge branch 'master' of https://github.com/pancake-batfish/VideoStor…
pancake-batfish May 12, 2017
b625ff9
Tests and action to accept sort parameter for customer index
pancake-batfish May 12, 2017
ee99fa7
fixed display for overdue
gofarann May 12, 2017
53d58d6
took out due date in past test
gofarann May 12, 2017
675237d
Merge branch 'master' of https://github.com/pancake-batfish/VideoStor…
pancake-batfish May 12, 2017
eeab146
Merge branch 'sort_customers'
pancake-batfish May 12, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
rental controller tests
gofarann committed May 10, 2017
commit bc286bbd27f858c2a5254bef36018143e2928972
25 changes: 25 additions & 0 deletions app/controllers/rentals_controller.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,27 @@
class RentalsController < ApplicationController

def create
if Movie.find_by_title(params[:title]).nil?
id = Movie.find_by_title(params[:title]).id
else
id = 0
end

rental = Rental.new(movie_id: id, customer_id: rental_params[:customer_id], due_date: rental_params[:due_date] )

if rental.save
render status: :ok, json: rental.as_json
else
render status: :error, json: { error: true }
end


end

private

def rental_params
params.permit(:customer_id, :due_date)
end

end
6 changes: 6 additions & 0 deletions app/models/rental.rb
Original file line number Diff line number Diff line change
@@ -3,6 +3,12 @@ class Rental < ApplicationRecord
belongs_to :customer
after_initialize :set_defaults

validates :due_date, presence: true
validates :customer_id, presence: true




def set_defaults
self.checkout_date ||= Date.today
self.due_date ||= Chronic.parse('two weeks from today')
2 changes: 1 addition & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@
#
# get "/movies/:title", to: "movies#show"
#
post "/rentals/:title/check-out", to: "rentals#create"
post "/rentals/:title/check-out", to: "rentals#create", as: "checkout"
# [post customer_id and due_date]
#
# post "/rentals/:title/check-in", to: "rentals#update"
66 changes: 60 additions & 6 deletions test/controllers/rentals_controller_test.rb
Original file line number Diff line number Diff line change
@@ -1,24 +1,78 @@
require "test_helper"

describe RentalsController do

describe "Create (checkout)" do

it "given valid customer id and movie id, can checkout movie" do
it "given valid customer id and movie title, can checkout movie (increase rental record by 1)" do
proc {
post checkout_path("Psycho"), params: {
customer_id: Customer.all.first.id, #this is going to AR to get the actual record but is talkign to the fixtures
due_date: Chronic.parse("two weeks from today")

}
}.must_change 'Rental.count', 1
must_respond_with :success
end

it "given invalide customer_id, cannot checkout movie" do
it "given invalid customer_id, cannot checkout movie" do
proc {
post checkout_path("Psycho"), params: {
customer_id: Customer.all.last.id+1,
due_date: Chronic.parse("two weeks from today")
}
}.must_change 'Rental.count', 0
must_respond_with :error

body = JSON.parse(response.body)
body.must_be_kind_of Hash
body.must_include "error"
end

it "given invalide movie_id, cannot checkout movie" do
it "given invalid movie_title, cannot checkout movie" do
proc {
post checkout_path("Psychosss"), params: {
customer_id: Customer.all.first.id,
due_date: Chronic.parse("two weeks from today")
}
}.must_change 'Rental.count', 0
must_respond_with :bad_request

body = JSON.parse(response.body)
body.must_be_kind_of Hash
body.must_include "errors"
body["errors"].must_include "invalid movie"
end

it "can checkout a movie with enough inventory" do
it "can checkout a movie with enough inventory" do skip
proc {
post checkout_path("Psycho"), params: { rental: enough_inventory}
}.must_change 'Rental.count', 1
must_respond_with :success
end

it "cannot checkout movie with no inventory" do
it "cannot checkout movie with no inventory" do skip
proc {
post checkout_path("Psycho"), params: { rental: no_inventory}
}.must_change 'Rental.count', 0
must_respond_with :bad_request

body = JSON.parse(response.body)
body.must_be_kind_of Hash
body.must_include "errors"
body["errors"].must_include "not enough inventory"
end

it "returns a due_date that is 2 weeks from the checkout date" do
it "returns error when due date is in the past" do skip
proc {
post checkout_path("Psycho"), params: { rental: invalid_due_date}
}.must_change 'Rental.count', 0
must_respond_with :bad_request

body = JSON.parse(response.body)
body.must_be_kind_of Hash
body.must_include "errors"
body["errors"].must_include "due date cannot be in the past"

end

6 changes: 6 additions & 0 deletions test/fixtures/movies.yml
Original file line number Diff line number Diff line change
@@ -9,3 +9,9 @@ psycho:
overview: "When larcenous real estate clerk Marion Crane goes on the lam with a wad of cash and hopes of starting a new life, she ends up at the notorious Bates Motel, where manager Norman Bates cares for his housebound mother. The place seems quirky, but fine… until Marion decides to take a shower."
release_date: 1960-06-16
inventory: 8

bringit:
title: "Bring it On"
overview: "Cheerleading drama"
release_date: 1960-06-16
inventory: 0