From 059c98d72a027c44155dcb7d90b2143fc27335cc Mon Sep 17 00:00:00 2001 From: Lee Sheppard Date: Sat, 2 Nov 2024 22:47:18 +1100 Subject: [PATCH] Update visitor_signs_up_spec.rb --- spec/features/visitor_signs_up_spec.rb | 60 +++++++++++--------------- 1 file changed, 26 insertions(+), 34 deletions(-) diff --git a/spec/features/visitor_signs_up_spec.rb b/spec/features/visitor_signs_up_spec.rb index 6ff7c2c..79fe6d7 100644 --- a/spec/features/visitor_signs_up_spec.rb +++ b/spec/features/visitor_signs_up_spec.rb @@ -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 "valid@example.com", "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: "valid@example.com" - expect(user).to be_present - expect(user).not_to be_confirmed - expect(user.memberships.count).to be_zero + verify_user_presence("valid@example.com") + verify_user_not_confirmed("valid@example.com") 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 "valid@example.com", "" - expect_user_not_to_be_registered end - scenario "as a bot" do - visit new_user_registration_path - - fill_in "Email", with: "valid@example.com" - 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: "valid@example.com" + 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