fix for response_filter regression and matching test
John Napiorkowski [Mon, 10 Jan 2011 19:24:35 +0000 (14:24 -0500)]
lib/Web/Dispatch/Wrapper.pm
t/response-filter.t [new file with mode: 0644]

index 65739fd..c838261 100644 (file)
@@ -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 (file)
index 0000000..c03ccd3
--- /dev/null
@@ -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;