Commit dc38ab91 authored by Jan Provaznik's avatar Jan Provaznik Committed by Sean McGivern

Fix scoped_label? check for admin view

On admin labels page all labels are "generic" labels, so
label's subject (project/group) is not available here. When
checking if a label is scoped label we should first check if
subject method is available.
parent 95655138
......@@ -7,7 +7,7 @@ module EE
SCOPED_LABEL_PATTERN = /^.*::/.freeze
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
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