Skip to content

Commit

Permalink
test namespace precedence
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Dec 20, 2012
1 parent dba7301 commit 6d2ceb0
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 3 deletions.
1 change: 1 addition & 0 deletions Changes
Expand Up @@ -16,6 +16,7 @@
- Added week_field helper to Mojolicious::Plugin::TagHelpers.
- Improved Mojo::Base to use utf8.
- Improved documentation.
- Improved tests.

3.68 2012-12-16
- Added monkey_patch function to Mojo::Util.
Expand Down
8 changes: 7 additions & 1 deletion t/mojolicious/app.t
Expand Up @@ -240,11 +240,17 @@ $t->get_ok('/test8' => {'X-Test' => 'Hi there!'})->status_is(200)
->content_is("Class works!\n");

# MojoliciousTest3::Bar::index (controller class in development namespace)
$t->get_ok('/test9' => {'X-Test' => 'Hi there!'})->status_is(200)
$t->get_ok('/test9')->status_is(200)
->header_is(Server => 'Mojolicious (Perl)')
->header_is('X-Powered-By' => 'Mojolicious (Perl)')
->content_is('Development namespace works!');

# MojoliciousTest3::Baz::index (controller class precedence)
$t->get_ok('/test10')->status_is(200)
->header_is(Server => 'Mojolicious (Perl)')
->header_is('X-Powered-By' => 'Mojolicious (Perl)')
->content_is('Development namespace works again!');

# 404
$t->get_ok('/' => {'X-Test' => 'Hi there!'})->status_is(404)
->header_is(Server => 'Mojolicious (Perl)')
Expand Down
7 changes: 5 additions & 2 deletions t/mojolicious/lib/MojoliciousTest.pm
Expand Up @@ -14,7 +14,7 @@ sub development_mode {
unshift @{$self->static->paths}, $self->home->rel_dir('public_dev');

# Development namespace
push @{$self->routes->namespaces}, 'MojoliciousTest3';
unshift @{$self->routes->namespaces}, 'MojoliciousTest3';
}

sub startup {
Expand All @@ -29,7 +29,7 @@ sub startup {

# Plugins in custom namespace
unshift @{$self->plugins->namespaces},
$self->routes->namespaces->[0] . '::Plugin';
$self->routes->namespaces->[-1] . '::Plugin';
$self->plugin('test-some_plugin2');
$self->plugin('UPPERCASETestPlugin');

Expand Down Expand Up @@ -131,6 +131,9 @@ sub startup {
# /test9 (controller in development namespace)
$r->route('/test9')->to('bar#index');

# /test10 (controller in both namespaces)
$r->route('/test10')->to('baz#index');

# /withblock (template with blocks)
$r->route('/withblock')->to('foo#withblock');

Expand Down
9 changes: 9 additions & 0 deletions t/mojolicious/lib/MojoliciousTest/Baz.pm
@@ -0,0 +1,9 @@
package MojoliciousTest::Baz;
use Mojo::Base 'Mojolicious::Controller';

sub index {
my $self = shift;
$self->render(text => 'Production namespace works again!');
}

1;
9 changes: 9 additions & 0 deletions t/mojolicious/lib/MojoliciousTest3/Baz.pm
@@ -0,0 +1,9 @@
package MojoliciousTest3::Baz;
use Mojo::Base 'Mojolicious::Controller';

sub index {
my $self = shift;
$self->render(text => 'Development namespace works again!');
}

1;
6 changes: 6 additions & 0 deletions t/mojolicious/production_app.t
Expand Up @@ -126,4 +126,10 @@ $t->get_ok('/test9' => {'X-Test' => 'Hi there!'})->status_is(404)
->header_is('X-Powered-By' => 'Mojolicious (Perl)')
->content_like(qr/Page not found/);

# MojoliciousTest::Baz::index (controller class precedence)
$t->get_ok('/test10')->status_is(200)
->header_is(Server => 'Mojolicious (Perl)')
->header_is('X-Powered-By' => 'Mojolicious (Perl)')
->content_is('Production namespace works again!');

done_testing();

0 comments on commit 6d2ceb0

Please sign in to comment.