Allow mounting engines at '/'
Without that commit script_name always become '/', which results in paths like //posts/1 instead of /posts/1
This commit is contained in:
parent
74598fe7e9
commit
22b11a41cc
@ -511,7 +511,7 @@ def url_for(options)
|
|||||||
end
|
end
|
||||||
|
|
||||||
script_name = options.delete(:script_name)
|
script_name = options.delete(:script_name)
|
||||||
path = (script_name.blank? ? _generate_prefix(options) : script_name).to_s
|
path = (script_name.blank? ? _generate_prefix(options) : script_name.chomp('/')).to_s
|
||||||
|
|
||||||
path_options = options.except(*RESERVED_OPTIONS)
|
path_options = options.except(*RESERVED_OPTIONS)
|
||||||
path_options = yield(path_options) if block_given?
|
path_options = yield(path_options) if block_given?
|
||||||
|
@ -1,8 +1,23 @@
|
|||||||
require 'abstract_unit'
|
require 'abstract_unit'
|
||||||
|
require 'rack/test'
|
||||||
|
|
||||||
module TestGenerationPrefix
|
module TestGenerationPrefix
|
||||||
|
class Post
|
||||||
|
extend ActiveModel::Naming
|
||||||
|
|
||||||
|
def to_param
|
||||||
|
"1"
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.model_name
|
||||||
|
klass = "Post"
|
||||||
|
def klass.name; self end
|
||||||
|
|
||||||
|
ActiveModel::Name.new(klass)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
class WithMountedEngine < ActionDispatch::IntegrationTest
|
class WithMountedEngine < ActionDispatch::IntegrationTest
|
||||||
require 'rack/test'
|
|
||||||
include Rack::Test::Methods
|
include Rack::Test::Methods
|
||||||
|
|
||||||
class BlogEngine
|
class BlogEngine
|
||||||
@ -55,21 +70,6 @@ def self.call(env)
|
|||||||
# force draw
|
# force draw
|
||||||
RailsApplication.routes
|
RailsApplication.routes
|
||||||
|
|
||||||
class Post
|
|
||||||
extend ActiveModel::Naming
|
|
||||||
|
|
||||||
def to_param
|
|
||||||
"1"
|
|
||||||
end
|
|
||||||
|
|
||||||
def self.model_name
|
|
||||||
klass = "Post"
|
|
||||||
def klass.name; self end
|
|
||||||
|
|
||||||
ActiveModel::Name.new(klass)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
class ::InsideEngineGeneratingController < ActionController::Base
|
class ::InsideEngineGeneratingController < ActionController::Base
|
||||||
include BlogEngine.routes.url_helpers
|
include BlogEngine.routes.url_helpers
|
||||||
include RailsApplication.routes.mounted_helpers
|
include RailsApplication.routes.mounted_helpers
|
||||||
@ -253,4 +253,65 @@ def setup
|
|||||||
assert_equal "http://www.example.com/awesome/blog/posts/1", path
|
assert_equal "http://www.example.com/awesome/blog/posts/1", path
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
class EngineMountedAtRoot < ActionDispatch::IntegrationTest
|
||||||
|
include Rack::Test::Methods
|
||||||
|
|
||||||
|
class BlogEngine
|
||||||
|
def self.routes
|
||||||
|
@routes ||= begin
|
||||||
|
routes = ActionDispatch::Routing::RouteSet.new
|
||||||
|
routes.draw do
|
||||||
|
match "/posts/:id", :to => "posts#show", :as => :post
|
||||||
|
end
|
||||||
|
|
||||||
|
routes
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.call(env)
|
||||||
|
env['action_dispatch.routes'] = routes
|
||||||
|
routes.call(env)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
class RailsApplication
|
||||||
|
def self.routes
|
||||||
|
@routes ||= begin
|
||||||
|
routes = ActionDispatch::Routing::RouteSet.new
|
||||||
|
routes.draw do
|
||||||
|
mount BlogEngine => "/"
|
||||||
|
end
|
||||||
|
|
||||||
|
routes
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.call(env)
|
||||||
|
env['action_dispatch.routes'] = routes
|
||||||
|
routes.call(env)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# force draw
|
||||||
|
RailsApplication.routes
|
||||||
|
|
||||||
|
class ::PostsController < ActionController::Base
|
||||||
|
include BlogEngine.routes.url_helpers
|
||||||
|
include RailsApplication.routes.mounted_helpers
|
||||||
|
|
||||||
|
def show
|
||||||
|
render :text => post_path(:id => params[:id])
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def app
|
||||||
|
RailsApplication
|
||||||
|
end
|
||||||
|
|
||||||
|
test "generating path inside engine" do
|
||||||
|
get "/posts/1"
|
||||||
|
assert_equal "/posts/1", last_response.body
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user