From aa9435cddbe57841b4572e05fb4e7756f8b47405 Mon Sep 17 00:00:00 2001 From: Robert Speicher Date: Sat, 25 Apr 2015 19:18:09 -0400 Subject: [PATCH 1/3] Remove duplicate settings for default_url_options Closes internal https://dev.gitlab.org/gitlab/gitlabhq/issues/2269 --- app/controllers/application_controller.rb | 12 ------------ app/mailers/notify.rb | 7 +------ .../project_services/gitlab_issue_tracker_service.rb | 5 ----- 3 files changed, 1 insertion(+), 23 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index cfe2c76265c..69fd7901832 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -182,18 +182,6 @@ class ApplicationController < ActionController::Base response.headers["Expires"] = "Fri, 01 Jan 1990 00:00:00 GMT" end - def default_url_options - if !Rails.env.test? - port = Gitlab.config.gitlab.port unless Gitlab.config.gitlab_on_standard_port? - { host: Gitlab.config.gitlab.host, - protocol: Gitlab.config.gitlab.protocol, - port: port, - script_name: Gitlab.config.gitlab.relative_url_root } - else - super - end - end - def default_headers headers['X-Frame-Options'] = 'DENY' headers['X-XSS-Protection'] = '1; mode=block' diff --git a/app/mailers/notify.rb b/app/mailers/notify.rb index 2c0d451511f..79fb48b00d3 100644 --- a/app/mailers/notify.rb +++ b/app/mailers/notify.rb @@ -16,11 +16,6 @@ class Notify < ActionMailer::Base attr_accessor :current_user helper_method :current_user, :can? - default_url_options[:host] = Gitlab.config.gitlab.host - default_url_options[:protocol] = Gitlab.config.gitlab.protocol - default_url_options[:port] = Gitlab.config.gitlab.port unless Gitlab.config.gitlab_on_standard_port? - default_url_options[:script_name] = Gitlab.config.gitlab.relative_url_root - default from: Proc.new { default_sender_address.format } default reply_to: Gitlab.config.gitlab.email_reply_to @@ -69,7 +64,7 @@ class Notify < ActionMailer::Base # Only the displayed name changes; the actual email address is always the same. def sender(sender_id, send_from_user_email = false) return unless sender = User.find(sender_id) - + address = default_sender_address address.display_name = sender.name diff --git a/app/models/project_services/gitlab_issue_tracker_service.rb b/app/models/project_services/gitlab_issue_tracker_service.rb index 5f0553f3b0b..0ebc0a3ba1a 100644 --- a/app/models/project_services/gitlab_issue_tracker_service.rb +++ b/app/models/project_services/gitlab_issue_tracker_service.rb @@ -21,11 +21,6 @@ class GitlabIssueTrackerService < IssueTrackerService include Rails.application.routes.url_helpers - default_url_options[:host] = Gitlab.config.gitlab.host - default_url_options[:protocol] = Gitlab.config.gitlab.protocol - default_url_options[:port] = Gitlab.config.gitlab.port unless Gitlab.config.gitlab_on_standard_port? - default_url_options[:script_name] = Gitlab.config.gitlab.relative_url_root - prop_accessor :title, :description, :project_url, :issues_url, :new_issue_url def default? From 2c90579749459f0d4d5d534785aa3006bec1a444 Mon Sep 17 00:00:00 2001 From: Robert Speicher Date: Sat, 25 Apr 2015 19:41:46 -0400 Subject: [PATCH 2/3] Set default_url_options in test environments too --- config/initializers/8_default_url_options.rb | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/config/initializers/8_default_url_options.rb b/config/initializers/8_default_url_options.rb index 8c1b56846d2..8fd27b1d88e 100644 --- a/config/initializers/8_default_url_options.rb +++ b/config/initializers/8_default_url_options.rb @@ -1,13 +1,11 @@ -unless Rails.env.test? - default_url_options = { - host: Gitlab.config.gitlab.host, - protocol: Gitlab.config.gitlab.protocol, - script_name: Gitlab.config.gitlab.relative_url_root - } +default_url_options = { + host: Gitlab.config.gitlab.host, + protocol: Gitlab.config.gitlab.protocol, + script_name: Gitlab.config.gitlab.relative_url_root +} - unless Gitlab.config.gitlab_on_standard_port? - default_url_options[:port] = Gitlab.config.gitlab.port - end - - Rails.application.routes.default_url_options = default_url_options +unless Gitlab.config.gitlab_on_standard_port? + default_url_options[:port] = Gitlab.config.gitlab.port end + +Rails.application.routes.default_url_options = default_url_options From e3d2304d6971c42436e711ccf70b8e4d5114f887 Mon Sep 17 00:00:00 2001 From: Robert Speicher Date: Mon, 27 Apr 2015 15:43:50 -0400 Subject: [PATCH 3/3] Specs don't need to set default_url_options anymore --- spec/features/users_spec.rb | 7 ------- spec/support/reference_filter_spec_helper.rb | 11 ----------- 2 files changed, 18 deletions(-) diff --git a/spec/features/users_spec.rb b/spec/features/users_spec.rb index 4cfaab03caf..93d2b18b5fc 100644 --- a/spec/features/users_spec.rb +++ b/spec/features/users_spec.rb @@ -1,13 +1,6 @@ require 'spec_helper' feature 'Users' do - around do |ex| - old_url_options = Rails.application.routes.default_url_options - Rails.application.routes.default_url_options = { host: 'example.foo' } - ex.run - Rails.application.routes.default_url_options = old_url_options - end - scenario 'GET /users/sign_in creates a new user account' do visit new_user_session_path fill_in 'user_name', with: 'Name Surname' diff --git a/spec/support/reference_filter_spec_helper.rb b/spec/support/reference_filter_spec_helper.rb index bcee5715cad..0e035f0e597 100644 --- a/spec/support/reference_filter_spec_helper.rb +++ b/spec/support/reference_filter_spec_helper.rb @@ -4,17 +4,6 @@ module ReferenceFilterSpecHelper extend ActiveSupport::Concern - included do - before { set_default_url_options } - end - - # Allow *_url helpers to work - def set_default_url_options - Rails.application.routes.default_url_options = { - host: 'example.foo' - } - end - # Shortcut to Rails' auto-generated routes helpers, to avoid including the # module def urls