2019-10-12 21:52:04 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2019-12-04 20:38:33 +05:30
|
|
|
require 'spec_helper'
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2023-04-23 21:23:45 +05:30
|
|
|
RSpec.describe 'Profile > Emails', feature_category: :user_profile do
|
2018-03-17 18:26:18 +05:30
|
|
|
let(:user) { create(:user) }
|
2021-12-11 22:18:48 +05:30
|
|
|
let(:other_user) { create(:user) }
|
2018-03-17 18:26:18 +05:30
|
|
|
|
|
|
|
before do
|
|
|
|
sign_in(user)
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'User adds an email' do
|
|
|
|
before do
|
|
|
|
visit profile_emails_path
|
|
|
|
end
|
|
|
|
|
2018-11-08 19:23:39 +05:30
|
|
|
it 'saves the new email' do
|
2018-03-17 18:26:18 +05:30
|
|
|
fill_in('Email', with: 'my@email.com')
|
|
|
|
click_button('Add email address')
|
|
|
|
|
|
|
|
expect(page).to have_content('my@email.com Unverified')
|
|
|
|
expect(page).to have_content("#{user.email} Verified")
|
|
|
|
expect(page).to have_content('Resend confirmation email')
|
|
|
|
end
|
|
|
|
|
2021-12-11 22:18:48 +05:30
|
|
|
it 'does not add an email that is the primary email of another user' do
|
|
|
|
fill_in('Email', with: other_user.email)
|
2018-03-17 18:26:18 +05:30
|
|
|
click_button('Add email address')
|
|
|
|
|
2021-12-11 22:18:48 +05:30
|
|
|
email = user.emails.find_by(email: other_user.email)
|
2018-03-17 18:26:18 +05:30
|
|
|
expect(email).to be_nil
|
|
|
|
expect(page).to have_content('Email has already been taken')
|
|
|
|
end
|
2020-05-24 23:13:21 +05:30
|
|
|
|
2021-12-11 22:18:48 +05:30
|
|
|
it 'adds an email that is the primary email of the same user' do
|
|
|
|
fill_in('Email', with: user.email)
|
|
|
|
click_button('Add email address')
|
|
|
|
|
|
|
|
email = user.emails.find_by(email: user.email)
|
|
|
|
expect(email).to be_present
|
|
|
|
expect(page).to have_content("#{user.email} Verified")
|
|
|
|
expect(page).not_to have_content("#{user.email} Unverified")
|
|
|
|
end
|
|
|
|
|
2020-05-24 23:13:21 +05:30
|
|
|
it 'does not add an invalid email' do
|
2022-03-02 08:16:31 +05:30
|
|
|
fill_in('Email', with: 'test@@example.com')
|
2020-05-24 23:13:21 +05:30
|
|
|
click_button('Add email address')
|
|
|
|
|
|
|
|
email = user.emails.find_by(email: email)
|
|
|
|
expect(email).to be_nil
|
|
|
|
expect(page).to have_content('Email is invalid')
|
|
|
|
end
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|
|
|
|
|
2021-02-22 17:27:13 +05:30
|
|
|
it 'user removes email' do
|
2021-04-29 21:17:54 +05:30
|
|
|
user.emails.create!(email: 'my@email.com')
|
2018-03-17 18:26:18 +05:30
|
|
|
visit profile_emails_path
|
|
|
|
expect(page).to have_content("my@email.com")
|
|
|
|
|
|
|
|
click_link('Remove')
|
|
|
|
expect(page).not_to have_content("my@email.com")
|
|
|
|
end
|
|
|
|
|
2021-02-22 17:27:13 +05:30
|
|
|
it 'user confirms email' do
|
2021-04-29 21:17:54 +05:30
|
|
|
email = user.emails.create!(email: 'my@email.com')
|
2018-03-17 18:26:18 +05:30
|
|
|
visit profile_emails_path
|
|
|
|
expect(page).to have_content("#{email.email} Unverified")
|
|
|
|
|
|
|
|
email.confirm
|
|
|
|
expect(email.confirmed?).to be_truthy
|
|
|
|
|
|
|
|
visit profile_emails_path
|
|
|
|
expect(page).to have_content("#{email.email} Verified")
|
|
|
|
end
|
|
|
|
|
2021-02-22 17:27:13 +05:30
|
|
|
it 'user re-sends confirmation email' do
|
2021-04-29 21:17:54 +05:30
|
|
|
email = user.emails.create!(email: 'my@email.com')
|
2018-03-17 18:26:18 +05:30
|
|
|
visit profile_emails_path
|
|
|
|
|
2020-05-24 23:13:21 +05:30
|
|
|
expect { click_link("Resend confirmation email") }.to have_enqueued_job.on_queue('mailers')
|
2018-03-17 18:26:18 +05:30
|
|
|
expect(page).to have_content("Confirmation email sent to #{email.email}")
|
|
|
|
end
|
|
|
|
|
2018-11-08 19:23:39 +05:30
|
|
|
it 'old unconfirmed emails show Send Confirmation button' do
|
2021-04-29 21:17:54 +05:30
|
|
|
email = user.emails.create!(email: 'my@email.com')
|
2018-03-17 18:26:18 +05:30
|
|
|
email.update_attribute(:confirmation_sent_at, nil)
|
|
|
|
visit profile_emails_path
|
|
|
|
|
|
|
|
expect(page).not_to have_content('Resend confirmation email')
|
|
|
|
expect(page).to have_content('Send confirmation email')
|
|
|
|
end
|
|
|
|
end
|