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
making changes in overdue method
gofarann committed May 12, 2017
commit e8fb92295d5a3ac24695f67ea9f8dedf5ad6bd9b
15 changes: 8 additions & 7 deletions app/controllers/movies_controller.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
class MoviesController < ApplicationController

before_action :find_movie, :only => [:show]
# before_action :find_movie, :only => [:show]

def index
movies = Movie.all
render json: movies.as_json(only: [:title, :release_date]), status: :ok
end

def show
movie = Movie.find_by(title: params[:title])
if movie.nil?
render json: { nothing: true }, status: :not_found
else
@@ -17,9 +18,9 @@ def show
end
end

private

def find_movie
movie = Movie.find_by(title: params[:title])
return movie
end
# private
#
# def find_movie
# movie = Movie.find_by(title: params[:title])
# return movie
# end
12 changes: 4 additions & 8 deletions app/controllers/rentals_controller.rb
Original file line number Diff line number Diff line change
@@ -47,15 +47,11 @@ def update


def overdue
movie = Movie.find_by_title(params[:title])
if movie
if customers_with_overdue.length != 0
render json: over_due_rentals.as_json(only: [:title, :customer_id, :name, :postal_code, :checkout_date, :due_date], status: :ok)
else
render json: { overdue: "none" }, status: :ok
end
overdue_customers = Rental.over_due_rentals
if overdue_customers.nil?
render json: { overdue: "none" }, status: :ok
else
render json: { movie: "not found" }, status: :error
render json: overdue_customers.as_json(only: [:title, :customer_id, :name, :postal_code, :checkout_date, :due_date], status: :ok)
end
end

10 changes: 5 additions & 5 deletions app/models/rental.rb
Original file line number Diff line number Diff line change
@@ -28,13 +28,13 @@ def set_defaults
self.due_date ||= Chronic.parse('two weeks from today')
end

def over_due_rentals #returns array of Customer objects
movie_rentals = Rental.find_by_movie_id(movie.id)
over_due_rentals = movie_rentals.where('due_date > Today.date')
def self.over_due_rentals #returns array of Customer objects
rentals = Rental.where("due_date < ?", Date.today)
overdue_rentals = rentals.where.not('checkin_date': nil)

customers_with_overdue = []
over_due_rentals.each do |rental|
customers_with_overdue << Customer.find_by_customer_id(rental.customer_id)
overdue_rentals.each do |rental|
customers_with_overdue << Customer.find_by_id(rental.customer_id)
end
return customers_with_overdue
end
3 changes: 2 additions & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
Rails.application.routes.draw do
# For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
get "/rentals/overdue", to: "rentals#overdue"

get "/customers", to: "customers#index"

get "/movies", to: "movies#index"
#
get "/movies/:title", to: "movies#show", as: "movie"

#
post "/rentals/:title/check-out", to: "rentals#create", as: "checkout"
# [post customer_id and due_date]
#
post "/rentals/:title/check-in", to: "rentals#update", as: "checkin"
# [post customer_id]
#
get "/rentals/overdue", to: "rentals#overdue", as: "overdue"
end
17 changes: 0 additions & 17 deletions test/controllers/movies_controller_test.rb
Original file line number Diff line number Diff line change
@@ -68,21 +68,4 @@
end
end

describe "overdue" do
let(:arabia) { movies(:arabia) }

it "should list customers given a movie with overdue inventory" do
get overdue(arabia.title)
must_respond_with :success

end

it "should return no movies given a title with no overdue inventory" do skip
end

it "should return an error when an invalid movie is given" do skip
end

end

end
99 changes: 56 additions & 43 deletions test/controllers/rentals_controller_test.rb
Original file line number Diff line number Diff line change
@@ -87,59 +87,72 @@
post checkout_path("Psycho"), params: {
customer_id: Customer.all.first.id,
due_date: Chronic.parse("two weeks from today")
}
}.must_change 'Movie.find_by_title("Psycho").inventory', -1
}
}.must_change 'Movie.find_by_title("Psycho").inventory', -1

end

end


describe "check_in" do
let(:rental) { rentals(:one) }
let(:customer) { customers(:good_data) }
let(:movie) { movies(:psycho) }
let(:customer2) { customers(:no_rentals)}
describe "check_in" do
let(:rental) { rentals(:one) }
let(:customer) { customers(:good_data) }
let(:movie) { movies(:psycho) }
let(:customer2) { customers(:no_rentals)}

it "succeeds for valid title and customer id" do
#valid means: rental exists [and therefore movie and customer exist]
post checkin_path(movie.title), params: { customer_id: customer.id }
must_respond_with :success
end
it "succeeds for valid title and customer id" do
#valid means: rental exists [and therefore movie and customer exist]
post checkin_path(movie.title), params: { customer_id: customer.id }
must_respond_with :success
end

it "modifies the db with today's date as checkin date" do
it "modifies the db with today's date as checkin date" do
post checkin_path(movie.title), params: { customer_id: customer.id }
rental.checkin_date.must_equal Date.today
end

it "modifies the db" do
proc {
post checkin_path(movie.title), params: { customer_id: customer.id }
rental.checkin_date.must_equal Date.today
end

it "modifies the db" do
proc {
post checkin_path(movie.title), params: { customer_id: customer.id }
}.must_change rental.checkin_date
end

it "renders bad request for invalid customer id data" do
post checkin_path(movie.title), params: { customer_id: (Customer.last.id + 1)}
must_respond_with :bad_request
body = JSON.parse(response.body)
body["error"].must_include "customer"
end

it "renders bad request if movie not found" do
post checkin_path("totally made up title"), params: { customer_id: customer.id }
must_respond_with :bad_request
body = JSON.parse(response.body)
body["error"].must_include "movie"
end

it "renders a different message if rental does not exist" do
#rental does not exist (customer does not actually have that movie checked out)
post checkin_path(movie.title), params: { customer_id: customer2.id}
must_respond_with :bad_request
body = JSON.parse(response.body)
body["error"].must_include "not checked out"
end
}.must_change rental.checkin_date
end

it "renders bad request for invalid customer id data" do
post checkin_path(movie.title), params: { customer_id: (Customer.last.id + 1)}
must_respond_with :bad_request
body = JSON.parse(response.body)
body["error"].must_include "customer"
end

it "renders bad request if movie not found" do
post checkin_path("totally made up title"), params: { customer_id: customer.id }
must_respond_with :bad_request
body = JSON.parse(response.body)
body["error"].must_include "movie"
end

it "renders a different message if rental does not exist" do
#rental does not exist (customer does not actually have that movie checked out)
post checkin_path(movie.title), params: { customer_id: customer2.id}
must_respond_with :bad_request
body = JSON.parse(response.body)
body["error"].must_include "not checked out"
end
end


describe "overdue" do

it "should list customers with overdue titles" do
get rentals_overdue_path
must_respond_with :success
end

it "response should be in json" do skip
end


end

end
6 changes: 6 additions & 0 deletions test/fixtures/rentals.yml
Original file line number Diff line number Diff line change
@@ -9,3 +9,9 @@ two:
movie: arabia
customer: good_data
checkout_date: 2017-05-09 13:34:33

three:
movie: arabia
customer: good_data
checkout_date: 2017-05-09 13:34:33
due_date: 2017-05-09 13:34:33