| 1 |
3 |
dpavlin |
#!/usr/bin/env perl |
| 2 |
|
|
use warnings; |
| 3 |
|
|
use strict; |
| 4 |
|
|
|
| 5 |
|
|
=head1 DESCRIPTION |
| 6 |
|
|
|
| 7 |
|
|
A basic test harness for the Location model. |
| 8 |
|
|
|
| 9 |
|
|
=cut |
| 10 |
|
|
|
| 11 |
|
|
use Jifty::Test tests => 11; |
| 12 |
|
|
|
| 13 |
|
|
# Make sure we can load the model |
| 14 |
|
|
use_ok('Arh::Model::Location'); |
| 15 |
|
|
|
| 16 |
|
|
# Grab a system user |
| 17 |
|
|
my $system_user = Arh::CurrentUser->superuser; |
| 18 |
|
|
ok($system_user, "Found a system user"); |
| 19 |
|
|
|
| 20 |
|
|
# Try testing a create |
| 21 |
|
|
my $o = Arh::Model::Location->new(current_user => $system_user); |
| 22 |
|
|
my ($id) = $o->create( |
| 23 |
|
|
name => 'test location', |
| 24 |
|
|
); |
| 25 |
|
|
ok($id, "Location create returned success"); |
| 26 |
|
|
ok($o->id, "New Location has valid id set"); |
| 27 |
|
|
is($o->id, $id, "Create returned the right id"); |
| 28 |
|
|
|
| 29 |
|
|
# And another |
| 30 |
|
|
$o->create( |
| 31 |
|
|
name => 'another location', |
| 32 |
|
|
); |
| 33 |
|
|
ok($o->id, "Location create returned another value"); |
| 34 |
|
|
isnt($o->id, $id, "And it is different from the previous one"); |
| 35 |
|
|
|
| 36 |
|
|
# Searches in general |
| 37 |
|
|
my $collection = Arh::Model::LocationCollection->new(current_user => $system_user); |
| 38 |
|
|
$collection->unlimit; |
| 39 |
9 |
dpavlin |
is($collection->count, 3, "Finds 3 records"); |
| 40 |
3 |
dpavlin |
|
| 41 |
|
|
# Searches in specific |
| 42 |
|
|
$collection->limit(column => 'id', value => $o->id); |
| 43 |
|
|
is($collection->count, 1, "Finds one record with specific id"); |
| 44 |
|
|
|
| 45 |
|
|
# Delete one of them |
| 46 |
|
|
$o->delete; |
| 47 |
|
|
$collection->redo_search; |
| 48 |
|
|
is($collection->count, 0, "Deleted row is gone"); |
| 49 |
|
|
|
| 50 |
|
|
# And the other one is still there |
| 51 |
|
|
$collection->unlimit; |
| 52 |
9 |
dpavlin |
is($collection->count, 2, "Still 2 left"); |
| 53 |
3 |
dpavlin |
|