| File: | t/route.t |
| Coverage: | 86.0% |
| line | stmt | bran | cond | sub | pod | time | code |
|---|---|---|---|---|---|---|---|
| 1 | #!/usr/bin/env perl -w | ||||||
| 2 | 1 1 1 | 101 9 10 | use strict; | ||||
| 3 | 1 1 1 | 109 6 19 | use Test::More tests => 9; | ||||
| 4 | |||||||
| 5 | 1 1 1 | 87 4 16 | use Railsish::Router; | ||||
| 6 | |||||||
| 7 | Railsish::Router->draw( | ||||||
| 8 | sub { | ||||||
| 9 | 1 | 6 | my ($map) = @_; | ||||
| 10 | |||||||
| 11 | 1 | 12 | $map->connect( | ||||
| 12 | "/dashboard/:year/:month/:date", | ||||||
| 13 | controller => "users", | ||||||
| 14 | action => "dashboard" | ||||||
| 15 | ); | ||||||
| 16 | |||||||
| 17 | 1 | 25 | $map->connect("/:controller/:action/:id"); | ||||
| 18 | } | ||||||
| 19 | 1 | 22 | ); | ||||
| 20 | |||||||
| 21 | 1 | 20 | my $uri = Railsish::Router->uri_for( | ||||
| 22 | controller => "users", | ||||||
| 23 | action => "dashboard", | ||||||
| 24 | year => "3009", | ||||||
| 25 | month => "12", | ||||||
| 26 | date => "23" | ||||||
| 27 | ); | ||||||
| 28 | |||||||
| 29 | 1 | 9 | is($uri, "/dashboard/3009/12/23"); | ||||
| 30 | |||||||
| 31 | { | ||||||
| 32 | 1 1 | 4 10 | my $matched = Railsish::Router->match("/admin/show/123"); | ||||
| 33 | |||||||
| 34 | 1 | 8 | if ($matched) { | ||||
| 35 | 1 | 10 | my $mapping = $matched->mapping; | ||||
| 36 | 1 | 23 | is $mapping->{controller}, "admin"; | ||||
| 37 | 1 | 9 | is $mapping->{action}, "show"; | ||||
| 38 | 1 | 8 | is $mapping->{id}, "123"; | ||||
| 39 | } else { | ||||||
| 40 | 0 0 | 0 0 | fail "Not maching /admin/show/123" for 1..3; | ||||
| 41 | } | ||||||
| 42 | } | ||||||
| 43 | |||||||
| 44 | { | ||||||
| 45 | 1 1 | 61 9 | my $matched = Railsish::Router->match("/dashboard/1234/12/21"); | ||||
| 46 | |||||||
| 47 | 1 | 10 | if ($matched) { | ||||
| 48 | 1 | 8 | my $mapping = $matched->mapping; | ||||
| 49 | 1 | 22 | is $mapping->{controller}, "users"; | ||||
| 50 | 1 | 8 | is $mapping->{action}, "dashboard"; | ||||
| 51 | 1 | 8 | is $mapping->{year}, "1234"; | ||||
| 52 | 1 | 9 | is $mapping->{month}, "12"; | ||||
| 53 | 1 | 9 | is $mapping->{date}, "21"; | ||||
| 54 | } else { | ||||||
| 55 | 0 0 | 0 0 | fail "Not maching /dashboard/1234/12/21" for 1..3; | ||||
| 56 | } | ||||||
| 57 | } | ||||||