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