Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
10 changes: 10 additions & 0 deletions app/controllers/movies_controller.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,12 @@
class MoviesController < ApplicationController
def index
movies = Movie.all
render status: :ok, json: movies.as_json(only: [:id, :title, :release_date])
end

private

def movie_params
return params.require(:movie).permits(:title, :overview, :release_date, :inventory)
end
end
3 changes: 2 additions & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
Rails.application.routes.draw do
get 'zomg/index'
get "zomg/index"
# For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
resources :customers, only: [:index]
resources :movies, only: [:index]
get "/zomg", to: "zomg#index", as: "zomg"
end
32 changes: 29 additions & 3 deletions test/controllers/movies_controller_test.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,33 @@
require "test_helper"

describe MoviesController do
# it "must be a real test" do
# flunk "Need real tests"
# end
describe "index" do
it "is a working route" do
get movies_path
must_respond_with :success
end

it "returns an Array" do
get movies_path

body = JSON.parse(response.body)
body.must_be_kind_of Array
end

it "returns all of the movies" do
get movies_path

body = JSON.parse(response.body)
body.length.must_equal Movie.count
end

it "returns movies with exactly the required fields" do
keys = %w(id title release_date)
get movies_path
body = JSON.parse(response.body)
body.each do |movie|
movie.keys.must_equal keys
end
end
end
end