Commit 2088cee9 authored by Stan Hu's avatar Stan Hu

Fix URL builder to use GitlabRoutingHelper

parent abc69c89
module Gitlab module Gitlab
class UrlBuilder class UrlBuilder
include Rails.application.routes.url_helpers include Rails.application.routes.url_helpers
include GitlabRoutingHelper
def initialize(type) def initialize(type)
@type = type @type = type
...@@ -9,27 +10,22 @@ module Gitlab ...@@ -9,27 +10,22 @@ module Gitlab
def build(id) def build(id)
case @type case @type
when :issue when :issue
issue_url(id) build_issue_url(id)
when :merge_request when :merge_request
merge_request_url(id) build_merge_request_url(id)
end end
end end
private private
def issue_url(id) def build_issue_url(id)
issue = Issue.find(id) issue = Issue.find(id)
namespace_project_issue_url(namespace_id: issue.project.namespace, issue_url(issue, host: Gitlab.config.gitlab['url'])
id: issue.iid,
project_id: issue.project,
host: Gitlab.config.gitlab['url'])
end end
def merge_request_url(id) def build_merge_request_url(id)
merge_request = MergeRequest.find(id) merge_request = MergeRequest.find(id)
project_merge_request_url(id: merge_request.id, merge_request_url(merge_request, host: Gitlab.config.gitlab['url'])
project_id: merge_request.project,
host: Gitlab.config.gitlab['url'])
end end
end end
end end
...@@ -13,7 +13,7 @@ describe Gitlab::UrlBuilder do ...@@ -13,7 +13,7 @@ describe Gitlab::UrlBuilder do
it 'returns the merge request url' do it 'returns the merge request url' do
merge_request = create(:merge_request) merge_request = create(:merge_request)
url = Gitlab::UrlBuilder.new(:merge_request).build(merge_request.id) url = Gitlab::UrlBuilder.new(:merge_request).build(merge_request.id)
expect(url).to eq "#{Settings.gitlab['url']}/#{merge_request.project.to_param}/merge_requests/#{merge_request.id}" expect(url).to eq "#{Settings.gitlab['url']}/#{merge_request.project.path_with_namespace}/merge_requests/#{merge_request.iid}"
end end
end end
end end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment