From 6f544b120963a63738121cacdd4d450e8c977994 Mon Sep 17 00:00:00 2001 From: Tom Bloor Date: Tue, 18 Apr 2017 13:14:35 +0100 Subject: [PATCH] Change to using memory sqlite db and schema based populating --- t/register.t | 44 ++++++++++++++++++++++++-------------------- 1 file changed, 24 insertions(+), 20 deletions(-) diff --git a/t/register.t b/t/register.t index 692b043..b337852 100644 --- a/t/register.t +++ b/t/register.t @@ -1,39 +1,43 @@ use Mojo::Base -strict; +use File::Temp; use Test::More; use Test::Mojo; use Mojo::JSON; -use FindBin; +my $file = File::Temp->new; -BEGIN { - $ENV{MOJO_MODE} = 'testing'; - $ENV{MOJO_LOG_LEVEL} = 'debug'; +print $file <<'END'; +{ + dsn => "dbi:SQLite::memory:", + user => undef, + pass => undef, } +END +$file->seek( 0, SEEK_END ); -my $t = Test::Mojo->new("Pear::LocalLoop"); +$ENV{MOJO_CONFIG} = $file->filename; -my $dbh = $t->app->db; +my $t = Test::Mojo->new('Pear::LocalLoop'); +my $schema = $t->app->schema; +$schema->deploy; -#Dump all pf the test tables and start again. -my $sqlDeployment = Mojo::File->new("$FindBin::Bin/../dropschema.sql")->slurp; -for (split ';', $sqlDeployment){ - $dbh->do($_) or die $dbh->errstr; -} - -$sqlDeployment = Mojo::File->new("$FindBin::Bin/../schema.sql")->slurp; -for (split ';', $sqlDeployment){ - $dbh->do($_) or die $dbh->errstr; -} +$schema->resultset('AgeRange')->populate([ + [ qw/ agerangestring / ], + [ '20-35' ], + [ '35-50' ], + [ '50+' ], +]); #Variables to be used for uniqueness when testing. my @names = ('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'); my @emails = ('a@a.com', 'b@a.com', 'c@a.com', 'd@a.com', 'e@a.com', 'f@a.com', 'g@a.com', 'h@a.com', 'i@a.com', 'j@a.com', 'k@a.com', 'l@a.com', 'm@a.com', 'n@a.com', 'o@a.com', 'p@a.com', 'q@a.com', 'r@a.com', 's@a.com', 't@a.com', 'u@a.com', 'v@a.com', 'w@a.com', 'x@a.com', 'y@a.com', 'z@a.com'); my @tokens = ('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'); -my $tokenStatement = $dbh->prepare('INSERT INTO AccountTokens (AccountTokenName) VALUES (?)'); -foreach (@tokens){ - my $rowsAdded = $tokenStatement->execute($_); -} + +$schema->resultset('AccountToken')->populate([ + [ qw/ accounttokenname / ], + map { [ $_ ] } @tokens, +]); #No JSON sent $t->post_ok('/api/register')