[Bps-public-commit] r16924 - in Path-Dispatcher/trunk: t

sartak at bestpractical.com sartak at bestpractical.com
Tue Nov 18 21:21:55 EST 2008


Author: sartak
Date: Tue Nov 18 21:21:55 2008
New Revision: 16924

Added:
   Path-Dispatcher/trunk/t/019-intersection-metadata.t
Modified:
   Path-Dispatcher/trunk/   (props changed)

Log:
 r75795 at onn:  sartak | 2008-11-18 21:21:50 -0500
 Test to make sure that path + metadata matching works, as that'll be the most common use case for intersections


Added: Path-Dispatcher/trunk/t/019-intersection-metadata.t
==============================================================================
--- (empty file)
+++ Path-Dispatcher/trunk/t/019-intersection-metadata.t	Tue Nov 18 21:21:55 2008
@@ -0,0 +1,42 @@
+#!/usr/bin/env perl
+use strict;
+use warnings;
+use Test::More tests => 2;
+use Path::Dispatcher;
+
+my $dispatcher = Path::Dispatcher->new(
+    rules => [
+        Path::Dispatcher::Rule::Intersection->new(
+            block => sub { "creating a ticket" },
+            rules => [
+                Path::Dispatcher::Rule::Tokens->new(
+                    delimiter => '/',
+                    tokens    => ['=', 'model', 'Ticket'],
+                ),
+                Path::Dispatcher::Rule::Metadata->new(
+                    name    => 'http_method',
+                    matcher => Path::Dispatcher::Rule::Eq->new(string => 'POST'),
+                ),
+            ],
+        ),
+    ],
+);
+
+my @results = $dispatcher->run(Path::Dispatcher::Path->new(
+    path     => "/=/model/Ticket",
+    metadata => {
+        http_method => "POST",
+    },
+));
+
+is_deeply(\@results, ["creating a ticket"], "matched path and metadata");
+
+ at results = $dispatcher->run(Path::Dispatcher::Path->new(
+    path => "/=/model/Ticket.yml",
+    metadata => {
+        http_method => "GET",
+    },
+));
+
+is_deeply(\@results, [], "didn't match metadata");
+



More information about the Bps-public-commit mailing list