Commit 60797a42 authored by Rémy Coutable's avatar Rémy Coutable

Ensure Gitlab::Application.routes.default_url_options are set correctly in Capybara + :js specs

Signed-off-by: default avatarRémy Coutable <remy@rymai.me>
parent 48c51e20
...@@ -223,7 +223,7 @@ Settings.gitlab['default_can_create_group'] = true if Settings.gitlab['default_c ...@@ -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['host'] ||= ENV['GITLAB_HOST'] || 'localhost'
Settings.gitlab['ssh_host'] ||= Settings.gitlab.host Settings.gitlab['ssh_host'] ||= Settings.gitlab.host
Settings.gitlab['https'] = false if Settings.gitlab['https'].nil? 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['relative_url_root'] ||= ENV['RAILS_RELATIVE_URL_ROOT'] || ''
Settings.gitlab['protocol'] ||= Settings.gitlab.https ? "https" : "http" Settings.gitlab['protocol'] ||= Settings.gitlab.https ? "https" : "http"
Settings.gitlab['email_enabled'] ||= true if Settings.gitlab['email_enabled'].nil? Settings.gitlab['email_enabled'] ||= true if Settings.gitlab['email_enabled'].nil?
......
...@@ -12,7 +12,7 @@ module API ...@@ -12,7 +12,7 @@ module API
end end
def expose_url(path) 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 protocol, host, port = url_options.slice(:protocol, :host, :port).values
URI::HTTP.build(scheme: protocol, host: host, port: port, path: path).to_s URI::HTTP.build(scheme: protocol, host: host, port: port, path: path).to_s
......
...@@ -79,15 +79,7 @@ RSpec.describe 'Dashboard Issues' do ...@@ -79,15 +79,7 @@ RSpec.describe 'Dashboard Issues' do
end end
end end
it 'shows the new issue page', js: true do it 'shows the new issue page', :js 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'
}
find('.new-project-item-select-button').trigger('click') find('.new-project-item-select-button').trigger('click')
wait_for_requests wait_for_requests
find('.select2-results li').click find('.select2-results li').click
...@@ -97,8 +89,6 @@ RSpec.describe 'Dashboard Issues' do ...@@ -97,8 +89,6 @@ RSpec.describe 'Dashboard Issues' do
page.within('#content-body') do page.within('#content-body') do
expect(page).to have_selector('.issue-form') expect(page).to have_selector('.issue-form')
end end
Gitlab::Application.routes.default_url_options = original_defaults
end end
end end
end end
...@@ -21,7 +21,7 @@ describe ProjectWiki do ...@@ -21,7 +21,7 @@ describe ProjectWiki do
describe '#web_url' do describe '#web_url' do
it 'returns the full web URL to the wiki' 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
end end
......
...@@ -59,6 +59,7 @@ RSpec.configure do |config| ...@@ -59,6 +59,7 @@ RSpec.configure do |config|
config.include Gitlab::Routing, type: :routing config.include Gitlab::Routing, type: :routing
config.include MigrationsHelpers, :migration config.include MigrationsHelpers, :migration
config.include StubFeatureFlags config.include StubFeatureFlags
config.include StubENV
config.infer_spec_type_from_file_location! config.infer_spec_type_from_file_location!
......
...@@ -36,7 +36,14 @@ RSpec.configure do |config| ...@@ -36,7 +36,14 @@ RSpec.configure do |config|
$capybara_server_already_started = true $capybara_server_already_started = true
end 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, # capybara/rspec already calls Capybara.reset_sessions! in an `after` hook,
# but `block_and_wait_for_requests_complete` is called before it so by # 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 # 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