Dancer2-Session-DBIC

 view release on metacpan or  search on metacpan

t/plugin_dbic.t  view on Meta::CPAN

use strict;
use warnings;

use utf8;
use open ':std', ':encoding(utf8)';
use Test::More;

BEGIN {
    eval "use Dancer2";
    eval "use Dancer2::Plugin::DBIC 0.0009";
    plan skip_all => "Dancer2::Plugin::DBIC 0.0009 required to run this test"
      if $@;
}

diag "Dancer2::Plugin::DBIC version: ", $Dancer2::Plugin::DBIC::VERSION;
use Plack::Test;
use HTTP::Request::Common;

use File::Spec;
use lib File::Spec->catdir( 't', 'lib' );

my $deploy_once = 1;

{

    package Foo;

    use Dancer2;
    use Dancer2::Plugin::DBIC;

    set plugins => {
        DBIC => {
            default => {
                dsn          => 'dbi:SQLite:dbname=:memory:',
                schema_class => 'Test::Schema',
                options      => {
                    sqlite_unicode => 1,
                    quote_names    => 1,
                },
            },
        },
    };

    if ( $deploy_once ) {
        schema->deploy;
    }
    else {
        $deploy_once = 0;
    }

    # engines needs to set before the session itself
    set engines => {
        session => {
            DBIC => {
                db_connection_name => 'default',
            },
        },
    };

    set session => 'DBIC';

    get '/id' => sub {
        return session->id;
    };

    get '/getfoo' => sub {
        return session('foo');
    };

    get '/putfoo' => sub {
        session foo => 'bar';
        return session('foo');
    };

    get '/getcamel' => sub {
        return session('camel');
    };

    get '/putcamel' => sub {
        session camel => 'ラクダ';
        return session('camel');
    };

    get '/destroy' => sub {
        if ( app->can('destroy_session') ) {
            app->destroy_session;
        }

        # legacy
        else {
            context->destroy_session;
        }
        return "Session destroyed";
    };

    get '/sessionid' => sub {
        return session->id;



( run in 1.077 second using v1.01-cache-2.11-cpan-39bf76dae61 )