summaryrefslogtreecommitdiff
path: root/spec/services/labels/find_or_create_service_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/services/labels/find_or_create_service_spec.rb')
-rw-r--r--spec/services/labels/find_or_create_service_spec.rb29
1 files changed, 29 insertions, 0 deletions
diff --git a/spec/services/labels/find_or_create_service_spec.rb b/spec/services/labels/find_or_create_service_spec.rb
index aa9eb0e6a0d..3ea2727dc60 100644
--- a/spec/services/labels/find_or_create_service_spec.rb
+++ b/spec/services/labels/find_or_create_service_spec.rb
@@ -25,6 +25,35 @@ RSpec.describe Labels::FindOrCreateService do
project.add_developer(user)
end
+ context 'when existing_labels_by_title is provided' do
+ let(:preloaded_label) { build(:label, title: 'Security') }
+
+ before do
+ params.merge!(
+ existing_labels_by_title: {
+ 'Security' => preloaded_label
+ })
+ end
+
+ context 'when label exists' do
+ it 'returns preloaded label' do
+ expect(service.execute).to eq preloaded_label
+ end
+ end
+
+ context 'when label does not exists' do
+ before do
+ params[:title] = 'Audit'
+ end
+
+ it 'does not generates additional label search' do
+ service.execute
+
+ expect(LabelsFinder).not_to receive(:new)
+ end
+ end
+ end
+
context 'when label does not exist at group level' do
it 'creates a new label at project level' do
expect { service.execute }.to change(project.labels, :count).by(1)