From 39aa431e2c28ec89e4a4322f8efa4b0fd9b4ea41 Mon Sep 17 00:00:00 2001 From: Colin Kuskie Date: Sat, 23 Feb 2008 06:17:39 +0000 Subject: [PATCH] Move the delete test after the new test, so that there's an object to pull from the db. Sheesh. Remove the id generation from inside the private build method and make sure it returns the built object. --- lib/WebGUI/Shop/ShipDriver.pm | 3 +-- t/Shop/ShipDriver.t | 34 ++++++++++++++++++++-------------- 2 files changed, 21 insertions(+), 16 deletions(-) diff --git a/lib/WebGUI/Shop/ShipDriver.pm b/lib/WebGUI/Shop/ShipDriver.pm index 8930659f9..0bdb285ec 100644 --- a/lib/WebGUI/Shop/ShipDriver.pm +++ b/lib/WebGUI/Shop/ShipDriver.pm @@ -49,7 +49,6 @@ sub _buildObj { bless $self, $class; register $self; - my $shipperId = $session->id->generate; my $id = id $self; $session{ $id } = $session; @@ -207,7 +206,7 @@ sub new { unless exists $properties->{options} and $properties->{options}; my $options = from_json($properties->{options}); my $self = WebGUI::Shop::ShipDriver->_buildObj($session, $shipperId, $options); - return; + return $self; } #------------------------------------------------------------------- diff --git a/t/Shop/ShipDriver.t b/t/Shop/ShipDriver.t index eb24ea27c..41ab549b6 100644 --- a/t/Shop/ShipDriver.t +++ b/t/Shop/ShipDriver.t @@ -29,7 +29,7 @@ my $session = WebGUI::Test->session; #---------------------------------------------------------------------------- # Tests -my $tests = 18; +my $tests = 21; plan tests => 1 + $tests; #---------------------------------------------------------------------------- @@ -154,19 +154,6 @@ is ($driver->getName, 'Shipper Driver', 'getName returns the human readable name # ####################################################################### -####################################################################### -# -# delete -# -####################################################################### - -$driver->delete; - -my $count = $session->db->quickScalar('select count(*) from shipper where shipperId=?',[$driver->shipperId]); -is($count, 0, 'delete deleted the object'); - -undef $driver; - ####################################################################### # # new @@ -184,6 +171,25 @@ like ($@, qr/^new requires a shipperId/, 'new croaks without a shipperId'); eval { $oldDriver = WebGUI::Shop::ShipDriver->new($session, 'notEverAnId'); }; like ($@, qr/^The requested shipperId does not exist in the db/, 'new croaks unless the requested shipperId object exists in the db'); +my $driverCopy = WebGUI::Shop::ShipDriver->new($session, $driver->shipperId); + +is($driver->getId, $driverCopy->getId, 'same id'); +is($driver->className, $driverCopy->className, 'same className'); +cmp_deeply($driver->options, $driverCopy->options, 'same options'); + +####################################################################### +# +# delete +# +####################################################################### + +$driver->delete; + +my $count = $session->db->quickScalar('select count(*) from shipper where shipperId=?',[$driver->shipperId]); +is($count, 0, 'delete deleted the object'); + +undef $driver; + ####################################################################### # # calculate