Navigation Menu

Skip to content

Commit

Permalink
a few more introspection tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Mar 19, 2012
1 parent d7885a3 commit e78a3b1
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 21 deletions.
1 change: 0 additions & 1 deletion lib/Mojolicious/Controller.pm
Expand Up @@ -904,7 +904,6 @@ Automatically select best possible representation for resource from C<Accept>
request header, C<format> stash value or C<format> GET/POST parameter,
defaults to rendering an empty C<204> response.
# Negotiate content
$c->respond_to(
json => sub { $c->render_json({just => 'works'}) },
xml => {text => '<just>works</just>'},
Expand Down
25 changes: 7 additions & 18 deletions lib/Mojolicious/Plugin/TagHelpers.pm
Expand Up @@ -18,11 +18,7 @@ sub register {
# Add "checkbox" helper
$app->helper(
check_box => sub {
$self->_input(
shift, shift,
value => shift,
@_, type => 'checkbox'
);
$self->_input(shift, shift, value => shift, @_, type => 'checkbox');
}
);

Expand All @@ -33,12 +29,12 @@ sub register {
# Add "form_for" helper
$app->helper(
form_for => sub {
my $c = shift;
my @url = (shift);
my ($c, @url) = (shift, shift);
push @url, shift if ref $_[0] eq 'HASH';

# POST detection
my @post;
if (my $r = $c->app->routes->find(@url)) {
if (my $r = $c->app->routes->find($url[0])) {
my %methods = (GET => 1, POST => 1);
do {
my @via = @{$r->via || []};
Expand All @@ -47,9 +43,6 @@ sub register {
@post = (method => 'POST') if $methods{POST} && !$methods{GET};
}

# Captures
push @url, shift if ref $_[0] eq 'HASH';

return $self->_tag('form', action => $c->url_for(@url), @post, @_);
}
);
Expand Down Expand Up @@ -88,8 +81,7 @@ sub register {
}

# Path
my $src;
$src = shift if @_ % 2;
my $src = @_ % 2 ? shift : undef;

# Attributes
my %attrs = @_;
Expand Down Expand Up @@ -272,8 +264,7 @@ sub _input {
my %attrs;
if (@_ % 2) {
my $value = shift;
%attrs = @_;
$attrs{value} = $value;
%attrs = (@_, value => $value);
}

# Even
Expand Down Expand Up @@ -324,9 +315,7 @@ sub _tag {

# Block
if ($cb || defined $content) {
$tag .= '>';
$tag .= $cb ? $cb->() : $content;
$tag .= "</$name>";
$tag .= '>' . ($cb ? $cb->() : $content) . "</$name>";
}

# Empty element
Expand Down
8 changes: 7 additions & 1 deletion t/mojolicious/app.t
Expand Up @@ -7,7 +7,7 @@ BEGIN {
$ENV{MOJO_MODE} = 'development';
}

use Test::More tests => 280;
use Test::More tests => 282;

use FindBin;
use lib "$FindBin::Bin/lib";
Expand All @@ -25,6 +25,12 @@ my $t = Test::Mojo->new('MojoliciousTest');
# Application is already available
is $t->app->routes->find('something')->to_string, '/test4/:something',
'right pattern';
is $t->app->routes->find('test3')->pattern->defaults->{namespace},
'MojoliciousTestController',
'right namespace';
is $t->app->routes->find('authenticated')->pattern->defaults->{controller},
'foo',
'right controller';
is $t->app->sessions->cookie_domain, '.example.com', 'right domain';
is $t->app->sessions->cookie_path, '/bar', 'right path';

Expand Down
8 changes: 7 additions & 1 deletion t/mojolicious/production_app.t
Expand Up @@ -7,7 +7,7 @@ BEGIN {
$ENV{MOJO_MODE} = 'production';
}

use Test::More tests => 65;
use Test::More tests => 67;

use FindBin;
use lib "$FindBin::Bin/lib";
Expand All @@ -20,6 +20,12 @@ my $t = Test::Mojo->new('MojoliciousTest');
# Application is already available
is $t->app->routes->find('something')->to_string, '/test4/:something',
'right pattern';
is $t->app->routes->find('test3')->pattern->defaults->{namespace},
'MojoliciousTestController',
'right namespace';
is $t->app->routes->find('authenticated')->pattern->defaults->{controller},
'foo',
'right controller';
is $t->app->sessions->cookie_domain, '.example.com', 'right domain';
is $t->app->sessions->cookie_path, '/bar', 'right path';

Expand Down

0 comments on commit e78a3b1

Please sign in to comment.