2019-07-25 05:24:42 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2019-08-29 07:56:52 +00:00
|
|
|
require 'spec_helper'
|
2017-09-09 13:10:34 +00:00
|
|
|
|
2020-06-16 18:09:01 +00:00
|
|
|
RSpec.describe 'Profile > Emails' do
|
2017-09-09 13:10:34 +00:00
|
|
|
let(:user) { create(:user) }
|
|
|
|
|
|
|
|
before do
|
2017-09-18 17:00:38 +00:00
|
|
|
sign_in(user)
|
2017-09-09 13:10:34 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
describe 'User adds an email' do
|
|
|
|
before do
|
|
|
|
visit profile_emails_path
|
|
|
|
end
|
|
|
|
|
2018-07-05 06:32:05 +00:00
|
|
|
it 'saves the new email' do
|
2017-09-09 13:10:34 +00:00
|
|
|
fill_in('Email', with: 'my@email.com')
|
|
|
|
click_button('Add email address')
|
|
|
|
|
|
|
|
expect(page).to have_content('my@email.com Unverified')
|
2017-09-09 13:55:07 +00:00
|
|
|
expect(page).to have_content("#{user.email} Verified")
|
|
|
|
expect(page).to have_content('Resend confirmation email')
|
2017-09-09 13:10:34 +00:00
|
|
|
end
|
|
|
|
|
2018-07-05 06:32:05 +00:00
|
|
|
it 'does not add a duplicate email' do
|
2017-09-09 13:10:34 +00:00
|
|
|
fill_in('Email', with: user.email)
|
|
|
|
click_button('Add email address')
|
|
|
|
|
|
|
|
email = user.emails.find_by(email: user.email)
|
|
|
|
expect(email).to be_nil
|
|
|
|
expect(page).to have_content('Email has already been taken')
|
|
|
|
end
|
2020-05-06 09:10:02 +00:00
|
|
|
|
|
|
|
it 'does not add an invalid email' do
|
|
|
|
fill_in('Email', with: 'test.@example.com')
|
|
|
|
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
|
2017-09-09 13:10:34 +00:00
|
|
|
end
|
|
|
|
|
2018-07-05 06:32:05 +00:00
|
|
|
it 'User removes email' do
|
2017-09-09 13:10:34 +00:00
|
|
|
user.emails.create(email: 'my@email.com')
|
|
|
|
visit profile_emails_path
|
|
|
|
expect(page).to have_content("my@email.com")
|
|
|
|
|
|
|
|
click_link('Remove')
|
2017-09-09 16:32:27 +00:00
|
|
|
expect(page).not_to have_content("my@email.com")
|
2017-09-09 13:10:34 +00:00
|
|
|
end
|
|
|
|
|
2018-07-05 06:32:05 +00:00
|
|
|
it 'User confirms email' do
|
2017-09-09 13:10:34 +00:00
|
|
|
email = user.emails.create(email: 'my@email.com')
|
|
|
|
visit profile_emails_path
|
2017-09-09 13:55:07 +00:00
|
|
|
expect(page).to have_content("#{email.email} Unverified")
|
2017-09-09 13:10:34 +00:00
|
|
|
|
|
|
|
email.confirm
|
|
|
|
expect(email.confirmed?).to be_truthy
|
|
|
|
|
|
|
|
visit profile_emails_path
|
2017-09-09 13:55:07 +00:00
|
|
|
expect(page).to have_content("#{email.email} Verified")
|
|
|
|
end
|
2017-09-09 16:32:27 +00:00
|
|
|
|
2018-07-05 06:32:05 +00:00
|
|
|
it 'User re-sends confirmation email' do
|
2017-09-09 13:55:07 +00:00
|
|
|
email = user.emails.create(email: 'my@email.com')
|
|
|
|
visit profile_emails_path
|
2017-09-09 16:32:27 +00:00
|
|
|
|
2020-05-18 09:08:12 +00:00
|
|
|
expect { click_link("Resend confirmation email") }.to have_enqueued_job.on_queue('mailers')
|
2017-09-09 13:55:07 +00:00
|
|
|
expect(page).to have_content("Confirmation email sent to #{email.email}")
|
|
|
|
end
|
2017-09-09 16:32:27 +00:00
|
|
|
|
2018-07-05 06:32:05 +00:00
|
|
|
it 'old unconfirmed emails show Send Confirmation button' do
|
2017-09-09 13:55:07 +00:00
|
|
|
email = user.emails.create(email: 'my@email.com')
|
|
|
|
email.update_attribute(:confirmation_sent_at, nil)
|
|
|
|
visit profile_emails_path
|
|
|
|
|
2017-09-09 16:32:27 +00:00
|
|
|
expect(page).not_to have_content('Resend confirmation email')
|
2017-09-09 13:55:07 +00:00
|
|
|
expect(page).to have_content('Send confirmation email')
|
2017-09-09 13:10:34 +00:00
|
|
|
end
|
|
|
|
end
|