diff --git a/app/helpers/gitlab_routing_helper.rb b/app/helpers/gitlab_routing_helper.rb index 7f3c118c7ab..40073f714ee 100644 --- a/app/helpers/gitlab_routing_helper.rb +++ b/app/helpers/gitlab_routing_helper.rb @@ -81,6 +81,14 @@ module GitlabRoutingHelper end end + def edit_milestone_path(entity, *args) + if entity.parent.is_a?(Group) + edit_group_milestone_path(entity.parent, entity, *args) + else + edit_project_milestone_path(entity.parent, entity, *args) + end + end + def toggle_subscription_path(entity, *args) if entity.is_a?(Issue) toggle_subscription_project_issue_path(entity.project, entity) diff --git a/spec/helpers/gitlab_routing_helper_spec.rb b/spec/helpers/gitlab_routing_helper_spec.rb index 6c4f7050ee0..143b28728a3 100644 --- a/spec/helpers/gitlab_routing_helper_spec.rb +++ b/spec/helpers/gitlab_routing_helper_spec.rb @@ -89,4 +89,19 @@ describe GitlabRoutingHelper do expect(preview_markdown_path(project)).to eq("/#{project.full_path}/preview_markdown") end end + + describe '#edit_milestone_path' do + it 'returns group milestone edit path when given entity parent is a Group' do + group = create(:group) + milestone = create(:milestone, group: group) + + expect(edit_milestone_path(milestone)).to eq("/groups/#{group.path}/-/milestones/#{milestone.iid}/edit") + end + + it 'returns project milestone edit path when given entity parent is not a Group' do + milestone = create(:milestone, group: nil) + + expect(edit_milestone_path(milestone)).to eq("/#{milestone.project.full_path}/milestones/#{milestone.iid}/edit") + end + end end