diff options
author | Alberto Almagro <albertoalmagro@gmail.com> | 2018-12-08 22:42:40 +0100 |
---|---|---|
committer | Alberto Almagro <albertoalmagro@gmail.com> | 2019-05-22 23:03:54 +0200 |
commit | fb9117e190e39872fff7ae5d6b96bfb26ef8b32c (patch) | |
tree | 6269b64939b1a15b672c1deb4b871b3b3e9256fb /actionpack/test | |
parent | d5a2f7ec148726d7547e367d7a968e3b4be9b509 (diff) | |
download | rails-fb9117e190e39872fff7ae5d6b96bfb26ef8b32c.tar.gz rails-fb9117e190e39872fff7ae5d6b96bfb26ef8b32c.tar.bz2 rails-fb9117e190e39872fff7ae5d6b96bfb26ef8b32c.zip |
Keep part when scope option has value
When a route was defined within an optional scope, if that route didn't
take parameters the scope was lost when using path helpers. This patch
ensures scope is kept both when the route takes parameters or when it
doesn't.
Fixes #33219
Diffstat (limited to 'actionpack/test')
-rw-r--r-- | actionpack/test/dispatch/routing_test.rb | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/actionpack/test/dispatch/routing_test.rb b/actionpack/test/dispatch/routing_test.rb index 362488d585..0070d7af72 100644 --- a/actionpack/test/dispatch/routing_test.rb +++ b/actionpack/test/dispatch/routing_test.rb @@ -4959,6 +4959,47 @@ class TestPartialDynamicPathSegments < ActionDispatch::IntegrationTest end end +class TestOptionalScopesWithOrWithoutParams < ActionDispatch::IntegrationTest + Routes = ActionDispatch::Routing::RouteSet.new.tap do |app| + app.draw do + scope module: "test_optional_scopes_with_or_without_params" do + scope "(:locale)", locale: /en|es/ do + get "home", to: "home#index" + get "with_param/:foo", to: "home#with_param", as: "with_param" + get "without_param", to: "home#without_param" + end + end + end + end + + class HomeController < ActionController::Base + include Routes.url_helpers + + def index + render inline: "<%= with_param_path(foo: 'bar') %> | <%= without_param_path %>" + end + + def with_param; end + def without_param; end + end + + APP = build_app Routes + + def app + APP + end + + def test_stays_unscoped_with_or_without_params + get "/home" + assert_equal "/with_param/bar | /without_param", response.body + end + + def test_preserves_scope_with_or_without_params + get "/es/home" + assert_equal "/es/with_param/bar | /es/without_param", response.body + end +end + class TestPathParameters < ActionDispatch::IntegrationTest Routes = ActionDispatch::Routing::RouteSet.new.tap do |app| app.draw do |