1
0
Fork 0
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:
Sean Griffin 2014-11-29 15:31:12 -07:00
commit 5493d16d9e
3 changed files with 22 additions and 8 deletions

View file

@ -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

View file

@ -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

View file

@ -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