| File: | t/mini-app-session.t |
| Coverage: | 100.0% |
| line | stmt | bran | cond | sub | pod | time | code |
|---|---|---|---|---|---|---|---|
| 1 | #!/usr/bin/env perl -w | ||||||
| 2 | 1 1 1 | 102 10 11 | use strict; | ||||
| 3 | 1 1 1 | 10 3 10 | use warnings; | ||||
| 4 | 1 1 1 | 125 6 4 | use Moose (); | ||||
| 5 | 1 1 1 | 90 5 18 | use Test::More tests => 4; | ||||
| 6 | |||||||
| 7 | package FooController; | ||||||
| 8 | 1 1 1 | 87 5 16 | use Railsish::Controller; | ||||
| 9 | |||||||
| 10 | sub index { | ||||||
| 11 | 2 | 15 | if (session->{counter}) { | ||||
| 12 | 1 | 7 | session->{counter} = session->{counter} + 1; | ||||
| 13 | } | ||||||
| 14 | else { | ||||||
| 15 | 1 | 5 | session->{counter} = 1; | ||||
| 16 | } | ||||||
| 17 | 2 | 14 | response->body("Hi from Foo: " . session->{counter}); | ||||
| 18 | } | ||||||
| 19 | |||||||
| 20 | package main; | ||||||
| 21 | 1 1 1 | 142 8 16 | use Railsish::Router; | ||||
| 22 | 1 1 1 | 94 5 21 | use Railsish::Dispatcher; | ||||
| 23 | 1 1 1 | 79 6 21 | use HTTP::Engine; | ||||
| 24 | 1 1 1 | 108 6 23 | use HTTP::Request; | ||||
| 25 | 1 1 1 | 9 3 16 | use HTTP::Headers; | ||||
| 26 | 1 1 1 | 81 5 21 | use HTTP::Cookies; | ||||
| 27 | 1 1 1 | 79 6 18 | use CGI::Cookie; | ||||
| 28 | |||||||
| 29 | Railsish::Router->draw( | ||||||
| 30 | sub { | ||||||
| 31 | 1 | 6 | my ($map) = @_; | ||||
| 32 | 1 | 10 | $map->connect("/:controller/:action/:id"); | ||||
| 33 | 1 | 24 | $map->connect("/:controller/:action"); | ||||
| 34 | 1 | 24 | $map->connect("/:controller", action => 'index'); | ||||
| 35 | 1 | 25 | $map->connect("", controller => "foo"); | ||||
| 36 | } | ||||||
| 37 | 1 | 26 | ); | ||||
| 38 | |||||||
| 39 | my $engine = HTTP::Engine->new( | ||||||
| 40 | interface => { | ||||||
| 41 | module => "Test", | ||||||
| 42 | request_handler => sub { | ||||||
| 43 | 2 | 66 | Railsish::Dispatcher->dispatch(@_); | ||||
| 44 | } | ||||||
| 45 | } | ||||||
| 46 | 1 | 33 | ); | ||||
| 47 | |||||||
| 48 | 1 | 80 | my $response = $engine->run(HTTP::Request->new(GET => "http://localhost/")); | ||||
| 49 | 1 | 17 | is($response->content, "Hi from Foo: 1"); | ||||
| 50 | # diag $response->content; | ||||||
| 51 | 1 | 29 | ok($response->header("Set-Cookie")); | ||||
| 52 | # diag($response->header("Set-Cookie")); | ||||||
| 53 | |||||||
| 54 | 1 1 1 | 10 4 19 | use YAML; | ||||
| 55 | |||||||
| 56 | 1 | 15 | my $cookies = $response->header("Set-Cookie"); | ||||
| 57 | |||||||
| 58 | # diag(Dump($cookies)); | ||||||
| 59 | |||||||
| 60 | 1 | 120 | my $request = HTTP::Request->new(GET => "http://localhost/"); | ||||
| 61 | 1 | 35 | $request->header(Cookie => $cookies); | ||||
| 62 | |||||||
| 63 | 1 | 255 | $response = $engine->run($request); | ||||
| 64 | 1 | 3 | is($response->content, "Hi from Foo: 2"); | ||||
| 65 | # diag $response->content; | ||||||
| 66 | |||||||
| 67 | 1 | 9 | ok($response->header("Set-Cookie")); | ||||
| 68 | # diag($response->header("Set-Cookie")); | ||||||