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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 22 - (hide annotations)
Fri Nov 30 20:13:06 2007 UTC (16 years, 4 months ago) by dpavlin
File MIME type: application/x-troff
File size: 2010 byte(s)
better tests
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 UnitMaterial model.
8    
9     =cut
10    
11 dpavlin 22 use Jifty::Test tests => 20;
12 dpavlin 3
13     # Make sure we can load the model
14     use_ok('Arh::Model::UnitMaterial');
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     name => 'mjesto iskapanja',
23     ), 'create' );
24    
25     ok(my $campaign = Arh::Model::Campaign->new, 'Campaign' );
26     ok($campaign->create(
27     place => $place,
28     name => 'prvo iskapanje',
29     date_from => '2007-11-28',
30     date_to => '2008-03-15',
31     ), 'create' );
32    
33     ok( my $unit = Arh::Model::Unit->new, 'Unit' );
34     ok( $unit->create(
35     name => 'test unit',
36     number => 42,
37     campaign => $campaign,
38     ), 'create' );
39    
40     ok( my $material = Arh::Model::Material->new, 'Material' );
41     ok( $material->create(
42     name => 'test material',
43     ), 'create' );
44    
45 dpavlin 3 # Try testing a create
46     my $o = Arh::Model::UnitMaterial->new(current_user => $system_user);
47 dpavlin 22 my ($id) = $o->create(
48     unit => $unit,
49     material => $material,
50     );
51 dpavlin 3 ok($id, "UnitMaterial create returned success");
52     ok($o->id, "New UnitMaterial has valid id set");
53     is($o->id, $id, "Create returned the right id");
54    
55 dpavlin 22 ok( $material->create( name => 'another' ), 'another material' );
56    
57 dpavlin 3 # And another
58 dpavlin 22 $o->create(
59     unit => $unit,
60     material => $material,
61     );
62 dpavlin 3 ok($o->id, "UnitMaterial create returned another value");
63     isnt($o->id, $id, "And it is different from the previous one");
64    
65     # Searches in general
66     my $collection = Arh::Model::UnitMaterialCollection->new(current_user => $system_user);
67     $collection->unlimit;
68 dpavlin 14 is($collection->count, 5, "Finds 5 records");
69 dpavlin 3
70     # Searches in specific
71     $collection->limit(column => 'id', value => $o->id);
72     is($collection->count, 1, "Finds one record with specific id");
73    
74     # Delete one of them
75     $o->delete;
76     $collection->redo_search;
77     is($collection->count, 0, "Deleted row is gone");
78    
79     # And the other one is still there
80     $collection->unlimit;
81 dpavlin 14 is($collection->count, 4, "Still 4 left");
82 dpavlin 3

  ViewVC Help
Powered by ViewVC 1.1.26