/[Grep]/t/00-model-Item.t
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Annotation of /t/00-model-Item.t

Parent Directory Parent Directory | Revision Log Revision Log


Revision 171 - (hide annotations)
Wed Jul 4 14:10:43 2007 UTC (16 years, 10 months ago) by dpavlin
File MIME type: application/x-troff
File size: 2879 byte(s)
added link_current to Grep::Model::Item which will check do we want to use
local cached version (if newer than 24h) or fetch new one.
This *dramatically* decreases load on wikis we are scraping ;-)
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 dpavlin 171 use Jifty::Test tests => 29;
12 dpavlin 2
13 dpavlin 21 use blib;
14    
15 dpavlin 2 # Make sure we can load the model
16     use_ok('Grep::Model::Item');
17 dpavlin 142 use_ok('Grep::Model::Feed');
18 dpavlin 2
19     # Grab a system user
20     my $system_user = Grep::CurrentUser->superuser;
21     ok($system_user, "Found a system user");
22    
23 dpavlin 142 # 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 dpavlin 170 ok($feed->created_on, "created_on");
34    
35 dpavlin 2 # Try testing a create
36     my $o = Grep::Model::Item->new(current_user => $system_user);
37 dpavlin 142 ($id) = $o->create(
38     in_feed => $feed,
39     title => 'example title',
40     link => 'http://www.example.com/item1',
41     content => 'some content',
42     );
43 dpavlin 2 ok($id, "Item create returned success");
44     ok($o->id, "New Item has valid id set");
45     is($o->id, $id, "Create returned the right id");
46    
47 dpavlin 170 ok($o->created_on, "created_on");
48     ok(my $old_dt = $o->last_update, "last_update");
49    
50     ok(sleep 1, 'sleep');
51    
52     $o->set_content('changed content');
53     cmp_ok( $o->content, 'eq', 'changed content', 'changed content');
54    
55     ok(my $new_dt = $o->last_update, "last_update again");
56     ok(my $dt = $new_dt - $old_dt, 'dt');
57     ok( $dt->is_positive, 'updated last_update' );
58    
59 dpavlin 171 ok( my $item = $o->link_current( 'http://www.example.com/item1' ), 'link_current' );
60    
61     isa_ok( $item, 'Grep::Model::Item', 'result is Grep::Model::Item' );
62    
63     undef $o;
64    
65     ok( $o = Grep::Model::Item->link_current( 'http://www.example.com/item1' ), 'link_current' );
66     isa_ok( $o, 'Grep::Model::Item', 'result is Grep::Model::Item' );
67    
68     diag "before: ",$o->last_update;
69    
70     my $fake_dt = $o->last_update->subtract( hours => 25 );
71     # $o->set_last_update( $fake_dt ); # this doesn't work because we override _set
72     $o->{values}->{last_update} = $fake_dt; # yaick!
73    
74     ok( $o->last_update, 'time-travel last_update');
75    
76     ok( ! $o->link_current( 'http://www.example.com/item1' ), 'link_current' );
77    
78 dpavlin 2 # And another
79 dpavlin 142 $o->create(
80     in_feed => $feed,
81     title => 'example title',
82     link => 'http://www.example.com/item2',
83     content => 'some content',
84     );
85 dpavlin 2 ok($o->id, "Item create returned another value");
86     isnt($o->id, $id, "And it is different from the previous one");
87    
88     # Searches in general
89     my $collection = Grep::Model::ItemCollection->new(current_user => $system_user);
90     $collection->unlimit;
91     is($collection->count, 2, "Finds two records");
92    
93     # Searches in specific
94     $collection->limit(column => 'id', value => $o->id);
95     is($collection->count, 1, "Finds one record with specific id");
96    
97     # Delete one of them
98     $o->delete;
99     $collection->redo_search;
100     is($collection->count, 0, "Deleted row is gone");
101    
102     # And the other one is still there
103     $collection->unlimit;
104     is($collection->count, 1, "Still one left");
105    

  ViewVC Help
Powered by ViewVC 1.1.26