CatalystX-Eta
view release on metacpan or search on metacpan
t/lib/MyApp/Test/Further.pm view on Meta::CPAN
package MyApp::Test::Further;
use strict;
use warnings;
use utf8;
use URI;
use Carp;
use CatalystX::Eta::Test::REST;
use JSON::MaybeXS;
use Test::More;
use Catalyst::Test q(MyApp);
# ugly hack
sub import {
strict->import;
warnings->import;
no strict 'refs';
my $caller = caller;
while ( my ( $name, $symbol ) = each %{ __PACKAGE__ . '::' } ) {
next if $name eq 'BEGIN'; # don't export BEGIN blocks
next if $name eq 'import'; # don't export this sub
next unless *{$symbol}{CODE}; # export subs only
my $imported = $caller . '::' . $name;
*{$imported} = \*{$symbol};
}
}
my $obj = CatalystX::Eta::Test::REST->new(
do_request => sub {
my $req = shift;
#use DDP; p $req;
eval 'use DDP; do{my $x = $req->as_string; p $x}' if exists $ENV{TRACE} && $ENV{TRACE};
my ( $res, $c ) = ctx_request($req);
eval 'use DDP; do{my $x = $res->as_string; p $x}' if exists $ENV{TRACE} && $ENV{TRACE};
return $res;
},
decode_response => sub {
my $res = shift;
return decode_json( $res->content );
}
);
for (qw/rest_get rest_put rest_head rest_delete rest_post rest_reload rest_reload_list/) {
eval( 'sub ' . $_ . ' { return $obj->' . $_ . '(@_) }' );
}
sub stash_test($&) {
$obj->stash_ctx(@_);
}
sub stash($) {
$obj->stash->{ $_[0] };
}
sub test_instance { $obj }
sub db_transaction (&) {
my ( $subref, $modelname ) = @_;
my $schema = MyApp->model( $modelname || 'DB' );
eval {
$schema->txn_do(
sub {
$subref->($schema);
die 'rollback';
}
);
};
( run in 1.897 second using v1.01-cache-2.11-cpan-364913b4093 )