Allow addressBookId to be updated in an Address.
This is required for Address Book merging to work correctly in Shop::AddressBook->newBySession.
This commit is contained in:
parent
90b42437af
commit
f2e8d6a70b
2 changed files with 12 additions and 16 deletions
|
|
@ -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});
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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');
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue