| 1 | use t::Router; |
|---|
| 2 | |
|---|
| 3 | plan tests => 2 * blocks; |
|---|
| 4 | |
|---|
| 5 | my $router = build_router(); |
|---|
| 6 | |
|---|
| 7 | filters { |
|---|
| 8 | conditions => ['eval'], |
|---|
| 9 | params => ['yaml'], |
|---|
| 10 | }; |
|---|
| 11 | |
|---|
| 12 | run { |
|---|
| 13 | my $block = shift; |
|---|
| 14 | my $match = $router->route_for($block->path, $block->conditions); |
|---|
| 15 | is_deeply $match->params, $block->params, "@{[ $block->name ]} (params)"; |
|---|
| 16 | is $match->path, $block->path, "@{[ $block->name ]} (path)"; |
|---|
| 17 | }; |
|---|
| 18 | |
|---|
| 19 | __END__ |
|---|
| 20 | === / |
|---|
| 21 | --- path: / |
|---|
| 22 | --- params |
|---|
| 23 | controller: Root |
|---|
| 24 | action: index |
|---|
| 25 | |
|---|
| 26 | === GET / |
|---|
| 27 | --- path: / |
|---|
| 28 | --- conditions: { method => 'GET' } |
|---|
| 29 | --- params |
|---|
| 30 | controller: Root |
|---|
| 31 | action: index |
|---|
| 32 | |
|---|
| 33 | === POST / |
|---|
| 34 | --- path: / |
|---|
| 35 | --- conditions: { method => 'POST' } |
|---|
| 36 | --- params |
|---|
| 37 | controller: Root |
|---|
| 38 | action: index |
|---|
| 39 | |
|---|
| 40 | === GET /account/login |
|---|
| 41 | --- path: /account/login |
|---|
| 42 | --- conditions: { method => 'GET' } |
|---|
| 43 | --- params |
|---|
| 44 | controller: Account |
|---|
| 45 | action: login |
|---|
| 46 | |
|---|
| 47 | === POST /account/login |
|---|
| 48 | --- path: /account/login |
|---|
| 49 | --- conditions: { method => 'POST' } |
|---|
| 50 | --- params |
|---|
| 51 | controller: Account |
|---|
| 52 | action: login |
|---|
| 53 | |
|---|
| 54 | === GET /archives/{year} |
|---|
| 55 | --- path: /archives/2008 |
|---|
| 56 | --- params |
|---|
| 57 | controller: Archive |
|---|
| 58 | action: by_year |
|---|
| 59 | year: 2008 |
|---|
| 60 | |
|---|
| 61 | === GET /archives/{year}/{month} |
|---|
| 62 | --- path: /archives/2008/12 |
|---|
| 63 | --- params |
|---|
| 64 | controller: Archive |
|---|
| 65 | action: by_month |
|---|
| 66 | year: 2008 |
|---|
| 67 | month: 12 |
|---|
| 68 | |
|---|
| 69 | === GET /archives/{year}/{month}/{day} |
|---|
| 70 | --- path: /archives/2008/12/31 |
|---|
| 71 | --- params |
|---|
| 72 | controller: Archive |
|---|
| 73 | action: by_day |
|---|
| 74 | year: 2008 |
|---|
| 75 | month: 12 |
|---|
| 76 | day: 31 |
|---|
| 77 | |
|---|
| 78 | === GET /articles |
|---|
| 79 | --- path: /articles |
|---|
| 80 | --- conditions: { method => 'GET' } |
|---|
| 81 | --- params |
|---|
| 82 | controller: Article |
|---|
| 83 | action: index |
|---|
| 84 | |
|---|
| 85 | === GET /articles/new |
|---|
| 86 | --- path: /articles/new |
|---|
| 87 | --- conditions: { method => 'GET' } |
|---|
| 88 | --- params |
|---|
| 89 | controller: Article |
|---|
| 90 | action: post |
|---|
| 91 | |
|---|
| 92 | === POST /articles |
|---|
| 93 | --- path: /articles |
|---|
| 94 | --- conditions: { method => 'POST' } |
|---|
| 95 | --- params |
|---|
| 96 | controller: Article |
|---|
| 97 | action: create |
|---|
| 98 | |
|---|
| 99 | === GET /articles/{article_id} |
|---|
| 100 | --- path: /articles/14 |
|---|
| 101 | --- conditions: { method => 'GET' } |
|---|
| 102 | --- params |
|---|
| 103 | controller: Article |
|---|
| 104 | action: show |
|---|
| 105 | article_id: 14 |
|---|
| 106 | |
|---|
| 107 | === GET /articles/{article_id}/edit |
|---|
| 108 | --- path: /articles/14/edit |
|---|
| 109 | --- conditions: { method => 'GET' } |
|---|
| 110 | --- params |
|---|
| 111 | controller: Article |
|---|
| 112 | action: edit |
|---|
| 113 | article_id: 14 |
|---|
| 114 | |
|---|
| 115 | === PUT /articles/{article_id} |
|---|
| 116 | --- path: /articles/15 |
|---|
| 117 | --- conditions: { method => 'PUT' } |
|---|
| 118 | --- params |
|---|
| 119 | controller: Article |
|---|
| 120 | action: update |
|---|
| 121 | article_id: 15 |
|---|
| 122 | |
|---|
| 123 | === DELETE /articles/{article_id} |
|---|
| 124 | --- path: /articles/16 |
|---|
| 125 | --- conditions: { method => 'DELETE' } |
|---|
| 126 | --- params |
|---|
| 127 | controller: Article |
|---|
| 128 | action: destroy |
|---|
| 129 | article_id: 16 |
|---|