Last active
August 29, 2015 13:57
-
-
Save nikita-d/9390784 to your computer and use it in GitHub Desktop.
Memory cycle output
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
use utf8::all; | |
use Modern::Perl qw|2013|; | |
use Data::Printer (use_prototypes => 0); | |
use Mojolicious::Lite; | |
use Test::Most; | |
use Test::More; | |
use Test::Mojo; | |
use RT::Admin; | |
use Test::Memory::Cycle; | |
BEGIN { use_ok('InoTV') }; | |
my $stash; | |
push @{app->plugins->{namespaces}}, 'RT::Plugin'; | |
app->plugin('Config' => { 'file' => '../../rtadmin.testing.conf' }); | |
app->plugin('Model'); | |
app->hook('after_dispatch' => sub { | |
my $c = shift; | |
$stash = $c->stash; | |
Scalar::Util::weaken($stash); | |
return $c->render_later(); | |
}); | |
get '/' => sub { | |
my $c = shift; | |
my $model = $c->model('Document'); | |
$c->stash('m_document' => $model); | |
return $c->render(text => 1); | |
}; | |
get '/stash' => sub { | |
my $c = shift; | |
my $model = $c->model('Document'); | |
$c->stash('key' => 'value', 'm_document' => $model); | |
return $c->render(text => 1); | |
}; | |
app->start; | |
my $t = Test::Mojo->new(); | |
my $model; | |
$t->get_ok('/')->status_is(200)->content_is(1); | |
$model = $stash->{m_document}; | |
isa_ok ($model, 'InoTV::Model::Document'); | |
ok (my $log = $model->log, 'got logger object'); | |
isa_ok ($log, 'Mojo::Log'); | |
ok (my $schema = $model->schema, 'got schema object'); | |
isa_ok ($schema, 'InoTV::Schema'); | |
ok (my $resultset = $schema->resultset('Staff'), 'got resultset'); | |
ok (my $user = $resultset->find({ 'id_user' => 1 }, { 'key' => 'primary' }), 'found admin user'); | |
ok (my $user_json = $user->to_hash, 'result methods work'); | |
is ($user_json->{id_user}, 1, 'id user is correct'); | |
is ($user_json->{is_banned}, 0, 'id user is not banned'); | |
is ($user_json->{login}, 'admin', 'login correct'); | |
is ($user_json->{person_name}, 'Администратор', 'person name correct'); | |
$t->get_ok('/stash')->status_is(200)->content_is(1); | |
$model = $stash->{m_document}; | |
isa_ok ($model, 'InoTV::Model::Document'); | |
ok (my $m_stash = $model->stash, 'got model stash'); | |
ok ((List::MoreUtils::any { $_ =~ m|mojo\..+|gi } keys %$m_stash), 'is mojolicious stash - has mojo.* keys'); | |
is ($m_stash->{key}, 'value', 'model stash contains key set in controller'); | |
memory_cycle_ok(app); | |
$stash = undef; | |
done_testing(23); | |
# Cycle #1 | |
# Mojolicious::Lite A->{plugins} => Mojolicious::Plugins B | |
# Mojolicious::Plugins B->{events} => %C | |
# %C->{after_dispatch} => @D | |
# @D->[0] => &E | |
# closure &E, $stash => $F | |
# $F => %G | |
# %G->{m_document} => InoTV::Model::Document H | |
# InoTV::Model::Document H->{ctx} => Mojolicious::Controller I | |
# Mojolicious::Controller I->{stash} => %G | |
# Cycle #2 | |
# Mojolicious::Lite A->{renderer} => Mojolicious::Renderer J | |
# Mojolicious::Renderer J->{helpers} => %K | |
# %K->{model} => &L | |
# closure &L, $app => $M | |
# $M => Mojolicious::Lite A |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment