Showing 6 changed files with 59 additions and 21 deletions
+14 -14
lib/Gitprep/Git.pm
... ...
@@ -1576,6 +1576,20 @@ sub _slurp {
1576 1576
   return $content;
1577 1577
 }
1578 1578
 
1579
+sub _tab_to_space {
1580
+  my ($self, $line) = @_;
1581
+  
1582
+  # Tab to space
1583
+  while ((my $pos = index($line, "\t")) != -1) {
1584
+    if (my $count = (2 - ($pos % 2))) {
1585
+      my $spaces = ' ' x $count;
1586
+      $line =~ s/\t/$spaces/;
1587
+    }
1588
+  }
1589
+
1590
+  return $line;
1591
+}
1592
+
1579 1593
 sub _unquote {
1580 1594
   my ($self, $str) = @_;
1581 1595
   
... ...
@@ -1608,18 +1622,4 @@ sub _unquote {
1608 1622
   return $str;
1609 1623
 }
1610 1624
 
1611
-sub _tab_to_space {
1612
-  my ($self, $line) = @_;
1613
-  
1614
-  # Tab to space
1615
-  while ((my $pos = index($line, "\t")) != -1) {
1616
-    if (my $count = (2 - ($pos % 2))) {
1617
-      my $spaces = ' ' x $count;
1618
-      $line =~ s/\t/$spaces/;
1619
-    }
1620
-  }
1621
-
1622
-  return $line;
1623
-}
1624
-
1625 1625
 1;
+2 -2
lib/Gitprep/Manager.pm
... ...
@@ -9,12 +9,12 @@ use File::Temp ();
9 9
 
10 10
 has 'app';
11 11
 
12
-sub admin_id {
12
+sub admin_user {
13 13
   my $self = shift;
14 14
   
15 15
   # Admin user
16 16
   my $admin_user = $self->app->dbi->model('user')
17
-    ->select('id', where => {admin => 1})->value;
17
+    ->select(where => {admin => 1})->one;
18 18
   
19 19
   return $admin_user;
20 20
 }
+4 -4
templates/auto/_start.html.ep
... ...
@@ -9,24 +9,24 @@
9 9
   if ($op eq 'create') {
10 10
     
11 11
     # Sleep to protect password atack
12
-    sleep 3;
12
+    sleep 3 unless $ENV{GITPREP_TEST};
13 13
     
14 14
     # Check existence admin user
15 15
     my $admin_user = app->manager->admin_user;
16
-    if (defined $admin_user) { $errors = ['admin user already exists'] }
16
+    if (defined $admin_user) { $errors = ['admin user already exists.'] }
17 17
     else {
18 18
       # Validation
19 19
       my $params = $api->params;
20 20
       my $rule = [
21 21
         password => [
22
-          ['not_blank' => 'Password is emplty'],
22
+          ['not_blank' => 'Password is empty.'],
23 23
           ['ascii' => 'Password contain invalid character.'],
24 24
           [{'length' => {max => 20}} => 'Password is too long.']
25 25
         ],
26 26
         {password_check => [qw/password password2/]}
27 27
           => {copy => 0}
28 28
           => [
29
-            ['duplication' => "Two password don't match"]
29
+            ['duplication' => "Two password don't match."]
30 30
           ]
31 31
       ];
32 32
       my $vresult = $self->app->validator->validate($params, $rule);
+1 -1
templates/auto/index.html.ep
... ...
@@ -4,7 +4,7 @@
4 4
   my $users = $manager->users;
5 5
   
6 6
   # Goto Start page
7
-  unless (defined $manager->admin_id) {
7
+  unless (defined $manager->admin_user) {
8 8
     $self->redirect_to('/_start');
9 9
     $self->finish_rendering;
10 10
     return;
BIN
xt/admin.db
Binary file not shown.
+38
xt/admin.t
... ...
@@ -0,0 +1,38 @@
1
+use Test::More 'no_plan';
2
+
3
+use FindBin;
4
+use utf8;
5
+use lib "$FindBin::Bin/../mojo/lib";
6
+use lib "$FindBin::Bin/../lib";
7
+use lib "$FindBin::Bin/../extlib/lib/perl5";
8
+use Encode qw/encode decode/;
9
+
10
+use Test::Mojo;
11
+
12
+$ENV{GITPREP_TEST} = 1;
13
+
14
+# Test DB
15
+my $db_file = $ENV{GITPREP_DB_FILE} = "$FindBin::Bin/admin.db";
16
+
17
+# Test Repository home
18
+my $rep_home = $ENV{GITPREP_REP_HOME} = "$FindBin::Bin/admin";
19
+
20
+use Gitprep;
21
+
22
+my $app = Gitprep->new;
23
+my $t = Test::Mojo->new($app);
24
+$t->ua->max_redirects(3);
25
+
26
+note '_start page';
27
+{
28
+  # Redirect to _start page
29
+  $t->get_ok('/')->content_like(qr/Create Admin User/);
30
+
31
+  # Page access
32
+  $t->get_ok('/_start')->content_like(qr/Create Admin User/);
33
+  
34
+  # Password is empty
35
+  $t->post_ok('/_start?op=create', form => {password => ''})
36
+    ->content_like(qr/Password is empty/)
37
+  ;
38
+}