From 6778ed4a5467fb8a9ad584888d7513fa5267e866 Mon Sep 17 00:00:00 2001 From: xLJohnsonx Date: Mon, 5 Nov 2018 12:41:50 -0800 Subject: [PATCH 01/62] rails api setup, customer, rental, movie models created --- .DS_Store | Bin 0 -> 6148 bytes .gitignore | 23 +++ .idea/VideoStoreAPI.iml | 71 +++++++ .idea/misc.xml | 7 + .idea/modules.xml | 8 + .idea/vcs.xml | 6 + .idea/workspace.xml | 174 ++++++++++++++++++ .ruby-version | 1 + Gemfile | 54 ++++++ Gemfile.lock | 169 +++++++++++++++++ Guardfile | 9 + Rakefile | 6 + app/channels/application_cable/channel.rb | 4 + app/channels/application_cable/connection.rb | 4 + app/controllers/application_controller.rb | 2 + app/controllers/concerns/.keep | 0 app/jobs/application_job.rb | 2 + app/mailers/application_mailer.rb | 4 + app/models/application_record.rb | 3 + app/models/concerns/.keep | 0 app/models/customer.rb | 2 + app/models/movie.rb | 2 + app/models/rental.rb | 2 + app/views/layouts/mailer.html.erb | 13 ++ app/views/layouts/mailer.text.erb | 1 + bin/bundle | 3 + bin/rails | 9 + bin/rake | 9 + bin/setup | 33 ++++ bin/spring | 17 ++ bin/update | 28 +++ config.ru | 5 + config/application.rb | 41 +++++ config/boot.rb | 4 + config/cable.yml | 10 + config/credentials.yml.enc | 1 + config/database.yml | 85 +++++++++ config/environment.rb | 5 + config/environments/development.rb | 54 ++++++ config/environments/production.rb | 85 +++++++++ config/environments/test.rb | 46 +++++ .../application_controller_renderer.rb | 8 + config/initializers/backtrace_silencers.rb | 7 + config/initializers/cors.rb | 16 ++ .../initializers/filter_parameter_logging.rb | 4 + config/initializers/inflections.rb | 16 ++ config/initializers/mime_types.rb | 4 + config/initializers/wrap_parameters.rb | 14 ++ config/locales/en.yml | 33 ++++ config/puma.rb | 34 ++++ config/routes.rb | 3 + config/spring.rb | 6 + config/storage.yml | 34 ++++ db/migrate/20181105203219_create_customers.rb | 15 ++ db/migrate/20181105203750_create_rentals.rb | 11 ++ db/migrate/20181105203957_create_movies.rb | 12 ++ lib/tasks/.keep | 0 log/.keep | 0 public/robots.txt | 1 + storage/.keep | 0 test/controllers/.keep | 0 test/fixtures/.keep | 0 test/fixtures/customers.yml | 19 ++ test/fixtures/files/.keep | 0 test/fixtures/movies.yml | 13 ++ test/fixtures/rentals.yml | 11 ++ test/integration/.keep | 0 test/mailers/.keep | 0 test/models/.keep | 0 test/models/customer_test.rb | 9 + test/models/movie_test.rb | 9 + test/models/rental_test.rb | 9 + test/test_helper.rb | 24 +++ tmp/.keep | 0 vendor/.keep | 0 75 files changed, 1314 insertions(+) create mode 100644 .DS_Store create mode 100644 .gitignore create mode 100644 .idea/VideoStoreAPI.iml create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/vcs.xml create mode 100644 .idea/workspace.xml create mode 100644 .ruby-version create mode 100644 Gemfile create mode 100644 Gemfile.lock create mode 100644 Guardfile create mode 100644 Rakefile create mode 100644 app/channels/application_cable/channel.rb create mode 100644 app/channels/application_cable/connection.rb create mode 100644 app/controllers/application_controller.rb create mode 100644 app/controllers/concerns/.keep create mode 100644 app/jobs/application_job.rb create mode 100644 app/mailers/application_mailer.rb create mode 100644 app/models/application_record.rb create mode 100644 app/models/concerns/.keep create mode 100644 app/models/customer.rb create mode 100644 app/models/movie.rb create mode 100644 app/models/rental.rb create mode 100644 app/views/layouts/mailer.html.erb create mode 100644 app/views/layouts/mailer.text.erb create mode 100755 bin/bundle create mode 100755 bin/rails create mode 100755 bin/rake create mode 100755 bin/setup create mode 100755 bin/spring create mode 100755 bin/update create mode 100644 config.ru create mode 100644 config/application.rb create mode 100644 config/boot.rb create mode 100644 config/cable.yml create mode 100644 config/credentials.yml.enc create mode 100644 config/database.yml create mode 100644 config/environment.rb create mode 100644 config/environments/development.rb create mode 100644 config/environments/production.rb create mode 100644 config/environments/test.rb create mode 100644 config/initializers/application_controller_renderer.rb create mode 100644 config/initializers/backtrace_silencers.rb create mode 100644 config/initializers/cors.rb create mode 100644 config/initializers/filter_parameter_logging.rb create mode 100644 config/initializers/inflections.rb create mode 100644 config/initializers/mime_types.rb create mode 100644 config/initializers/wrap_parameters.rb create mode 100644 config/locales/en.yml create mode 100644 config/puma.rb create mode 100644 config/routes.rb create mode 100644 config/spring.rb create mode 100644 config/storage.yml create mode 100644 db/migrate/20181105203219_create_customers.rb create mode 100644 db/migrate/20181105203750_create_rentals.rb create mode 100644 db/migrate/20181105203957_create_movies.rb create mode 100644 lib/tasks/.keep create mode 100644 log/.keep create mode 100644 public/robots.txt create mode 100644 storage/.keep create mode 100644 test/controllers/.keep create mode 100644 test/fixtures/.keep create mode 100644 test/fixtures/customers.yml create mode 100644 test/fixtures/files/.keep create mode 100644 test/fixtures/movies.yml create mode 100644 test/fixtures/rentals.yml create mode 100644 test/integration/.keep create mode 100644 test/mailers/.keep create mode 100644 test/models/.keep create mode 100644 test/models/customer_test.rb create mode 100644 test/models/movie_test.rb create mode 100644 test/models/rental_test.rb create mode 100644 test/test_helper.rb create mode 100644 tmp/.keep create mode 100644 vendor/.keep diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..1ce14b06bd8e8a2f8083a5dbb7792cc0c0f1681a GIT binary patch literal 6148 zcmeH~JqiLr422WjLa^D=avBfd4F=H@cmdJ16D-tzj_%73f~&QNyg>3zG82}4#m+`V zbbTLIBE5*r;6_}#|6BN{`G3^HlnPLRKT|-v z&2F>COXc1A_Ig&|XVumX4*GF~m!AM6b`>w+ZrCrj0Bf=ZQGxMCz-3^d0$)|&0hY}Y A!vFvP literal 0 HcmV?d00001 diff --git a/.gitignore b/.gitignore new file mode 100644 index 000000000..ea4b32f59 --- /dev/null +++ b/.gitignore @@ -0,0 +1,23 @@ +# See https://help.github.com/articles/ignoring-files for more about ignoring files. +# +# If you find yourself ignoring temporary files generated by your text editor +# or operating system, you probably want to add a global ignore instead: +# git config --global core.excludesfile '~/.gitignore_global' + +# Ignore bundler config. +/.bundle + +# Ignore all logfiles and tempfiles. +/log/* +/tmp/* +!/log/.keep +!/tmp/.keep + +# Ignore uploaded files in development +/storage/* +!/storage/.keep + +.byebug_history + +# Ignore master key for decrypting credentials and more. +/config/master.key diff --git a/.idea/VideoStoreAPI.iml b/.idea/VideoStoreAPI.iml new file mode 100644 index 000000000..3801824ba --- /dev/null +++ b/.idea/VideoStoreAPI.iml @@ -0,0 +1,71 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 000000000..18d9fdb1d --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,7 @@ + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 000000000..20562e841 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 000000000..94a25f7f4 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml new file mode 100644 index 000000000..3e8ecf172 --- /dev/null +++ b/.idea/workspace.xml @@ -0,0 +1,174 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + true + DEFINITION_ORDER + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -123,23 +252,24 @@ - - + + - + - + @@ -170,5 +300,72 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/models/customer.rb b/app/models/customer.rb index 0b5277335..4a5df9882 100644 --- a/app/models/customer.rb +++ b/app/models/customer.rb @@ -1,2 +1,5 @@ class Customer < ApplicationRecord + has_many :rentals + has_many :movies, :through => rentals + end diff --git a/app/models/movie.rb b/app/models/movie.rb index dc614df15..61a627836 100644 --- a/app/models/movie.rb +++ b/app/models/movie.rb @@ -1,2 +1,5 @@ class Movie < ApplicationRecord + has_many :rentals + has_many :customers, :through => rentals + end diff --git a/app/models/rental.rb b/app/models/rental.rb index 79e3a65ca..8d754d5b7 100644 --- a/app/models/rental.rb +++ b/app/models/rental.rb @@ -1,2 +1,6 @@ class Rental < ApplicationRecord + belongs_to :customer + belongs_to :movie + + end diff --git a/db/migrate/20181105203219_create_customers.rb b/db/migrate/20181105203219_create_customers.rb index 4008e1462..48cb222bf 100644 --- a/db/migrate/20181105203219_create_customers.rb +++ b/db/migrate/20181105203219_create_customers.rb @@ -3,7 +3,7 @@ def change create_table :customers do |t| t.string :name t.datetime :registered_at - t.stringcity :address + t.string :address t.string :state t.string :postal_code t.string :phone diff --git a/db/migrate/20181105204725_fix_address_cols.rb b/db/migrate/20181105204725_fix_address_cols.rb new file mode 100644 index 000000000..3bfe7248d --- /dev/null +++ b/db/migrate/20181105204725_fix_address_cols.rb @@ -0,0 +1,6 @@ +class FixAddressCols < ActiveRecord::Migration[5.2] + def change + add_column :customers, :city, :string + + end +end diff --git a/db/migrate/20181105205256_add_refs_to_rental.rb b/db/migrate/20181105205256_add_refs_to_rental.rb new file mode 100644 index 000000000..5110bae28 --- /dev/null +++ b/db/migrate/20181105205256_add_refs_to_rental.rb @@ -0,0 +1,6 @@ +class AddRefsToRental < ActiveRecord::Migration[5.2] + def change + add_column :rentals, :customer_id, :integer + add_column :rentals, :movie_id, :integer + end +end diff --git a/db/migrate/20181105205609_rm_refs_rentals.rb b/db/migrate/20181105205609_rm_refs_rentals.rb new file mode 100644 index 000000000..ed07d7fe1 --- /dev/null +++ b/db/migrate/20181105205609_rm_refs_rentals.rb @@ -0,0 +1,6 @@ +class RmRefsRentals < ActiveRecord::Migration[5.2] + def change + remove_column :rentals, :customer_id + remove_column :rentals, :movie_id + end +end diff --git a/db/migrate/20181105205816_add_refs_to_rental_proper_way.rb b/db/migrate/20181105205816_add_refs_to_rental_proper_way.rb new file mode 100644 index 000000000..bc6481faf --- /dev/null +++ b/db/migrate/20181105205816_add_refs_to_rental_proper_way.rb @@ -0,0 +1,8 @@ +class AddRefsToRentalProperWay < ActiveRecord::Migration[5.2] + def change + add_column :rentals, :customer_id, :integer + add_column :rentals, :movie_id, :integer + add_foreign_key :rentals, :customers + add_foreign_key :rentals, :movies + end +end diff --git a/db/schema.rb b/db/schema.rb new file mode 100644 index 000000000..5911e50ed --- /dev/null +++ b/db/schema.rb @@ -0,0 +1,52 @@ +# This file is auto-generated from the current state of the database. Instead +# of editing this file, please use the migrations feature of Active Record to +# incrementally modify your database, and then regenerate this schema definition. +# +# Note that this schema.rb definition is the authoritative source for your +# database schema. If you need to create the application database on another +# system, you should be using db:schema:load, not running all the migrations +# from scratch. The latter is a flawed and unsustainable approach (the more migrations +# you'll amass, the slower it'll run and the greater likelihood for issues). +# +# It's strongly recommended that you check this file into your version control system. + +ActiveRecord::Schema.define(version: 2018_11_05_205816) do + + # These are extensions that must be enabled in order to support this database + enable_extension "plpgsql" + + create_table "customers", force: :cascade do |t| + t.string "name" + t.datetime "registered_at" + t.string "address" + t.string "state" + t.string "postal_code" + t.string "phone" + t.integer "movies_out_count" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.string "city" + end + + create_table "movies", force: :cascade do |t| + t.string "title" + t.string "overview" + t.date "release_date" + t.integer "inventory" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + + create_table "rentals", force: :cascade do |t| + t.date "checkout_date" + t.date "checkin_date" + t.date "due_date" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.integer "customer_id" + t.integer "movie_id" + end + + add_foreign_key "rentals", "customers" + add_foreign_key "rentals", "movies" +end From b2ad5e05a525763183d559b953322b829d13bf1f Mon Sep 17 00:00:00 2001 From: xLJohnsonx Date: Mon, 5 Nov 2018 13:16:17 -0800 Subject: [PATCH 03/62] customers, movies, rentals, controllers all added --- .idea/workspace.xml | 73 ++++++++++++------- app/controllers/customers_controller.rb | 4 + app/controllers/movies_controller.rb | 13 ++++ app/controllers/rentals_controller.rb | 14 ++++ config/routes.rb | 12 +++ test/controllers/customers_controller_test.rb | 9 +++ test/controllers/movies_controller_test.rb | 24 ++++++ test/controllers/rentals_controller_test.rb | 19 +++++ 8 files changed, 141 insertions(+), 27 deletions(-) create mode 100644 app/controllers/customers_controller.rb create mode 100644 app/controllers/movies_controller.rb create mode 100644 app/controllers/rentals_controller.rb create mode 100644 test/controllers/customers_controller_test.rb create mode 100644 test/controllers/movies_controller_test.rb create mode 100644 test/controllers/rentals_controller_test.rb diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 5e1d1406e..85e9d4611 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -2,10 +2,14 @@ - - - - + + + + + + + + - - - - - - - - - @@ -86,7 +81,16 @@ - + + + + + + + + + + @@ -99,7 +103,7 @@ - + @@ -143,6 +147,7 @@ @@ -252,19 +257,19 @@ \ No newline at end of file diff --git a/app/controllers/customers_controller.rb b/app/controllers/customers_controller.rb new file mode 100644 index 000000000..73302240c --- /dev/null +++ b/app/controllers/customers_controller.rb @@ -0,0 +1,4 @@ +class CustomersController < ApplicationController + def index + end +end diff --git a/app/controllers/movies_controller.rb b/app/controllers/movies_controller.rb new file mode 100644 index 000000000..8103f2c3c --- /dev/null +++ b/app/controllers/movies_controller.rb @@ -0,0 +1,13 @@ +class MoviesController < ApplicationController + def show + end + + def index + end + + def create + end + + def update + end +end diff --git a/app/controllers/rentals_controller.rb b/app/controllers/rentals_controller.rb new file mode 100644 index 000000000..133d9384a --- /dev/null +++ b/app/controllers/rentals_controller.rb @@ -0,0 +1,14 @@ +class RentalsController < ApplicationController + def index + end + + def show + end + + def update + end + + def zomg + render json: {message: "it_works"} + end +end diff --git a/config/routes.rb b/config/routes.rb index 787824f88..40d258489 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,3 +1,15 @@ Rails.application.routes.draw do + get 'customers/index' + get 'movies/show' + get 'movies/index' + get 'movies/create' + get 'movies/update' + get 'rentals/index' + get 'rentals/show' + get 'rentals/update' + get 'customer/index' + get 'customer/show' + get 'customer/create' + get 'customer/destroy' # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html end diff --git a/test/controllers/customers_controller_test.rb b/test/controllers/customers_controller_test.rb new file mode 100644 index 000000000..c5ec6f20b --- /dev/null +++ b/test/controllers/customers_controller_test.rb @@ -0,0 +1,9 @@ +require "test_helper" + +describe CustomersController do + it "should get index" do + get customers_index_url + value(response).must_be :success? + end + +end diff --git a/test/controllers/movies_controller_test.rb b/test/controllers/movies_controller_test.rb new file mode 100644 index 000000000..3f55dec0d --- /dev/null +++ b/test/controllers/movies_controller_test.rb @@ -0,0 +1,24 @@ +require "test_helper" + +describe MoviesController do + it "should get show" do + get movies_show_url + value(response).must_be :success? + end + + it "should get index" do + get movies_index_url + value(response).must_be :success? + end + + it "should get create" do + get movies_create_url + value(response).must_be :success? + end + + it "should get update" do + get movies_update_url + value(response).must_be :success? + end + +end diff --git a/test/controllers/rentals_controller_test.rb b/test/controllers/rentals_controller_test.rb new file mode 100644 index 000000000..6443455e4 --- /dev/null +++ b/test/controllers/rentals_controller_test.rb @@ -0,0 +1,19 @@ +require "test_helper" + +describe RentalsController do + it "should get index" do + get rentals_index_url + value(response).must_be :success? + end + + it "should get show" do + get rentals_show_url + value(response).must_be :success? + end + + it "should get update" do + get rentals_update_url + value(response).must_be :success? + end + +end From dea6384f199a73ea04393c8b371d7bfccb7ee75e Mon Sep 17 00:00:00 2001 From: xLJohnsonx Date: Mon, 5 Nov 2018 13:23:33 -0800 Subject: [PATCH 04/62] cleaned up controller actions layout --- .idea/workspace.xml | 81 +++++++++++++++---------- app/controllers/customers_controller.rb | 1 + app/controllers/movies_controller.rb | 5 ++ app/controllers/rentals_controller.rb | 23 ++++++- 4 files changed, 75 insertions(+), 35 deletions(-) diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 85e9d4611..5955ef846 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -2,14 +2,9 @@ - - - - - - - - + + + - - - - - - - - - @@ -85,11 +71,29 @@ - + - - + + + + + + + + + + + + + + + + + + + + @@ -121,11 +125,6 @@ - - - - - @@ -148,6 +147,8 @@ @@ -257,12 +258,12 @@ - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -296,17 +357,17 @@ - + - - + + - + @@ -325,9 +386,67 @@ - + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -336,13 +455,19 @@ - - + + + + + - - + + + + + @@ -358,54 +483,65 @@ - - + + + + + - - + + - - + + - - + + - - + + - - + + - - + + + + + + + + - - + - + - - - - - - - - - - - - + + + + + + + + + + + + + @@ -468,13 +604,6 @@ - - - - - - - @@ -523,72 +652,83 @@ + + + + + + + - - + + - + - - + + - + - - + + - + - + - - - - - + + + + + + - - + + - + - - + + - + + + + - - + + - + - - + + - + - - + + diff --git a/Gemfile b/Gemfile index 46b4757ff..815e33590 100644 --- a/Gemfile +++ b/Gemfile @@ -51,6 +51,6 @@ end group :test do gem 'minitest-rails' gem 'minitest-reporters' - gem 'shoulda' - gem 'shoulda-matchers' + # gem 'shoulda', '~> 3.5' + # gem 'shoulda-matchers', '~> 2.0' end diff --git a/Gemfile.lock b/Gemfile.lock index eede95470..6ce785ca6 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -125,12 +125,6 @@ GEM ffi (>= 0.5.0, < 2) ruby-progressbar (1.10.0) ruby_dep (1.5.0) - shoulda (3.6.0) - shoulda-context (~> 1.0, >= 1.0.1) - shoulda-matchers (~> 3.0) - shoulda-context (1.2.2) - shoulda-matchers (3.1.2) - activesupport (>= 4.0.0) spring (2.0.2) activesupport (>= 4.2) spring-watcher-listen (2.0.1) @@ -164,8 +158,6 @@ DEPENDENCIES pry-rails puma (~> 3.11) rails (~> 5.2.1) - shoulda - shoulda-matchers spring spring-watcher-listen (~> 2.0.0) tzinfo-data diff --git a/README.md b/README.md index 53ab809c5..50db07891 100644 --- a/README.md +++ b/README.md @@ -308,4 +308,4 @@ Fields to return: ## What We're Looking For -Check the [feedback template](./feedback.md) to see how we will evaluate your project. +Check the [feedback template](feedback.md) to see how we will evaluate your project. diff --git a/app/controllers/rentals_controller.rb b/app/controllers/rentals_controller.rb index 5a828c0f3..a82032cc4 100644 --- a/app/controllers/rentals_controller.rb +++ b/app/controllers/rentals_controller.rb @@ -1,4 +1,5 @@ class RentalsController < ApplicationController + protect_from_forgery with: :null_session # GET RENTALS def index diff --git a/test/fixtures/movies.yml b/test/fixtures/movies.yml index d2dc57812..26ed209bc 100644 --- a/test/fixtures/movies.yml +++ b/test/fixtures/movies.yml @@ -13,3 +13,11 @@ movie_in: release_date: 2018-11-05 inventory: 1 inventory_available: 1 + + +movie_out3: + title: MyString + overview: MyString + release_date: 2018-11-05 + inventory: 5 + inventory_available: 3 \ No newline at end of file diff --git a/test/fixtures/rentals.yml b/test/fixtures/rentals.yml index 5653f36b2..3de95125d 100644 --- a/test/fixtures/rentals.yml +++ b/test/fixtures/rentals.yml @@ -13,3 +13,17 @@ rental_in: due_date: 2018-11-10 movie: movie_in customer: customer_in + +rental_out2: + checkout_date: 2018-11-05 + checkin_date: + due_date: 2018-11-10 + movie: movie_out3 + customer: customer_out + +rental_out3: + checkout_date: 2018-11-05 + checkin_date: + due_date: 2018-11-10 + movie: movie_out3 + customer: customer_out \ No newline at end of file diff --git a/test/models/customer_test.rb b/test/models/customer_test.rb index c447b5eeb..63ff0ce83 100644 --- a/test/models/customer_test.rb +++ b/test/models/customer_test.rb @@ -27,12 +27,23 @@ end describe 'relationships' do + let(:cust) { customers(:customer_out) } it 'can have many rentals' do + rents = cust.rentals + expect(rents.length).must_be :>, 1 + rents.each do |r| + expect(r).must_be_instance_of Rental + end end - it 'has many movies through rentals' do - + it 'can have many movies through rentals' do + movies = cust.movies + # binding.pry + expect(movies.length).must_be :>, 1 + movies.each do |m| + expect(m).must_be_instance_of Movie + end end diff --git a/test/models/movie_test.rb b/test/models/movie_test.rb index 4a631fe85..0257158e2 100644 --- a/test/models/movie_test.rb +++ b/test/models/movie_test.rb @@ -1,8 +1,6 @@ require "test_helper" describe Movie do - - describe 'Validations' do let (:movie) { Movie.new(title: "valid movie", overview: "overview", @@ -31,11 +29,24 @@ end end - it 'belongs to movie' do + describe 'relationships' do + let(:mov) { movies(:movie_out3) } - end + it 'has many rentals' do + rents = mov.rentals - it 'belongs to customer' do + expect(rents.length).must_be :>, 1 + rents.each do |r| + expect(r).must_be_instance_of Rental + end + end + it 'has many customers through rental' do + custs = mov.customers + expect(custs.length).must_be :>, 1 + custs.each do |c| + expect(c).must_be_instance_of Customer + end + end end end diff --git a/test/models/rental_test.rb b/test/models/rental_test.rb index e84828e10..101dc42eb 100644 --- a/test/models/rental_test.rb +++ b/test/models/rental_test.rb @@ -1,17 +1,29 @@ require "test_helper" -describe Rental do +describe Rental do + describe 'relationships' do + let(:rental) { rentals(:rental_in) } + it 'belongs to a customer' do + # Arrange (done with let) - describe 'relationships' do - it 'has customers' do + # Act + customer = rental.customer + # Assert + expect(customer).must_be_instance_of Customer + expect(customer.id).must_equal rental.customer_id end - # - # it 'has many movies' do - # should have_many(:movies) - # end + it 'belongs to a movie' do + # Arrange (done with let) + # Act + movie = rental.movie + + # Assert + expect(movie).must_be_instance_of Movie + expect(movie.id).must_equal rental.movie_id + end end end diff --git a/test/test_helper.rb b/test/test_helper.rb index 10594a324..556cc10b2 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -23,4 +23,5 @@ class ActiveSupport::TestCase # Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical order. fixtures :all # Add more helper methods to be used by all tests here... + end From ab3450d04daf796191f9f13fa7049204f1d0f586 Mon Sep 17 00:00:00 2001 From: xLJohnsonx Date: Tue, 6 Nov 2018 09:49:37 -0800 Subject: [PATCH 18/62] added rabl gem --- .gitignore | 1 + .idea/workspace.xml | 116 ++++++++++++++++++++++---------------------- Gemfile | 2 +- Gemfile.lock | 3 ++ 4 files changed, 64 insertions(+), 58 deletions(-) diff --git a/.gitignore b/.gitignore index 584a5efa8..da46f7f04 100644 --- a/.gitignore +++ b/.gitignore @@ -22,3 +22,4 @@ # Ignore master key for decrypting credentials and more. /config/master.key .idea +.idea diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 1cf5691aa..7e5e9087e 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -2,18 +2,8 @@ - - - - - - - - - - @@ -75,31 +65,34 @@ - - + + + + - + + - + @@ -114,8 +107,8 @@ - - + + @@ -123,11 +116,11 @@ - + - + @@ -138,25 +131,34 @@ - + - + - + - + + + + + + + + + + @@ -166,7 +168,7 @@ - + @@ -201,13 +203,13 @@ @@ -218,10 +220,9 @@ DEFINITION_ORDER - @@ -483,14 +484,12 @@ - - - @@ -518,21 +517,24 @@ + + + - - + - + - + @@ -540,7 +542,7 @@ - + @@ -659,13 +661,6 @@ - - - - - - - @@ -696,39 +691,46 @@ - - + + - + - - + + + + + + + + + - + - - + + - + - + - - + + diff --git a/Gemfile b/Gemfile index 815e33590..a315c7c79 100644 --- a/Gemfile +++ b/Gemfile @@ -21,7 +21,7 @@ gem 'puma', '~> 3.11' # Use Capistrano for deployment # gem 'capistrano-rails', group: :development - +gem 'rabl' # Reduces boot times through caching; required in config/boot.rb gem 'bootsnap', '>= 1.1.0', require: false diff --git a/Gemfile.lock b/Gemfile.lock index 6ce785ca6..b95b46a62 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -92,6 +92,8 @@ GEM pry-rails (0.3.6) pry (>= 0.10.4) puma (3.12.0) + rabl (0.14.0) + activesupport (>= 2.3.14) rack (2.0.6) rack-test (1.1.0) rack (>= 1.0, < 3) @@ -157,6 +159,7 @@ DEPENDENCIES pg (>= 0.18, < 2.0) pry-rails puma (~> 3.11) + rabl rails (~> 5.2.1) spring spring-watcher-listen (~> 2.0.0) From 1f7c8dd6260f151054f76971c1543e27269ef52f Mon Sep 17 00:00:00 2001 From: Sammi-Jo Lee Date: Tue, 6 Nov 2018 11:01:29 -0800 Subject: [PATCH 19/62] Set up rabl for Customers index and show --- Gemfile | 1 + Gemfile.lock | 3 +++ app/controllers/rentals_controller.rb | 4 +--- app/views/customers/index.html.erb | 1 + app/views/customers/index.json.rabl | 3 +++ app/views/customers/show.json.rabl | 17 +++++++++++++++++ config/initializers/rabl_config.rb | 5 +++++ 7 files changed, 31 insertions(+), 3 deletions(-) create mode 100644 app/views/customers/index.html.erb create mode 100644 app/views/customers/index.json.rabl create mode 100644 app/views/customers/show.json.rabl create mode 100644 config/initializers/rabl_config.rb diff --git a/Gemfile b/Gemfile index 6a2f75432..6776ca983 100644 --- a/Gemfile +++ b/Gemfile @@ -2,6 +2,7 @@ source 'https://rubygems.org' git_source(:github) { |repo| "https://github.com/#{repo}.git" } ruby '2.5.1' +gem 'rabl' # Bundle edge Rails instead: gem 'rails', github: 'rails/rails' gem 'rails', '~> 5.2.1' diff --git a/Gemfile.lock b/Gemfile.lock index d77184d71..010f16c9f 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -94,6 +94,8 @@ GEM pry-rails (0.3.6) pry (>= 0.10.4) puma (3.12.0) + rabl (0.14.0) + activesupport (>= 2.3.14) rack (2.0.6) rack-test (1.1.0) rack (>= 1.0, < 3) @@ -164,6 +166,7 @@ DEPENDENCIES pg (>= 0.18, < 2.0) pry-rails puma (~> 3.11) + rabl rails (~> 5.2.1) simplecov spring diff --git a/app/controllers/rentals_controller.rb b/app/controllers/rentals_controller.rb index dbf1c7cc1..a43f5e19c 100644 --- a/app/controllers/rentals_controller.rb +++ b/app/controllers/rentals_controller.rb @@ -1,6 +1,6 @@ class RentalsController < ApplicationController protect_from_forgery with: :null_session - + # GET RENTALS def index end @@ -9,7 +9,6 @@ def index def show end - # GET RENTALS def zomg render json: {message: "it_works"} @@ -19,7 +18,6 @@ def zomg def update end - # POST RENTALS def check_out diff --git a/app/views/customers/index.html.erb b/app/views/customers/index.html.erb new file mode 100644 index 000000000..d453b15f5 --- /dev/null +++ b/app/views/customers/index.html.erb @@ -0,0 +1 @@ +
"> diff --git a/app/views/customers/index.json.rabl b/app/views/customers/index.json.rabl new file mode 100644 index 000000000..233e685d4 --- /dev/null +++ b/app/views/customers/index.json.rabl @@ -0,0 +1,3 @@ +collection @customers + +extends "customers/show" diff --git a/app/views/customers/show.json.rabl b/app/views/customers/show.json.rabl new file mode 100644 index 000000000..69560a3b2 --- /dev/null +++ b/app/views/customers/show.json.rabl @@ -0,0 +1,17 @@ +object @customer + +# object @article +# attributes :id, :name, :published_at +# +# if current_user.admin? +# node(:edit_url) { |article| edit_article_url(article) } +# end +# +# child :author do +# attributes :id, :name +# node(:url) { |author| author_url(author) } +# end +# +# child :comments do +# attributes :id, :name, :content +# end diff --git a/config/initializers/rabl_config.rb b/config/initializers/rabl_config.rb new file mode 100644 index 000000000..d2a0095bd --- /dev/null +++ b/config/initializers/rabl_config.rb @@ -0,0 +1,5 @@ +# Be sure to restart your server when you modify this file. + +Rabl.configure do |config| + config.include_json_root = false +end From 86eda1000844cd458102334e1685557e615fded9 Mon Sep 17 00:00:00 2001 From: xLJohnsonx Date: Tue, 6 Nov 2018 11:02:43 -0800 Subject: [PATCH 20/62] added api testing for movies controller --- .gitignore | 1 + .idea/workspace.xml | 225 ++++++++++++--------- test/controllers/movies_controller_test.rb | 53 +++++ 3 files changed, 183 insertions(+), 96 deletions(-) diff --git a/.gitignore b/.gitignore index ea4b32f59..584a5efa8 100644 --- a/.gitignore +++ b/.gitignore @@ -21,3 +21,4 @@ # Ignore master key for decrypting credentials and more. /config/master.key +.idea diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 369f6a24a..aecdabef1 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -2,8 +2,8 @@ - - + + - - - - - - - - - - + - - - - - - - - - - - - - - - - - - - - - - - - + + - - - - - - - - - - + - + - - - - - - - - - - + - - - - - - - - - - - + + - - + + @@ -158,6 +130,7 @@ @@ -169,7 +142,7 @@ @@ -237,6 +210,24 @@ + + + + + + + + + + + + + + + + + +