diff options
author | Douwe Maan <douwe@selenight.nl> | 2017-07-07 10:43:37 -0500 |
---|---|---|
committer | Douwe Maan <douwe@selenight.nl> | 2017-07-07 10:43:37 -0500 |
commit | c81928cfa757b6f42debd6d1c3b6cdb860fc14f5 (patch) | |
tree | 2069795e9fce322b3ab27a20c54dd8348fd4277a | |
parent | 1dab640357fa1ba8992757499e4167fcd4ce6276 (diff) | |
download | gitlab-ce-dm-fix-project-path-helpers-production.tar.gz |
Include new URL helpers retroactively into includers of Gitlab::Routingdm-fix-project-path-helpers-production
-rw-r--r-- | app/models/project_services/gitlab_issue_tracker_service.rb | 2 | ||||
-rw-r--r-- | app/models/project_services/jira_service.rb | 2 | ||||
-rw-r--r-- | app/services/chat_names/authorize_user_service.rb | 2 | ||||
-rw-r--r-- | config/application.rb | 14 | ||||
-rw-r--r-- | lib/gitlab/badge/metadata.rb | 2 | ||||
-rw-r--r-- | lib/gitlab/conflict/file.rb | 2 | ||||
-rw-r--r-- | lib/gitlab/email/message/repository_push.rb | 2 | ||||
-rw-r--r-- | lib/gitlab/routing.rb | 20 | ||||
-rw-r--r-- | lib/gitlab/slash_commands/presenters/base.rb | 2 | ||||
-rw-r--r-- | lib/gitlab/url_builder.rb | 2 | ||||
-rw-r--r-- | spec/lib/extracts_path_spec.rb | 2 | ||||
-rw-r--r-- | spec/models/project_services/jira_service_spec.rb | 2 | ||||
-rw-r--r-- | spec/services/system_note_service_spec.rb | 2 | ||||
-rw-r--r-- | spec/spec_helper.rb | 2 |
14 files changed, 36 insertions, 22 deletions
diff --git a/app/models/project_services/gitlab_issue_tracker_service.rb b/app/models/project_services/gitlab_issue_tracker_service.rb index 5e31f393bbe..420102875a5 100644 --- a/app/models/project_services/gitlab_issue_tracker_service.rb +++ b/app/models/project_services/gitlab_issue_tracker_service.rb @@ -1,5 +1,5 @@ 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? diff --git a/app/models/project_services/jira_service.rb b/app/models/project_services/jira_service.rb index 8af642b44aa..5498a2e17b2 100644 --- a/app/models/project_services/jira_service.rb +++ b/app/models/project_services/jira_service.rb @@ -1,5 +1,5 @@ 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 diff --git a/app/services/chat_names/authorize_user_service.rb b/app/services/chat_names/authorize_user_service.rb index 321bf3a9205..7256466c9e8 100644 --- a/app/services/chat_names/authorize_user_service.rb +++ b/app/services/chat_names/authorize_user_service.rb @@ -1,6 +1,6 @@ module ChatNames class AuthorizeUserService - include Gitlab::Routing.url_helpers + include Gitlab::Routing def initialize(service, params) @service = service diff --git a/config/application.rb b/config/application.rb index 3e6d72810cd..d88740ef8d7 100644 --- a/config/application.rb +++ b/config/application.rb @@ -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 diff --git a/lib/gitlab/badge/metadata.rb b/lib/gitlab/badge/metadata.rb index 86c193650fb..8ad6f3cb986 100644 --- a/lib/gitlab/badge/metadata.rb +++ b/lib/gitlab/badge/metadata.rb @@ -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 diff --git a/lib/gitlab/conflict/file.rb b/lib/gitlab/conflict/file.rb index d2b4e6e209e..98dfe900044 100644 --- a/lib/gitlab/conflict/file.rb +++ b/lib/gitlab/conflict/file.rb @@ -1,7 +1,7 @@ module Gitlab module Conflict class File - include Gitlab::Routing.url_helpers + include Gitlab::Routing include IconsHelper MissingResolution = Class.new(ResolutionError) diff --git a/lib/gitlab/email/message/repository_push.rb b/lib/gitlab/email/message/repository_push.rb index 42fc2a4ea19..dd1d9dcd555 100644 --- a/lib/gitlab/email/message/repository_push.rb +++ b/lib/gitlab/email/message/repository_push.rb @@ -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 diff --git a/lib/gitlab/routing.rb b/lib/gitlab/routing.rb index 632e2d87500..ac1e864433b 100644 --- a/lib/gitlab/routing.rb +++ b/lib/gitlab/routing.rb @@ -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 diff --git a/lib/gitlab/slash_commands/presenters/base.rb b/lib/gitlab/slash_commands/presenters/base.rb index 27696436574..e13808a2720 100644 --- a/lib/gitlab/slash_commands/presenters/base.rb +++ b/lib/gitlab/slash_commands/presenters/base.rb @@ -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 diff --git a/lib/gitlab/url_builder.rb b/lib/gitlab/url_builder.rb index 073af685a09..35792d2d67f 100644 --- a/lib/gitlab/url_builder.rb +++ b/lib/gitlab/url_builder.rb @@ -1,6 +1,6 @@ module Gitlab class UrlBuilder - include Gitlab::Routing.url_helpers + include Gitlab::Routing include GitlabRoutingHelper include ActionView::RecordIdentifier diff --git a/spec/lib/extracts_path_spec.rb b/spec/lib/extracts_path_spec.rb index f2132d485ab..dfffef8b9b7 100644 --- a/spec/lib/extracts_path_spec.rb +++ b/spec/lib/extracts_path_spec.rb @@ -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') } diff --git a/spec/models/project_services/jira_service_spec.rb b/spec/models/project_services/jira_service_spec.rb index 4a1de76f099..105afed1337 100644 --- a/spec/models/project_services/jira_service_spec.rb +++ b/spec/models/project_services/jira_service_spec.rb @@ -1,7 +1,7 @@ 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 } diff --git a/spec/services/system_note_service_spec.rb b/spec/services/system_note_service_spec.rb index e35e4c1d631..60477b8e9ba 100644 --- a/spec/services/system_note_service_spec.rb +++ b/spec/services/system_note_service_spec.rb @@ -1,7 +1,7 @@ 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) } diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 3e90a642d56..a497b8613bb 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -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! |