support for options in namespaces
This commit is contained in:
parent
961d5d5ff7
commit
190455ded6
@ -139,9 +139,9 @@ module Rails
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def namespace(name)
|
def namespace(name, options = {})
|
||||||
debug "mapping namespace #{name}"
|
debug "mapping namespace #{name}"
|
||||||
namespace = FakeNamespace.new(name)
|
namespace = FakeNamespace.new(name, options)
|
||||||
|
|
||||||
namespace = stack(namespace) do
|
namespace = stack(namespace) do
|
||||||
yield(self)
|
yield(self)
|
||||||
@ -200,16 +200,22 @@ module Rails
|
|||||||
end
|
end
|
||||||
|
|
||||||
class FakeNamespace < RouteObject
|
class FakeNamespace < RouteObject
|
||||||
attr_accessor :routes, :name
|
attr_accessor :routes, :name, :options
|
||||||
|
|
||||||
def initialize(name)
|
def initialize(name, options = {})
|
||||||
@routes = []
|
@routes = []
|
||||||
@name = name
|
@name, @options = name, options
|
||||||
@indent = RouteRedrawer.indent
|
@indent = RouteRedrawer.indent
|
||||||
end
|
end
|
||||||
|
|
||||||
def to_route_code
|
def to_route_code
|
||||||
lines = ["namespace :#{@name} do", @routes.map {|r| r.to_route_code}, "end"]
|
if !@options.empty?
|
||||||
|
options = ', ' + opts_to_string(@options)
|
||||||
|
else
|
||||||
|
options = ''
|
||||||
|
end
|
||||||
|
|
||||||
|
lines = ["namespace :#{@name}#{options} do", @routes.map {|r| r.to_route_code}, "end"]
|
||||||
|
|
||||||
indent_lines(lines)
|
indent_lines(lines)
|
||||||
end
|
end
|
||||||
|
@ -74,6 +74,14 @@ end
|
|||||||
assert_equal "namespace :static do\nmatch '/about' => 'static#about'\nend\n", ns.to_route_code
|
assert_equal "namespace :static do\nmatch '/about' => 'static#about'\nend\n", ns.to_route_code
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_generates_code_for_namespace_with_options
|
||||||
|
ns = Rails::Upgrading::FakeNamespace.new("static", { :path_prefix => 'prefix' })
|
||||||
|
# Add a route to the namespace
|
||||||
|
ns << Rails::Upgrading::FakeRoute.new("/about", {:controller => 'static', :action => 'about'})
|
||||||
|
|
||||||
|
assert_equal "namespace :static, :path_prefix => 'prefix' do\nmatch '/about' => 'static#about'\nend\n", ns.to_route_code
|
||||||
|
end
|
||||||
|
|
||||||
def test_generates_code_for_resources
|
def test_generates_code_for_resources
|
||||||
route = Rails::Upgrading::FakeResourceRoute.new("hats")
|
route = Rails::Upgrading::FakeResourceRoute.new("hats")
|
||||||
assert_equal "resources :hats", route.to_route_code
|
assert_equal "resources :hats", route.to_route_code
|
||||||
|
Loading…
Reference in New Issue
Block a user