Skip to content

Commit

Permalink
added rental controller
Browse files Browse the repository at this point in the history
  • Loading branch information
aruna79 committed May 8, 2018
1 parent a8b3835 commit 20e80e5
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 9 deletions.
1 change: 0 additions & 1 deletion app/controllers/movies_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ def show

if @movie


render json: @movie.as_json(only:[:title,:overview,:release_date,:inventory],methods: :available_inventory),status: :ok

else
Expand Down
24 changes: 24 additions & 0 deletions app/controllers/rentals_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
class RentalsController < ApplicationController

# def check_out
#
# rental = Rental.new(rental_params)
# if rental.save
#
# if @rental
#
# render json: @rental.as_json(rental.customer_id,rental.video_id),status: :ok
#
# else
# render json: {ok: false,errors:"movie not found"}, status: :not_found
# end
#
# end
#
# def check_in
# end
#
# def rentals_params
# return params.permit(:customer_id,:movie_id,:due_date,:checkout_date)
# end
end
1 change: 1 addition & 0 deletions app/models/rental.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ class Rental < ApplicationRecord
belongs_to :movie
validates :checkout_date, presence: true
validates :due_date, presence: true

end
3 changes: 3 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
Rails.application.routes.draw do


resources :movies, only: [:index, :show, :create]
resources :customers, only: [:index]

# For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
end
10 changes: 5 additions & 5 deletions test/controllers/movies_controller_test.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require "test_helper"
require 'date'

describe MoviesController do
describe "index" do
Expand Down Expand Up @@ -63,15 +64,15 @@

title: "Planet",
overview: "fiction",
release_date: Date.new(2018-05-07),
release_date:"2018-05-07",
inventory: 5

}
}

it "Creates a new movie" do
proc{
post movies_path, params:{movie: movie_data}
post movies_path, params: movie_data
}.must_change 'Movie.count',1
must_respond_with :success

Expand All @@ -80,7 +81,7 @@
it "returns bad request for params data" do
movie_data[:title] = nil
proc{
post movies_path, params: {movie: movie_data}
post movies_path, params: movie_data
}.must_change 'Movie.count',0
must_respond_with :bad_request

Expand All @@ -90,8 +91,7 @@
body["ok"].must_equal false
body.must_include "errors"
body["errors"].must_include "title"
#Movie.find(body["id"]).title.must_equal movie_data[:title]
# end

end

end
Expand Down
21 changes: 21 additions & 0 deletions test/controllers/rentals_controller_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
require "test_helper"


# describe RentalsController do
# let(:rental_data) {
# {
# customer_id: 1,
# movie_id: 1
#
# }
# }
#
# it "Creates a new rental" do
# proc{
# post rentals_path, params: rental_data
# }.must_change 'Rental.count',1
# must_respond_with :success
#
# end
#
# end
6 changes: 3 additions & 3 deletions test/fixtures/rentals.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

one:
checkout_date: 2018-05-07
due_date: 2018-05-07
due_date: 2018-05-14
customer: mary
movie: one

two:
checkout_date: 2018-05-07
due_date: 2018-05-07
due_date: 2018-05-14
customer: mary
movie: one
movie: two

0 comments on commit 20e80e5

Please sign in to comment.