diff options
author | Grzegorz Bizon <grzegorz@gitlab.com> | 2019-08-12 18:27:14 +0300 |
---|---|---|
committer | Grzegorz Bizon <grzegorz@gitlab.com> | 2019-08-12 18:27:14 +0300 |
commit | 37496d5916fffd2e09a0722ac92a264fe83ff136 (patch) | |
tree | 4f025481a61c3c2fba1201d9f36b1bc0987e5f39 /spec | |
parent | 216acee11dfecbb095e151d1b1cac4203d08355b (diff) | |
parent | 23dfc5d60650d099d7f2b95af64f88e82edb3f4d (diff) |
Merge branch 'georgekoltsov/63408-user-mapping' into 'master'
Add author lines to project import comments
See merge request gitlab-org/gitlab-ce!31579
Diffstat (limited to 'spec')
4 files changed, 34 insertions, 11 deletions
diff --git a/spec/lib/bitbucket/representation/comment_spec.rb b/spec/lib/bitbucket/representation/comment_spec.rb index 2dcc933ee61..1874296df8c 100644 --- a/spec/lib/bitbucket/representation/comment_spec.rb +++ b/spec/lib/bitbucket/representation/comment_spec.rb @@ -4,7 +4,7 @@ require 'spec_helper' describe Bitbucket::Representation::Comment do describe '#author' do - it { expect(described_class.new('user' => { 'username' => 'Ben' }).author).to eq('Ben') } + it { expect(described_class.new('user' => { 'nickname' => 'Ben' }).author).to eq('Ben') } it { expect(described_class.new({}).author).to be_nil } end diff --git a/spec/lib/bitbucket/representation/issue_spec.rb b/spec/lib/bitbucket/representation/issue_spec.rb index c7d1ebdd597..655b9b78b47 100644 --- a/spec/lib/bitbucket/representation/issue_spec.rb +++ b/spec/lib/bitbucket/representation/issue_spec.rb @@ -17,7 +17,7 @@ describe Bitbucket::Representation::Issue do end describe '#author' do - it { expect(described_class.new({ 'reporter' => { 'username' => 'Ben' } }).author).to eq('Ben') } + it { expect(described_class.new({ 'reporter' => { 'nickname' => 'Ben' } }).author).to eq('Ben') } it { expect(described_class.new({}).author).to be_nil } end diff --git a/spec/lib/bitbucket/representation/pull_request_spec.rb b/spec/lib/bitbucket/representation/pull_request_spec.rb index 7cf43b2b6fd..70b51b8efec 100644 --- a/spec/lib/bitbucket/representation/pull_request_spec.rb +++ b/spec/lib/bitbucket/representation/pull_request_spec.rb @@ -8,7 +8,7 @@ describe Bitbucket::Representation::PullRequest do end describe '#author' do - it { expect(described_class.new({ 'author' => { 'username' => 'Ben' } }).author).to eq('Ben') } + it { expect(described_class.new({ 'author' => { 'nickname' => 'Ben' } }).author).to eq('Ben') } it { expect(described_class.new({}).author).to be_nil } end diff --git a/spec/lib/gitlab/bitbucket_import/importer_spec.rb b/spec/lib/gitlab/bitbucket_import/importer_spec.rb index 280941ff601..3d0d3f91859 100644 --- a/spec/lib/gitlab/bitbucket_import/importer_spec.rb +++ b/spec/lib/gitlab/bitbucket_import/importer_spec.rb @@ -25,12 +25,12 @@ describe Gitlab::BitbucketImport::Importer do let(:reporters) do [ nil, - { "username" => "reporter1" }, + { "nickname" => "reporter1" }, nil, - { "username" => "reporter2" }, - { "username" => "reporter1" }, + { "nickname" => "reporter2" }, + { "nickname" => "reporter1" }, nil, - { "username" => "reporter3" } + { "nickname" => "reporter3" } ] end @@ -115,6 +115,7 @@ describe Gitlab::BitbucketImport::Importer do created_at: Time.now, updated_at: Time.now) end + let(:author_line) { "*Created by: someuser*\n\n" } before do allow(subject).to receive(:import_wiki) @@ -128,7 +129,7 @@ describe Gitlab::BitbucketImport::Importer do old_pos: nil, new_pos: 4, note: 'Hello world', - author: 'root', + author: 'someuser', created_at: Time.now, updated_at: Time.now, inline?: true, @@ -139,7 +140,7 @@ describe Gitlab::BitbucketImport::Importer do iid: 3, file_path: '.gitmodules', note: 'Hello world', - author: 'root', + author: 'someuser', created_at: Time.now, updated_at: Time.now, inline?: true, @@ -163,11 +164,33 @@ describe Gitlab::BitbucketImport::Importer do notes = merge_request.notes.order(:id).to_a start_note = notes.first expect(start_note).to be_a(DiffNote) - expect(start_note.note).to eq(@inline_note.note) + expect(start_note.note).to include(@inline_note.note) + expect(start_note.note).to include(author_line) reply_note = notes.last expect(reply_note).to be_a(DiffNote) - expect(reply_note.note).to eq(@reply.note) + expect(reply_note.note).to include(@reply.note) + expect(reply_note.note).to include(author_line) + end + + context 'when user exists in GitLab' do + let!(:existing_user) { create(:user, username: 'someuser') } + let!(:identity) { create(:identity, provider: 'bitbucket', extern_uid: existing_user.username, user: existing_user) } + + it 'does not add author line to comments' do + expect { subject.execute }.to change { MergeRequest.count }.by(1) + + merge_request = MergeRequest.first + + notes = merge_request.notes.order(:id).to_a + start_note = notes.first + expect(start_note.note).to eq(@inline_note.note) + expect(start_note.note).not_to include(author_line) + + reply_note = notes.last + expect(reply_note.note).to eq(@reply.note) + expect(reply_note.note).not_to include(author_line) + end end context 'when importing a pull request throws an exception' do |