debian-mirror-gitlab/spec/features/profiles/user_manages_emails_spec.rb

82 lines
2 KiB
Ruby
Raw Normal View History

2019-10-12 21:52:04 +05:30
# frozen_string_literal: true
2018-03-17 18:26:18 +05:30
require 'spec_helper'
2020-06-23 00:09:42 +05:30
RSpec.describe 'User manages emails' 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)
visit(profile_emails_path)
end
2021-12-11 22:18:48 +05:30
it "shows user's emails", :aggregate_failures do
2018-03-17 18:26:18 +05:30
expect(page).to have_content(user.email)
user.emails.each do |email|
expect(page).to have_content(email.email)
end
end
2021-12-11 22:18:48 +05:30
it 'adds an email', :aggregate_failures do
2018-03-17 18:26:18 +05:30
fill_in('email_email', with: 'my@email.com')
click_button('Add')
email = user.emails.find_by(email: 'my@email.com')
expect(email).not_to be_nil
expect(page).to have_content('my@email.com')
expect(page).to have_content(user.email)
user.emails.each do |email|
expect(page).to have_content(email.email)
end
end
2021-12-11 22:18:48 +05:30
it 'does not add an email that is the primary email of another user', :aggregate_failures do
fill_in('email_email', with: other_user.email)
2018-03-17 18:26:18 +05:30
click_button('Add')
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
2021-12-11 22:18:48 +05:30
expect(page).to have_content('Email has already been taken')
2018-03-17 18:26:18 +05:30
user.emails.each do |email|
expect(page).to have_content(email.email)
end
end
2021-12-11 22:18:48 +05:30
it 'removes an email', :aggregate_failures do
2018-03-17 18:26:18 +05:30
fill_in('email_email', with: 'my@email.com')
click_button('Add')
email = user.emails.find_by(email: 'my@email.com')
expect(email).not_to be_nil
expect(page).to have_content('my@email.com')
expect(page).to have_content(user.email)
user.emails.each do |email|
expect(page).to have_content(email.email)
end
# There should be only one remove button at this time
click_link('Remove')
# Force these to reload as they have been cached
user.emails.reload
email = user.emails.find_by(email: 'my@email.com')
expect(email).to be_nil
expect(page).not_to have_content('my@email.com')
expect(page).to have_content(user.email)
user.emails.each do |email|
expect(page).to have_content(email.email)
end
end
end