Permalink
Browse files

Merge pull request #5 from dagolden/bug-if-flash-error

demonstrate error with conditional in template
  • Loading branch information...
2 parents 47f923a + 0ef55af commit 8ad42a894787a06c24c9e4d6a1df491f1db02ae8 @dams committed Jul 10, 2013
Showing with 37 additions and 0 deletions.
  1. +34 −0 t/04_conditional.t
  2. +3 −0 t/views/div.tt
View
@@ -0,0 +1,34 @@
+use Test::More tests => 10, import => ['!pass'];
+use Dancer ':syntax';
+use Dancer::Test;
+
+use_ok 'Dancer::Plugin::FlashMessage';
+
+setting views => path('t', 'views');
+
+ok(
+ get '/nothing' => sub {
+ template 'div', { };
+ });
+ok(
+ get '/' => sub {
+ flash(error => 'plop');
+ template 'div', { foo => 'bar' };
+ });
+ok(
+ get '/different' => sub {
+ template 'div', { foo => 'bar' };
+ }
+);
+
+# empty route
+route_exists [ GET => '/nothing' ];
+response_content_like( [ GET => '/nothing' ], qr/^\n\n$/m );
+
+# first time we get the error message
+route_exists [ GET => '/' ];
+response_content_like( [ GET => '/' ], qr{<div class=error>plop</div>} );
+# second time the error has disappeared
+route_exists [ GET => '/different' ];
+response_content_like( [ GET => '/different' ], qr/^\n\n$/m );
+
View
@@ -0,0 +1,3 @@
+<% IF flash.error %>
+ <div class=error><% flash.error %></div>
+<% END %>

0 comments on commit 8ad42a8

Please sign in to comment.