|
| 1 | +require "rails_helper" |
| 2 | + |
| 3 | +describe "The /movies page" do |
| 4 | + it "can be visited", points: 1 do |
| 5 | + visit "/movies" |
| 6 | + |
| 7 | + expect(page.status_code).to be(200), |
| 8 | + "Expected to visit /movies successfully." |
| 9 | + end |
| 10 | + |
| 11 | + it "has a link to add a movie", points: 1 do |
| 12 | + visit "/movies" |
| 13 | + |
| 14 | + expect(page).to have_link('Add a new movie', href: "/movies/new"), |
| 15 | + "Expected /movies to have an 'Add a new movie' link to '/movies/new'." |
| 16 | + end |
| 17 | +end |
| 18 | + |
| 19 | +describe "The /movies/new page" do |
| 20 | + it "can be visited", points: 1 do |
| 21 | + visit "/movies/new" |
| 22 | + |
| 23 | + expect(page.status_code).to be(200), |
| 24 | + "Expected to visit /movies/new successfully." |
| 25 | + end |
| 26 | + |
| 27 | + it "has a form", points: 1 do |
| 28 | + visit "/movies/new" |
| 29 | + |
| 30 | + expect(page).to have_selector("form[action='/movies']"), |
| 31 | + "Expected /movies/new to have a form with action='/movies'." |
| 32 | + end |
| 33 | + |
| 34 | + it "has a hidden authenticity token input", points: 2 do |
| 35 | + visit "/movies/new" |
| 36 | + |
| 37 | + expect(page).to have_selector("input[name='authenticity_token']", visible: false), |
| 38 | + "Expected the new movie form to have an input field of type='hidden' and name='authenticity_token'." |
| 39 | + end |
| 40 | + |
| 41 | + it "creates a movie successfully", point: 1 do |
| 42 | + visit "/movies/new" |
| 43 | + |
| 44 | + fill_in "Title", with: "My test movie" |
| 45 | + fill_in "Description", with: "description" |
| 46 | + click_button "Create movie" |
| 47 | + |
| 48 | + expect(page).to have_content("Movie created successfully."), |
| 49 | + "Expected to fill in the new movie form, click 'Create movie', and be redirected to the movie index with a success notice" |
| 50 | + end |
| 51 | +end |
| 52 | + |
| 53 | +describe "The movie details page" do |
| 54 | + let(:movie) { Movie.create(title: "My title", description: "My description") } |
| 55 | + |
| 56 | + it "can be visited", points: 1 do |
| 57 | + visit "/movies/#{movie.id}" |
| 58 | + |
| 59 | + expect(page.status_code).to be(200), |
| 60 | + "Expected to visit /movies/ID successfully." |
| 61 | + end |
| 62 | + |
| 63 | + it "has a link to delete the movie with a DELETE request", points: 2 do |
| 64 | + visit "/movies/#{movie.id}" |
| 65 | + |
| 66 | + expect(page).to have_selector("a[href='/movies/#{movie.id}'][data-method='delete']", text: 'Delete movie'), |
| 67 | + "Expected /movies/ID to have 'Delete movie' link with the proper data-method='delete'." |
| 68 | + end |
| 69 | +end |
| 70 | + |
| 71 | +describe "The movie edit page" do |
| 72 | + let(:movie) { Movie.create(title: "My title", description: "My description") } |
| 73 | + |
| 74 | + it "can be visited", points: 1 do |
| 75 | + visit "/movies/#{movie.id}/edit" |
| 76 | + |
| 77 | + expect(page.status_code).to be(200), |
| 78 | + "Expected to visit /movies/ID/edit successfully." |
| 79 | + end |
| 80 | + |
| 81 | + it "has a form", points: 1 do |
| 82 | + visit "/movies/#{movie.id}/edit" |
| 83 | + |
| 84 | + expect(page).to have_selector("form[action='/movies/#{movie.id}'][method='post']"), |
| 85 | + "Expected /movies/ID/edit to have a form with action='/movies/ID' and method='post'." |
| 86 | + end |
| 87 | + |
| 88 | + it "has a hidden patch input", points: 2 do |
| 89 | + visit "/movies/#{movie.id}/edit" |
| 90 | + |
| 91 | + expect(page).to have_selector("input[name='_method'][value='patch']", visible: false), |
| 92 | + "Expected the edit movie form to have an input field of type='hidden' with name='_method' and value='patch'." |
| 93 | + end |
| 94 | +end |
0 commit comments