1 |
#!/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 => 15; |
12 |
|
13 |
use blib; |
14 |
|
15 |
# Make sure we can load the model |
16 |
use_ok('Grep::Model::Item'); |
17 |
use_ok('Grep::Model::Feed'); |
18 |
|
19 |
# Grab a system user |
20 |
my $system_user = Grep::CurrentUser->superuser; |
21 |
ok($system_user, "Found a system user"); |
22 |
|
23 |
# create test feed |
24 |
my $feed = Grep::Model::Feed->new(current_user => $system_user); |
25 |
my ($id) = $feed->create( |
26 |
uri => 'http://www.example.com/', |
27 |
title => 'example feed', |
28 |
); |
29 |
ok($id, "Feed create returned success"); |
30 |
ok($feed->id, "New Feed has valid id set"); |
31 |
is($feed->id, $id, "Create returned the right id"); |
32 |
|
33 |
# Try testing a create |
34 |
my $o = Grep::Model::Item->new(current_user => $system_user); |
35 |
($id) = $o->create( |
36 |
in_feed => $feed, |
37 |
title => 'example title', |
38 |
link => 'http://www.example.com/item1', |
39 |
content => 'some content', |
40 |
); |
41 |
ok($id, "Item create returned success"); |
42 |
ok($o->id, "New Item has valid id set"); |
43 |
is($o->id, $id, "Create returned the right id"); |
44 |
|
45 |
# And another |
46 |
$o->create( |
47 |
in_feed => $feed, |
48 |
title => 'example title', |
49 |
link => 'http://www.example.com/item2', |
50 |
content => 'some content', |
51 |
); |
52 |
ok($o->id, "Item create returned another value"); |
53 |
isnt($o->id, $id, "And it is different from the previous one"); |
54 |
|
55 |
# Searches in general |
56 |
my $collection = Grep::Model::ItemCollection->new(current_user => $system_user); |
57 |
$collection->unlimit; |
58 |
is($collection->count, 2, "Finds two records"); |
59 |
|
60 |
# Searches in specific |
61 |
$collection->limit(column => 'id', value => $o->id); |
62 |
is($collection->count, 1, "Finds one record with specific id"); |
63 |
|
64 |
# Delete one of them |
65 |
$o->delete; |
66 |
$collection->redo_search; |
67 |
is($collection->count, 0, "Deleted row is gone"); |
68 |
|
69 |
# And the other one is still there |
70 |
$collection->unlimit; |
71 |
is($collection->count, 1, "Still one left"); |
72 |
|