Commit cc307f44 authored by Jan Provaznik's avatar Jan Provaznik

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

Use Label#scoped_label_key when determining scope

See merge request gitlab-org/gitlab!25952
parents c394109a 3b7b5f11
......@@ -11,14 +11,12 @@ module EE
def render_colored_label(label, suffix: '')
return super unless label.scoped_label?
scope_name, label_name = label.name.split(Label::SCOPED_LABEL_SEPARATOR)
render_label_text(
scope_name,
label.scoped_label_key,
css_class: text_color_class_for_bg(label.color),
bg_color: label.color
) + render_label_text(
label_name,
label.scoped_label_value,
suffix: suffix
)
end
......
......@@ -12,7 +12,11 @@ module EE
end
def scoped_label_key
title[Label::SCOPED_LABEL_PATTERN]
title[Label::SCOPED_LABEL_PATTERN]&.delete_suffix(SCOPED_LABEL_SEPARATOR)
end
def scoped_label_value
title.sub(SCOPED_LABEL_PATTERN, '')
end
end
end
......@@ -263,9 +263,6 @@ describe 'Issue Boards', :js do
end
it 'removes existing scoped label' do
scoped1 = scoped_label_1.title.split(Label::SCOPED_LABEL_SEPARATOR)
scoped2 = scoped_label_2.title.split(Label::SCOPED_LABEL_SEPARATOR)
click_card(card1)
page.within('.labels') do
......@@ -285,9 +282,9 @@ describe 'Issue Boards', :js do
page.within('.value') do
expect(page).to have_selector('.gl-label-scoped', count: 1)
expect(page).not_to have_content(scoped1.last)
expect(page).to have_content(scoped2.first)
expect(page).to have_content(scoped2.last)
expect(page).not_to have_content(scoped_label_1.scoped_label_value)
expect(page).to have_content(scoped_label_2.scoped_label_key)
expect(page).to have_content(scoped_label_2.scoped_label_value)
end
end
......
......@@ -14,9 +14,7 @@ describe LabelsHelper do
end
it 'includes link to scoped labels documentation' do
scope, name = scoped_label.title.split(Label::SCOPED_LABEL_SEPARATOR)
expect(render_label(scoped_label)).to match(%r(<span.+>#{scope}</span><span.+>#{name}</span><a.+>.*question-circle.*</a>)m)
expect(render_label(scoped_label)).to match(%r(<span.+>#{scoped_label.scoped_label_key}</span><span.+>#{scoped_label.scoped_label_value}</span><a.+>.*question-circle.*</a>)m)
end
it 'does not include link to scoped label documentation for common labels' do
......
......@@ -16,9 +16,8 @@ describe Banzai::Filter::LabelReferenceFilter do
it 'includes link to scoped documentation' do
doc = reference_filter("See #{scoped_label.to_reference}")
scope, name = scoped_label.name.split(Label::SCOPED_LABEL_SEPARATOR)
expect(doc.to_html).to match(%r(<span.+><a.+><span.+>#{scope}</span><span.+>#{name}</span></a><a.+>.*question-circle.*</a></span>))
expect(doc.to_html).to match(%r(<span.+><a.+><span.+>#{scoped_label.scoped_label_key}</span><span.+>#{scoped_label.scoped_label_value}</span></a><a.+>.*question-circle.*</a></span>))
end
it 'does not include link to scoped documentation for common labels' do
......
......@@ -19,17 +19,25 @@ describe Label do
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)
describe 'splitting scoped labels' do
using RSpec::Parameterized::TableSyntax
where(:title, :key, :value) do
'key1::key 2::some value' | 'key1::key 2' | 'some value'
'key1::some value' | 'key1' | 'some value'
'::some value' | '' | 'some value'
'some value' | nil | 'some value'
end
with_them do
let(:label) { build(:label, title: title) }
it '#scoped_label_key returns key for scoped labels' do
expect(label.scoped_label_key).to eq(key)
end
it '#scoped_label_value returns title without the key' do
expect(label.scoped_label_value).to eq(value)
end
end
end
......
......@@ -26,8 +26,8 @@ describe ScopedLabelSet do
expect(sets.size).to eq 3
expect(get_labels(sets, nil)).to match_array([labels[0].id, labels[1].id])
expect(get_labels(sets, 'key::')).to match_array([labels[2].id, labels[3].id])
expect(get_labels(sets, 'key::another key::')).to match_array([labels[4].id, labels[5].id])
expect(get_labels(sets, 'key')).to match_array([labels[2].id, labels[3].id])
expect(get_labels(sets, 'key::another key')).to match_array([labels[4].id, labels[5].id])
end
end
......
......@@ -3,7 +3,7 @@
module Gitlab
module MarkdownCache
# Increment this number every time the renderer changes its output
CACHE_COMMONMARK_VERSION = 19
CACHE_COMMONMARK_VERSION = 20
CACHE_COMMONMARK_VERSION_START = 10
BaseError = Class.new(StandardError)
......
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