mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Merge pull request #17823 from byroot/fix-mount-rack-apps-with-as
Pure rack apps can be mounted with a name
This commit is contained in:
commit
5493d16d9e
3 changed files with 22 additions and 8 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue