summaryrefslogtreecommitdiff
path: root/features/steps/project/commits/user_lookup.rb
blob: 4599e0d032a81cd92f470bd2ee0f70444e368706 (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
class Spinach::Features::ProjectCommitsUserLookup < Spinach::FeatureSteps
  include SharedAuthentication
  include SharedProject
  include SharedPaths

  step 'I click on commit link' do
    visit project_commit_path(@project, sample_commit.id)
  end

  step 'I click on another commit link' do
    visit project_commit_path(@project, sample_commit.parent_id)
  end

  step 'I have user with primary email' do
    user_primary
  end

  step 'I have user with secondary email' do
    user_secondary
  end

  step 'I see author based on primary email' do
    check_author_link(sample_commit.author_email, user_primary)
  end

  step 'I see author based on secondary email' do
    check_author_link(sample_commit.author_email, user_secondary)
  end

  def check_author_link(email, user)
    author_link = find('.commit-author-link')

    expect(author_link['href']).to eq user_path(user)
    expect(author_link['title']).to eq email
    expect(find('.commit-author-name').text).to eq user.name
  end

  def user_primary
    @user_primary ||= create(:user, email: 'dmitriy.zaporozhets@gmail.com')
  end

  def user_secondary
    @user_secondary ||= begin
                          user = create(:user, email: 'dzaporozhets@example.com')
                          create(:email, { user: user, email: 'dmitriy.zaporozhets@gmail.com' })
                          user
                        end
  end
end