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