diff --git a/Supporters/lib/Supporters.pm b/Supporters/lib/Supporters.pm index 82e6615..5a52d10 100644 --- a/Supporters/lib/Supporters.pm +++ b/Supporters/lib/Supporters.pm @@ -54,6 +54,15 @@ sub addSupporter ($$) { if ($sp->{public_ack}) { 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; } diff --git a/Supporters/t/Supporters.t b/Supporters/t/Supporters.t index 2e319cc..194549d 100644 --- a/Supporters/t/Supporters.t +++ b/Supporters/t/Supporters.t @@ -9,6 +9,8 @@ use warnings; use Test::More tests => 7; use Test::Exception; +use Scalar::Util qw(looks_like_number); + BEGIN { use_ok('Supporters') }; =pod @@ -36,15 +38,22 @@ Test adding a supporter to the database. dies_ok { $sp->addSupporter({}) } "addSupporter: ledger_entity_id required"; -lives_ok { $sp->addSupporter({ ledger_entity_id => "Whitman-Dick" }) } - "addSupporter: minimal acceptable settings"; +my $id1; +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" }) } "addSupporter: display_name required"; -lives_ok { $sp->addSupporter({ display_name => "Donald Drapper", - public_ack => 1, ledger_entity_id => "Whitman-Dick" }) } +my $id2; +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"; -$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();