diff --git a/spec/features/1_basic_spec.rb b/spec/features/1_basic_spec.rb new file mode 100644 index 0000000..4819845 --- /dev/null +++ b/spec/features/1_basic_spec.rb @@ -0,0 +1,184 @@ +require "rails_helper" + +describe "User authentication" do + it "requires sign in before any action with the Devise `before_action :authenticate_user!` method", points: 2 do + visit "/movies/new" + current_url = page.current_path + + expect(current_url).to eq(new_user_session_path), + "Expected `before_action :authenticate_user!` in `ApplicationController` to redirect guest to /users/sign_in before visiting another page." + end + + it "allows a user to sign up", points: 2 do + old_users_count = User.count + visit new_user_registration_path + + fill_in "Email", with: "user@example.com" + fill_in "Password", with: "password" + fill_in "Password confirmation", with: "password" + click_button "Sign up" + + new_users_count = User.count + + expect(old_users_count).to be < new_users_count, + "Expected 'Sign up' form on /users/sign_up to successfully add a User record to the database." + end +end + +describe "The /movies page" do + before do + sign_in_user if user_model_exists? + end + + it "can be visited", points: 1 do + visit "/movies" + + 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 + + it "has a large, light-themed bootstrap navbar", points: 1 do + visit "/movies" + + expect(page).to have_selector("nav[class='navbar navbar-expand-lg navbar-light bg-light']"), + "Expected /movies to have have a