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

@ -580,13 +580,7 @@ def mount(app, options = nil)
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 @@ def inspect
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 @@ def foo_or_bar?
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