8 |
|
|
9 |
=cut |
=cut |
10 |
|
|
11 |
use Jifty::Test tests => 11; |
use Jifty::Test tests => 16; |
12 |
|
|
13 |
# Make sure we can load the model |
# Make sure we can load the model |
14 |
use_ok('Arh::Model::UnitMaterial'); |
use_ok('Arh::Model::UnitMaterial'); |
15 |
|
use_ok('Arh::Test'); |
16 |
|
|
17 |
# Grab a system user |
# Grab a system user |
18 |
my $system_user = Arh::CurrentUser->superuser; |
my $system_user = Arh::CurrentUser->superuser; |
19 |
ok($system_user, "Found a system user"); |
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 |
# Try testing a create |
29 |
my $o = Arh::Model::UnitMaterial->new(current_user => $system_user); |
my $o = Arh::Model::UnitMaterial->new(current_user => $system_user); |
30 |
my ($id) = $o->create(); |
my ($id) = $o->create( |
31 |
|
unit => $unit, |
32 |
|
material => $material, |
33 |
|
); |
34 |
ok($id, "UnitMaterial create returned success"); |
ok($id, "UnitMaterial create returned success"); |
35 |
ok($o->id, "New UnitMaterial has valid id set"); |
ok($o->id, "New UnitMaterial has valid id set"); |
36 |
is($o->id, $id, "Create returned the right id"); |
is($o->id, $id, "Create returned the right id"); |
37 |
|
|
38 |
|
ok( $material->create( name => 'another' ), 'another material' ); |
39 |
|
|
40 |
# And another |
# And another |
41 |
$o->create(); |
$o->create( |
42 |
|
unit => $unit, |
43 |
|
material => $material, |
44 |
|
); |
45 |
ok($o->id, "UnitMaterial create returned another value"); |
ok($o->id, "UnitMaterial create returned another value"); |
46 |
isnt($o->id, $id, "And it is different from the previous one"); |
isnt($o->id, $id, "And it is different from the previous one"); |
47 |
|
|
48 |
# Searches in general |
# Searches in general |
49 |
my $collection = Arh::Model::UnitMaterialCollection->new(current_user => $system_user); |
my $collection = Arh::Model::UnitMaterialCollection->new(current_user => $system_user); |
50 |
$collection->unlimit; |
$collection->unlimit; |
51 |
is($collection->count, 3, "Finds 3 records"); |
is($collection->count, 5, "Finds 5 records"); |
52 |
|
|
53 |
# Searches in specific |
# Searches in specific |
54 |
$collection->limit(column => 'id', value => $o->id); |
$collection->limit(column => 'id', value => $o->id); |
61 |
|
|
62 |
# And the other one is still there |
# And the other one is still there |
63 |
$collection->unlimit; |
$collection->unlimit; |
64 |
is($collection->count, 2, "Still 2 left"); |
is($collection->count, 4, "Still 4 left"); |
65 |
|
|