Commit c81928cf authored by Douwe Maan's avatar Douwe Maan

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

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