Commit ae8bfa83 authored by Sean McGivern's avatar Sean McGivern

Merge branch 'scoped-labels-fix' into 'master'

Fix scoped_label? check for admin view

Closes #11141

See merge request gitlab-org/gitlab-ee!10981
parents 95655138 dc38ab91
...@@ -7,7 +7,7 @@ module EE ...@@ -7,7 +7,7 @@ module EE
SCOPED_LABEL_PATTERN = /^.*::/.freeze SCOPED_LABEL_PATTERN = /^.*::/.freeze
def scoped_label? def scoped_label?
SCOPED_LABEL_PATTERN.match?(name) && subject.feature_available?(:scoped_labels) SCOPED_LABEL_PATTERN.match?(name) && respond_to?(:subject) && subject.feature_available?(:scoped_labels)
end end
def scoped_label_key def scoped_label_key
......
# frozen_string_literal: true
require 'spec_helper'
describe Label do
describe '#scoped_label?' do
context 'with scoped_labels available' do
before do
stub_licensed_features(scoped_labels: true)
end
it 'returns false for unscoped labels' do
expect(build(:label, title: 'some name').scoped_label?).to be_falsey
end
it 'returns true for scoped labels' do
expect(build(:label, title: 'key::some name').scoped_label?).to be_truthy
end
it 'returns false for scoped labels without subject' do
label = described_class.new(title: 'key::some name')
expect(label.scoped_label?).to be_falsey
end
end
context 'with scoped_labels not available' do
before do
stub_licensed_features(scoped_labels: false)
end
it 'returns false for scoped labels' do
expect(build(:label, title: 'key::some name').scoped_label?).to be_falsey
end
end
end
describe '#scoped_label_key' do
it 'returns key for scoped labels' do
mappings = {
'key1::key 2::some value' => 'key1::key 2::',
'key1::some value' => 'key1::',
'::some value' => '::',
'some value' => nil
}
mappings.each do |title, expected_key|
expect(build(:label, title: title).scoped_label_key).to eq(expected_key)
end
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment