Commit 426271da authored by Douwe Maan's avatar Douwe Maan

Merge branch 'dm-fix-project-path-helpers-production' into 'master'

Include new URL helpers retroactively into includers of Gitlab::Routing

Closes #34821

See merge request !12716
parents 787a2347 c81928cf
class GitlabIssueTrackerService < IssueTrackerService class GitlabIssueTrackerService < IssueTrackerService
include Gitlab::Routing.url_helpers include Gitlab::Routing
validates :project_url, :issues_url, :new_issue_url, presence: true, url: true, if: :activated? validates :project_url, :issues_url, :new_issue_url, presence: true, url: true, if: :activated?
......
class JiraService < IssueTrackerService class JiraService < IssueTrackerService
include Gitlab::Routing.url_helpers include Gitlab::Routing
validates :url, url: true, presence: true, if: :activated? validates :url, url: true, presence: true, if: :activated?
validates :api_url, url: true, allow_blank: true validates :api_url, url: true, allow_blank: true
......
module ChatNames module ChatNames
class AuthorizeUserService class AuthorizeUserService
include Gitlab::Routing.url_helpers include Gitlab::Routing
def initialize(service, params) def initialize(service, params)
@service = service @service = service
......
...@@ -166,9 +166,10 @@ module Gitlab ...@@ -166,9 +166,10 @@ module Gitlab
config.after_initialize do config.after_initialize do
Rails.application.reload_routes! Rails.application.reload_routes!
named_routes_set = Gitlab::Application.routes.named_routes
project_url_helpers = Module.new do project_url_helpers = Module.new do
named_routes_set.helper_names.each do |name| extend ActiveSupport::Concern
Gitlab::Application.routes.named_routes.helper_names.each do |name|
next unless name.include?('namespace_project') next unless name.include?('namespace_project')
define_method(name.sub('namespace_project', 'project')) do |project, *args| define_method(name.sub('namespace_project', 'project')) do |project, *args|
...@@ -177,14 +178,7 @@ module Gitlab ...@@ -177,14 +178,7 @@ module Gitlab
end end
end end
named_routes_set.url_helpers_module.include project_url_helpers Gitlab::Routing.add_helpers(project_url_helpers)
named_routes_set.url_helpers_module.extend project_url_helpers
Gitlab::Routing.url_helpers.include project_url_helpers
Gitlab::Routing.url_helpers.extend project_url_helpers
GitlabRoutingHelper.include project_url_helpers
GitlabRoutingHelper.extend project_url_helpers
end end
end end
end end
...@@ -4,7 +4,7 @@ module Gitlab ...@@ -4,7 +4,7 @@ module Gitlab
# Abstract class for badge metadata # Abstract class for badge metadata
# #
class Metadata class Metadata
include Gitlab::Routing.url_helpers include Gitlab::Routing
include ActionView::Helpers::AssetTagHelper include ActionView::Helpers::AssetTagHelper
include ActionView::Helpers::UrlHelper include ActionView::Helpers::UrlHelper
......
module Gitlab module Gitlab
module Conflict module Conflict
class File class File
include Gitlab::Routing.url_helpers include Gitlab::Routing
include IconsHelper include IconsHelper
MissingResolution = Class.new(ResolutionError) MissingResolution = Class.new(ResolutionError)
......
...@@ -4,7 +4,7 @@ module Gitlab ...@@ -4,7 +4,7 @@ module Gitlab
class RepositoryPush class RepositoryPush
attr_reader :author_id, :ref, :action attr_reader :author_id, :ref, :action
include Gitlab::Routing.url_helpers include Gitlab::Routing
include DiffHelper include DiffHelper
delegate :namespace, :name_with_namespace, to: :project, prefix: :project delegate :namespace, :name_with_namespace, to: :project, prefix: :project
......
...@@ -2,10 +2,30 @@ module Gitlab ...@@ -2,10 +2,30 @@ module Gitlab
module Routing module Routing
extend ActiveSupport::Concern extend ActiveSupport::Concern
mattr_accessor :_includers
self._includers = []
included do included do
Gitlab::Routing._includers << self
include Gitlab::Routing.url_helpers include Gitlab::Routing.url_helpers
end end
def self.add_helpers(mod)
url_helpers.include mod
url_helpers.extend mod
app_url_helpers = Gitlab::Application.routes.named_routes.url_helpers_module
app_url_helpers.include mod
app_url_helpers.extend mod
GitlabRoutingHelper.include mod
GitlabRoutingHelper.extend mod
_includers.each do |klass|
klass.include mod
end
end
# Returns the URL helpers Module. # Returns the URL helpers Module.
# #
# This method caches the output as Rails' "url_helpers" method creates an # This method caches the output as Rails' "url_helpers" method creates an
......
...@@ -2,7 +2,7 @@ module Gitlab ...@@ -2,7 +2,7 @@ module Gitlab
module SlashCommands module SlashCommands
module Presenters module Presenters
class Base class Base
include Gitlab::Routing.url_helpers include Gitlab::Routing
def initialize(resource = nil) def initialize(resource = nil)
@resource = resource @resource = resource
......
module Gitlab module Gitlab
class UrlBuilder class UrlBuilder
include Gitlab::Routing.url_helpers include Gitlab::Routing
include GitlabRoutingHelper include GitlabRoutingHelper
include ActionView::RecordIdentifier include ActionView::RecordIdentifier
......
...@@ -3,7 +3,7 @@ require 'spec_helper' ...@@ -3,7 +3,7 @@ require 'spec_helper'
describe ExtractsPath, lib: true do describe ExtractsPath, lib: true do
include ExtractsPath include ExtractsPath
include RepoHelpers include RepoHelpers
include Gitlab::Routing.url_helpers include Gitlab::Routing
let(:project) { double('project') } let(:project) { double('project') }
let(:request) { double('request') } let(:request) { double('request') }
......
require 'spec_helper' require 'spec_helper'
describe JiraService, models: true do describe JiraService, models: true do
include Gitlab::Routing.url_helpers include Gitlab::Routing
describe "Associations" do describe "Associations" do
it { is_expected.to belong_to :project } it { is_expected.to belong_to :project }
......
require 'spec_helper' require 'spec_helper'
describe SystemNoteService, services: true do describe SystemNoteService, services: true do
include Gitlab::Routing.url_helpers include Gitlab::Routing
let(:project) { create(:empty_project) } let(:project) { create(:empty_project) }
let(:author) { create(:user) } let(:author) { create(:user) }
......
...@@ -57,7 +57,7 @@ RSpec.configure do |config| ...@@ -57,7 +57,7 @@ RSpec.configure do |config|
config.include StubGitlabCalls config.include StubGitlabCalls
config.include StubGitlabData config.include StubGitlabData
config.include ApiHelpers, :api config.include ApiHelpers, :api
config.include Gitlab::Routing.url_helpers, type: :routing config.include Gitlab::Routing, type: :routing
config.include MigrationsHelpers, :migration config.include MigrationsHelpers, :migration
config.infer_spec_type_from_file_location! config.infer_spec_type_from_file_location!
......
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