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