File: random.t

package info (click to toggle)
libdbix-class-helpers-perl 2.013002-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 420 kB
  • sloc: perl: 1,931; sql: 73; makefile: 2
file content (26 lines) | stat: -rw-r--r-- 610 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#!perl

use strict;
use warnings;

use lib 't/lib';
use Test::More;
use Test::Exception;

use TestSchema;
my $schema = TestSchema->deploy_or_connect();
$schema->prepopulate;

my $row = $schema->resultset('Foo')->rand->single;
# testing actual randomness is hard, and it's not actually random anyway,
# so suck it.
ok $row->id >= 1 && $row->id <= 5, 'row is one of the rows from the database';

my @rows = map $_->id, $schema->resultset('Foo')->rand(4)->all;
ok @rows == 4, 'correct amount of rows selected';
for (@rows) {
   ok $_ >= 1 && $_ <= 5, 'row is one of the rows from the database';
}


done_testing;