Add subject to group and projects labels which return group/project

parent d3b76e83
...@@ -14,7 +14,7 @@ module LabelsHelper ...@@ -14,7 +14,7 @@ module LabelsHelper
# #
# Examples: # Examples:
# #
# # Allow the generated link to use the label's own project # # Allow the generated link to use the label's own subject
# link_to_label(label) # link_to_label(label)
# #
# # Force the generated link to use a provided group # # Force the generated link to use a provided group
...@@ -31,13 +31,7 @@ module LabelsHelper ...@@ -31,13 +31,7 @@ module LabelsHelper
# #
# Returns a String # Returns a String
def link_to_label(label, subject: nil, type: :issue, tooltip: true, css_class: nil, &block) def link_to_label(label, subject: nil, type: :issue, tooltip: true, css_class: nil, &block)
subject ||= link = label_filter_path(subject || label.subject, label, type: type)
case label
when GroupLabel then label.group
when ProjectLabel then label.project
end
link = label_filter_path(subject, label, type: type)
if block_given? if block_given?
link_to link, class: css_class, &block link_to link, class: css_class, &block
......
...@@ -3,6 +3,8 @@ class GroupLabel < Label ...@@ -3,6 +3,8 @@ class GroupLabel < Label
validates :group, presence: true validates :group, presence: true
alias_attribute :subject, :group
def to_reference(source_project = nil, target_project = nil, format: :id) def to_reference(source_project = nil, target_project = nil, format: :id)
super(source_project, target_project, format: format) super(source_project, target_project, format: format)
end end
......
...@@ -10,6 +10,8 @@ class ProjectLabel < Label ...@@ -10,6 +10,8 @@ class ProjectLabel < Label
delegate :group, to: :project, allow_nil: true delegate :group, to: :project, allow_nil: true
alias_attribute :subject, :project
def to_reference(target_project = nil, format: :id) def to_reference(target_project = nil, format: :id)
super(project, target_project, format: format) super(project, target_project, format: format)
end end
......
...@@ -9,6 +9,14 @@ describe GroupLabel, models: true do ...@@ -9,6 +9,14 @@ describe GroupLabel, models: true do
it { is_expected.to validate_presence_of(:group) } it { is_expected.to validate_presence_of(:group) }
end end
describe '#subject' do
it 'aliases group to subject' do
subject = described_class.new(group: build(:group))
expect(subject.subject).to be(subject.group)
end
end
describe '#to_reference' do describe '#to_reference' do
let(:label) { create(:group_label) } let(:label) { create(:group_label) }
......
...@@ -64,6 +64,14 @@ describe ProjectLabel, models: true do ...@@ -64,6 +64,14 @@ describe ProjectLabel, models: true do
end end
end end
describe '#subject' do
it 'aliases project to subject' do
subject = described_class.new(project: build(:empty_project))
expect(subject.subject).to be(subject.project)
end
end
describe '#to_reference' do describe '#to_reference' do
let(:label) { create(:label) } let(:label) { create(:label) }
......
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