1 |
#!/usr/bin/env perl |
2 |
use warnings; |
3 |
use strict; |
4 |
|
5 |
use blib; |
6 |
|
7 |
=head1 DESCRIPTION |
8 |
|
9 |
A basic test harness for the Query model. |
10 |
|
11 |
=cut |
12 |
|
13 |
use Jifty::Test tests => 11; |
14 |
my $b = 2; |
15 |
|
16 |
# Make sure we can load the model |
17 |
use_ok('SQLSession::Model::Query'); |
18 |
|
19 |
# Grab a system user |
20 |
my $system_user = SQLSession::CurrentUser->superuser; |
21 |
ok($system_user, "Found a system user"); |
22 |
|
23 |
# Try testing a create |
24 |
my $o = SQLSession::Model::Query->new(current_user => $system_user); |
25 |
my ($id) = $o->create( name => 'foo', sql_query => 'bar', on_database => 1 ); |
26 |
ok($id, "Query create returned success"); |
27 |
ok($o->id, "New Query has valid id set"); |
28 |
is($o->id, $id, "Create returned the right id"); |
29 |
|
30 |
# And another |
31 |
$o->create( name => 'baz', sql_query => 'baz', on_database => 1 ); |
32 |
ok($o->id, "Query create returned another value"); |
33 |
isnt($o->id, $id, "And it is different from the previous one"); |
34 |
|
35 |
# Searches in general |
36 |
my $collection = SQLSession::Model::QueryCollection->new(current_user => $system_user); |
37 |
$collection->unlimit; |
38 |
is($collection->count, $b + 2, "Finds two records"); |
39 |
|
40 |
# Searches in specific |
41 |
$collection->limit(column => 'id', value => $o->id); |
42 |
is($collection->count, 1, "Finds one record with specific id"); |
43 |
|
44 |
# Delete one of them |
45 |
$o->delete; |
46 |
$collection->redo_search; |
47 |
is($collection->count, 0, "Deleted row is gone"); |
48 |
|
49 |
# And the other one is still there |
50 |
$collection->unlimit; |
51 |
is($collection->count, $b + 1, "Still one left"); |
52 |
|