Skip to content

Commit 9b24690

Browse files
committed
Don't assume a router in Route#name=.
1 parent 16822ea commit 9b24690

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

lib/http_router/route.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def matches_with(var_name)
2626

2727
def name=(name)
2828
@name = name
29-
router.named_routes[name] << self
29+
router.named_routes[name] << self if router
3030
end
3131
end
32-
end
32+
end

test/test_misc.rb

+6
Original file line numberDiff line numberDiff line change
@@ -118,4 +118,10 @@ def test_to_s_and_inspect
118118
assert router.inspect.match(/^#<HttpRouter:0x[0-9a-f-]+ number of routes \(3\) ignore_trailing_slash\? \(true\) redirect_trailing_slash\? \(false\)>/)
119119
assert router.inspect.match(/Path: "\/test" for route unnamed route to :test3/)
120120
end
121+
122+
def test_naming_route_with_no_router
123+
route = HttpRouter::Route.new
124+
route.name = 'named_route'
125+
assert_equal 'named_route', route.name
126+
end
121127
end

0 commit comments

Comments
 (0)