17 |
my $system_user = Arh::CurrentUser->superuser; |
my $system_user = Arh::CurrentUser->superuser; |
18 |
ok($system_user, "Found a system user"); |
ok($system_user, "Found a system user"); |
19 |
|
|
20 |
|
my $place = Arh::Model::Place->new; |
21 |
|
$place->create( |
22 |
|
name => 'mjesto iskapanja', |
23 |
|
); |
24 |
|
|
25 |
|
my $campaign = Arh::Model::Campaign->new(current_user => $system_user); |
26 |
|
$campaign->create( |
27 |
|
place => $place, |
28 |
|
name => 'prvo iskapanje', |
29 |
|
date_from => '2007-11-28', |
30 |
|
date_to => '2008-03-15', |
31 |
|
); |
32 |
|
|
33 |
# Try testing a create |
# Try testing a create |
34 |
my $o = Arh::Model::Unit->new(current_user => $system_user); |
my $o = Arh::Model::Unit->new(current_user => $system_user); |
35 |
my ($id) = $o->create( |
my ($id) = $o->create( |
36 |
name => 'test unit', |
name => 'test unit', |
37 |
number => 'TEST42', |
number => 'TEST42', |
38 |
|
campaign => $campaign, |
39 |
); |
); |
40 |
ok($id, "Unit create returned success"); |
ok($id, "Unit create returned success"); |
41 |
ok($o->id, "New Unit has valid id set"); |
ok($o->id, "New Unit has valid id set"); |
45 |
$o->create( |
$o->create( |
46 |
name => 'unit 2', |
name => 'unit 2', |
47 |
number => 'TEST2', |
number => 'TEST2', |
48 |
|
campaign => $campaign, |
49 |
); |
); |
50 |
ok($o->id, "Unit create returned another value"); |
ok($o->id, "Unit create returned another value"); |
51 |
isnt($o->id, $id, "And it is different from the previous one"); |
isnt($o->id, $id, "And it is different from the previous one"); |
53 |
# Searches in general |
# Searches in general |
54 |
my $collection = Arh::Model::UnitCollection->new(current_user => $system_user); |
my $collection = Arh::Model::UnitCollection->new(current_user => $system_user); |
55 |
$collection->unlimit; |
$collection->unlimit; |
56 |
is($collection->count, 2, "Finds two records"); |
is($collection->count, 3, "Finds 3 records"); |
57 |
|
|
58 |
# Searches in specific |
# Searches in specific |
59 |
$collection->limit(column => 'id', value => $o->id); |
$collection->limit(column => 'id', value => $o->id); |
66 |
|
|
67 |
# And the other one is still there |
# And the other one is still there |
68 |
$collection->unlimit; |
$collection->unlimit; |
69 |
is($collection->count, 1, "Still one left"); |
is($collection->count, 2, "Still 2 left"); |
70 |
|
|