/[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 170 - (hide annotations)
Wed Jul 4 12:52:50 2007 UTC (16 years, 11 months ago) by dpavlin
File MIME type: application/x-troff
File size: 2204 byte(s)
last_update is now by default set to on_create, test last_update update
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 170 use Jifty::Test tests => 23;
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 2 # And another
60 dpavlin 142 $o->create(
61     in_feed => $feed,
62     title => 'example title',
63     link => 'http://www.example.com/item2',
64     content => 'some content',
65     );
66 dpavlin 2 ok($o->id, "Item create returned another value");
67     isnt($o->id, $id, "And it is different from the previous one");
68    
69     # Searches in general
70     my $collection = Grep::Model::ItemCollection->new(current_user => $system_user);
71     $collection->unlimit;
72     is($collection->count, 2, "Finds two records");
73    
74     # Searches in specific
75     $collection->limit(column => 'id', value => $o->id);
76     is($collection->count, 1, "Finds one record with specific id");
77    
78     # Delete one of them
79     $o->delete;
80     $collection->redo_search;
81     is($collection->count, 0, "Deleted row is gone");
82    
83     # And the other one is still there
84     $collection->unlimit;
85     is($collection->count, 1, "Still one left");
86    

  ViewVC Help
Powered by ViewVC 1.1.26