diff options
author | Douglas Barbosa Alexandre <dbalexandre@gmail.com> | 2016-10-17 17:48:46 -0200 |
---|---|---|
committer | Douglas Barbosa Alexandre <dbalexandre@gmail.com> | 2016-10-19 14:58:27 -0200 |
commit | 8379fbcd47930320bf4dd6a3ac41c6efd427a91a (patch) | |
tree | c7f2f16f69032ae1584837c203d003c6b756ba25 | |
parent | d3b76e832f0afc38e2d0ffdff540c708a74ac26c (diff) | |
download | gitlab-ce-8379fbcd47930320bf4dd6a3ac41c6efd427a91a.tar.gz |
Add subject to group and projects labels which return group/project
-rw-r--r-- | app/helpers/labels_helper.rb | 10 | ||||
-rw-r--r-- | app/models/group_label.rb | 2 | ||||
-rw-r--r-- | app/models/project_label.rb | 2 | ||||
-rw-r--r-- | spec/models/group_label_spec.rb | 8 | ||||
-rw-r--r-- | spec/models/project_label_spec.rb | 8 |
5 files changed, 22 insertions, 8 deletions
diff --git a/app/helpers/labels_helper.rb b/app/helpers/labels_helper.rb index af8741f5e06..a1d7713b45f 100644 --- a/app/helpers/labels_helper.rb +++ b/app/helpers/labels_helper.rb @@ -14,7 +14,7 @@ module LabelsHelper # # 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) # # # Force the generated link to use a provided group @@ -31,13 +31,7 @@ module LabelsHelper # # Returns a String def link_to_label(label, subject: nil, type: :issue, tooltip: true, css_class: nil, &block) - subject ||= - case label - when GroupLabel then label.group - when ProjectLabel then label.project - end - - link = label_filter_path(subject, label, type: type) + link = label_filter_path(subject || label.subject, label, type: type) if block_given? link_to link, class: css_class, &block diff --git a/app/models/group_label.rb b/app/models/group_label.rb index a1d8d087726..a698b532d19 100644 --- a/app/models/group_label.rb +++ b/app/models/group_label.rb @@ -3,6 +3,8 @@ class GroupLabel < Label validates :group, presence: true + alias_attribute :subject, :group + def to_reference(source_project = nil, target_project = nil, format: :id) super(source_project, target_project, format: format) end diff --git a/app/models/project_label.rb b/app/models/project_label.rb index f863d442c21..0a79521ed09 100644 --- a/app/models/project_label.rb +++ b/app/models/project_label.rb @@ -10,6 +10,8 @@ class ProjectLabel < Label delegate :group, to: :project, allow_nil: true + alias_attribute :subject, :project + def to_reference(target_project = nil, format: :id) super(project, target_project, format: format) end diff --git a/spec/models/group_label_spec.rb b/spec/models/group_label_spec.rb index 92b07a3cd44..85eb889225b 100644 --- a/spec/models/group_label_spec.rb +++ b/spec/models/group_label_spec.rb @@ -9,6 +9,14 @@ describe GroupLabel, models: true do it { is_expected.to validate_presence_of(:group) } 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 let(:label) { create(:group_label) } diff --git a/spec/models/project_label_spec.rb b/spec/models/project_label_spec.rb index cd4732fb737..18c9d449ee5 100644 --- a/spec/models/project_label_spec.rb +++ b/spec/models/project_label_spec.rb @@ -64,6 +64,14 @@ describe ProjectLabel, models: true do 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 let(:label) { create(:label) } |