[Jifty-commit] r6109 - in jifty/trunk/t/TestApp-Dispatcher: . bin etc lib lib/TestApp lib/TestApp/Dispatcher
Jifty commits
jifty-commit at lists.jifty.org
Sun Dec 14 13:05:00 EST 2008
Author: ruz
Date: Sun Dec 14 13:05:00 2008
New Revision: 6109
Added:
jifty/trunk/t/TestApp-Dispatcher/
jifty/trunk/t/TestApp-Dispatcher/bin/
jifty/trunk/t/TestApp-Dispatcher/bin/jifty (contents, props changed)
jifty/trunk/t/TestApp-Dispatcher/etc/
jifty/trunk/t/TestApp-Dispatcher/etc/config.yml
jifty/trunk/t/TestApp-Dispatcher/lib/
jifty/trunk/t/TestApp-Dispatcher/lib/TestApp/
jifty/trunk/t/TestApp-Dispatcher/lib/TestApp/Dispatcher/
jifty/trunk/t/TestApp-Dispatcher/lib/TestApp/Dispatcher/Dispatcher.pm
jifty/trunk/t/TestApp-Dispatcher/lib/TestApp/Dispatcher/View.pm
jifty/trunk/t/TestApp-Dispatcher/t/
jifty/trunk/t/TestApp-Dispatcher/t/00-basic.t
jifty/trunk/t/TestApp-Dispatcher/t/on.t
jifty/trunk/t/TestApp-Dispatcher/t/under.t
Log:
* add TestApp-Dispatcher, app that tests different syntax
of the jifty dispatcher
Added: jifty/trunk/t/TestApp-Dispatcher/bin/jifty
==============================================================================
--- (empty file)
+++ jifty/trunk/t/TestApp-Dispatcher/bin/jifty Sun Dec 14 13:05:00 2008
@@ -0,0 +1,16 @@
+#!/usr/bin/env perl
+use warnings;
+use strict;
+use UNIVERSAL::require;
+
+BEGIN {
+ Jifty::Util->require or die $UNIVERSAL::require::ERROR;
+ my $root = Jifty::Util->app_root;
+ unshift @INC, "$root/lib" if ($root);
+}
+
+use Jifty;
+use Jifty::Script;
+
+local $SIG{INT} = sub { warn "Stopped\n"; exit; };
+Jifty::Script->dispatch();
Added: jifty/trunk/t/TestApp-Dispatcher/etc/config.yml
==============================================================================
--- (empty file)
+++ jifty/trunk/t/TestApp-Dispatcher/etc/config.yml Sun Dec 14 13:05:00 2008
@@ -0,0 +1,45 @@
+---
+framework:
+ ConfigFileVersion: 4
+
+ ApplicationClass: TestApp::Dispatcher
+ ApplicationName: TestApp-Dispatcher
+ ApplicationUUID: 910B667E-C97B-11DD-9E38-714D7437C21E
+
+ AdminMode: 0
+ DevelMode: 0
+
+ Database:
+ AutoUpgrade: 1
+ CheckSchema: 1
+ Database: testapp_dispatcher
+ Driver: SQLite
+ Host: localhost
+ Password: ''
+ RecordBaseClass: Jifty::DBI::Record::Cachable
+ User: ''
+ Version: 0.0.1
+ LogLevel: DEBUG
+
+ Plugins:
+ -
+ SkeletonApp: {}
+
+ -
+ CompressedCSSandJS: {}
+
+ PubSub:
+ Backend: Memcached
+ Enable: ~
+ SkipAccessControl: 0
+ TemplateClass: TestApp::Dispatcher::View
+ View:
+ Handlers:
+ - Jifty::View::Static::Handler
+ - Jifty::View::Declare::Handler
+ Web:
+ BaseURL: http://localhost
+ DataDir: var/mason
+ Port: 8888
+ ServeStaticFiles: 1
+ StaticRoot: share/web/static
Added: jifty/trunk/t/TestApp-Dispatcher/lib/TestApp/Dispatcher/Dispatcher.pm
==============================================================================
--- (empty file)
+++ jifty/trunk/t/TestApp-Dispatcher/lib/TestApp/Dispatcher/Dispatcher.pm Sun Dec 14 13:05:00 2008
@@ -0,0 +1,44 @@
+use strict;
+use warnings;
+
+package TestApp::Dispatcher::Dispatcher;
+use Jifty::Dispatcher -base;
+
+on '/redirect' => run { redirect('/woot') };
+
+on 'on_not_exist_show' => run { show('/woot') };
+
+on ['on_array1', 'on_array2'] => run { show('/woot') };
+
+on ['on_array/1', 'on_array/2'] => run { show('/woot') };
+
+on qr{^/on_re$} => run { show('/woot') };
+
+on [ qr{^/on/array/re1$}, qr{^/on/array/re2$} ] => run { show('/woot') };
+
+on 'on_arg' => run { set woot => 'x'; show('/woot') };
+
+on 'on_run_run' => run { run { show('/woot') } };
+on 'on_run_array' => [ show('/woot') ];
+on 'on_run_array_run' => [ run { show('/woot') } ];
+
+
+under 'under_any' => run { show('/woot') };
+under 'under/some_any' => run {show('/woot') };
+
+under qr{^/under_re/(.*)} => run { set woot => $1; show('/woot') };
+
+under 'under_run_array_on' => [ on woot => run { show('/woot') } ];
+under 'under_run_on_re' => run { on qr{^/woot$} => run { show('/woot') } };
+
+under 'under/some' => run { on qr{^/woot$} => run { show('/woot') } };
+
+# regression: check that /under_run_on_exist_run/not_exist doesn't match
+under 'under_run_on_exist_run' => run { on exist => run { set woot => 'exist'; show('/woot') } };
+
+{ # test caching
+ under 'under_run_on_special' => run { on some_special => run { set woot => 'under'; show('/woot') } };
+ on 'some_special' => run { set woot => 'top'; show('/woot') };
+}
+
+1;
Added: jifty/trunk/t/TestApp-Dispatcher/lib/TestApp/Dispatcher/View.pm
==============================================================================
--- (empty file)
+++ jifty/trunk/t/TestApp-Dispatcher/lib/TestApp/Dispatcher/View.pm Sun Dec 14 13:05:00 2008
@@ -0,0 +1,12 @@
+use warnings;
+use strict;
+
+package TestApp::Dispatcher::View;
+use Jifty::View::Declare -base;
+
+template woot => page {
+ if ( my $v = get('woot') ) { outs("woot: $v") }
+ else { outs('woot') }
+};
+
+1;
Added: jifty/trunk/t/TestApp-Dispatcher/t/00-basic.t
==============================================================================
--- (empty file)
+++ jifty/trunk/t/TestApp-Dispatcher/t/00-basic.t Sun Dec 14 13:05:00 2008
@@ -0,0 +1,35 @@
+#!/usr/bin/env perl
+use warnings;
+use strict;
+
+use Jifty::Test::Dist tests => 8;
+use Jifty::Test::WWW::Mechanize;
+
+
+my $server = Jifty::Test->make_server;
+ok($server, 'got a server');
+
+isa_ok($server, 'Jifty::Server');
+
+my $url = $server->started_ok;
+my $mech = Jifty::Test::WWW::Mechanize->new();
+
+sub get_ok($) {
+ my $path = shift;
+ local $Test::Builder::Level = $Test::Builder::Level + 1;
+ $mech->get_ok($url.$path, "got $path");
+}
+sub get_nok($) {
+ my $path = shift;
+ local $Test::Builder::Level = $Test::Builder::Level + 1;
+ $mech->get($url.$path);
+ is $mech->status, 404, "no $path (404)";
+}
+
+get_ok("/woot");
+$mech->content_contains("woot");
+
+get_ok("/on_not_exist_show");
+$mech->content_contains("woot");
+
+get_nok("/something_that_really_not_exists");
Added: jifty/trunk/t/TestApp-Dispatcher/t/on.t
==============================================================================
--- (empty file)
+++ jifty/trunk/t/TestApp-Dispatcher/t/on.t Sun Dec 14 13:05:00 2008
@@ -0,0 +1,59 @@
+#!/usr/bin/env perl
+use warnings;
+use strict;
+
+use Jifty::Test::Dist tests => 25;
+use Jifty::Test::WWW::Mechanize;
+
+
+my $server = Jifty::Test->make_server;
+ok($server, 'got a server');
+
+isa_ok($server, 'Jifty::Server');
+
+my $url = $server->started_ok;
+my $mech = Jifty::Test::WWW::Mechanize->new();
+
+sub get_ok($) {
+ my $path = shift;
+ local $Test::Builder::Level = $Test::Builder::Level + 1;
+ $mech->get_ok($url.$path, "got $path");
+}
+
+sub get_nok($) {
+ my $path = shift;
+ local $Test::Builder::Level = $Test::Builder::Level + 1;
+ $mech->get($url.$path);
+ is $mech->status, 404, "no $path (404)";
+}
+
+for(1..2) {
+ get_ok("/on_array$_");
+ $mech->content_contains("woot");
+}
+
+for(1..2) {
+ get_ok("/on_array/$_");
+ $mech->content_contains("woot");
+}
+
+get_ok("/on_re");
+$mech->content_contains("woot");
+
+for(1..2) {
+ get_ok("/on/array/re$_");
+ $mech->content_contains("woot");
+}
+
+get_ok("/on_run_run");
+$mech->content_contains("woot");
+
+get_ok("/on_arg");
+$mech->content_contains("woot: x");
+
+get_ok("/on_run_array");
+$mech->content_contains("woot");
+
+get_ok("/on_run_array_run");
+$mech->content_contains("woot");
+
Added: jifty/trunk/t/TestApp-Dispatcher/t/under.t
==============================================================================
--- (empty file)
+++ jifty/trunk/t/TestApp-Dispatcher/t/under.t Sun Dec 14 13:05:00 2008
@@ -0,0 +1,63 @@
+#!/usr/bin/env perl
+use warnings;
+use strict;
+
+use Jifty::Test::Dist tests => 32;
+use Jifty::Test::WWW::Mechanize;
+
+my $server = Jifty::Test->make_server;
+ok($server, 'got a server');
+
+isa_ok($server, 'Jifty::Server');
+
+my $url = $server->started_ok;
+my $mech = Jifty::Test::WWW::Mechanize->new();
+
+sub get_ok($) {
+ my $path = shift;
+ local $Test::Builder::Level = $Test::Builder::Level + 1;
+ $mech->get_ok($url.$path, "got $path");
+}
+
+sub get_nok($) {
+ my $path = shift;
+ local $Test::Builder::Level = $Test::Builder::Level + 1;
+ $mech->get($url.$path);
+ is $mech->status, 404, "no $path (404)";
+}
+
+for(qw(some another some/deep)) {
+ get_ok("/under_any/$_");
+ $mech->content_contains("woot");
+}
+
+for(qw(some another some/deep)) {
+ get_ok("/under/some_any/$_");
+ $mech->content_contains("woot");
+}
+
+for(qw(some another some/deep)) {
+ get_ok("/under_re/$_");
+ $mech->content_contains("woot: $_");
+}
+
+get_ok("/under_run_array_on/woot");
+$mech->content_contains("woot");
+
+get_ok("/under_run_on_re/woot");
+$mech->content_contains("woot");
+
+{
+ get_ok("/under_run_on_exist_run/exist");
+ $mech->content_contains("woot: exist");
+ get_nok("/under_run_on_exist_run/not_exist");
+}
+
+diag('test caching of compiled regular expressions');
+{
+ get_ok("/under_run_on_special/some_special");
+ $mech->content_contains("woot: under");
+ get_ok("/some_special");
+ $mech->content_contains("woot: top");
+}
+
More information about the Jifty-commit
mailing list