Commit 1e63ff75 authored by Douglas Barbosa Alexandre's avatar Douglas Barbosa Alexandre

Merge branch 'web-url-in-presenters' into 'master'

Add web_url/web_path on Gitlab::View::Presenter::Base

See merge request gitlab-org/gitlab!30176
parents 9dec6f8c a3af78f3
...@@ -17,14 +17,6 @@ class CommitPresenter < Gitlab::View::Presenter::Delegated ...@@ -17,14 +17,6 @@ class CommitPresenter < Gitlab::View::Presenter::Delegated
commit.pipelines.any? commit.pipelines.any?
end end
def web_url
url_builder.build(commit)
end
def web_path
url_builder.build(commit, only_path: true)
end
def signature_html def signature_html
return unless commit.has_signature? return unless commit.has_signature?
......
...@@ -3,10 +3,6 @@ ...@@ -3,10 +3,6 @@
class IssuePresenter < Gitlab::View::Presenter::Delegated class IssuePresenter < Gitlab::View::Presenter::Delegated
presents :issue presents :issue
def web_url
url_builder.build(issue)
end
def issue_path def issue_path
url_builder.build(issue, only_path: true) url_builder.build(issue, only_path: true)
end end
......
...@@ -202,10 +202,6 @@ class MergeRequestPresenter < Gitlab::View::Presenter::Delegated ...@@ -202,10 +202,6 @@ class MergeRequestPresenter < Gitlab::View::Presenter::Delegated
end end
end end
def web_url
Gitlab::UrlBuilder.build(merge_request)
end
def subscribed? def subscribed?
merge_request.subscribed?(current_user, merge_request.target_project) merge_request.subscribed?(current_user, merge_request.target_project)
end end
......
...@@ -3,12 +3,8 @@ ...@@ -3,12 +3,8 @@
class SnippetPresenter < Gitlab::View::Presenter::Delegated class SnippetPresenter < Gitlab::View::Presenter::Delegated
presents :snippet presents :snippet
def web_url
Gitlab::UrlBuilder.build(snippet)
end
def raw_url def raw_url
Gitlab::UrlBuilder.build(snippet, raw: true) url_builder.build(snippet, raw: true)
end end
def ssh_url_to_repo def ssh_url_to_repo
......
...@@ -2,12 +2,4 @@ ...@@ -2,12 +2,4 @@
class UserPresenter < Gitlab::View::Presenter::Delegated class UserPresenter < Gitlab::View::Presenter::Delegated
presents :user presents :user
def web_url
Gitlab::Routing.url_helpers.user_url(user)
end
def web_path
Gitlab::Routing.url_helpers.user_path(user)
end
end end
...@@ -34,6 +34,14 @@ module Gitlab ...@@ -34,6 +34,14 @@ module Gitlab
super || subject.is_a?(type) super || subject.is_a?(type)
end end
def web_url
url_builder.build(subject)
end
def web_path
url_builder.build(subject, only_path: true)
end
class_methods do class_methods do
def presenter? def presenter?
true true
......
...@@ -57,4 +57,32 @@ RSpec.describe Gitlab::View::Presenter::Base do ...@@ -57,4 +57,32 @@ RSpec.describe Gitlab::View::Presenter::Base do
expect(presenter.present).to eq(presenter) expect(presenter.present).to eq(presenter)
end end
end end
describe '#url_builder' do
it 'returns the UrlBuilder instance' do
presenter = presenter_class.new(project)
expect(presenter.url_builder).to eq(Gitlab::UrlBuilder.instance)
end
end
describe '#web_url' do
it 'delegates to the UrlBuilder' do
presenter = presenter_class.new(project)
expect(presenter.url_builder).to receive(:build).with(project)
presenter.web_url
end
end
describe '#web_path' do
it 'delegates to the UrlBuilder' do
presenter = presenter_class.new(project)
expect(presenter.url_builder).to receive(:build).with(project, only_path: true)
presenter.web_path
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