summaryrefslogtreecommitdiff
path: root/spec/services/labels
diff options
context:
space:
mode:
authorDouglas Barbosa Alexandre <dbalexandre@gmail.com>2016-09-26 17:10:54 -0300
committerDouglas Barbosa Alexandre <dbalexandre@gmail.com>2016-10-19 14:58:24 -0200
commit8522ef44bf4298a750d352ff17832b3f4fc6756d (patch)
treed2d7edb6337ca5a15b3f37e969a408b6a129e6a7 /spec/services/labels
parente28058c4107ce454a84b3e3b5750f936dace7db1 (diff)
downloadgitlab-ce-8522ef44bf4298a750d352ff17832b3f4fc6756d.tar.gz
Recreates missing group labels when moving project to another group
Diffstat (limited to 'spec/services/labels')
-rw-r--r--spec/services/labels/transfer_service_spec.rb41
1 files changed, 41 insertions, 0 deletions
diff --git a/spec/services/labels/transfer_service_spec.rb b/spec/services/labels/transfer_service_spec.rb
new file mode 100644
index 00000000000..a72a05f6c99
--- /dev/null
+++ b/spec/services/labels/transfer_service_spec.rb
@@ -0,0 +1,41 @@
+require 'spec_helper'
+
+describe Labels::TransferService, services: true do
+ describe '#execute' do
+ let(:user) { create(:user) }
+ let(:group_1) { create(:group) }
+ let(:group_2) { create(:group) }
+ let(:project) { create(:project, namespace: group_2) }
+
+ let(:group_label_1) { create(:group_label, group: group_1, name: 'Group Label 1') }
+ let(:group_label_2) { create(:group_label, group: group_1, name: 'Group Label 2') }
+ let(:group_label_3) { create(:group_label, group: group_1, name: 'Group Label 3') }
+ let(:group_label_4) { create(:group_label, group: group_2, name: 'Group Label 4') }
+ let(:project_label_1) { create(:label, project: project, name: 'Project Label 1') }
+
+ subject(:service) { described_class.new(user, group_1, project) }
+
+ before do
+ create(:labeled_issue, project: project, labels: [group_label_1])
+ create(:labeled_issue, project: project, labels: [group_label_4])
+ create(:labeled_issue, project: project, labels: [project_label_1])
+ create(:labeled_merge_request, source_project: project, labels: [group_label_1, group_label_2])
+ end
+
+ it 'recreates the missing group labels at project level' do
+ expect { service.execute }.to change(project.labels, :count).by(2)
+ end
+
+ it 'does not recreate missing group labels that are not applied to issues or merge requests' do
+ service.execute
+
+ expect(project.labels.where(title: group_label_3.title)).to be_empty
+ end
+
+ it 'does not recreate missing group labels that already exist in the project group' do
+ service.execute
+
+ expect(project.labels.where(title: group_label_4.title)).to be_empty
+ end
+ end
+end