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
8 changes: 4 additions & 4 deletions app/controllers/customers_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ def index
end


def zomg
render json: { :zomg => "it works"}
end
# def zomg
# render json: { :zomg => "it works"}
# end

private
#strong params
Expand All @@ -17,7 +17,7 @@ def customer_params
end

def jsonify(customer_data)
return customer_data.as_json(only: [:name, :registered_at, :address, :city, :state, :postal_code, :phone]), status: :ok
return customer_data.as_json(only: [:name, :registered_at, :address, :city, :state, :postal_code, :phone])
end

end
20 changes: 0 additions & 20 deletions db/generate_seeds.rb

This file was deleted.

2 changes: 1 addition & 1 deletion db/seeds/rentals.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[{"checkout_date":"2018-10-27","due_date":"2018-11-14","movie_id":79,"customer_id":70},{"checkout_date":"2018-10-23","due_date":"2018-11-10","movie_id":35,"customer_id":56},{"checkout_date":"2018-11-03","due_date":"2018-11-14","movie_id":88,"customer_id":68},{"checkout_date":"2018-11-02","due_date":"2018-11-13","movie_id":4,"customer_id":196},{"checkout_date":"2018-10-27","due_date":"2018-11-08","movie_id":66,"customer_id":9},{"checkout_date":"2018-10-31","due_date":"2018-11-07","movie_id":82,"customer_id":152},{"checkout_date":"2018-10-26","due_date":"2018-11-13","movie_id":46,"customer_id":193},{"checkout_date":"2018-10-28","due_date":"2018-11-06","movie_id":11,"customer_id":15},{"checkout_date":"2018-11-02","due_date":"2018-11-09","movie_id":10,"customer_id":194},{"checkout_date":"2018-10-28","due_date":"2018-11-13","movie_id":50,"customer_id":123},{"checkout_date":"2018-10-23","due_date":"2018-11-14","movie_id":68,"customer_id":28},{"checkout_date":"2018-10-29","due_date":"2018-11-07","movie_id":44,"customer_id":154},{"checkout_date":"2018-11-04","due_date":"2018-11-06","movie_id":57,"customer_id":161},{"checkout_date":"2018-11-01","due_date":"2018-11-18","movie_id":3,"customer_id":98},{"checkout_date":"2018-10-29","due_date":"2018-11-06","movie_id":69,"customer_id":199},{"checkout_date":"2018-10-30","due_date":"2018-11-14","movie_id":49,"customer_id":90},{"checkout_date":"2018-10-22","due_date":"2018-11-13","movie_id":67,"customer_id":183},{"checkout_date":"2018-10-28","due_date":"2018-11-19","movie_id":84,"customer_id":157},{"checkout_date":"2018-10-24","due_date":"2018-11-11","movie_id":43,"customer_id":1},{"checkout_date":"2018-10-22","due_date":"2018-11-19","movie_id":48,"customer_id":78},{"checkout_date":"2018-10-27","due_date":"2018-11-18","movie_id":6,"customer_id":179},{"checkout_date":"2018-10-29","due_date":"2018-11-11","movie_id":30,"customer_id":155},{"checkout_date":"2018-10-25","due_date":"2018-11-16","movie_id":12,"customer_id":85},{"checkout_date":"2018-10-24","due_date":"2018-11-12","movie_id":64,"customer_id":170},{"checkout_date":"2018-10-27","due_date":"2018-11-17","movie_id":41,"customer_id":81},{"checkout_date":"2018-11-04","due_date":"2018-11-09","movie_id":41,"customer_id":119},{"checkout_date":"2018-10-28","due_date":"2018-11-07","movie_id":82,"customer_id":26},{"checkout_date":"2018-10-28","due_date":"2018-11-07","movie_id":54,"customer_id":71},{"checkout_date":"2018-10-22","due_date":"2018-11-07","movie_id":11,"customer_id":147},{"checkout_date":"2018-11-04","due_date":"2018-11-11","movie_id":90,"customer_id":1},{"checkout_date":"2018-10-22","due_date":"2018-11-17","movie_id":17,"customer_id":146},{"checkout_date":"2018-10-22","due_date":"2018-11-10","movie_id":32,"customer_id":119},{"checkout_date":"2018-10-23","due_date":"2018-11-11","movie_id":60,"customer_id":60},{"checkout_date":"2018-10-29","due_date":"2018-11-11","movie_id":79,"customer_id":64},{"checkout_date":"2018-10-30","due_date":"2018-11-13","movie_id":70,"customer_id":95},{"checkout_date":"2018-10-25","due_date":"2018-11-13","movie_id":24,"customer_id":181},{"checkout_date":"2018-10-22","due_date":"2018-11-08","movie_id":72,"customer_id":93},{"checkout_date":"2018-10-22","due_date":"2018-11-09","movie_id":46,"customer_id":48},{"checkout_date":"2018-10-27","due_date":"2018-11-09","movie_id":43,"customer_id":28},{"checkout_date":"2018-10-23","due_date":"2018-11-16","movie_id":45,"customer_id":8},{"checkout_date":"2018-10-25","due_date":"2018-11-19","movie_id":65,"customer_id":76},{"checkout_date":"2018-10-22","due_date":"2018-11-08","movie_id":15,"customer_id":171},{"checkout_date":"2018-11-01","due_date":"2018-11-11","movie_id":26,"customer_id":53},{"checkout_date":"2018-10-22","due_date":"2018-11-07","movie_id":52,"customer_id":157},{"checkout_date":"2018-10-30","due_date":"2018-11-15","movie_id":72,"customer_id":72},{"checkout_date":"2018-10-22","due_date":"2018-11-16","movie_id":42,"customer_id":102},{"checkout_date":"2018-11-03","due_date":"2018-11-16","movie_id":54,"customer_id":144},{"checkout_date":"2018-11-01","due_date":"2018-11-19","movie_id":81,"customer_id":153},{"checkout_date":"2018-11-04","due_date":"2018-11-19","movie_id":66,"customer_id":67},{"checkout_date":"2018-10-25","due_date":"2018-11-14","movie_id":38,"customer_id":75}]
[{"checkout_date":"2018-10-27","due_date":"2018-11-14","movie_id":79,"customer_id":70},{"checkout_date":"2018-10-23","due_date":"2018-11-10","movie_id":35,"customer_id":56},{"checkout_date":"2018-11-03","due_date":"2018-11-14","movie_id":88,"customer_id":68},{"checkout_date":"2018-11-02","due_date":"2018-11-13","movie_id":4,"customer_id":196},{"checkout_date":"2018-10-27","due_date":"2018-11-08","movie_id":66,"customer_id":9},{"checkout_date":"2018-10-31","due_date":"2018-11-07","movie_id":82,"customer_id":152},{"checkout_date":"2018-10-26","due_date":"2018-11-13","movie_id":46,"customer_id":193},{"checkout_date":"2018-10-28","due_date":"2018-11-06","movie_id":11,"customer_id":15},{"checkout_date":"2018-11-02","due_date":"2018-11-09","movie_id":10,"customer_id":194},{"checkout_date":"2018-10-28","due_date":"2018-11-13","movie_id":50,"customer_id":123},{"checkout_date":"2018-10-23","due_date":"2018-11-14","movie_id":68,"customer_id":28},{"checkout_date":"2018-10-29","due_date":"2018-11-07","movie_id":44,"customer_id":154},{"checkout_date":"2018-11-04","due_date":"2018-11-06","movie_id":57,"customer_id":161},{"checkout_date":"2018-11-01","due_date":"2018-11-18","movie_id":3,"customer_id":98},{"checkout_date":"2018-10-29","due_date":"2018-11-06","movie_id":69,"customer_id":199},{"checkout_date":"2018-10-30","due_date":"2018-11-14","movie_id":49,"customer_id":90},{"checkout_date":"2018-10-22","due_date":"2018-11-13","movie_id":67,"customer_id":183},{"checkout_date":"2018-10-28","due_date":"2018-11-19","movie_id":84,"customer_id":157},{"checkout_date":"2018-10-24","due_date":"2018-11-11","movie_id":43,"customer_id":1},{"checkout_date":"2018-10-22","due_date":"2018-11-19","movie_id":48,"customer_id":78},{"checkout_date":"2018-10-27","due_date":"2018-11-18","movie_id":6,"customer_id":179},{"checkout_date":"2018-10-29","due_date":"2018-11-11","movie_id":30,"customer_id":155},{"checkout_date":"2018-10-25","due_date":"2018-11-16","movie_id":12,"customer_id":85},{"checkout_date":"2018-10-24","due_date":"2018-11-12","movie_id":64,"customer_id":170},{"checkout_date":"2018-10-27","due_date":"2018-11-17","movie_id":41,"customer_id":81},{"checkout_date":"2018-11-04","due_date":"2018-11-09","movie_id":41,"customer_id":119},{"checkout_date":"2018-10-28","due_date":"2018-11-07","movie_id":82,"customer_id":26},{"checkout_date":"2018-10-28","due_date":"2018-11-07","movie_id":54,"customer_id":71},{"checkout_date":"2018-10-22","due_date":"2018-11-07","movie_id":11,"customer_id":147},{"checkout_date":"2018-11-04","due_date":"2018-11-11","movie_id":90,"customer_id":1},{"checkout_date":"2018-10-22","due_date":"2018-11-17","movie_id":17,"customer_id":146},{"checkout_date":"2018-10-22","due_date":"2018-11-10","movie_id":32,"customer_id":119},{"checkout_date":"2018-10-23","due_date":"2018-11-11","movie_id":60,"customer_id":60},{"checkout_date":"2018-10-29","due_date":"2018-11-11","movie_id":79,"customer_id":64},{"checkout_date":"2018-10-30","due_date":"2018-11-13","movie_id":70,"customer_id":95},{"checkout_date":"2018-10-25","due_date":"2018-11-13","movie_id":24,"customer_id":181},{"checkout_date":"2018-10-22","due_date":"2018-11-08","movie_id":72,"customer_id":93},{"checkout_date":"2018-10-22","due_date":"2018-11-09","movie_id":46,"customer_id":48},{"checkout_date":"2018-10-27","due_date":"2018-11-09","movie_id":43,"customer_id":28},{"checkout_date":"2018-10-23","due_date":"2018-11-16","movie_id":45,"customer_id":8},{"checkout_date":"2018-10-25","due_date":"2018-11-19","movie_id":65,"customer_id":76},{"checkout_date":"2018-10-22","due_date":"2018-11-08","movie_id":15,"customer_id":171},{"checkout_date":"2018-11-01","due_date":"2018-11-11","movie_id":26,"customer_id":53},{"checkout_date":"2018-10-22","due_date":"2018-11-07","movie_id":52,"customer_id":157},{"checkout_date":"2018-10-30","due_date":"2018-11-15","movie_id":72,"customer_id":72},{"checkout_date":"2018-10-22","due_date":"2018-11-16","movie_id":42,"customer_id":102},{"checkout_date":"2018-11-03","due_date":"2018-11-16","movie_id":54,"customer_id":144},{"checkout_date":"2018-11-01","due_date":"2018-11-19","movie_id":81,"customer_id":153},{"checkout_date":"2018-11-04","due_date":"2018-11-19","movie_id":66,"customer_id":67},{"checkout_date":"2018-10-25","due_date":"2018-11-14","movie_id":38,"customer_id":75}]
21 changes: 19 additions & 2 deletions test/controllers/customers_controller_test.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,29 @@
require 'test_helper'

class CustomersControllerTest < ActionDispatch::IntegrationTest
describe CustomersController do
CUSTOMER_FIELDS = %w(name registered_at address city state postal_code phone).sort

def parse_body(expected_type:, expected_status: :success)
must_respond_with expected_status

expect(response.header['Content-Type']).must_include 'json'
body = JSON.parse(response.body)

expect(body).must_be_kind_of expected_type
return body
end

describe "index" do

it "successfully gets list of customers" do
get customers_path
must_respond_with :success

body = parse_body(expected_type: Array)

body.each do |customer|

expect(customer.keys.sort).must_equal CUSTOMER_FIELDS
end
end

end
Expand Down
85 changes: 75 additions & 10 deletions test/controllers/movies_controller_test.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,39 @@
require 'test_helper'

class MoviesControllerTest < ActionDispatch::IntegrationTest
describe MoviesController do
MOVIE_FIELDS = %w(title overview release_date inventory).sort

def parse_body(expected_type:, expected_status: :success)
must_respond_with expected_status

expect(response.header['Content-Type']).must_include 'json'
body = JSON.parse(response.body)

expect(body).must_be_kind_of expected_type
return body
end

describe "index" do

it "successfully gets list of movies" do
get movies_path
must_respond_with :success

body = parse_body(expected_type: Array)

body.each do |movie|
expect(movie.keys.sort).must_equal MOVIE_FIELDS
end
end

it "returns an empty array when there are no movies" do
Movie.destroy_all

get movies_path

body = parse_body(expected_type: Array)

expect(body).must_equal []
end
end

describe "show" do
Expand All @@ -19,24 +44,64 @@ class MoviesControllerTest < ActionDispatch::IntegrationTest
it "successfully returns valid movie" do

get movie_path(movie.id)
must_respond_with :success

body = parse_body(expected_type: Hash)
expect(body.keys.sort).must_equal MOVIE_FIELDS
end

it 'does not successfully return if invalid movie'
it 'does not successfully return if invalid movie' do

movie.destroy

get movie_path(movie.id)
must_respond_with :not_found

body = parse_body(expected_type: Hash, expected_status: :not_found)

expect(body).must_include "errors"
end

describe "create" do
describe "create" do

it "successfully creates a new movie" do
let (:movie_data) {
{
movie: {
title: "test movie",
inventory: 10
}
}
}


it "successfully creates a new movie" do
expect {
post movies_path, params: movie_data
}.must_change('Movie.count', +1)

end
body = parse_body(expected_type: Hash)

expect(body).must_include "id"

movie = Movie.find(body["id"].to_i)

expect(movie.title).must_equal movie_data[:movie][:title]


end

it 'does not successfully return if invalid'
it 'does not successfully return if invalid' do

movie_data[:movie][:title] = nil

expect {
post movies_path, params: movie_data
}.wont_change('Movie.count')

body = parse_body(expected_type: Hash, expected_status: :bad_request)

expect(body).must_include "errors"
expect(body["errors"]).must_include "title"

end

end
end
end