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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 39 - (show 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 #!/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 use Jifty::Test tests => 16;
12
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 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 # Try testing a create
34 ok(my $o = Arh::Model::Unit->new(current_user => $system_user), 'Unit' );
35 my ($id) = $o->create(
36 name => 'test unit',
37 inventory_nr => 'TEST42',
38 campaign => $campaign,
39 );
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 inventory_nr => 'TEST2',
48 campaign => $campaign,
49 );
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 is($collection->count, 4, "Finds 4 records");
57
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 is($collection->count, 3, "Still 3 left");
70

  ViewVC Help
Powered by ViewVC 1.1.26