10 use_ok("Catalyst::Plugin::Session::State::Stash" );
11 use_ok("Catalyst::Plugin::Session");
13 my $ctx_meta = Class::MOP::Class->create_anon_class(
15 Catalyst::Plugin::Session::State::Stash
16 Catalyst::Plugin::Session
20 $ctx_meta->add_attribute( $_, reader => $_, default => sub { {} } )
21 for qw/config session stash/;;
22 $ctx_meta->add_method("debug" => sub { 0 });
25 $ctx_meta->add_method( sessionid => sub { shift; $sessionid = shift if @_; $sessionid } );
27 $ctx_meta->make_immutable( replace_constructor => 1 );
28 my $app = $ctx_meta->name->new;
30 isa_ok($app, 'Catalyst::Plugin::Session::State::Stash');
31 isa_ok($app, 'Catalyst::Plugin::Session');
33 can_ok( $app, 'config');
34 can_ok( $app, "setup_session" );
35 can_ok( $app, '_session_plugin_config');
39 is( $app->config->{'Plugin::Session'}{stash_key},
40 '_session', "default cookie name is set" );
42 can_ok( $app, "get_session_id" );
44 ok( !$app->get_session_id, "no session id yet");
46 $app->stash->{ '_session' } = {id => 1};
47 $app->stash->{'session_id'} = {id => 2};
48 $app->stash->{'other_thing'} = { id => 3 };
50 is( $app->get_session_id, "1", "Pull newfound session id" );
52 $app->config->{'Plugin::Session'}{stash_key} = "session_id";
54 is( $app->get_session_id, "2", "Pull session id from second key" );
56 can_ok( $app, "set_session_id" );
58 # Check forwards config compatibility..
59 $app->config->{'Plugin::Session'} = {};
62 is( $app->config->{'Plugin::Session'}{stash_key},
63 '_session', "default cookie name is set when new stash key used" );
65 $app->config->{'Plugin::Session'}{stash_key} = "other_thing";
67 is( $app->get_session_id, "3", "Pull session id from key in new config" );