/[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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 170 - (show annotations)
Wed Jul 4 12:52:50 2007 UTC (16 years, 10 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 #!/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 => 23;
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 ok($feed->created_on, "created_on");
34
35 # Try testing a create
36 my $o = Grep::Model::Item->new(current_user => $system_user);
37 ($id) = $o->create(
38 in_feed => $feed,
39 title => 'example title',
40 link => 'http://www.example.com/item1',
41 content => 'some content',
42 );
43 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 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 # And another
60 $o->create(
61 in_feed => $feed,
62 title => 'example title',
63 link => 'http://www.example.com/item2',
64 content => 'some content',
65 );
66 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