Skip to content
This repository
Browse code

Added basic tests for the new public URLs

  • Loading branch information...
commit b7701909bc5cbcf08b083328c414475f1fcba057 1 parent 9436dbc
Dave Cross authored February 06, 2014
16  lib/Lystyng.pm
@@ -10,21 +10,23 @@ use Dancer ':syntax';
10 10
 our $VERSION = '0.0.1';
11 11
 use Dancer::Plugin::DBIC qw[schema resultset];
12 12
 
13  
-defined $ENV{LYSTYNG_DB_USER} && defined $ENV{LYSTYNG_DB_PASS}
14  
-  or die 'Must set LYSTYNG_DB_USER and LYSTYNG_DB_PASS';
15  
-
16  
-my $cfg = setting('plugins');
17  
-$cfg->{DBIC}{default}{user} = $ENV{LYSTYNG_DB_USER};
18  
-$cfg->{DBIC}{default}{pass} = $ENV{LYSTYNG_DB_PASS};
  13
+hook before => sub {
  14
+  defined $ENV{LYSTYNG_DB_USER} && defined $ENV{LYSTYNG_DB_PASS}
  15
+    or die 'Must set LYSTYNG_DB_USER and LYSTYNG_DB_PASS';
19 16
 
  17
+  my $cfg = setting('plugins');
  18
+  $cfg->{DBIC}{default}{user} = $ENV{LYSTYNG_DB_USER};
  19
+  $cfg->{DBIC}{default}{pass} = $ENV{LYSTYNG_DB_PASS};
  20
+};
20 21
 
21 22
 get '/' => sub {
22 23
   template 'index';
23 24
 };
24 25
 
25 26
 get '/user' => sub {
  27
+  my @users = resultset('User')->all;
26 28
   template 'users', {
27  
-    users => resultset('User')->all,
  29
+    users => \@users,
28 30
   };
29 31
 };
30 32
 
24  t/004_public_urls.t
... ...
@@ -0,0 +1,24 @@
  1
+use Test::More;
  2
+use strict;
  3
+use warnings;
  4
+
  5
+use lib 'lib';
  6
+
  7
+# the order is important
  8
+use Lystyng;
  9
+use Dancer::Test;
  10
+
  11
+my %route = (
  12
+  ''       => 200,
  13
+  'user'   => 200,
  14
+  'user/test' => 404,
  15
+  'user/test/list/test' => 404,
  16
+);
  17
+
  18
+for (keys %route) {
  19
+  route_exists [ GET => "/$_" ], "a get route handler is defined for /$_";
  20
+  response_status_is ['GET' => "/$_"], $route{$_},
  21
+    "response status is $route{$_} for /$_";
  22
+}
  23
+
  24
+done_testing;

0 notes on commit b770190

Please sign in to comment.
Something went wrong with that request. Please try again.