Skip to content

Commit

Permalink
more diverse application tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Mar 16, 2015
1 parent 3fa9dad commit 3f6e564
Show file tree
Hide file tree
Showing 11 changed files with 16 additions and 21 deletions.
8 changes: 4 additions & 4 deletions lib/Mojo/Loader.pm
Expand Up @@ -36,13 +36,13 @@ sub find_modules {
sub load_class {
my $class = shift;

# Check class name
return 1 if !$class || $class !~ /^\w(?:[\w:']*\w)?$/;
# Check for a valid class name
return 1 if ($class || '') !~ /^\w(?:[\w:']*\w)?$/;

# Load
# Load if not already loaded
return undef if $class->can('new') || eval "require $class; 1";

# Exists
# Does not exist
return 1 if $@ =~ /^Can't locate \Q@{[class_to_path $class]}\E in \@INC/;

# Real error
Expand Down
2 changes: 1 addition & 1 deletion lib/Mojo/Message.pm
Expand Up @@ -20,7 +20,7 @@ has version => '1.1';
sub body {
my $self = shift;

# Downgrade multipart content
# Multipart content needs to be downgraded
my $content = $self->content;
$content = $self->content(Mojo::Content::Single->new)->content
if $content->is_multipart;
Expand Down
1 change: 0 additions & 1 deletion lib/Mojo/Server/CGI.pm
Expand Up @@ -20,7 +20,6 @@ sub run {
last if ($len -= $read) <= 0;
}

# Handle request
$self->emit(request => $tx);

# Response start-line
Expand Down
1 change: 0 additions & 1 deletion lib/Mojo/Server/PSGI.pm
Expand Up @@ -17,7 +17,6 @@ sub run {
last if ($len -= $read) <= 0;
}

# Handle request
$self->emit(request => $tx);

# Response headers
Expand Down
6 changes: 2 additions & 4 deletions lib/Mojolicious/Controller.pm
Expand Up @@ -167,16 +167,14 @@ sub render {
my $plugins = $app->plugins->emit_hook(before_render => $self, $args);
my $maybe = delete $args->{'mojo.maybe'};

# Render
my $ts = $args->{'mojo.to_string'};
my ($output, $format) = $app->renderer->render($self, $args);
return defined $output ? Mojo::ByteStream->new($output) : undef if $ts;

# Maybe
# Maybe no 404
return defined $output ? Mojo::ByteStream->new($output) : undef if $ts;
return $maybe ? undef : !$self->helpers->reply->not_found
unless defined $output;

# Prepare response
$plugins->emit_hook(after_render => $self, \$output, $format);
my $headers = $self->res->body($output)->headers;
$headers->content_type($app->types->type($format) || 'text/plain')
Expand Down
2 changes: 1 addition & 1 deletion lib/Mojolicious/Plugin/Config.pm
Expand Up @@ -13,7 +13,7 @@ sub load {
sub parse {
my ($self, $content, $file, $conf, $app) = @_;

# Run Perl code
# Run Perl code in sandbox
my $config
= eval 'package Mojolicious::Plugin::Config::Sandbox; no warnings;'
. "sub app; local *app = sub { \$app }; use Mojo::Base -strict; $content";
Expand Down
2 changes: 1 addition & 1 deletion lib/Mojolicious/Renderer.pm
Expand Up @@ -96,7 +96,7 @@ sub render {
local @{$stash}{keys %$args} if my $ts = delete $args->{'mojo.to_string'};
delete @{$stash}{qw(layout extends)} if $ts;

# Merge stash and arguments
# All other arguments just become part of the stash
@$stash{keys %$args} = values %$args;

my $options = {
Expand Down
4 changes: 1 addition & 3 deletions lib/Mojolicious/Routes/Pattern.pm
Expand Up @@ -23,11 +23,9 @@ sub match_partial {
$self->_compile unless $self->{regex};
$self->_compile_format if $detect && !$self->{format_regex};

# Match
# Path
return undef unless my @captures = $$pathref =~ $self->regex;
$$pathref = ${^POSTMATCH};

# Merge captures
my $captures = {%{$self->defaults}};
for my $placeholder (@{$self->placeholders}) {
last unless @captures;
Expand Down
4 changes: 1 addition & 3 deletions lib/Mojolicious/Routes/Route.pm
Expand Up @@ -43,11 +43,9 @@ sub find {
my $candidate;
while (my $child = shift @children) {

# Match
# Custom names have priority
$candidate = $child->has_custom_name ? return $child : $child
if $child->name eq $name;

# Search children too
push @children, @{$child->children};
}

Expand Down
5 changes: 4 additions & 1 deletion t/mojolicious/app.t
Expand Up @@ -315,8 +315,11 @@ $t->get_ok('/foo-bar' => {'X-Test' => 'Hi there!'})->status_is(200)
->content_like(qr|Hello Mojo from the other template /foo-bar!|);

# Foo::something
$t->get_ok('/somethingtest' => {'X-Test' => 'Hi there!'})->status_is(200)
$t->put_ok('/somethingtest' => {'X-Test' => 'Hi there!'})->status_is(200)
->header_is(Server => 'Mojolicious (Perl)')->content_is('/test4/42');
$t->get_ok('/somethingtest?_method=PUT' => {'X-Test' => 'Hi there!'})
->status_is(200)->header_is(Server => 'Mojolicious (Perl)')
->content_is('/test4/42');

# Foo::url_for_missing
$t->get_ok('/something_missing' => {'X-Test' => 'Hi there!'})->status_is(200)
Expand Down
2 changes: 1 addition & 1 deletion t/mojolicious/lib/MojoliciousTest.pm
Expand Up @@ -86,7 +86,7 @@ sub startup {
->name('something');

# /somethingtest (refer to another route with url_for)
$r->route('/somethingtest')->to('foo#something');
$r->put('/somethingtest')->to('foo#something');

# /something_missing (refer to a non-existing route with url_for)
$r->route('/something_missing')->to('foo#url_for_missing');
Expand Down

0 comments on commit 3f6e564

Please sign in to comment.