Commit da967803 authored by Robert Speicher's avatar Robert Speicher

Merge branch '35599-fix-uncontrolled-default_url_options-overriding' into 'master'

Ensure Gitlab.config.gitlab.host/port and Gitlab::Application.routes.default_url_options are set correctly in Capybara + :js specs

Closes #35599

See merge request !13126
parents 62e9bb16 a2ba403e
......@@ -223,7 +223,7 @@ Settings.gitlab['default_can_create_group'] = true if Settings.gitlab['default_c
Settings.gitlab['host'] ||= ENV['GITLAB_HOST'] || 'localhost'
Settings.gitlab['ssh_host'] ||= Settings.gitlab.host
Settings.gitlab['https'] = false if Settings.gitlab['https'].nil?
Settings.gitlab['port'] ||= Settings.gitlab.https ? 443 : 80
Settings.gitlab['port'] ||= ENV['GITLAB_PORT'] || (Settings.gitlab.https ? 443 : 80)
Settings.gitlab['relative_url_root'] ||= ENV['RAILS_RELATIVE_URL_ROOT'] || ''
Settings.gitlab['protocol'] ||= Settings.gitlab.https ? "https" : "http"
Settings.gitlab['email_enabled'] ||= true if Settings.gitlab['email_enabled'].nil?
......
......@@ -12,7 +12,7 @@ module API
end
def expose_url(path)
url_options = Rails.application.routes.default_url_options
url_options = Gitlab::Application.routes.default_url_options
protocol, host, port = url_options.slice(:protocol, :host, :port).values
URI::HTTP.build(scheme: protocol, host: host, port: port, path: path).to_s
......
......@@ -79,15 +79,7 @@ RSpec.describe 'Dashboard Issues' do
end
end
it 'shows the new issue page', js: true do
original_defaults = Gitlab::Application.routes.default_url_options
Gitlab::Application.routes.default_url_options = {
host: Capybara.current_session.server.host,
port: Capybara.current_session.server.port,
protocol: 'http'
}
it 'shows the new issue page', :js do
find('.new-project-item-select-button').trigger('click')
wait_for_requests
find('.select2-results li').click
......@@ -97,8 +89,6 @@ RSpec.describe 'Dashboard Issues' do
page.within('#content-body') do
expect(page).to have_selector('.issue-form')
end
Gitlab::Application.routes.default_url_options = original_defaults
end
end
end
......@@ -16,15 +16,13 @@ feature 'Create Branch/Merge Request Dropdown on issue page', js: true do
select_dropdown_option('create-mr')
wait_for_requests
expect(page).to have_content('WIP: Resolve "Cherry-Coloured Funk"')
expect(current_path).to eq(project_merge_request_path(project, MergeRequest.first))
visit project_issue_path(project, issue)
expect(page).to have_content("created branch 1-cherry-coloured-funk")
expect(page).to have_content("mentioned in merge request !1")
visit project_merge_request_path(project, MergeRequest.first)
expect(page).to have_content('WIP: Resolve "Cherry-Coloured Funk"')
expect(current_path).to eq(project_merge_request_path(project, MergeRequest.first))
end
it 'allows creating a branch from the issue page' do
......
......@@ -21,7 +21,7 @@ describe ProjectWiki do
describe '#web_url' do
it 'returns the full web URL to the wiki' do
expect(subject.web_url).to match("https?://[^\/]+/#{project.path_with_namespace}/wikis/home")
expect(subject.web_url).to eq("#{Gitlab.config.gitlab.url}/#{project.path_with_namespace}/wikis/home")
end
end
......
......@@ -59,6 +59,7 @@ RSpec.configure do |config|
config.include Gitlab::Routing, type: :routing
config.include MigrationsHelpers, :migration
config.include StubFeatureFlags
config.include StubENV
config.infer_spec_type_from_file_location!
......
......@@ -36,7 +36,14 @@ RSpec.configure do |config|
$capybara_server_already_started = true
end
config.after(:each, :js) do |example|
config.before(:example, :js) do
allow(Gitlab::Application.routes).to receive(:default_url_options).and_return(
host: Capybara.current_session.server.host,
port: Capybara.current_session.server.port,
protocol: 'http')
end
config.after(:example, :js) do |example|
# capybara/rspec already calls Capybara.reset_sessions! in an `after` hook,
# but `block_and_wait_for_requests_complete` is called before it so by
# calling it explicitely here, we prevent any new requests from being fired
......
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