|
1 | 1 | require 'spec_helper'
|
2 | 2 |
|
3 | 3 | describe Gitlab::GithubImport::IssueFormatter, lib: true do
|
| 4 | + let(:client) { double } |
4 | 5 | let!(:project) { create(:empty_project, namespace: create(:namespace, path: 'octocat')) }
|
5 |
| - let(:octocat) { double(id: 123456, login: 'octocat') } |
| 6 | + let(:octocat) { double(id: 123456, login: 'octocat', email: '[email protected]') } |
6 | 7 | let(:created_at) { DateTime.strptime('2011-01-26T19:01:12Z') }
|
7 | 8 | let(:updated_at) { DateTime.strptime('2011-01-27T19:01:12Z') }
|
8 | 9 |
|
|
23 | 24 | }
|
24 | 25 | end
|
25 | 26 |
|
26 |
| - subject(:issue) { described_class.new(project, raw_data) } |
| 27 | + subject(:issue) { described_class.new(project, raw_data, client) } |
| 28 | + |
| 29 | + before do |
| 30 | + allow(client).to receive(:user).and_return(octocat) |
| 31 | + end |
27 | 32 |
|
28 | 33 | shared_examples 'Gitlab::GithubImport::IssueFormatter#attributes' do
|
29 | 34 | context 'when issue is open' do
|
|
75 | 80 | expect(issue.attributes.fetch(:assignee_id)).to be_nil
|
76 | 81 | end
|
77 | 82 |
|
78 |
| - it 'returns GitLab user id as assignee_id when is a GitLab user' do |
| 83 | + it 'returns GitLab user id associated with GitHub id as assignee_id' do |
79 | 84 | gl_user = create(:omniauth_user, extern_uid: octocat.id, provider: 'github')
|
80 | 85 |
|
81 | 86 | expect(issue.attributes.fetch(:assignee_id)).to eq gl_user.id
|
82 | 87 | end
|
| 88 | + |
| 89 | + it 'returns GitLab user id associated with GitHub email as assignee_id' do |
| 90 | + gl_user = create(:user, email: octocat.email) |
| 91 | + |
| 92 | + expect(issue.attributes.fetch(:assignee_id)).to eq gl_user.id |
| 93 | + end |
83 | 94 | end
|
84 | 95 |
|
85 | 96 | context 'when it has a milestone' do
|
|
100 | 111 | context 'when author is a GitLab user' do
|
101 | 112 | let(:raw_data) { double(base_data.merge(user: octocat)) }
|
102 | 113 |
|
103 |
| - it 'returns project#creator_id as author_id when is not a GitLab user' do |
| 114 | + it 'returns project creator_id as author_id when is not a GitLab user' do |
104 | 115 | expect(issue.attributes.fetch(:author_id)).to eq project.creator_id
|
105 | 116 | end
|
106 | 117 |
|
107 |
| - it 'returns GitLab user id as author_id when is a GitLab user' do |
| 118 | + it 'returns GitLab user id associated with GitHub id as author_id' do |
108 | 119 | gl_user = create(:omniauth_user, extern_uid: octocat.id, provider: 'github')
|
109 | 120 |
|
110 | 121 | expect(issue.attributes.fetch(:author_id)).to eq gl_user.id
|
111 | 122 | end
|
112 | 123 |
|
| 124 | + it 'returns GitLab user id associated with GitHub email as author_id' do |
| 125 | + gl_user = create(:user, email: octocat.email) |
| 126 | + |
| 127 | + expect(issue.attributes.fetch(:author_id)).to eq gl_user.id |
| 128 | + end |
| 129 | + |
113 | 130 | it 'returns description without created at tag line' do
|
114 | 131 | create(:omniauth_user, extern_uid: octocat.id, provider: 'github')
|
115 | 132 |
|
|
0 commit comments