Permalink
Browse files

Add has_named_route? to the mapper API

  • Loading branch information...
1 parent 97a607b commit 378ea96905e5f95be1a413b7bdd6fbb000265129 @josevalim josevalim committed May 20, 2013
Showing with 18 additions and 0 deletions.
  1. +5 −0 actionpack/lib/action_dispatch/routing/mapper.rb
  2. +13 −0 actionpack/test/dispatch/routing_test.rb
View
5 actionpack/lib/action_dispatch/routing/mapper.rb
@@ -515,6 +515,11 @@ def with_default_scope(scope, &block)
end
end
+ # Query if the following named route was already defined.
+ def has_named_route?(name)
+ @set.named_routes.routes[name.to_sym]
+ end
+
private
def app_name(app)
return unless app.respond_to?(:routes)
View
13 actionpack/test/dispatch/routing_test.rb
@@ -2662,6 +2662,19 @@ def test_redirect_argument_error
assert_raises(ArgumentError) { routes.redirect Object.new }
end
+ def test_named_route_check
+ before, after = nil
+
+ draw do
+ before = has_named_route?(:hello)
+ get "/hello", as: :hello, to: "hello#world"
+ after = has_named_route?(:hello)
+ end
+
+ assert !before, "expected to not have named route :hello before route definition"
+ assert after, "expected to have named route :hello after route definition"
+ end
+
def test_explicitly_avoiding_the_named_route
draw do
scope :as => "routes" do

0 comments on commit 378ea96

Please sign in to comment.