From f2e8d6a70b82c427508a2dc9d2f91a024d163a2d Mon Sep 17 00:00:00 2001 From: Colin Kuskie Date: Mon, 21 Sep 2009 17:27:25 -0700 Subject: [PATCH] Allow addressBookId to be updated in an Address. This is required for Address Book merging to work correctly in Shop::AddressBook->newBySession. --- lib/WebGUI/Shop/Address.pm | 3 +-- t/Shop/Address.t | 25 +++++++++++-------------- 2 files changed, 12 insertions(+), 16 deletions(-) diff --git a/lib/WebGUI/Shop/Address.pm b/lib/WebGUI/Shop/Address.pm index 5ddff73a5..220ac845f 100644 --- a/lib/WebGUI/Shop/Address.pm +++ b/lib/WebGUI/Shop/Address.pm @@ -263,10 +263,9 @@ The address book that this address belongs to. sub update { my ($self, $newProperties) = @_; my $id = id $self; - foreach my $field (qw(email organization address1 address2 address3 state code city label firstName lastName country phoneNumber)) { + foreach my $field (qw(addressBookId email organization address1 address2 address3 state code city label firstName lastName country phoneNumber)) { $properties{$id}{$field} = (exists $newProperties->{$field}) ? $newProperties->{$field} : $properties{$id}{$field}; } - $properties{$id}{addressBookId} = $self->addressBook->getId; $self->addressBook->session->db->setRow("address","addressId",$properties{$id}); } diff --git a/t/Shop/Address.t b/t/Shop/Address.t index b27f64142..c0b8c0868 100644 --- a/t/Shop/Address.t +++ b/t/Shop/Address.t @@ -31,19 +31,12 @@ my $session = WebGUI::Test->session; #---------------------------------------------------------------------------- # Tests -my $tests = 27; -plan tests => 1 + $tests; +plan tests => 28; #---------------------------------------------------------------------------- # put your tests here -my $loaded = use_ok('WebGUI::Shop::Address'); - my $storage; - -SKIP: { - -skip 'Unable to load module WebGUI::Shop::Address', $tests unless $loaded; my $e; my $address; @@ -81,7 +74,8 @@ cmp_deeply( 'create takes exception to giving it a session variable', ); -my $book = WebGUI::Shop::AddressBook->create($session); +my $book = WebGUI::Shop::AddressBook->create($session); +my $book2 = WebGUI::Shop::AddressBook->create($session); eval { $address = WebGUI::Shop::Address->create($book); }; $e = Exception::Class->caught(); @@ -159,10 +153,15 @@ is($address->get('label'), undef, 'get returns a safe copy of the hash'); ####################################################################### $address->update({ label => 'home'}); -is($address->get('label'), 'home', 'update updates the object properties cache'); +is($address->get('label'), 'home', 'update: updates the object properties cache'); $address->update({ address1 => 'Shawshank Prison', 'state' => 'Maine'}); -is($address->get('address1'), 'Shawshank Prison', 'update updates the object properties cache for more than one key'); -is($address->get('state'), 'Maine', 'update updates the object properties cache for more than one key'); +is($address->get('address1'), 'Shawshank Prison', '... updates the object properties cache for more than one key'); +is($address->get('state'), 'Maine', '... updates the object properties cache for more than one key'); + +$address->update({ addressBookId => $book2->getId }); +is($address->get('addressBookId'), $book2->getId, '... addressBookId can be updated'); +##Restore it back to normal for downstream tests; +$address->update({ addressBookId => $book->getId }); ####################################################################### # @@ -244,8 +243,6 @@ $address->delete; my $check = $session->db->quickScalar('select count(*) from address where addressId=?',[$address->getId]); is( $check, 0, 'delete worked'); -} - END { $session->db->write('delete from addressBook'); $session->db->write('delete from address');