Skip to content

Commit

Permalink
fixed small application initialization bug in Mojo::Server
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Jun 22, 2012
1 parent bc00d4c commit df72a6e
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 11 deletions.
1 change: 1 addition & 0 deletions Changes
Expand Up @@ -24,6 +24,7 @@
- Fixed bug that prevented sessions from working in embedded applications.
- Fixed JSON Pointer escaping.
- Fixed small JSON Pointer bug in get command. (avkhozov)
- Fixed small application initialization bug in Mojo::Server.

2.98 2012-05-30
- Switched from IO::Socket::IP to IO::Socket::INET6 for IPv6 support.
Expand Down
2 changes: 1 addition & 1 deletion lib/Mojo/Server.pm
Expand Up @@ -10,7 +10,7 @@ has app => sub {
my $self = shift;
return $ENV{MOJO_APP} if ref $ENV{MOJO_APP};
if (my $e = Mojo::Loader->load($self->app_class)) { die $e if ref $e }
return $self->app_class->new;
return $ENV{MOJO_APP} = $self->app_class->new;
};
has app_class =>
sub { ref $ENV{MOJO_APP} || $ENV{MOJO_APP} || 'Mojo::HelloWorld' };
Expand Down
20 changes: 13 additions & 7 deletions t/mojo/server.t
Expand Up @@ -16,17 +16,23 @@ use Mojo::Server;
my $server = Mojo::Server->new;
isa_ok $server, 'Mojo::Server', 'right object';

# Test the default
{
local $ENV{MOJO_APP};
my $app = $server->new->app;
isa_ok $app, 'Mojolicious::Lite', 'right default app';
}

# Test an explicit class name
my $app = $server->new(app_class => 'Mojo::TestServerViaApp')->app;
isa_ok $app, 'Mojo::TestServerViaApp', 'right object';
{
local $ENV{MOJO_APP};
my $app = $server->new(app_class => 'Mojo::TestServerViaApp')->app;
isa_ok $app, 'Mojo::TestServerViaApp', 'right object';
}

# Test setting the class name through the environment
{
local $ENV{MOJO_APP} = 'Mojo::TestServerViaEnv';
$app = $server->new->app;
my $app = $server->new->app;
isa_ok $app, 'Mojo::TestServerViaEnv', 'right object';
}

# Test the default
$app = $server->new->app;
isa_ok $app, 'Mojolicious::Lite', 'right default app';
3 changes: 2 additions & 1 deletion t/mojolicious/app.t
Expand Up @@ -7,7 +7,7 @@ BEGIN {
$ENV{MOJO_REACTOR} = 'Mojo::Reactor::Poll';
}

use Test::More tests => 325;
use Test::More tests => 326;

use FindBin;
use lib "$FindBin::Bin/lib";
Expand Down Expand Up @@ -37,6 +37,7 @@ is $t->app->sessions->cookie_domain, '.example.com', 'right domain';
is $t->app->sessions->cookie_path, '/bar', 'right path';
is_deeply $t->app->commands->namespaces,
[qw(Mojolicious::Command MojoliciousTest::Command)], 'right namespaces';
is $t->app, $t->app->commands->app, 'applications are equal';

# Plugin::Test::SomePlugin2::register (security violation)
$t->get_ok('/plugin-test-some_plugin2/register')->status_isnt(500)
Expand Down
3 changes: 2 additions & 1 deletion t/mojolicious/lite_app.t
Expand Up @@ -9,7 +9,7 @@ BEGIN {
$ENV{MOJO_REACTOR} = 'Mojo::Reactor::Poll';
}

use Test::More tests => 691;
use Test::More tests => 692;

# "Wait you're the only friend I have...
# You really want a robot for a friend?
Expand Down Expand Up @@ -545,6 +545,7 @@ my $t = Test::Mojo->new;

# Application is already available
is $t->app->test_helper2, 'Mojolicious::Controller', 'right class';
is $t->app, app->commands->app, 'applications are equal';

# User agent timer
my $ua = Mojo::UserAgent->new(ioloop => Mojo::IOLoop->singleton)->app(app);
Expand Down
3 changes: 2 additions & 1 deletion t/mojolicious/production_app.t
Expand Up @@ -7,7 +7,7 @@ BEGIN {
$ENV{MOJO_REACTOR} = 'Mojo::Reactor::Poll';
}

use Test::More tests => 80;
use Test::More tests => 81;

use FindBin;
use lib "$FindBin::Bin/lib";
Expand All @@ -32,6 +32,7 @@ is $t->app->sessions->cookie_domain, '.example.com', 'right domain';
is $t->app->sessions->cookie_path, '/bar', 'right path';
is_deeply $t->app->commands->namespaces,
[qw(Mojolicious::Command MojoliciousTest::Command)], 'right namespaces';
is $t->app, $t->app->commands->app, 'applications are equal';

# Plugin::Test::SomePlugin2::register (security violation)
$t->get_ok('/plugin-test-some_plugin2/register')->status_isnt(500)
Expand Down

0 comments on commit df72a6e

Please sign in to comment.