From: John Napiorkowski Date: Mon, 10 Jan 2011 19:24:35 +0000 (-0500) Subject: fix for response_filter regression and matching test X-Git-Tag: v0.005~2 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=16c72d232d9b3bf1b55cbb944aa1e97e383360df;hp=b6bf9ed3faa4fead683ce3c301a4342cd0930fda;p=catagits%2FWeb-Simple.git fix for response_filter regression and matching test --- diff --git a/lib/Web/Dispatch/Wrapper.pm b/lib/Web/Dispatch/Wrapper.pm index 65739fd..c838261 100644 --- a/lib/Web/Dispatch/Wrapper.pm +++ b/lib/Web/Dispatch/Wrapper.pm @@ -41,7 +41,7 @@ sub response_filter (&) { sub to_app { my $code = $_[0]->wrapper; - my $app = $_[1]; + my $app = $_[0]->app; sub { $code->($_[0], $app) } } diff --git a/t/response-filter.t b/t/response-filter.t new file mode 100644 index 0000000..c03ccd3 --- /dev/null +++ b/t/response-filter.t @@ -0,0 +1,38 @@ +use strict; +use warnings FATAL => 'all'; + +use Test::More; +use Plack::Test; +use HTTP::Request::Common qw(GET POST); + +{ + package t::Web::Simple::ResponseFilter; + use Web::Simple; + sub dispatch_request { + my $self = shift; + sub (.html) { + response_filter { + return [ + 200, + [ 'Content-Type' => 'text/html' ], + [ shift->{name} ], + ]; + }; + }, + sub (GET + /index) { + bless {name=>'john'}, 'CrazyHotWildWet'; + }, + } +} + +ok my $app = t::Web::Simple::ResponseFilter->new->to_psgi_app, + 'Got a plack app'; + +test_psgi $app, sub { + my $cb = shift; + my $res = $cb->(GET "/index.html"); + like $res->content, qr/john/, + 'Got Expected Content'; +}; + +done_testing;