From 3d672d1f682457d59ab5c2cab48db2ca5bf78400 Mon Sep 17 00:00:00 2001 From: "Bradley M. Kuhn" Date: Sun, 6 Dec 2015 19:24:10 -0800 Subject: [PATCH] Correct arguments to method; add public_ack --- Supporters/lib/Supporters.pm | 10 ++++++++-- Supporters/t/Supporters.t | 14 ++++++++++++-- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/Supporters/lib/Supporters.pm b/Supporters/lib/Supporters.pm index 5d3b545..82e6615 100644 --- a/Supporters/lib/Supporters.pm +++ b/Supporters/lib/Supporters.pm @@ -44,10 +44,16 @@ sub ledgerCmd ($) { return $_[0]->{ledgerCmd}; } ###################################################################### -sub addSupporter ($) { - my($sp) = @_; +sub addSupporter ($$) { + my($this, $sp) = @_; die "ledger_entity_id required" unless defined $sp->{ledger_entity_id}; + + $sp->{public_ack} = 0 if not defined $sp->{public_ack}; + + if ($sp->{public_ack}) { + die "display_name required if public_ack requested" unless defined $sp->{display_name}; + } } diff --git a/Supporters/t/Supporters.t b/Supporters/t/Supporters.t index 53a8580..2e319cc 100644 --- a/Supporters/t/Supporters.t +++ b/Supporters/t/Supporters.t @@ -6,7 +6,7 @@ use strict; use warnings; -use Test::More tests => 4; +use Test::More tests => 7; use Test::Exception; BEGIN { use_ok('Supporters') }; @@ -33,8 +33,18 @@ Test adding a supporter to the database. =cut -dies_ok(sub { $sp->addSupporter({}) }, "addSupporter: ledger_entity_id required"); +dies_ok { $sp->addSupporter({}) } + "addSupporter: ledger_entity_id required"; +lives_ok { $sp->addSupporter({ ledger_entity_id => "Whitman-Dick" }) } + "addSupporter: 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" }) } + "addSupporter: public_ack set to true with a display_name given"; $dbh->disconnect();