diff options
author | Eileen M. Uchitelle <eileencodes@users.noreply.github.com> | 2019-07-24 08:16:23 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-07-24 08:16:23 -0400 |
commit | bee689dad9e2a42ebc3fc398ed9d316825e217cf (patch) | |
tree | 2ad476b61c4b7d37cc7b15b59d114c2c77fd9548 | |
parent | 6cd364cfe5cc36b5754139967780f9f3b6ddd503 (diff) | |
parent | e6cf57df8a609c697c0bc593576f06895414da64 (diff) | |
download | rails-bee689dad9e2a42ebc3fc398ed9d316825e217cf.tar.gz rails-bee689dad9e2a42ebc3fc398ed9d316825e217cf.tar.bz2 rails-bee689dad9e2a42ebc3fc398ed9d316825e217cf.zip |
Merge pull request #36741 from Edouard-chin/ec-system-test-url-options
Define the `url_options` needed for SytemTest inside the route proxy:
-rw-r--r-- | actionpack/lib/action_dispatch/system_test_case.rb | 12 | ||||
-rw-r--r-- | railties/test/application/system_test_case_test.rb | 45 |
2 files changed, 52 insertions, 5 deletions
diff --git a/actionpack/lib/action_dispatch/system_test_case.rb b/actionpack/lib/action_dispatch/system_test_case.rb index 9772beb8aa..4fda2cf44f 100644 --- a/actionpack/lib/action_dispatch/system_test_case.rb +++ b/actionpack/lib/action_dispatch/system_test_case.rb @@ -120,7 +120,13 @@ module ActionDispatch super self.class.driver.use @proxy_route = if ActionDispatch.test_app - Class.new { include ActionDispatch.test_app.routes.url_helpers }.new + Class.new do + include ActionDispatch.test_app.routes.url_helpers + + def url_options + default_url_options.merge(host: Capybara.app_host) + end + end.new else nil end @@ -164,10 +170,6 @@ module ActionDispatch driven_by :selenium - def url_options # :nodoc: - default_url_options.merge(host: Capybara.app_host) - end - def method_missing(method, *args, &block) if @proxy_route.respond_to?(method) @proxy_route.send(method, *args, &block) diff --git a/railties/test/application/system_test_case_test.rb b/railties/test/application/system_test_case_test.rb new file mode 100644 index 0000000000..d15a0d9210 --- /dev/null +++ b/railties/test/application/system_test_case_test.rb @@ -0,0 +1,45 @@ +# frozen_string_literal: true + +require "isolation/abstract_unit" +require "rack/test" + +class SystemTestCaseTest < ActiveSupport::TestCase + include ActiveSupport::Testing::Isolation + + def setup + build_app + end + + def teardown + teardown_app + end + + test "url helpers are delegated to a proxy class" do + app_file "config/routes.rb", <<-RUBY + Rails.application.routes.draw do + get 'foo', to: 'foo#index', as: 'test_foo' + end + RUBY + + app("test") + + assert_not_includes(ActionDispatch::SystemTestCase.runnable_methods, :test_foo_url) + end + + test "system tests set the Capybara host in the url_options by default" do + app_file "config/routes.rb", <<-RUBY + Rails.application.routes.draw do + get 'foo', to: 'foo#index', as: 'test_foo' + end + RUBY + + app("test") + system_test = ActionDispatch::SystemTestCase.new("my_test") + previous_app_host = ::Capybara.app_host + ::Capybara.app_host = "https://my_test_example.com" + + assert_equal("https://my_test_example.com/foo", system_test.test_foo_url) + ensure + ::Capybara.app_host = previous_app_host + end +end |