2 |
use warnings; |
use warnings; |
3 |
use strict; |
use strict; |
4 |
|
|
5 |
|
use blib; |
6 |
|
|
7 |
=head1 DESCRIPTION |
=head1 DESCRIPTION |
8 |
|
|
9 |
A basic test harness for the Database model. |
A basic test harness for the Database model. |
12 |
|
|
13 |
use Jifty::Test tests => 11; |
use Jifty::Test tests => 11; |
14 |
|
|
15 |
|
my $b = 2; # number of bootstrap records |
16 |
|
|
17 |
# Make sure we can load the model |
# Make sure we can load the model |
18 |
use_ok('SQLSession::Model::Database'); |
use_ok('SQLSession::Model::Database'); |
19 |
|
|
23 |
|
|
24 |
# Try testing a create |
# Try testing a create |
25 |
my $o = SQLSession::Model::Database->new(current_user => $system_user); |
my $o = SQLSession::Model::Database->new(current_user => $system_user); |
26 |
my ($id) = $o->create(); |
my ($id) = $o->create( |
27 |
|
name => 'foo', |
28 |
|
dsn => 'bar', |
29 |
|
); |
30 |
ok($id, "Database create returned success"); |
ok($id, "Database create returned success"); |
31 |
ok($o->id, "New Database has valid id set"); |
ok($o->id, "New Database has valid id set"); |
32 |
is($o->id, $id, "Create returned the right id"); |
is($o->id, $id, "Create returned the right id"); |
33 |
|
|
34 |
# And another |
# And another |
35 |
$o->create(); |
$o->create( |
36 |
|
name => 'baz', |
37 |
|
dsn => 'baz', |
38 |
|
); |
39 |
ok($o->id, "Database create returned another value"); |
ok($o->id, "Database create returned another value"); |
40 |
isnt($o->id, $id, "And it is different from the previous one"); |
isnt($o->id, $id, "And it is different from the previous one"); |
41 |
|
|
42 |
# Searches in general |
# Searches in general |
43 |
my $collection = SQLSession::Model::DatabaseCollection->new(current_user => $system_user); |
my $collection = SQLSession::Model::DatabaseCollection->new(current_user => $system_user); |
44 |
$collection->unlimit; |
$collection->unlimit; |
45 |
is($collection->count, 2, "Finds two records"); |
is($collection->count, $b + 2, "Finds two records"); |
46 |
|
|
47 |
# Searches in specific |
# Searches in specific |
48 |
$collection->limit(column => 'id', value => $o->id); |
$collection->limit(column => 'id', value => $o->id); |
55 |
|
|
56 |
# And the other one is still there |
# And the other one is still there |
57 |
$collection->unlimit; |
$collection->unlimit; |
58 |
is($collection->count, 1, "Still one left"); |
is($collection->count, $b + 1, "Still one left"); |
59 |
|
|