From ea1313fcc847862d2989ca13faa776fdd72dcff8 Mon Sep 17 00:00:00 2001 From: Ben Purinton Date: Wed, 5 Apr 2023 18:11:07 +0000 Subject: [PATCH 01/12] added helper-methods specs --- spec/features/1_basic_spec.rb | 91 +++++++++++++++++++++++++++++++++++ spec/features/dummy_spec.rb | 7 --- 2 files changed, 91 insertions(+), 7 deletions(-) create mode 100644 spec/features/1_basic_spec.rb delete mode 100644 spec/features/dummy_spec.rb diff --git a/spec/features/1_basic_spec.rb b/spec/features/1_basic_spec.rb new file mode 100644 index 0000000..0743f74 --- /dev/null +++ b/spec/features/1_basic_spec.rb @@ -0,0 +1,91 @@ +require "rails_helper" + +describe "The /movies page" do + before do + visit "/movies" + end + + it "can be visited", points: 1 do + expect(page.status_code).to be(200), + "Expected to visit /movies successfully." + end + + it "has a link to add a movie", points: 1 do + expect(page).to have_link('Add a new movie', href: "/movies/new"), + "Expected /movies to have an 'Add a new movie' link to '/movies/new'." + end +end + +describe "The /movies/new page" do + before do + visit "/movies/new" + end + + it "can be visited", points: 1 do + expect(page.status_code).to be(200), + "Expected to visit /movies/new successfully." + end + + it "has a form", points: 1 do + expect(page).to have_selector("form[action='/movies']"), + "Expected /movies/new to have a form with action='/movies'." + end + + it "has a hidden authenticity token input", points: 2 do + expect(page).to have_selector("input")#[name='authenticity_token']", visible: false), + "Expected the new movie form to have an input field of type='hidden' and name='authenticity_token'." + end + + it "creates a movie successfully", point: 1 do + fill_in "Title", with: "My test movie" + fill_in "Description", with: "description" + click_button "Create Movie" + expect(page).to have_content("Movie created successfully."), + "Expected to fill in the new movie form, click 'Create Movie', and be redirected to the movie index with a success notice" + end +end + +describe "The movie details page" do + before do + @movie = Movie.create( + title: "My title", + description: "My description" + ) + visit "/movies/#{@movie.id}" + end + + it "can be visited", points: 1 do + expect(page.status_code).to be(200), + "Expected to visit /movies/ID successfully." + end + + it "has a link to delete the movie with a DELETE request", points: 2 do + expect(page).to have_selector("a[href='/movies/#{ @movie.id }'][data-method='delete']", text: 'Delete Movie'), + "Expected /movies/ID to have 'Delete Movie' link with the proper data-method='delete'." + end +end + +describe "The movie edit page" do + before do + @movie = Movie.create( + title: "My title", + description: "My description" + ) + visit "/movies/#{@movie.id}/edit" + end + + it "can be visited", points: 1 do + expect(page.status_code).to be(200), + "Expected to visit /movies/ID/edit successfully." + end + + it "has a form", points: 1 do + expect(page).to have_selector("form[action='/movies/#{@movie.id}'][method='post']"), + "Expected /movies/ID/edit to have a form with action='/movies/ID' and method='post'." + end + + it "has a hidden patch input", points: 2 do + expect(page).to have_selector("input[name='_method'][value='patch']", visible: false), + "Expected the edit movie form to have an input field of type='hidden' with name='_method' and value='patch'." + end +end diff --git a/spec/features/dummy_spec.rb b/spec/features/dummy_spec.rb deleted file mode 100644 index a2c737b..0000000 --- a/spec/features/dummy_spec.rb +++ /dev/null @@ -1,7 +0,0 @@ -require "rails_helper" - -describe "This project" do - it "has no tests" do - expect(1).to eq(1) - end -end From 81e2d2f17d0c2e70bfdb452401e989bc5793ff6e Mon Sep 17 00:00:00 2001 From: Ben Purinton Date: Wed, 5 Apr 2023 18:18:07 +0000 Subject: [PATCH 02/12] remove authenticity_token spec --- spec/features/1_basic_spec.rb | 5 ----- 1 file changed, 5 deletions(-) diff --git a/spec/features/1_basic_spec.rb b/spec/features/1_basic_spec.rb index 0743f74..f21428f 100644 --- a/spec/features/1_basic_spec.rb +++ b/spec/features/1_basic_spec.rb @@ -31,11 +31,6 @@ "Expected /movies/new to have a form with action='/movies'." end - it "has a hidden authenticity token input", points: 2 do - expect(page).to have_selector("input")#[name='authenticity_token']", visible: false), - "Expected the new movie form to have an input field of type='hidden' and name='authenticity_token'." - end - it "creates a movie successfully", point: 1 do fill_in "Title", with: "My test movie" fill_in "Description", with: "description" From d813134fcf7dda4512fa6f7008c6086fd8ec1cd0 Mon Sep 17 00:00:00 2001 From: Ben Purinton Date: Wed, 5 Apr 2023 18:31:15 +0000 Subject: [PATCH 03/12] added some card and font awesome specs --- spec/features/1_basic_spec.rb | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/spec/features/1_basic_spec.rb b/spec/features/1_basic_spec.rb index f21428f..9ba5bbd 100644 --- a/spec/features/1_basic_spec.rb +++ b/spec/features/1_basic_spec.rb @@ -54,8 +54,18 @@ "Expected to visit /movies/ID successfully." end - it "has a link to delete the movie with a DELETE request", points: 2 do - expect(page).to have_selector("a[href='/movies/#{ @movie.id }'][data-method='delete']", text: 'Delete Movie'), + it "shows the movie on a bootstrap card", points: 2 do + expect(page).to have_selector("div[class='card']"), + "Expected /movies/ID to have have a
element to display the movie." + end + + it "has a Font Awesome trash can icon to delete the movie", points: 2 do + expect(page).to have_selector("i[class='fa-regular fa-trash-can']"), + "Expected /movies/ID to have a Font Awesome trash can icon on the card, with class='fa-regular fa-trash-can'." + end + + it "deletes the movie with a DELETE request", points: 2 do + expect(page).to have_selector("a[href='/movies/#{@movie.id}'][data-method='delete']"), "Expected /movies/ID to have 'Delete Movie' link with the proper data-method='delete'." end end From 5020e80c32acde6b81d9daef169ca773e15001a6 Mon Sep 17 00:00:00 2001 From: Ben Purinton Date: Wed, 5 Apr 2023 18:55:45 +0000 Subject: [PATCH 04/12] added spec for navbar --- spec/features/1_basic_spec.rb | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/spec/features/1_basic_spec.rb b/spec/features/1_basic_spec.rb index 9ba5bbd..a946d7a 100644 --- a/spec/features/1_basic_spec.rb +++ b/spec/features/1_basic_spec.rb @@ -14,6 +14,11 @@ expect(page).to have_link('Add a new movie', href: "/movies/new"), "Expected /movies to have an 'Add a new movie' link to '/movies/new'." end + + it "has a bootstrap navbar", points: 1 do + expect(page).to have_selector("nav[class='navbar navbar-expand-lg navbar-light bg-light']"), + "Expected /movies to have have a