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 |
# Make sure we can load the model |
14 |
use_ok('Transports::Model::Transport'); |
15 |
|
16 |
# Grab a system use |
17 |
my $system_user = Transports::CurrentUser->superuser; |
18 |
ok($system_user, "Found a system user"); |
19 |
|
20 |
my $s = Transports::Model::Source->new(current_user => $system_user); |
21 |
ok(my $s_id = $s->create( name => 'test source' ), 'test source'); |
22 |
|
23 |
my $d = Transports::Model::Destination->new(current_user => $system_user); |
24 |
ok(my $d_id = $s->create( name => 'test destination' ), 'test destination'); |
25 |
|
26 |
# Try testing a create |
27 |
my $o = Transports::Model::Transport->new(current_user => $system_user); |
28 |
my ($id) = $o->create( |
29 |
source => $s_id, |
30 |
destination => $d_id, |
31 |
request_nr => 12345, |
32 |
client_dependent => 0, |
33 |
); |
34 |
ok($id, "Transport create returned success"); |
35 |
ok($o->id, "New Transport has valid id set"); |
36 |
is($o->id, $id, "Create returned the right id"); |
37 |
|
38 |
# And another |
39 |
$o->create( |
40 |
source => $s_id, |
41 |
destination => $d_id, |
42 |
request_nr => 54321, |
43 |
client_dependent => 1, |
44 |
); |
45 |
ok($o->id, "Transport 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 = Transports::Model::TransportCollection->new(current_user => $system_user); |
50 |
$collection->unlimit; |
51 |
is($collection->count, 2, "Finds two 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, 1, "Still one left"); |
65 |
|