Initial basic support for creating a new Supporter.
This is incomplete as of yet, since it doesn't properly set up other tables.
This commit is contained in:
parent
a10e2e3a57
commit
70ad0b8b30
2 changed files with 23 additions and 5 deletions
|
@ -54,6 +54,15 @@ sub addSupporter ($$) {
|
||||||
if ($sp->{public_ack}) {
|
if ($sp->{public_ack}) {
|
||||||
die "display_name required if public_ack requested" unless defined $sp->{display_name};
|
die "display_name required if public_ack requested" unless defined $sp->{display_name};
|
||||||
}
|
}
|
||||||
|
my $sth = $this->dbh->prepare(
|
||||||
|
"INSERT INTO supporter(ledger_entity_id, display_name, public_ack)" .
|
||||||
|
" values(?, ?, ?)");
|
||||||
|
|
||||||
|
$sth->execute($sp->{ledger_entity_id}, $sp->{display_name}, $sp->{public_ack});
|
||||||
|
my $id = $this->dbh->last_insert_id("","","","");
|
||||||
|
$sth->finish();
|
||||||
|
|
||||||
|
return $id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -9,6 +9,8 @@ use warnings;
|
||||||
use Test::More tests => 7;
|
use Test::More tests => 7;
|
||||||
use Test::Exception;
|
use Test::Exception;
|
||||||
|
|
||||||
|
use Scalar::Util qw(looks_like_number);
|
||||||
|
|
||||||
BEGIN { use_ok('Supporters') };
|
BEGIN { use_ok('Supporters') };
|
||||||
|
|
||||||
=pod
|
=pod
|
||||||
|
@ -36,15 +38,22 @@ Test adding a supporter to the database.
|
||||||
dies_ok { $sp->addSupporter({}) }
|
dies_ok { $sp->addSupporter({}) }
|
||||||
"addSupporter: ledger_entity_id required";
|
"addSupporter: ledger_entity_id required";
|
||||||
|
|
||||||
lives_ok { $sp->addSupporter({ ledger_entity_id => "Whitman-Dick" }) }
|
my $id1;
|
||||||
"addSupporter: minimal acceptable settings";
|
lives_ok { $id1 = $sp->addSupporter({ ledger_entity_id => "Campbell-Peter" }); }
|
||||||
|
"addSupporter: add works for minimal acceptable settings";
|
||||||
|
|
||||||
|
ok( (looks_like_number($id1) and $id1 > 0),
|
||||||
|
"addSupporter: add works for minimal acceptable settings");
|
||||||
|
|
||||||
dies_ok { $sp->addSupporter({ public_ack => 1, ledger_entity_id => "Whitman-Dick" }) }
|
dies_ok { $sp->addSupporter({ public_ack => 1, ledger_entity_id => "Whitman-Dick" }) }
|
||||||
"addSupporter: display_name required";
|
"addSupporter: display_name required";
|
||||||
|
|
||||||
lives_ok { $sp->addSupporter({ display_name => "Donald Drapper",
|
my $id2;
|
||||||
public_ack => 1, ledger_entity_id => "Whitman-Dick" }) }
|
lives_ok { $id2 = $sp->addSupporter({ display_name => "Donald Drapper",
|
||||||
|
public_ack => 1, ledger_entity_id => "Whitman-Dick" }); }
|
||||||
"addSupporter: public_ack set to true with a display_name given";
|
"addSupporter: public_ack set to true with a display_name given";
|
||||||
|
|
||||||
$dbh->disconnect();
|
ok( (looks_like_number($id2) and $id2 > $id1),
|
||||||
|
"addSupporter: add works with public_ack set to true and a display_name given");
|
||||||
|
|
||||||
|
$dbh->disconnect();
|
||||||
|
|
Loading…
Reference in a new issue