diff --git a/app/controllers/movies_controller.rb b/app/controllers/movies_controller.rb index 4c4b40018..88ea1aed5 100644 --- a/app/controllers/movies_controller.rb +++ b/app/controllers/movies_controller.rb @@ -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 diff --git a/app/controllers/rentals_controller.rb b/app/controllers/rentals_controller.rb new file mode 100644 index 000000000..3f7d47826 --- /dev/null +++ b/app/controllers/rentals_controller.rb @@ -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 diff --git a/app/models/rental.rb b/app/models/rental.rb index 9ce1bbff6..6202e6e5f 100644 --- a/app/models/rental.rb +++ b/app/models/rental.rb @@ -3,4 +3,5 @@ class Rental < ApplicationRecord belongs_to :movie validates :checkout_date, presence: true validates :due_date, presence: true + end diff --git a/config/routes.rb b/config/routes.rb index f34f09fe6..e7f906233 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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 diff --git a/test/controllers/movies_controller_test.rb b/test/controllers/movies_controller_test.rb index f379cf383..30f90beb9 100644 --- a/test/controllers/movies_controller_test.rb +++ b/test/controllers/movies_controller_test.rb @@ -1,4 +1,5 @@ require "test_helper" +require 'date' describe MoviesController do describe "index" do @@ -63,7 +64,7 @@ title: "Planet", overview: "fiction", - release_date: Date.new(2018-05-07), + release_date:"2018-05-07", inventory: 5 } @@ -71,7 +72,7 @@ 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 @@ -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 @@ -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 diff --git a/test/controllers/rentals_controller_test.rb b/test/controllers/rentals_controller_test.rb new file mode 100644 index 000000000..b1105f2a5 --- /dev/null +++ b/test/controllers/rentals_controller_test.rb @@ -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 diff --git a/test/fixtures/rentals.yml b/test/fixtures/rentals.yml index 9dfdab362..0ebc02201 100644 --- a/test/fixtures/rentals.yml +++ b/test/fixtures/rentals.yml @@ -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