From 9b24690f1f7e2bccec3df3d76c6e4a58c9dbdd46 Mon Sep 17 00:00:00 2001 From: Jimmy Cuadra Date: Fri, 1 Aug 2014 04:07:40 -0700 Subject: [PATCH] Don't assume a router in Route#name=. --- lib/http_router/route.rb | 4 ++-- test/test_misc.rb | 6 ++++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/http_router/route.rb b/lib/http_router/route.rb index ff6437d..0a41462 100644 --- a/lib/http_router/route.rb +++ b/lib/http_router/route.rb @@ -26,7 +26,7 @@ class HttpRouter def name=(name) @name = name - router.named_routes[name] << self + router.named_routes[name] << self if router end end -end \ No newline at end of file +end diff --git a/test/test_misc.rb b/test/test_misc.rb index aa0a94b..e7b2e9d 100644 --- a/test/test_misc.rb +++ b/test/test_misc.rb @@ -118,4 +118,10 @@ class TestMisc < MiniTest::Unit::TestCase assert router.inspect.match(/^#/) assert router.inspect.match(/Path: "\/test" for route unnamed route to :test3/) end + + def test_naming_route_with_no_router + route = HttpRouter::Route.new + route.name = 'named_route' + assert_equal 'named_route', route.name + end end