File tree Expand file tree Collapse file tree 2 files changed +20
-0
lines changed
spec/amber_router/routed_result Expand file tree Collapse file tree 2 files changed +20
-0
lines changed Original file line number Diff line number Diff line change @@ -44,4 +44,16 @@ describe Amber::Router::RoutedResult do
44
44
result[" name" ].should eq " john"
45
45
end
46
46
end
47
+
48
+ context " path" do
49
+ it " allows retrieving the matched path" do
50
+ router = build do
51
+ add " /get/users/:id" , :user
52
+ end
53
+
54
+ result = router.find(" /get/users/3" )
55
+ result.found?.should be_true
56
+ result.path.should eq " /get/users/:id"
57
+ end
58
+ end
47
59
end
Original file line number Diff line number Diff line change @@ -11,6 +11,14 @@ module Amber::Router
11
11
@terminal_segment .not_nil!
12
12
end
13
13
14
+ def path
15
+ if @terminal_segment
16
+ terminal_segment.full_path
17
+ else
18
+ raise " Cannot provide route path when no route was found. Ask first with #found?"
19
+ end
20
+ end
21
+
14
22
def found ?
15
23
! @terminal_segment .nil?
16
24
end
You can’t perform that action at this time.
0 commit comments