Files
astuto/spec/system/user_sign_up_spec.rb

92 lines
2.2 KiB
Ruby
Raw Normal View History

require 'rails_helper'
2023-03-19 19:57:53 +01:00
feature 'sign up', type: :system, js: true do
let(:user) { FactoryBot.build(:user) }
def sign_up_as(user)
visit new_user_registration_path
2023-03-19 19:57:53 +01:00
fill_in 'Full name', with: user.full_name
fill_in 'Email', with: user.email
fill_in 'Password', with: user.password
fill_in 'Password confirmation', with: user.password
click_button 'Sign up'
end
def expect_to_be_on_sign_up_page
expect(page).to have_content('Sign up')
end
scenario 'with valid fields' do
user_count = User.count
sign_up_as user
expect(page).to have_current_path(root_path)
expect(page).to have_css('.notice')
2023-03-19 19:57:53 +01:00
expect(User.count).to eq(user_count + 1)
end
scenario 'with invalid Full Name' do
user_count = User.count
user.full_name = 'a'
sign_up_as user
expect_to_be_on_sign_up_page
2023-03-19 19:57:53 +01:00
expect(page).to have_css('#error_explanation')
expect(User.count).to eq(user_count)
end
scenario 'with invalid email' do
user_count = User.count
user.email = 'a'
sign_up_as user
2023-03-19 19:57:53 +01:00
# client side validation blocks submission if email format is incorrect
# so we don't check for #error_explanation notice
expect_to_be_on_sign_up_page
expect(User.count).to eq(user_count)
2023-03-19 19:57:53 +01:00
end
scenario 'with already taken email' do
user.save # create user with same email
user_count = User.count
sign_up_as user
expect_to_be_on_sign_up_page
2023-03-19 19:57:53 +01:00
expect(page).to have_css('#error_explanation')
expect(page).to have_content('Email is already in use')
expect(User.count).to eq(user_count)
end
scenario 'with invalid password' do
user_count = User.count
user.password = 'a'
sign_up_as user
expect_to_be_on_sign_up_page
2023-03-19 19:57:53 +01:00
expect(page).to have_css('#error_explanation')
expect(User.count).to eq(user_count)
end
scenario 'with mismatching passwords' do
user_count = User.count
visit new_user_registration_path
fill_in 'Full name', with: user.full_name
fill_in 'Email', with: user.email
fill_in 'Password', with: user.password
fill_in 'Password confirmation', with: user.password + 'a'
click_button 'Sign up'
expect_to_be_on_sign_up_page
2023-03-19 19:57:53 +01:00
expect(page).to have_css('#error_explanation')
expect(User.count).to eq(user_count)
end
end