From 15911ef32792b19daf192a0123a8a44ff393eb02 Mon Sep 17 00:00:00 2001 From: Sean McGivern Date: Mon, 31 Jul 2017 17:33:57 +0100 Subject: [PATCH] Fix group milestone path on issuable sidebar --- app/helpers/gitlab_routing_helper.rb | 14 ++++- app/views/shared/issuable/_sidebar.html.haml | 2 +- ...oup-milestone-link-in-issuable-sidebar.yml | 4 ++ spec/factories/milestones.rb | 2 +- spec/helpers/gitlab_routing_helper_spec.rb | 53 +++++++++++++++---- 5 files changed, 62 insertions(+), 13 deletions(-) create mode 100644 changelogs/unreleased/fix-group-milestone-link-in-issuable-sidebar.yml diff --git a/app/helpers/gitlab_routing_helper.rb b/app/helpers/gitlab_routing_helper.rb index 0517a699ae0..1f7db9b2eb8 100644 --- a/app/helpers/gitlab_routing_helper.rb +++ b/app/helpers/gitlab_routing_helper.rb @@ -48,7 +48,11 @@ module GitlabRoutingHelper end def milestone_path(entity, *args) - project_milestone_path(entity.project, entity, *args) + if entity.is_group_milestone? + group_milestone_path(entity.group, entity, *args) + elsif entity.is_project_milestone? + project_milestone_path(entity.project, entity, *args) + end end def issue_url(entity, *args) @@ -63,6 +67,14 @@ module GitlabRoutingHelper project_pipeline_url(pipeline.project, pipeline.id, *args) end + def milestone_url(entity, *args) + if entity.is_group_milestone? + group_milestone_url(entity.group, entity, *args) + elsif entity.is_project_milestone? + project_milestone_url(entity.project, entity, *args) + end + end + def pipeline_job_url(pipeline, build, *args) project_job_url(pipeline.project, build.id, *args) end diff --git a/app/views/shared/issuable/_sidebar.html.haml b/app/views/shared/issuable/_sidebar.html.haml index b08267357e5..e7510c1d1ec 100644 --- a/app/views/shared/issuable/_sidebar.html.haml +++ b/app/views/shared/issuable/_sidebar.html.haml @@ -37,7 +37,7 @@ = link_to 'Edit', '#', class: 'edit-link pull-right' .value.hide-collapsed - if issuable.milestone - = link_to issuable.milestone.title, project_milestone_path(@project, issuable.milestone), class: "bold has-tooltip", title: milestone_remaining_days(issuable.milestone), data: { container: "body", html: 1 } + = link_to issuable.milestone.title, milestone_path(issuable.milestone), class: "bold has-tooltip", title: milestone_remaining_days(issuable.milestone), data: { container: "body", html: 1 } - else %span.no-value None diff --git a/changelogs/unreleased/fix-group-milestone-link-in-issuable-sidebar.yml b/changelogs/unreleased/fix-group-milestone-link-in-issuable-sidebar.yml new file mode 100644 index 00000000000..1558e575e6d --- /dev/null +++ b/changelogs/unreleased/fix-group-milestone-link-in-issuable-sidebar.yml @@ -0,0 +1,4 @@ +--- +title: Fix links to group milestones from issue and merge request sidebar +merge_request: +author: diff --git a/spec/factories/milestones.rb b/spec/factories/milestones.rb index 113665ff11b..b5e2ec60072 100644 --- a/spec/factories/milestones.rb +++ b/spec/factories/milestones.rb @@ -17,7 +17,7 @@ FactoryGirl.define do state "closed" end - after(:build) do |milestone, evaluator| + after(:build, :stub) do |milestone, evaluator| if evaluator.group milestone.group = evaluator.group elsif evaluator.group_id diff --git a/spec/helpers/gitlab_routing_helper_spec.rb b/spec/helpers/gitlab_routing_helper_spec.rb index 717ac1962d1..9aaed0edf87 100644 --- a/spec/helpers/gitlab_routing_helper_spec.rb +++ b/spec/helpers/gitlab_routing_helper_spec.rb @@ -1,6 +1,9 @@ require 'spec_helper' describe GitlabRoutingHelper do + let(:project) { build_stubbed(:empty_project) } + let(:group) { build_stubbed(:group) } + describe 'Project URL helpers' do describe '#project_member_path' do let(:project_member) { create(:project_member) } @@ -9,14 +12,10 @@ describe GitlabRoutingHelper do end describe '#request_access_project_members_path' do - let(:project) { build_stubbed(:empty_project) } - it { expect(request_access_project_members_path(project)).to eq request_access_project_project_members_path(project) } end describe '#leave_project_members_path' do - let(:project) { build_stubbed(:empty_project) } - it { expect(leave_project_members_path(project)).to eq leave_project_project_members_path(project) } end @@ -35,8 +34,6 @@ describe GitlabRoutingHelper do describe 'Group URL helpers' do describe '#group_members_url' do - let(:group) { build_stubbed(:group) } - it { expect(group_members_url(group)).to eq group_group_members_url(group) } end @@ -47,14 +44,10 @@ describe GitlabRoutingHelper do end describe '#request_access_group_members_path' do - let(:group) { build_stubbed(:group) } - it { expect(request_access_group_members_path(group)).to eq request_access_group_group_members_path(group) } end describe '#leave_group_members_path' do - let(:group) { build_stubbed(:group) } - it { expect(leave_group_members_path(group)).to eq leave_group_group_members_path(group) } end @@ -70,4 +63,44 @@ describe GitlabRoutingHelper do it { expect(resend_invite_group_member_path(group_member)).to eq resend_invite_group_group_member_path(group_member.source, group_member) } end end + + describe '#milestone_path' do + context 'for a group milestone' do + let(:milestone) { build_stubbed(:milestone, group: group, iid: 1) } + + it 'links to the group milestone page' do + expect(milestone_path(milestone)) + .to eq(group_milestone_path(group, milestone)) + end + end + + context 'for a project milestone' do + let(:milestone) { build_stubbed(:milestone, project: project, iid: 1) } + + it 'links to the project milestone page' do + expect(milestone_path(milestone)) + .to eq(project_milestone_path(project, milestone)) + end + end + end + + describe '#milestone_url' do + context 'for a group milestone' do + let(:milestone) { build_stubbed(:milestone, group: group, iid: 1) } + + it 'links to the group milestone page' do + expect(milestone_url(milestone)) + .to eq(group_milestone_url(group, milestone)) + end + end + + context 'for a project milestone' do + let(:milestone) { build_stubbed(:milestone, project: project, iid: 1) } + + it 'links to the project milestone page' do + expect(milestone_url(milestone)) + .to eq(project_milestone_url(project, milestone)) + end + end + end end