Welcome to mirror list, hosted at ThFree Co, Russian Federation.

user_manages_emails_spec.rb « profiles « features « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: b875dfec217f25a8cc216811e3207d2b1001c77d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe 'User manages emails', feature_category: :user_profile do
  let(:user) { create(:user) }
  let(:other_user) { create(:user) }

  before do
    sign_in(user)

    visit(profile_emails_path)
  end

  it "shows user's emails", :aggregate_failures do
    expect(page).to have_content(user.email)

    user.emails.each do |email|
      expect(page).to have_content(email.email)
    end
  end

  it 'adds an email', :aggregate_failures do
    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

  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)
    click_button('Add')

    email = user.emails.find_by(email: other_user.email)

    expect(email).to be_nil
    expect(page).to have_content('Email has already been taken')

    user.emails.each do |email|
      expect(page).to have_content(email.email)
    end
  end

  it 'removes an email', :aggregate_failures do
    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