diff options
author | Sean Griffin <sean@seantheprogrammer.com> | 2014-11-29 15:31:12 -0700 |
---|---|---|
committer | Sean Griffin <sean@seantheprogrammer.com> | 2014-11-29 15:31:12 -0700 |
commit | 5493d16d9e2fbc8efb0535c7a704a83d460a1beb (patch) | |
tree | a7cb945964ff8b477885414fdf6150ad73c1c577 | |
parent | f8c27e2a52847d8c293d1015b44e53160e7d684e (diff) | |
parent | f413cbee8dd702e2cae550c04b16e6c98411aeab (diff) | |
download | rails-5493d16d9e2fbc8efb0535c7a704a83d460a1beb.tar.gz rails-5493d16d9e2fbc8efb0535c7a704a83d460a1beb.tar.bz2 rails-5493d16d9e2fbc8efb0535c7a704a83d460a1beb.zip |
Merge pull request #17823 from byroot/fix-mount-rack-apps-with-as
Pure rack apps can be mounted with a name
-rw-r--r-- | actionpack/lib/action_dispatch/routing/mapper.rb | 8 | ||||
-rw-r--r-- | actionpack/test/dispatch/routing/inspector_test.rb | 2 | ||||
-rw-r--r-- | railties/test/application/routing_test.rb | 20 |
3 files changed, 22 insertions, 8 deletions
diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb index a8be77f46d..5040aa82b2 100644 --- a/actionpack/lib/action_dispatch/routing/mapper.rb +++ b/actionpack/lib/action_dispatch/routing/mapper.rb @@ -580,13 +580,7 @@ module ActionDispatch raise "A rack application must be specified" unless path rails_app = rails_app? app - - if rails_app - options[:as] ||= app.railtie_name - else - # non rails apps can't have an :as - options[:as] = nil - end + options[:as] ||= app.railtie_name if rails_app target_as = name_for_action(options[:as], path) options[:via] ||= :all diff --git a/actionpack/test/dispatch/routing/inspector_test.rb b/actionpack/test/dispatch/routing/inspector_test.rb index ff33dd5652..5910f364cc 100644 --- a/actionpack/test/dispatch/routing/inspector_test.rb +++ b/actionpack/test/dispatch/routing/inspector_test.rb @@ -235,7 +235,7 @@ module ActionDispatch assert_equal [ "Prefix Verb URI Pattern Controller#Action", - " /foo #{RackApp.name} {:constraint=>( my custom constraint )}" + " foo /foo #{RackApp.name} {:constraint=>( my custom constraint )}" ], output end diff --git a/railties/test/application/routing_test.rb b/railties/test/application/routing_test.rb index 8576a2b738..cbada6be97 100644 --- a/railties/test/application/routing_test.rb +++ b/railties/test/application/routing_test.rb @@ -123,6 +123,26 @@ module ApplicationTests assert_equal '/archives', last_response.body end + test "mount named rack app" do + controller :foo, <<-RUBY + class FooController < ApplicationController + def index + render text: my_blog_path + end + end + RUBY + + app_file 'config/routes.rb', <<-RUBY + Rails.application.routes.draw do + mount lambda { |env| [200, {}, [env["PATH_INFO"]]] }, at: "/blog", as: "my_blog" + get '/foo' => 'foo#index' + end + RUBY + + get '/foo' + assert_equal '/blog', last_response.body + end + test "multiple controllers" do controller :foo, <<-RUBY class FooController < ApplicationController |