-
-
Save hesco/403d3a74747c6fa0767c78171f8b387a to your computer and use it in GitHub Desktop.
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
package MyApp::Roles::DB; | |
use lib qw{ lib local/lib/perl5 }; | |
use Moose::Role; | |
use MyApp::Schema qw(); | |
has 'schema' => ( | |
is => 'rw', | |
lazy => 1, | |
default => sub { | |
my $self = shift; | |
my $dsn = $self->cfg->param('db.dsn'); | |
my $user = $self->cfg->param('db.user'); | |
my $pw = $self->cfg->param('db.pw'); | |
return MyApp::Schema->connect( $dsn, $user, $pw ); | |
}, | |
); | |
1; |
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
package MyApp; | |
use FindBin; | |
use lib "$FindBin::Bin/../lib", "$FindBin::Bin/../local/lib/perl5"; | |
use Mojo::Base 'Mojolicious'; | |
use Moose; | |
use MooseX::NonMoose; | |
with 'MyApp::Roles::Config', 'MyApp::Roles::DB'; | |
sub startup { | |
# snip | |
} | |
1; |
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
use lib 'lib', 'local/lib/perl5'; | |
use Mojo::Base -strict; | |
use Test::More; | |
use Test::Mojo; | |
use Data::Dumper; | |
my $t = Test::Mojo->new('MyApp'); | |
my @tables = $t->app->schema->sources; | |
isa_ok( $t->app->schema, 'DBIx::Class::Schema', '$t->app->schema' ); | |
is( grep(/AppMotdSeenByUser/, @tables), 1, 'found an expected table in schema' ) or diag( Dumper \@tables ); | |
done_testing(); |
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
$ prove -v t/r-0120-my_app-roles-db.t | |
t/r-0120-my_app-roles-db.t .. | |
ok 1 - '$t->app->schema' isa 'DBIx::Class::Schema' | |
ok 2 - found an expected table in schema | |
1..2 | |
ok | |
All tests successful. | |
Files=1, Tests=2, 2 wallclock secs ( 0.03 usr 0.02 sys + 0.94 cusr 0.07 csys = 1.06 CPU) | |
Result: PASS |
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
package MyApp::Roles::Auth; | |
use Moose::Role; | |
use FindBin; | |
use Data::Dumper; | |
use Mojolicious::Plugin::Authentication | |
has auth_init => ( | |
is => 'rw', | |
lazy => 1, | |
default => sub { | |
my $self = shift; | |
print STDERR Dumper \(keys %{$self}); | |
open ( 'DUMP', '>', 'my_app-roles-auth-self.dump' ); | |
print DUMP Dumper $self; | |
close DUMP; | |
$self->plugin( 'authentication' => { | |
autoload_user => 1, | |
session_key => 'gagp_api', | |
load_user => sub { | |
my $app = shift; | |
my $uid = shift; | |
my $user = { uid => 1, username => 'flhammer', foo => 'bar' }; | |
return $user; | |
}, | |
validate_user => sub { | |
my $app = shift; | |
my $username = shift; | |
my $password = shift; | |
my $extradata = shift; | |
my $uid = 1; | |
return $uid; | |
}, | |
current_user_fn => 'user', # compatibility with old code | |
}); | |
return $self; | |
}, | |
); | |
1; |
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
use lib 'lib', 'local/lib/perl5'; | |
use Mojo::Base -strict; | |
use Test::More; | |
use Test::Mojo; | |
use Data::Dumper; | |
my $t = Test::Mojo->new('MyApp'); | |
# $t->app->auth_init; | |
isa_ok( $t->app, 'MyApp' ); | |
can_ok( $t->app, 'authenticate' ); | |
can_ok( $t->app, 'is_user_authenticated' ); | |
can_ok( $t->app, 'current_user' ); | |
can_ok( $t->app, 'reload_user' ); | |
can_ok( $t->app, 'signature_exists' ); | |
can_ok( $t->app, 'logout' ); | |
done_testing(); |
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
$ prove -v t/r-0130-my_app-roles-auth.t | |
t/r-0130-my_app-roles-auth.t .. | |
ok 1 - An object of class 'MyApp' isa 'MyApp' | |
not ok 2 - MyApp->can('authenticate') | |
# Failed test 'MyApp->can('authenticate')' | |
# at t/r-0130-my_app-roles-auth.t line 12. | |
# MyApp->can('authenticate') failed | |
# <snip> | |
# Looks like you failed 6 tests of 7. | |
Dubious, test returned 6 (wstat 1536, 0x600) | |
Failed 6/7 subtests | |
Test Summary Report | |
------------------- | |
t/r-0130-my_app-roles-auth.t (Wstat: 1536 Tests: 7 Failed: 6) | |
Failed tests: 2-7 | |
Non-zero exit status: 6 | |
Files=1, Tests=7, 1 wallclock secs ( 0.03 usr 0.00 sys + 0.88 cusr 0.08 csys = 0.99 CPU) | |
Result: FAIL |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment