From bbc8c14d65ee77464b86fdeeb3d273d515668d1a Mon Sep 17 00:00:00 2001 From: Ben Purinton Date: Wed, 5 Apr 2023 17:19:08 +0000 Subject: [PATCH 1/3] re-using specs from ad2-getting-started --- 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..b03e1a2 --- /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 d5f9d925f6a4fb3ce849a43abe2c8b47293db53c Mon Sep 17 00:00:00 2001 From: Ben Purinton Date: Wed, 5 Apr 2023 19:55:58 +0000 Subject: [PATCH 2/3] PR comment fixes --- spec/features/1_basic_spec.rb | 47 +++++++++++++++++++---------------- 1 file changed, 25 insertions(+), 22 deletions(-) diff --git a/spec/features/1_basic_spec.rb b/spec/features/1_basic_spec.rb index b03e1a2..18cf456 100644 --- a/spec/features/1_basic_spec.rb +++ b/spec/features/1_basic_spec.rb @@ -1,90 +1,93 @@ require "rails_helper" describe "The /movies page" do - before do + it "can be visited", points: 1 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 + visit "/movies" + 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 + it "can be visited", points: 1 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 + visit "/movies/new" + 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 + visit "/movies/new" + 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 + visit "/movies/new" + 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 + let(:movie) { Movie.create(title: "My title", description: "My description") } it "can be visited", points: 1 do + visit "/movies/#{movie.id}" + 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'), + visit "/movies/#{movie.id}" + + 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 + let(:movie) { Movie.create(title: "My title", description: "My description") } it "can be visited", points: 1 do + visit "/movies/#{movie.id}/edit" + 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']"), + visit "/movies/#{movie.id}/edit" + + 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 + visit "/movies/#{movie.id}/edit" + 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 From c2486784ab269041113f9c2d68ced8cdf17674f2 Mon Sep 17 00:00:00 2001 From: Ben Purinton Date: Wed, 5 Apr 2023 20:19:09 +0000 Subject: [PATCH 3/3] PR comment remove authenticity_token --- spec/features/1_basic_spec.rb | 7 ------- 1 file changed, 7 deletions(-) diff --git a/spec/features/1_basic_spec.rb b/spec/features/1_basic_spec.rb index 18cf456..8a313a0 100644 --- a/spec/features/1_basic_spec.rb +++ b/spec/features/1_basic_spec.rb @@ -31,13 +31,6 @@ "Expected /movies/new to have a form with action='/movies'." end - it "has a hidden authenticity token input", points: 2 do - visit "/movies/new" - - 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 visit "/movies/new"