From 78b0106878fa1b2e2062e2c4ebb0a63375825879 Mon Sep 17 00:00:00 2001 From: Oswaldo Ferreira Date: Thu, 12 Jan 2017 10:28:37 -0200 Subject: [PATCH] Move issuable reference display to a helper method --- app/helpers/issuables_helper.rb | 4 ++ app/views/projects/issues/_issue.html.haml | 3 +- .../merge_requests/_merge_request.html.haml | 3 +- spec/helpers/issuables_helper_spec.rb | 40 +++++++++++++++++++ 4 files changed, 46 insertions(+), 4 deletions(-) diff --git a/app/helpers/issuables_helper.rb b/app/helpers/issuables_helper.rb index e5bb8b93e76..03354c235eb 100644 --- a/app/helpers/issuables_helper.rb +++ b/app/helpers/issuables_helper.rb @@ -162,6 +162,10 @@ module IssuablesHelper ] end + def issuable_reference(issuable) + @show_full_reference ? issuable.to_reference(full: true) : issuable.to_reference(@group || @project) + end + def issuable_filter_present? issuable_filter_params.any? { |k| params.key?(k) } end diff --git a/app/views/projects/issues/_issue.html.haml b/app/views/projects/issues/_issue.html.haml index 6173d9e21f6..f3be343daae 100644 --- a/app/views/projects/issues/_issue.html.haml +++ b/app/views/projects/issues/_issue.html.haml @@ -34,8 +34,7 @@ = note_count .issue-info - = @show_full_reference ? issue.to_reference(full: true) : issue.to_reference(@group || @project) - · + #{issuable_reference(issue)} · opened #{time_ago_with_tooltip(issue.created_at, placement: 'bottom')} by #{link_to_member(@project, issue.author, avatar: false)} - if issue.milestone diff --git a/app/views/projects/merge_requests/_merge_request.html.haml b/app/views/projects/merge_requests/_merge_request.html.haml index a1e6d09612c..513f0818169 100644 --- a/app/views/projects/merge_requests/_merge_request.html.haml +++ b/app/views/projects/merge_requests/_merge_request.html.haml @@ -46,8 +46,7 @@ = note_count .merge-request-info - = @show_full_reference ? merge_request.to_reference(full: true) : merge_request.to_reference(@group || @project) - · + #{issuable_reference(merge_request)} · opened #{time_ago_with_tooltip(merge_request.created_at, placement: 'bottom')} by #{link_to_member(@project, merge_request.author, avatar: false)} - if merge_request.target_project.default_branch != merge_request.target_branch diff --git a/spec/helpers/issuables_helper_spec.rb b/spec/helpers/issuables_helper_spec.rb index a4f08dc4af0..df71680e44c 100644 --- a/spec/helpers/issuables_helper_spec.rb +++ b/spec/helpers/issuables_helper_spec.rb @@ -115,6 +115,46 @@ describe IssuablesHelper do end end + describe '#issuable_reference' do + context 'when show_full_reference truthy' do + it 'display issuable full reference' do + assign(:show_full_reference, true) + issue = build_stubbed(:issue) + + expect(helper.issuable_reference(issue)).to eql(issue.to_reference(full: true)) + end + end + + context 'when show_full_reference falsey' do + context 'when @group present' do + it 'display issuable reference to @group' do + project = build_stubbed(:project) + + assign(:show_full_reference, nil) + assign(:group, project.namespace) + + issue = build_stubbed(:issue) + + expect(helper.issuable_reference(issue)).to eql(issue.to_reference(project.namespace)) + end + end + + context 'when @project present' do + it 'display issuable reference to @project' do + project = build_stubbed(:project) + + assign(:show_full_reference, nil) + assign(:group, nil) + assign(:project, project) + + issue = build_stubbed(:issue) + + expect(helper.issuable_reference(issue)).to eql(issue.to_reference(project)) + end + end + end + end + describe '#issuable_filter_present?' do it 'returns true when any key is present' do allow(helper).to receive(:params).and_return(