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