1 |
#!/usr/bin/env perl |
2 |
use warnings; |
3 |
use strict; |
4 |
|
5 |
=head1 DESCRIPTION |
6 |
|
7 |
A basic test harness for the Unit 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::Unit'); |
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::Unit->new(current_user => $system_user); |
22 |
my ($id) = $o->create( |
23 |
name => 'test unit', |
24 |
number => 'TEST42', |
25 |
); |
26 |
ok($id, "Unit create returned success"); |
27 |
ok($o->id, "New Unit has valid id set"); |
28 |
is($o->id, $id, "Create returned the right id"); |
29 |
|
30 |
# And another |
31 |
$o->create( |
32 |
name => 'unit 2', |
33 |
number => 'TEST2', |
34 |
); |
35 |
ok($o->id, "Unit create returned another value"); |
36 |
isnt($o->id, $id, "And it is different from the previous one"); |
37 |
|
38 |
# Searches in general |
39 |
my $collection = Arh::Model::UnitCollection->new(current_user => $system_user); |
40 |
$collection->unlimit; |
41 |
is($collection->count, 2, "Finds two records"); |
42 |
|
43 |
# Searches in specific |
44 |
$collection->limit(column => 'id', value => $o->id); |
45 |
is($collection->count, 1, "Finds one record with specific id"); |
46 |
|
47 |
# Delete one of them |
48 |
$o->delete; |
49 |
$collection->redo_search; |
50 |
is($collection->count, 0, "Deleted row is gone"); |
51 |
|
52 |
# And the other one is still there |
53 |
$collection->unlimit; |
54 |
is($collection->count, 1, "Still one left"); |
55 |
|