From caec162af07836e97a52b14db8a2fdca023ae707 Mon Sep 17 00:00:00 2001 From: Chris M Date: Wed, 18 Nov 2020 19:04:56 -0800 Subject: [PATCH 1/2] Added Due Date --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 108418438..99e39b7aa 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ ## At a Glance - Pair, [stage 2](https://github.com/Ada-Developers-Academy/pedagogy/blob/master/rule-of-three.md#stage-2) project -- Due EOD Friday at 6 PM on **DATE HERE** +- Due EOD Friday at 6 PM on **EOD Friday December 4th** - Submit this project with a PR ## Introduction From d0106ed30548a9b3dfc80ee2c0873a54d8adc9c9 Mon Sep 17 00:00:00 2001 From: CheezItMan Date: Mon, 23 Nov 2020 13:03:38 -0800 Subject: [PATCH 2/2] add wave 1 controller tests --- test/controllers/.keep | 0 test/controllers/customers_controller_test.rb | 36 ++++++ test/controllers/videos_controller_test.rb | 117 ++++++++++++++++++ test/fixtures/.keep | 0 test/fixtures/customers.yml | 18 +++ test/fixtures/files/.keep | 0 test/fixtures/videos.yml | 12 ++ 7 files changed, 183 insertions(+) create mode 100644 test/controllers/.keep create mode 100644 test/controllers/customers_controller_test.rb create mode 100644 test/controllers/videos_controller_test.rb 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/videos.yml diff --git a/test/controllers/.keep b/test/controllers/.keep new file mode 100644 index 000000000..e69de29bb diff --git a/test/controllers/customers_controller_test.rb b/test/controllers/customers_controller_test.rb new file mode 100644 index 000000000..b0aab0b35 --- /dev/null +++ b/test/controllers/customers_controller_test.rb @@ -0,0 +1,36 @@ +require "test_helper" + +describe CustomersController do + it "must get index" do + # Act + get customers_path + body = JSON.parse(response.body) + + # Assert + expect(body).must_be_instance_of Array + expect(body.length).must_equal Customer.count + + # Check that each customer has the proper keys + fields = ["id", "name", "registered_at", "postal_code", + "phone", "videos_checked_out_count"].sort + + body.each do |customer| + expect(customer.keys.sort).must_equal fields + end + + must_respond_with :ok + end + + it "works even with no customers" do + Customer.destroy_all + + get customers_path + body = JSON.parse(response.body) + + expect(body).must_be_instance_of Array + expect(body.length).must_equal 0 + + must_respond_with :ok + end + +end diff --git a/test/controllers/videos_controller_test.rb b/test/controllers/videos_controller_test.rb new file mode 100644 index 000000000..c1d9564b5 --- /dev/null +++ b/test/controllers/videos_controller_test.rb @@ -0,0 +1,117 @@ +require "test_helper" + +describe VideosController do + describe "index" do + it "must get index" do + # Act + get videos_path + body = JSON.parse(response.body) + + # Assert + expect(body).must_be_instance_of Array + expect(body.length).must_equal Video.count + + # Check that each customer has the proper keys + fields = ["id", "title", "release_date", "available_inventory"].sort + + body.each do |customer| + expect(customer.keys.sort).must_equal fields + end + + must_respond_with :ok + end + + it "works even with no videos" do + # Arrange + Video.destroy_all + + # Act + get videos_path + body = JSON.parse(response.body) + + # Assert + expect(body).must_be_instance_of Array + expect(body.length).must_equal 0 + + must_respond_with :ok + end + end + + describe "show" do + it "can get a video" do + # Arrange + wonder_woman = videos(:wonder_woman) + + # Act + get video_path(wonder_woman.id) + body = JSON.parse(response.body) + + # Assert + fields = ["title", "overview", "release_date", "total_inventory", "available_inventory"].sort + expect(body.keys.sort).must_equal fields + expect(body["title"]).must_equal "Wonder Woman 2" + expect(body["release_date"]).must_equal "December 25th 2020" + expect(body["available_inventory"]).must_equal 100 + expect(body["overview"]).must_equal "Wonder Woman squares off against Maxwell Lord and the Cheetah, a villainess who possesses superhuman strength and agility." + expect(body["total_inventory"]).must_equal 100 + + must_respond_with :ok + end + + it "responds with a 404 for non-existant videos" do + # Act + get video_path(-1) + body = JSON.parse(response.body) + + # Assert + expect(body.keys).must_include "errors" + expect(body["errors"]).must_include "Not Found" + must_respond_with :not_found + end + end + + describe "create" do + it "can create a valid video" do + # Arrange + video_hash = { + title: "Alf the movie", + overview: "The most early 90s movie of all time", + release_date: "December 16th 2025", + total_inventory: 6, + available_inventory: 6 + } + + # Assert + expect { + post videos_path, params: video_hash + }.must_change "Video.count", 1 + + must_respond_with :created + end + + it "will respond with bad request and errors for an invalid movie" do + # Arrange + video_hash = { + title: "Alf the movie", + overview: "The most early 90s movie of all time", + release_date: "December 16th 2025", + total_inventory: 6, + available_inventory: 6 + } + + video_hash[:title] = nil + + # Assert + expect { + post videos_path, params: video_hash + }.wont_change "Video.count" + body = JSON.parse(response.body) + + expect(body.keys).must_include "errors" + expect(body["errors"].keys).must_include "title" + expect(body["errors"]["title"]).must_include "can't be blank" + + must_respond_with :bad_request + end + end +end diff --git a/test/fixtures/.keep b/test/fixtures/.keep new file mode 100644 index 000000000..e69de29bb diff --git a/test/fixtures/customers.yml b/test/fixtures/customers.yml new file mode 100644 index 000000000..5380cf4b8 --- /dev/null +++ b/test/fixtures/customers.yml @@ -0,0 +1,18 @@ +customer_one: + name: Simon Del Rosario + registered_at: "Wed, 29 Apr 2015 07:54:14 -0700" + postal_code: 75007 + phone: (469) 734-9111 + videos_checked_out_count: 3 + address: 1314 Elm Street + city: Seattle + state: WA +customer_two: + name: Becca + registered_at: "Wed, 13 Mar 2020 07:54:14 -0700" + postal_code: 98177 + phone: (469) 734-9222 + videos_checked_out_count: 1 + address: 1414 Seasame Street + city: Seattle + state: WA diff --git a/test/fixtures/files/.keep b/test/fixtures/files/.keep new file mode 100644 index 000000000..e69de29bb diff --git a/test/fixtures/videos.yml b/test/fixtures/videos.yml new file mode 100644 index 000000000..cef2102b7 --- /dev/null +++ b/test/fixtures/videos.yml @@ -0,0 +1,12 @@ +wonder_woman: + title: Wonder Woman 2 + release_date: "December 25th 2020" + available_inventory: 100 + overview: Wonder Woman squares off against Maxwell Lord and the Cheetah, a villainess who possesses superhuman strength and agility. + total_inventory: 100 +black_widow: + title: Black Widow + release_date: "May 7th 2021" + available_inventory: 6 + overview: At birth the Black Widow (aka Natasha Romanova) is given to the KGB, which grooms her to become its ultimate operative. When the U.S.S.R. breaks up, the government tries to kill her as the action moves to present-day New York, where she is a freelance operative. + total_inventory: 7