summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan Provaznik <jprovaznik@gitlab.com>2018-07-05 10:12:15 +0200
committerJan Provaznik <jprovaznik@gitlab.com>2018-07-05 10:12:15 +0200
commit1f320d1c50ed5001d915dbaece670664f242691d (patch)
treecc0528c5aab5b1405b75900571386675cc4f359b
parentd785295fefa89315cdf0a72f572ed162678dcf1c (diff)
downloadgitlab-ce-1f320d1c50ed5001d915dbaece670664f242691d.tar.gz
Added tests for MRs
-rw-r--r--lib/gitlab/background_migration/fix_cross_project_label_links.rb2
-rw-r--r--spec/lib/gitlab/background_migration/fix_cross_project_label_links_spec.rb105
2 files changed, 67 insertions, 40 deletions
diff --git a/lib/gitlab/background_migration/fix_cross_project_label_links.rb b/lib/gitlab/background_migration/fix_cross_project_label_links.rb
index f210734c777..8a50b15cfae 100644
--- a/lib/gitlab/background_migration/fix_cross_project_label_links.rb
+++ b/lib/gitlab/background_migration/fix_cross_project_label_links.rb
@@ -106,7 +106,7 @@ module Gitlab
next unless matching_label
- LabelLink.find(label.label_link_id).update!(label_id: matching_label.id)
+ LabelLink.update(label.label_link_id, label_id: matching_label.id)
end
end
diff --git a/spec/lib/gitlab/background_migration/fix_cross_project_label_links_spec.rb b/spec/lib/gitlab/background_migration/fix_cross_project_label_links_spec.rb
index 0ff2b874a6e..20af63bc6c8 100644
--- a/spec/lib/gitlab/background_migration/fix_cross_project_label_links_spec.rb
+++ b/spec/lib/gitlab/background_migration/fix_cross_project_label_links_spec.rb
@@ -17,66 +17,93 @@ describe Gitlab::BackgroundMigration::FixCrossProjectLabelLinks, :migration, sch
let!(:label1) { labels_table.create(id: 1, title: 'bug', color: 'red', group_id: 10, type: 'GroupLabel') }
let!(:label2) { labels_table.create(id: 2, title: 'bug', color: 'red', group_id: 20, type: 'GroupLabel') }
- let(:merge_request) do
- merge_requests_table.create(target_project_id: project.id,
+ def create_merge_request(id, project_id)
+ merge_requests_table.create(id: id,
+ target_project_id: project_id,
target_branch: 'master',
- source_project_id: project.id,
+ source_project_id: project_id,
source_branch: 'mr name',
- title: 'mr name')
+ title: "mr name#{id}")
end
- it 'updates cross-project label links which exist in the local project or group' do
- issues_table.create(id: 1, title: 'issue1', project_id: 1)
- link = label_links_table.create(label_id: 2, target_type: 'Issue', target_id: 1)
-
- subject.perform(1, 100)
-
- expect(link.reload.label_id).to eq(1)
+ def create_issue(id, project_id)
+ issues_table.create(id: id, title: "issue#{id}", project_id: project_id)
end
- it 'ignores cross-project label links if label color is different' do
- labels_table.create(id: 3, title: 'bug', color: 'green', group_id: 20, type: 'GroupLabel')
- issues_table.create(id: 1, title: 'issue1', project_id: 1)
- link = label_links_table.create(label_id: 3, target_type: 'Issue', target_id: 1)
+ def create_resource(target_type, id, project_id)
+ target_type == 'Issue' ? create_issue(id, project_id) : create_merge_request(id, project_id)
+ end
- subject.perform(1, 100)
+ shared_examples_for 'resource with cross-project labels' do
+ it 'updates only cross-project label links which exist in the local project or group' do
+ create_resource(target_type, 1, 1)
+ create_resource(target_type, 2, 3)
+ labels_table.create(id: 3, title: 'bug', color: 'red', project_id: 3, type: 'ProjectLabel')
+ link = label_links_table.create(label_id: 2, target_type: target_type, target_id: 1)
+ link2 = label_links_table.create(label_id: 3, target_type: target_type, target_id: 2)
- expect(link.reload.label_id).to eq(3)
- end
+ subject.perform(1, 100)
- it 'ignores cross-project label links if label name is different' do
- labels_table.create(id: 3, title: 'bug1', color: 'red', group_id: 20, type: 'GroupLabel')
- issues_table.create(id: 1, title: 'issue1', project_id: 1)
- link = label_links_table.create(label_id: 3, target_type: 'Issue', target_id: 1)
+ expect(link.reload.label_id).to eq(1)
+ expect(link2.reload.label_id).to eq(3)
+ end
- subject.perform(1, 100)
+ it 'ignores cross-project label links if label color is different' do
+ labels_table.create(id: 3, title: 'bug', color: 'green', group_id: 20, type: 'GroupLabel')
+ create_resource(target_type, 1, 1)
+ link = label_links_table.create(label_id: 3, target_type: target_type, target_id: 1)
- expect(link.reload.label_id).to eq(3)
- end
+ subject.perform(1, 100)
- context 'with nested group' do
- before do
- namespaces_table.create(id: 11, type: 'Group', name: 'subgroup1', path: 'group1/subgroup1', parent_id: 10)
- projects_table.create(id: 2, name: 'subproject1', path: 'group1/subgroup1/subproject1', namespace_id: 11)
- issues_table.create(id: 1, title: 'issue1', project_id: 2)
+ expect(link.reload.label_id).to eq(3)
end
- it 'ignores label links referencing ancestor group labels', :nested_groups do
- labels_table.create(id: 4, title: 'bug', color: 'red', project_id: 2, type: 'ProjectLabel')
- label_links_table.create(label_id: 4, target_type: 'Issue', target_id: 1)
- link = label_links_table.create(label_id: 1, target_type: 'Issue', target_id: 1)
+ it 'ignores cross-project label links if label name is different' do
+ labels_table.create(id: 3, title: 'bug1', color: 'red', group_id: 20, type: 'GroupLabel')
+ create_resource(target_type, 1, 1)
+ link = label_links_table.create(label_id: 3, target_type: target_type, target_id: 1)
subject.perform(1, 100)
- expect(link.reload.label_id).to eq(1)
+ expect(link.reload.label_id).to eq(3)
end
- it 'checks also issues and MRs in subgroups', :nested_groups do
- link = label_links_table.create(label_id: 2, target_type: 'Issue', target_id: 1)
+ context 'with nested group' do
+ before do
+ namespaces_table.create(id: 11, type: 'Group', name: 'subgroup1', path: 'group1/subgroup1', parent_id: 10)
+ projects_table.create(id: 2, name: 'subproject1', path: 'group1/subgroup1/subproject1', namespace_id: 11)
+ create_resource(target_type, 1, 2)
+ end
- subject.perform(1, 100)
+ it 'ignores label links referencing ancestor group labels', :nested_groups do
+ labels_table.create(id: 4, title: 'bug', color: 'red', project_id: 2, type: 'ProjectLabel')
+ label_links_table.create(label_id: 4, target_type: target_type, target_id: 1)
+ link = label_links_table.create(label_id: 1, target_type: target_type, target_id: 1)
- expect(link.reload.label_id).to eq(1)
+ subject.perform(1, 100)
+
+ expect(link.reload.label_id).to eq(1)
+ end
+
+ it 'checks also issues and MRs in subgroups', :nested_groups do
+ link = label_links_table.create(label_id: 2, target_type: target_type, target_id: 1)
+
+ subject.perform(1, 100)
+
+ expect(link.reload.label_id).to eq(1)
+ end
+ end
+ end
+
+ context 'resource is Issue' do
+ it_behaves_like 'resource with cross-project labels' do
+ let(:target_type) { 'Issue' }
+ end
+ end
+
+ context 'resource is Merge Request' do
+ it_behaves_like 'resource with cross-project labels' do
+ let(:target_type) { 'MergeRequest' }
end
end
end