2017-09-09 09:10:34 -04:00
|
|
|
require 'rails_helper'
|
|
|
|
|
|
|
|
feature 'Profile > Emails' do
|
|
|
|
let(:user) { create(:user) }
|
|
|
|
|
|
|
|
before do
|
2017-09-18 13:00:38 -04:00
|
|
|
sign_in(user)
|
2017-09-09 09:10:34 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
describe 'User adds an email' do
|
|
|
|
before do
|
|
|
|
visit profile_emails_path
|
|
|
|
end
|
|
|
|
|
|
|
|
scenario 'saves the new email' do
|
|
|
|
fill_in('Email', with: 'my@email.com')
|
|
|
|
click_button('Add email address')
|
|
|
|
|
|
|
|
expect(page).to have_content('my@email.com Unverified')
|
2017-09-09 09:55:07 -04:00
|
|
|
expect(page).to have_content("#{user.email} Verified")
|
|
|
|
expect(page).to have_content('Resend confirmation email')
|
2017-09-09 09:10:34 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
scenario 'does not add a duplicate email' do
|
|
|
|
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
|
|
|
|
end
|
|
|
|
|
|
|
|
scenario 'User removes email' do
|
|
|
|
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 12:32:27 -04:00
|
|
|
expect(page).not_to have_content("my@email.com")
|
2017-09-09 09:10:34 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
scenario 'User confirms email' do
|
|
|
|
email = user.emails.create(email: 'my@email.com')
|
|
|
|
visit profile_emails_path
|
2017-09-09 09:55:07 -04:00
|
|
|
expect(page).to have_content("#{email.email} Unverified")
|
2017-09-09 09:10:34 -04:00
|
|
|
|
|
|
|
email.confirm
|
|
|
|
expect(email.confirmed?).to be_truthy
|
|
|
|
|
|
|
|
visit profile_emails_path
|
2017-09-09 09:55:07 -04:00
|
|
|
expect(page).to have_content("#{email.email} Verified")
|
|
|
|
end
|
2017-09-09 12:32:27 -04:00
|
|
|
|
2017-09-09 09:55:07 -04:00
|
|
|
scenario 'User re-sends confirmation email' do
|
|
|
|
email = user.emails.create(email: 'my@email.com')
|
|
|
|
visit profile_emails_path
|
2017-09-09 12:32:27 -04:00
|
|
|
|
2017-09-09 09:55:07 -04:00
|
|
|
expect { click_link("Resend confirmation email") }.to change { ActionMailer::Base.deliveries.size }
|
|
|
|
expect(page).to have_content("Confirmation email sent to #{email.email}")
|
|
|
|
end
|
2017-09-09 12:32:27 -04:00
|
|
|
|
2017-09-09 09:55:07 -04:00
|
|
|
scenario 'old unconfirmed emails show Send Confirmation button' do
|
|
|
|
email = user.emails.create(email: 'my@email.com')
|
|
|
|
email.update_attribute(:confirmation_sent_at, nil)
|
|
|
|
visit profile_emails_path
|
|
|
|
|
2017-09-09 12:32:27 -04:00
|
|
|
expect(page).not_to have_content('Resend confirmation email')
|
2017-09-09 09:55:07 -04:00
|
|
|
expect(page).to have_content('Send confirmation email')
|
2017-09-09 09:10:34 -04:00
|
|
|
end
|
|
|
|
end
|