Skip to content

Commit

Permalink
List and load prerequisites. create database for testing
Browse files Browse the repository at this point in the history
  • Loading branch information
szabgab committed Jul 26, 2011
1 parent 906723f commit 177a107
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 8 deletions.
17 changes: 14 additions & 3 deletions Makefile.PL
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -12,9 +12,20 @@ WriteMakefile(
: ()), : ()),
PL_FILES => {}, PL_FILES => {},
PREREQ_PM => { PREREQ_PM => {
'Test::More' => 0, 'Dancer' => 1.3060,
'YAML' => 0, 'Data::Dumper' => 0,
'Dancer' => 1.3060, 'DBIx::Class' => 0,
'DBIx::Class::Schema' => 0,
'DBIx::RunSQL' => 0,
'Email::Valid' => 0,
'File::Spec' => 0,
'Getopt::Long' => 0,
'MIME::Lite' => 0,
'Pod::Usage' => 0,
'String::Random' => 0,
'Template' => 0,
'Test::More' => 0,
'YAML' => 0,
}, },
dist => { COMPRESS => 'gzip -9f', SUFFIX => 'gz', }, dist => { COMPRESS => 'gzip -9f', SUFFIX => 'gz', },
clean => { FILES => 'Dwimmer-*' }, clean => { FILES => 'Dwimmer-*' },
Expand Down
6 changes: 3 additions & 3 deletions config.yml
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ engines:
encoding: 'utf8' encoding: 'utf8'
# start_tag: '[%' # start_tag: '[%'
# end_tag: '%]' # end_tag: '%]'
dwimmer: #dwimmer:
json: /home/gabor/dwimmer.json # json: /home/gabor/dwimmer.json
dbfile: /home/gabor/work/Dwimmer/db/dwimmer.db # dbfile: /home/gabor/work/Dwimmer/db/dwimmer.db
session: YAML session: YAML
4 changes: 3 additions & 1 deletion lib/Dwimmer.pm
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ use Dancer ':syntax';
our $VERSION = '0.01'; our $VERSION = '0.01';


use Data::Dumper; use Data::Dumper;
use Email::Valid;
use MIME::Lite;
use String::Random; use String::Random;


use Dwimmer::DB; use Dwimmer::DB;
Expand Down Expand Up @@ -173,7 +175,7 @@ get '/edit_this_page' => sub {
###### helper methods ###### helper methods


sub _get_db { sub _get_db {
my $dbfile = config->{dwimmer}{dbfile}; my $dbfile = path(config->{appdir}, 'db', 'dwimmer.db');
Dwimmer::DB->connect("dbi:SQLite:dbname=$dbfile", '', ''); Dwimmer::DB->connect("dbi:SQLite:dbname=$dbfile", '', '');
}; };


Expand Down
7 changes: 6 additions & 1 deletion script/dwimmer_setup.pl
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -15,15 +15,18 @@
GetOptions(\%opt, GetOptions(\%opt,
'email=s', 'email=s',
'password=s', 'password=s',
'root=s',
); );
usage() if not $opt{email}; usage() if not $opt{email};
die 'Invalid e-mail' if not Email::Valid->address($opt{email}); die 'Invalid e-mail' if not Email::Valid->address($opt{email});
usage() if not $opt{password}; usage() if not $opt{password};
die 'Password needs to be 6 characters' if length $opt{password} < 6; die 'Password needs to be 6 characters' if length $opt{password} < 6;
usage() if not $opt{root};





my $sql = File::Spec->catfile('share', 'schema', 'dwimmer.sql'); my $sql = File::Spec->catfile('share', 'schema', 'dwimmer.sql');
my $dbfile = get_dbfile(); my $dbfile = "$opt{root}/db/dwimmer.db"; #get_dbfile();
die "Database file '$dbfile' already exists\n" if -e $dbfile; die "Database file '$dbfile' already exists\n" if -e $dbfile;


DBIx::RunSQL->create( DBIx::RunSQL->create(
Expand Down Expand Up @@ -60,5 +63,7 @@ =head1 SYNOPSIS
--password PASSWORD of administrator --password PASSWORD of administrator
--root ROOT path to the root of the installation
=cut =cut


40 changes: 40 additions & 0 deletions t/003_admin.t
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,40 @@
use Test::More;
use strict;
use warnings;

use Cwd qw(abs_path);
use File::Basename qw(dirname);

plan tests => 2;


my $root = dirname dirname abs_path($0);
#diag $root;

#use Dancer qw(config);
#use Dwimmer;
#diag config->{appdir};

my $password = 'dwimmer';

# TODO do this in a temporary directory!
mkdir "$root/db";
unlink "$root/db/dwimmer.db";
system "$^X script/dwimmer_setup.pl --root $root --email test\@dwimmer.org --password $password";


use Dwimmer;
use Dancer::Test;

{
my $r = dancer_response GET => '/';
is $r->{status}, 200, '/ ok';
like $r->{content}, qr{/login}, '/login';
}

# {
# my $r = dancer_response POST => '/login', username => 'admin', password => $password;
# }



0 comments on commit 177a107

Please sign in to comment.