8 |
|
|
9 |
=cut |
=cut |
10 |
|
|
11 |
use Jifty::Test tests => 11; |
use Jifty::Test tests => 13; |
12 |
|
|
13 |
|
my $nr = 7; |
14 |
|
|
15 |
# Make sure we can load the model |
# Make sure we can load the model |
16 |
use_ok('Transports::Model::Transport'); |
use_ok('Transports::Model::Transport'); |
19 |
my $system_user = Transports::CurrentUser->superuser; |
my $system_user = Transports::CurrentUser->superuser; |
20 |
ok($system_user, "Found a system user"); |
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 |
# Try testing a create |
29 |
my $o = Transports::Model::Transport->new(current_user => $system_user); |
my $o = Transports::Model::Transport->new(current_user => $system_user); |
30 |
my ($id) = $o->create(); |
my ($id) = $o->create( |
31 |
|
class => 1, |
32 |
|
source => $s_id, |
33 |
|
destination => $d_id, |
34 |
|
request_nr => 12345, |
35 |
|
client_dependent => 0, |
36 |
|
created_by => 1, |
37 |
|
); |
38 |
ok($id, "Transport create returned success"); |
ok($id, "Transport create returned success"); |
39 |
ok($o->id, "New Transport has valid id set"); |
ok($o->id, "New Transport has valid id set"); |
40 |
is($o->id, $id, "Create returned the right id"); |
is($o->id, $id, "Create returned the right id"); |
41 |
|
|
42 |
# And another |
# And another |
43 |
$o->create(); |
$o->create( |
44 |
|
class => 2, |
45 |
|
source => $s_id, |
46 |
|
destination => $d_id, |
47 |
|
request_nr => 54321, |
48 |
|
client_dependent => 1, |
49 |
|
created_by => 1, |
50 |
|
); |
51 |
ok($o->id, "Transport create returned another value"); |
ok($o->id, "Transport create returned another value"); |
52 |
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 |
|
|
54 |
# Searches in general |
# Searches in general |
55 |
my $collection = Transports::Model::TransportCollection->new(current_user => $system_user); |
my $collection = Transports::Model::TransportCollection->new(current_user => $system_user); |
56 |
$collection->unlimit; |
$collection->unlimit; |
57 |
is($collection->count, 2, "Finds two records"); |
is($collection->count, $nr + 2, "Finds two records"); |
58 |
|
|
59 |
# Searches in specific |
# Searches in specific |
60 |
$collection->limit(column => 'id', value => $o->id); |
$collection->limit(column => 'id', value => $o->id); |
67 |
|
|
68 |
# And the other one is still there |
# And the other one is still there |
69 |
$collection->unlimit; |
$collection->unlimit; |
70 |
is($collection->count, 1, "Still one left"); |
is($collection->count, $nr + 1, "Still one left"); |
71 |
|
|