diff options
author | Douglas Barbosa Alexandre <dbalexandre@gmail.com> | 2016-09-05 18:44:21 -0300 |
---|---|---|
committer | Douglas Barbosa Alexandre <dbalexandre@gmail.com> | 2016-09-16 10:56:47 -0300 |
commit | ba1e93970b6fbdf7271f17d7ce471e4b249cc3ea (patch) | |
tree | a0b177c52c93910f4b29e093ff6dea200d2b9d63 | |
parent | 1030dc72c8edc3c7f7d41cb842f31e3dcaa1c0de (diff) | |
download | gitlab-ce-ba1e93970b6fbdf7271f17d7ce471e4b249cc3ea.tar.gz |
Fix LabelsHelper
-rw-r--r-- | app/helpers/labels_helper.rb | 12 | ||||
-rw-r--r-- | app/views/projects/issues/_issue.html.haml | 2 | ||||
-rw-r--r-- | app/views/projects/merge_requests/_merge_request.html.haml | 2 | ||||
-rw-r--r-- | spec/helpers/labels_helper_spec.rb | 27 |
4 files changed, 26 insertions, 17 deletions
diff --git a/app/helpers/labels_helper.rb b/app/helpers/labels_helper.rb index 5e9f5837101..c7d865799c9 100644 --- a/app/helpers/labels_helper.rb +++ b/app/helpers/labels_helper.rb @@ -4,9 +4,9 @@ module LabelsHelper # Link to a Label # # label - Label object to link to - # project - Project object which will be used as the context for the label's - # link. If omitted, defaults to `@project`, or the label's own - # project. + # subject - Project/Group object which will be used as the context for the + # label's link. If omitted, defaults to `@subject`, or the label's + # own subject. # type - The type of item the link will point to (:issue or # :merge_request). If omitted, defaults to :issue. # block - An optional block that will be passed to `link_to`, forming the @@ -23,7 +23,7 @@ module LabelsHelper # link_to_label(label) # # # Force the generated link to use a provided project - # link_to_label(label, project: Project.last) + # link_to_label(label, subject: Project.last) # # # Force the generated link to point to merge requests instead of issues # link_to_label(label, type: :merge_request) @@ -33,7 +33,7 @@ module LabelsHelper # # Returns a String def link_to_label(label, project: nil, type: :issue, tooltip: true, css_class: nil, &block) - project ||= @project || label.project + project ||= @project || label.subject link = label_filter_path(project, label, type: type) if block_given? @@ -69,7 +69,7 @@ module LabelsHelper end def render_colored_cross_project_label(label, tooltip: true) - label_suffix = label.project.name_with_namespace + label_suffix = label.subject.name_with_namespace label_suffix = " <i>in #{escape_once(label_suffix)}</i>" render_colored_label(label, label_suffix, tooltip: tooltip) end diff --git a/app/views/projects/issues/_issue.html.haml b/app/views/projects/issues/_issue.html.haml index 8b1a8a8a2d9..c80210d6ff4 100644 --- a/app/views/projects/issues/_issue.html.haml +++ b/app/views/projects/issues/_issue.html.haml @@ -50,7 +50,7 @@ - if issue.labels.any? - issue.labels.each do |label| - = link_to_label(label, project: issue.project) + = link_to_label(label, subject: issue.project) - if issue.tasks? %span.task-status diff --git a/app/views/projects/merge_requests/_merge_request.html.haml b/app/views/projects/merge_requests/_merge_request.html.haml index 68fb7d5a414..ad62bf50b57 100644 --- a/app/views/projects/merge_requests/_merge_request.html.haml +++ b/app/views/projects/merge_requests/_merge_request.html.haml @@ -62,7 +62,7 @@ - if merge_request.labels.any? - merge_request.labels.each do |label| - = link_to_label(label, project: merge_request.project, type: 'merge_request') + = link_to_label(label, subject: merge_request.project, type: 'merge_request') - if merge_request.tasks? %span.task-status diff --git a/spec/helpers/labels_helper_spec.rb b/spec/helpers/labels_helper_spec.rb index 42c89a6e897..a084f1ecfae 100644 --- a/spec/helpers/labels_helper_spec.rb +++ b/spec/helpers/labels_helper_spec.rb @@ -5,27 +5,36 @@ describe LabelsHelper do let(:project) { create(:empty_project) } let(:label) { create(:label, subject: project) } - context 'with @project set' do + context 'with @subject set' do before do - @project = project + @subject = project end it 'uses the instance variable' do - expect(link_to_label(label)).to match %r{<a href="/#{@project.to_reference}/issues\?label_name%5B%5D=#{label.name}"><span class="[\w\s\-]*has-tooltip".*</span></a>} + expect(link_to_label(label)).to match %r{<a href="/#{@subject.to_reference}/issues\?label_name%5B%5D=#{label.name}"><span class="[\w\s\-]*has-tooltip".*</span></a>} end end - context 'without @project set' do - it "uses the label's project" do + context 'without @subject set' do + it "uses the label's subject" do expect(link_to_label(label)).to match %r{<a href="/#{label.subject.to_reference}/issues\?label_name%5B%5D=#{label.name}">.*</a>} end end - context 'with a project argument' do - let(:another_project) { double('project', namespace: 'foo3', to_param: 'bar3') } + context 'with a project as subject' do + let(:namespace) { build(:namespace, name: 'foo3') } + let(:another_project) { build(:empty_project, namespace: namespace, name: 'bar3') } - it 'links to merge requests page' do - expect(link_to_label(label, project: another_project)).to match %r{<a href="/foo3/bar3/issues\?label_name%5B%5D=#{label.name}">.*</a>} + it 'links to project issues page' do + expect(link_to_label(label, subject: another_project)).to match %r{<a href="/foo3/bar3/issues\?label_name%5B%5D=#{label.name}">.*</a>} + end + end + + context 'with a group as subject' do + let(:group) { build(:group, name: 'bar') } + + it 'links to group issues page' do + expect(link_to_label(label, subject: group)).to match %r{<a href="/groups/bar/issues\?label_name%5B%5D=#{label.name}">.*</a>} end end |