Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Support for options in namespaces #9

Merged
merged 1 commit into from

2 participants

John Bintz Ryan Bigg
John Bintz

I added support for creating route namespaces that have additional options, as I have an app that used namespace options and the plugin was failing on those.

Ryan Bigg radar referenced this pull request from a commit
Ryan Bigg radar Merged pull request #9 from johnbintz/namespace-options.
Support for options in namespaces
5f3a37e
Ryan Bigg radar merged commit 5f3a37e into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Apr 28, 2011
  1. John Bintz
This page is out of date. Refresh to see the latest.
Showing with 22 additions and 8 deletions.
  1. +13 −7 lib/routes_upgrader.rb
  2. +9 −1 test/routes_upgrader_test.rb
20 lib/routes_upgrader.rb
View
@@ -139,9 +139,9 @@ def resource(*args)
end
end
- def namespace(name)
+ def namespace(name, options = {})
debug "mapping namespace #{name}"
- namespace = FakeNamespace.new(name)
+ namespace = FakeNamespace.new(name, options)
namespace = stack(namespace) do
yield(self)
@@ -200,16 +200,22 @@ def value_to_string(value)
end
class FakeNamespace < RouteObject
- attr_accessor :routes, :name
+ attr_accessor :routes, :name, :options
- def initialize(name)
+ def initialize(name, options = {})
@routes = []
- @name = name
+ @name, @options = name, options
@indent = RouteRedrawer.indent
end
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)
end
@@ -357,4 +363,4 @@ def app_name
end
end
end
-end
+end
10 test/routes_upgrader_test.rb
View
@@ -74,6 +74,14 @@ def test_generates_code_for_namespace
assert_equal "namespace :static do\nmatch '/about' => 'static#about'\nend\n", ns.to_route_code
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
route = Rails::Upgrading::FakeResourceRoute.new("hats")
assert_equal "resources :hats", route.to_route_code
@@ -173,4 +181,4 @@ def test_generates_code_for_delete_route
upgrader.routes_code = routes_code
assert_equal new_routes_code.strip, upgrader.generate_new_routes.strip
end
-end
+end
Something went wrong with that request. Please try again.