/[Arh]/t/00-model-Unit.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-Unit.t

Parent Directory Parent Directory | Revision Log Revision Log


Revision 39 - (hide annotations)
Sun Apr 6 11:12:58 2008 UTC (15 years, 11 months ago) by dpavlin
File MIME type: application/x-troff
File size: 1693 byte(s)
huge and merry code dump of lastest changes in middle of refactoring
1 dpavlin 3 #!/usr/bin/env perl
2     use warnings;
3     use strict;
4    
5     =head1 DESCRIPTION
6    
7     A basic test harness for the Unit model.
8    
9     =cut
10    
11 dpavlin 22 use Jifty::Test tests => 16;
12 dpavlin 3
13     # Make sure we can load the model
14     use_ok('Arh::Model::Unit');
15    
16     # Grab a system user
17     my $system_user = Arh::CurrentUser->superuser;
18     ok($system_user, "Found a system user");
19    
20 dpavlin 22 ok(my $place = Arh::Model::Place->new, 'Place' );
21     ok($place->create(
22 dpavlin 9 name => 'mjesto iskapanja',
23 dpavlin 22 ), 'create' );
24 dpavlin 9
25 dpavlin 22 ok(my $campaign = Arh::Model::Campaign->new, 'Campaign' );
26     ok($campaign->create(
27 dpavlin 9 place => $place,
28     name => 'prvo iskapanje',
29     date_from => '2007-11-28',
30     date_to => '2008-03-15',
31 dpavlin 22 ), 'create' );
32 dpavlin 9
33 dpavlin 3 # Try testing a create
34 dpavlin 22 ok(my $o = Arh::Model::Unit->new(current_user => $system_user), 'Unit' );
35 dpavlin 3 my ($id) = $o->create(
36     name => 'test unit',
37 dpavlin 39 inventory_nr => 'TEST42',
38 dpavlin 9 campaign => $campaign,
39 dpavlin 3 );
40     ok($id, "Unit create returned success");
41     ok($o->id, "New Unit has valid id set");
42     is($o->id, $id, "Create returned the right id");
43    
44     # And another
45     $o->create(
46     name => 'unit 2',
47 dpavlin 39 inventory_nr => 'TEST2',
48 dpavlin 9 campaign => $campaign,
49 dpavlin 3 );
50     ok($o->id, "Unit create returned another value");
51     isnt($o->id, $id, "And it is different from the previous one");
52    
53     # Searches in general
54     my $collection = Arh::Model::UnitCollection->new(current_user => $system_user);
55     $collection->unlimit;
56 dpavlin 14 is($collection->count, 4, "Finds 4 records");
57 dpavlin 3
58     # Searches in specific
59     $collection->limit(column => 'id', value => $o->id);
60     is($collection->count, 1, "Finds one record with specific id");
61    
62     # Delete one of them
63     $o->delete;
64     $collection->redo_search;
65     is($collection->count, 0, "Deleted row is gone");
66    
67     # And the other one is still there
68     $collection->unlimit;
69 dpavlin 14 is($collection->count, 3, "Still 3 left");
70 dpavlin 3

  ViewVC Help
Powered by ViewVC 1.1.26