diff options
-rw-r--r-- | Gemfile.lock | 135 | ||||
-rw-r--r-- | actionpack/actionpack.gemspec | 2 | ||||
-rw-r--r-- | actionpack/lib/action_controller/metal/strong_parameters.rb | 8 | ||||
-rw-r--r-- | actionpack/lib/action_dispatch/routing/mapper.rb | 5 | ||||
-rw-r--r-- | actionpack/lib/action_dispatch/routing/routes_proxy.rb | 23 | ||||
-rw-r--r-- | actionview/lib/action_view/helpers/controller_helper.rb | 2 | ||||
-rw-r--r-- | activesupport/test/hash_with_indifferent_access_test.rb | 2 | ||||
-rw-r--r-- | railties/test/application/rake/dbs_test.rb | 2 | ||||
-rw-r--r-- | railties/test/railties/engine_test.rb | 29 | ||||
-rw-r--r-- | railties/test/railties/mounted_engine_test.rb | 9 |
10 files changed, 143 insertions, 74 deletions
diff --git a/Gemfile.lock b/Gemfile.lock index 995aa9f7ba..304e44112d 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,6 +1,6 @@ GIT remote: https://github.com/QueueClassic/queue_classic.git - revision: 51d56ca6fa2fdf1eeffdffd702ae1cc0940b5156 + revision: cde82d17ded2799ed726dd7b0df6ce1fd4c1b7da branch: master specs: queue_classic (3.2.0.RC1) @@ -64,7 +64,7 @@ PATH actionview (= 5.2.0.alpha) activesupport (= 5.2.0.alpha) rack (~> 2.0) - rack-test (~> 0.6.3) + rack-test (>= 0.6.3) rails-dom-testing (~> 2.0) rails-html-sanitizer (~> 1.0, >= 1.0.2) actionview (5.2.0.alpha) @@ -111,9 +111,9 @@ GEM specs: addressable (2.5.1) public_suffix (~> 2.0, >= 2.0.2) - amq-protocol (2.1.0) + amq-protocol (2.2.0) ast (2.3.0) - backburner (1.3.1) + backburner (1.4.1) beaneater (~> 1.0) concurrent-ruby (~> 1.0.1) dante (> 0.1.5) @@ -135,28 +135,28 @@ GEM thor (~> 0.19.1) useragent (~> 0.16.7) blade-qunit_adapter (2.0.1) - blade-sauce_labs_plugin (0.6.2) + blade-sauce_labs_plugin (0.7.1) childprocess faraday selenium-webdriver - bootsnap (1.1.0) + bootsnap (1.1.2) msgpack (~> 1.0) builder (3.2.3) - bunny (2.6.2) - amq-protocol (>= 2.0.1) + bunny (2.6.6) + amq-protocol (>= 2.1.0) byebug (9.0.6) - capybara (2.14.1) + capybara (2.14.4) addressable mime-types (>= 1.16) nokogiri (>= 1.3.3) rack (>= 1.0.0) rack-test (>= 0.5.4) xpath (~> 2.0) - childprocess (0.5.9) + childprocess (0.7.1) ffi (~> 1.0, >= 1.0.11) - coffee-rails (4.2.1) + coffee-rails (4.2.2) coffee-script (>= 2.2.0) - railties (>= 4.0.0, < 5.2.x) + railties (>= 4.0.0) coffee-script (2.4.1) coffee-script-source execjs @@ -184,16 +184,18 @@ GEM http_parser.rb (>= 0.6.0) em-socksify (0.3.1) eventmachine (>= 1.0.0.beta.4) - erubi (1.6.0) + erubi (1.6.1) erubis (2.7.0) + et-orbi (1.0.5) + tzinfo event_emitter (0.2.5) - eventmachine (1.2.1) - eventmachine (1.2.1-x64-mingw32) - eventmachine (1.2.1-x86-mingw32) + eventmachine (1.2.3) + eventmachine (1.2.3-x64-mingw32) + eventmachine (1.2.3-x86-mingw32) execjs (2.7.0) - faraday (0.11.0) + faraday (0.12.2) multipart-post (>= 1.2, < 3) - faye (1.2.3) + faye (1.2.4) cookiejar (>= 0.3.0) em-http-request (>= 0.3.0) eventmachine (>= 0.12.0) @@ -201,33 +203,33 @@ GEM multi_json (>= 1.0.0) rack (>= 1.0.0) websocket-driver (>= 0.5.1) - faye-websocket (0.10.5) + faye-websocket (0.10.7) eventmachine (>= 0.12.0) websocket-driver (>= 0.5.1) - ffi (1.9.17) - ffi (1.9.17-x64-mingw32) - ffi (1.9.17-x86-mingw32) + ffi (1.9.18) + ffi (1.9.18-x64-mingw32) + ffi (1.9.18-x86-mingw32) globalid (0.4.0) activesupport (>= 4.2.0) hiredis (0.6.1) http_parser.rb (0.6.0) - i18n (0.8.1) - jquery-rails (4.2.2) + i18n (0.8.6) + jquery-rails (4.3.1) rails-dom-testing (>= 1, < 3) railties (>= 4.2.0) thor (>= 0.14, < 2.0) - json (2.0.3) + json (2.1.0) kindlerb (1.2.0) mustache nokogiri - libxml-ruby (2.9.0) + libxml-ruby (3.0.0) listen (3.1.5) rb-fsevent (~> 0.9, >= 0.9.4) rb-inotify (~> 0.9, >= 0.9.7) ruby_dep (~> 1.2) loofah (2.0.3) nokogiri (>= 1.5.9) - mail (2.6.5) + mail (2.6.6) mime-types (>= 1.16, < 4) metaclass (0.0.4) method_source (0.8.2) @@ -244,11 +246,12 @@ GEM msgpack (1.1.0-x86-mingw32) multi_json (1.12.1) multipart-post (2.0.0) - mustache (1.0.3) - mysql2 (0.4.6) - mysql2 (0.4.6-x64-mingw32) - mysql2 (0.4.6-x86-mingw32) - nio4r (2.0.0) + mustache (1.0.5) + mustermann (1.0.0) + mysql2 (0.4.8) + mysql2 (0.4.8-x64-mingw32) + mysql2 (0.4.8-x86-mingw32) + nio4r (2.1.0) nokogiri (1.8.0) mini_portile2 (~> 2.2.0) nokogiri (1.8.0-x64-mingw32) @@ -262,39 +265,39 @@ GEM pg (0.19.0-x64-mingw32) pg (0.19.0-x86-mingw32) powerpack (0.1.1) - psych (2.2.2) + psych (2.2.4) public_suffix (2.0.5) - puma (3.7.0) + puma (3.9.1) qu (0.2.0) multi_json qu-redis (0.2.0) qu (= 0.2.0) redis-namespace simple_uuid - que (0.12.0) + que (0.13.1) racc (1.4.14) rack (2.0.3) - rack-cache (1.6.1) + rack-cache (1.7.0) rack (>= 0.4) rack-protection (2.0.0) rack - rack-test (0.6.3) - rack (>= 1.0) - rails-dom-testing (2.0.2) - activesupport (>= 4.2.0, < 6.0) - nokogiri (~> 1.6) + rack-test (0.7.0) + rack (>= 1.0, < 3) + rails-dom-testing (2.0.3) + activesupport (>= 4.2.0) + nokogiri (>= 1.6) rails-html-sanitizer (1.0.3) loofah (~> 2.0) rainbow (2.2.2) rake rake (12.0.0) - rb-fsevent (0.9.8) + rb-fsevent (0.10.2) rdoc (5.1.0) redcarpet (3.2.3) redis (3.3.3) - redis-namespace (1.5.2) + redis-namespace (1.5.3) redis (~> 3.0, >= 3.0.4) - resque (1.27.0) + resque (1.27.4) mono_logger (~> 1.0) multi_json (~> 1.0) redis-namespace (~> 1.3) @@ -314,9 +317,9 @@ GEM unicode-display_width (~> 1.0, >= 1.0.1) ruby-progressbar (1.8.1) ruby_dep (1.5.0) - rubyzip (1.2.0) - rufus-scheduler (3.3.2) - tzinfo + rubyzip (1.2.1) + rufus-scheduler (3.4.2) + et-orbi (~> 1.0) sass (3.5.1) sass-listen (~> 4.0.0) sass-listen (4.0.0) @@ -324,31 +327,33 @@ GEM rb-inotify (~> 0.9, >= 0.9.7) sdoc (1.0.0.rc2) rdoc (~> 5.0) - selenium-webdriver (3.0.5) + selenium-webdriver (3.4.4) childprocess (~> 0.5) rubyzip (~> 1.0) - websocket (~> 1.0) - sequel (4.42.1) + sequel (4.48.0) serverengine (1.5.11) sigdump (~> 0.2.2) - sidekiq (5.0.0) + sidekiq (5.0.4) concurrent-ruby (~> 1.0) connection_pool (~> 2.2, >= 2.2.0) rack-protection (>= 1.5.0) redis (~> 3.3, >= 3.3.3) sigdump (0.2.4) simple_uuid (0.4.0) - sinatra (1.0) - rack (>= 1.0) - sneakers (2.4.0) - bunny (~> 2.6) + sinatra (2.0.0) + mustermann (~> 1.0) + rack (~> 2.0) + rack-protection (= 2.0.0) + tilt (~> 2.0) + sneakers (2.5.0) + bunny (~> 2.6.4) serverengine (~> 1.5.11) thor thread (~> 0.1.7) sprockets (3.7.1) concurrent-ruby (~> 1.0) rack (> 1, < 3) - sprockets-export (0.9.1) + sprockets-export (1.0.0) sprockets-rails (3.2.0) actionpack (>= 4.0) activesupport (>= 4.0) @@ -359,7 +364,7 @@ GEM stackprof (0.2.10) sucker_punch (2.0.2) concurrent-ruby (~> 1.0.0) - thin (1.7.0) + thin (1.7.2) daemons (~> 1.0, >= 1.0.9) eventmachine (~> 1.0, >= 1.0.4) rack (>= 1, < 3) @@ -368,23 +373,23 @@ GEM tilt (2.0.8) turbolinks (5.0.1) turbolinks-source (~> 5) - turbolinks-source (5.0.0) + turbolinks-source (5.0.3) tzinfo (1.2.3) thread_safe (~> 0.1) - tzinfo-data (1.2016.10) + tzinfo-data (1.2017.2) tzinfo (>= 1.0.0) - uglifier (3.0.4) + uglifier (3.2.0) execjs (>= 0.3.0, < 3) - unicode-display_width (1.2.1) + unicode-display_width (1.3.0) useragent (0.16.8) vegas (0.1.11) rack (>= 1.0.0) - w3c_validators (1.3.1) - json (~> 2.0) + w3c_validators (1.3.3) + json (>= 1.8) nokogiri (~> 1.6) wdm (0.1.1) - websocket (1.2.3) - websocket-driver (0.6.4) + websocket (1.2.4) + websocket-driver (0.6.5) websocket-extensions (>= 0.1.0) websocket-extensions (0.1.2) xpath (2.1.0) diff --git a/actionpack/actionpack.gemspec b/actionpack/actionpack.gemspec index 294cc45593..c4da62a8c8 100644 --- a/actionpack/actionpack.gemspec +++ b/actionpack/actionpack.gemspec @@ -27,7 +27,7 @@ Gem::Specification.new do |s| s.add_dependency "activesupport", version s.add_dependency "rack", "~> 2.0" - s.add_dependency "rack-test", "~> 0.6.3" + s.add_dependency "rack-test", ">= 0.6.3" s.add_dependency "rails-html-sanitizer", "~> 1.0", ">= 1.0.2" s.add_dependency "rails-dom-testing", "~> 2.0" s.add_dependency "actionview", version diff --git a/actionpack/lib/action_controller/metal/strong_parameters.rb b/actionpack/lib/action_controller/metal/strong_parameters.rb index a1b8b7cd6e..ef61485a70 100644 --- a/actionpack/lib/action_controller/metal/strong_parameters.rb +++ b/actionpack/lib/action_controller/metal/strong_parameters.rb @@ -673,10 +673,10 @@ module ActionController self end - # Deletes and returns a key-value pair from +Parameters+ whose key is equal - # to key. If the key is not found, returns the default value. If the - # optional code block is given and the key is not found, pass in the key - # and return the result of block. + # Deletes a key-value pair from +Parameters+ and returns the value. If + # +key+ is not found, returns +nil+ (or, with optional code block, yields + # +key+ and returns the result). Cf. +#extract!+, which returns the + # corresponding +ActionController::Parameters+ object. def delete(key, &block) convert_value_to_parameters(@parameters.delete(key, &block)) end diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb index eaa0e12b67..28809d7e67 100644 --- a/actionpack/lib/action_dispatch/routing/mapper.rb +++ b/actionpack/lib/action_dispatch/routing/mapper.rb @@ -658,6 +658,11 @@ module ActionDispatch script_namer = ->(options) do prefix_options = options.slice(*_route.segment_keys) prefix_options[:relative_url_root] = "".freeze + + if options[:_recall] + prefix_options.reverse_merge!(options[:_recall].slice(*_route.segment_keys)) + end + # We must actually delete prefix segment keys to avoid passing them to next url_for. _route.segment_keys.each { |k| options.delete(k) } _routes.url_helpers.send("#{name}_path", prefix_options) diff --git a/actionpack/lib/action_dispatch/routing/routes_proxy.rb b/actionpack/lib/action_dispatch/routing/routes_proxy.rb index 7a6c2e95d8..af0de7366b 100644 --- a/actionpack/lib/action_dispatch/routing/routes_proxy.rb +++ b/actionpack/lib/action_dispatch/routing/routes_proxy.rb @@ -31,7 +31,14 @@ module ActionDispatch def #{method}(*args) options = args.extract_options! options = url_options.merge((options || {}).symbolize_keys) - options.reverse_merge!(script_name: @script_namer.call(options)) if @script_namer + + if @script_namer + options[:script_name] = merge_script_names( + options[:script_name], + @script_namer.call(options) + ) + end + args << options @helpers.#{method}(*args) end @@ -41,6 +48,20 @@ module ActionDispatch super end end + + # Keeps the part of the script name provided by the global + # context via ENV["SCRIPT_NAME"], which `mount` doesn't know + # about since it depends on the specific request, but use our + # script name resolver for the mount point dependent part. + def merge_script_names(previous_script_name, new_script_name) + return new_script_name unless previous_script_name + + resolved_parts = new_script_name.count("/") + previous_parts = previous_script_name.count("/") + context_parts = previous_parts - resolved_parts + 1 + + (previous_script_name.split("/").slice(0, context_parts).join("/")) + new_script_name + end end end end diff --git a/actionview/lib/action_view/helpers/controller_helper.rb b/actionview/lib/action_view/helpers/controller_helper.rb index 8e7d896347..00d8b9665d 100644 --- a/actionview/lib/action_view/helpers/controller_helper.rb +++ b/actionview/lib/action_view/helpers/controller_helper.rb @@ -13,7 +13,7 @@ module ActionView :session, :cookies, :response, :headers, :flash, :action_name, :controller_name, :controller_path] - delegate *CONTROLLER_DELEGATES, to: :controller + delegate(*CONTROLLER_DELEGATES, to: :controller) def assign_controller(controller) if @_controller = controller diff --git a/activesupport/test/hash_with_indifferent_access_test.rb b/activesupport/test/hash_with_indifferent_access_test.rb index 77fc039459..b3788ee65c 100644 --- a/activesupport/test/hash_with_indifferent_access_test.rb +++ b/activesupport/test/hash_with_indifferent_access_test.rb @@ -560,7 +560,7 @@ class HashWithIndifferentAccessTest < ActiveSupport::TestCase def test_double_conversion_with_nil_key h = { nil => "defined" }.with_indifferent_access.with_indifferent_access - assert_equal nil, h[:undefined_key] + assert_nil h[:undefined_key] end def test_assorted_keys_not_stringified diff --git a/railties/test/application/rake/dbs_test.rb b/railties/test/application/rake/dbs_test.rb index 9e612f1526..3216121de3 100644 --- a/railties/test/application/rake/dbs_test.rb +++ b/railties/test/application/rake/dbs_test.rb @@ -262,7 +262,7 @@ module ApplicationTests test "db:schema:load fails if schema.rb doesn't exist yet" do Dir.chdir(app_path) do stderr_output = capture(:stderr) { `bin/rails db:schema:load` } - assert_match /Run `rails db:migrate` to create it/, stderr_output + assert_match(/Run `rails db:migrate` to create it/, stderr_output) end end diff --git a/railties/test/railties/engine_test.rb b/railties/test/railties/engine_test.rb index 0379394f31..6f762d2d3f 100644 --- a/railties/test/railties/engine_test.rb +++ b/railties/test/railties/engine_test.rb @@ -1427,6 +1427,35 @@ YAML assert_equal "/vegetables/1/bukkits/posts", last_response.body end + test "route helpers resolve script name correctly when called with different script name from current one" do + @plugin.write "app/controllers/posts_controller.rb", <<-RUBY + class PostsController < ActionController::Base + def index + render plain: fruit_bukkits.posts_path(fruit_id: 2) + end + end + RUBY + + app_file "config/routes.rb", <<-RUBY + Rails.application.routes.draw do + resources :fruits do + mount Bukkits::Engine => "/bukkits" + end + end + RUBY + + @plugin.write "config/routes.rb", <<-RUBY + Bukkits::Engine.routes.draw do + resources :posts, only: :index + end + RUBY + + boot_rails + + get("/fruits/1/bukkits/posts") + assert_equal "/fruits/2/bukkits/posts", last_response.body + end + private def app Rails.application diff --git a/railties/test/railties/mounted_engine_test.rb b/railties/test/railties/mounted_engine_test.rb index 6639e55382..6eb2c5acc6 100644 --- a/railties/test/railties/mounted_engine_test.rb +++ b/railties/test/railties/mounted_engine_test.rb @@ -111,6 +111,7 @@ module ApplicationTests @plugin.write "config/routes.rb", <<-RUBY Blog::Engine.routes.draw do resources :posts + get '/different_context', to: 'posts#different_context' get '/generate_application_route', to: 'posts#generate_application_route' get '/application_route_in_view', to: 'posts#application_route_in_view' get '/engine_polymorphic_path', to: 'posts#engine_polymorphic_path' @@ -125,6 +126,10 @@ module ApplicationTests render plain: blog.post_path(1) end + def different_context + render plain: blog.post_path(1, user: "ada") + end + def generate_application_route path = main_app.url_for(controller: "/main", action: "index", @@ -196,6 +201,10 @@ module ApplicationTests get "/john/blog/posts" assert_equal "/john/blog/posts/1", last_response.body + # test generating engine route from engine with a different context + get "/john/blog/different_context" + assert_equal "/ada/blog/posts/1", last_response.body + # test generating engine's route from engine with default_url_options get "/john/blog/posts", {}, "SCRIPT_NAME" => "/foo" assert_equal "/foo/john/blog/posts/1", last_response.body |