Skip to content

Commit

Permalink
Update visitor_signs_up_spec.rb
Browse files Browse the repository at this point in the history
  • Loading branch information
leesheppard committed Nov 2, 2024
1 parent 01b773a commit 059c98d
Showing 1 changed file with 26 additions and 34 deletions.
60 changes: 26 additions & 34 deletions spec/features/visitor_signs_up_spec.rb
Original file line number Diff line number Diff line change
@@ -1,70 +1,62 @@
require "rails_helper"

RSpec.feature "Visitor signs up", type: :feature do
scenario "by navigating to the page" do
visit new_user_session_path

click_link 'Join'

expect(page).to have_current_path new_user_registration_path, ignore_query: true
end

scenario "with valid email and password" do
sign_up_with "[email protected]", "password"

expect(page).to have_content 'A message with a confirmation link has been sent to your email address.'
expect(page).not_to have_link('Sign out')

user = User.find_by email: "[email protected]"
expect(user).to be_present
expect(user).not_to be_confirmed
expect(user.memberships.count).to be_zero
verify_user_presence("[email protected]")
verify_user_not_confirmed("[email protected]")
end

scenario "tries with invalid email" do
sign_up_with "invalid_email", "password"

expect_user_not_to_be_registered
end

scenario "tries with blank password" do
sign_up_with "[email protected]", ""

expect_user_not_to_be_registered
end

scenario "as a bot" do
visit new_user_registration_path

fill_in "Email", with: "[email protected]"
fill_in "Password", with: "password"
fill_in "Confirm Password", with: "password"
fill_in "Full Name", with: 'Jane Doe'
fill_in "Postal Address", with: '1 High Street'

check "Rails Camp"

fill_in "Ruby?", with: "Random bot generated string"

click_button 'Register'

scenario "as a user" do
simulate_registration
expect_user_not_to_be_registered
expect(User.count).to be_zero
end

def sign_up_with(email, password)
visit new_user_registration_path

fill_in "Email", with: email
fill_in "Password", with: password
fill_in "Confirm Password", with: password
fill_in "Full Name", with: 'Jane Doe'
fill_in "Postal Address", with: '1 High Street'

check "Rails Camp"

fill_in "Ruby?", with: "Ruby"
click_button 'Register'
end

def verify_user_presence(email)
user = User.find_by(email: email)
expect(user).to be_present
end

def verify_user_not_confirmed(email)
user = User.find_by(email: email)
expect(user).not_to be_confirmed
expect(user.memberships.count).to be_zero
end

def simulate_registration
visit new_user_registration_path
fill_in "Email", with: "[email protected]"
fill_in "Password", with: "password"
fill_in "Confirm Password", with: "password"
fill_in "Full Name", with: 'Jane Doe'
fill_in "Postal Address", with: '1 High Street'
check "Rails Camp"
fill_in "Ruby?", with: "Random bot generated string"
click_button 'Register'
end

Expand Down

0 comments on commit 059c98d

Please sign in to comment.