7 eval "use DBD::SQLite ();";
8 plan skip_all => 'DBD::SQLite required to run this test' if $@;
10 eval "use SQL::Translator ();";
11 plan skip_all => 'SQL::Translator required to run this test' if $@;
21 my ( undef, $db ) = File::Temp::tempfile();
22 my $schema = TestSchema->connect( "dbi:SQLite:dbname=${db}", undef, undef );
25 my @users = qw/root toor daemon operator bin tty/;
26 my @roles = qw/admin superuser user/;
28 @users = $schema->populate( 'User' => [ ['login'] => ( map { [$_] } @users ) ] );
29 @roles = $schema->populate( 'Role' => [ ['name'] => ( map { [$_] } @roles ) ] );
33 foreach my $user (@users) {
35 foreach my $role (@roles) {
37 push @user_roles, [ $user->id, $role->id ];
41 $u = 1 if $u > scalar @roles;
44 @user_roles = $schema->populate( 'UserRole' => [ [qw/user_id role_id/] => @user_roles ] );
47 my $rs = $schema->resultset('User')->search(
50 prefetch => { user_role => [qw/role/] },
51 order_by => 'me.id ASC'
109 'name' => 'superuser'
126 'login' => 'operator',
153 'name' => 'superuser'
175 'name' => 'superuser'
196 my @rs = $schema->resultset('User')->search( {}, { order_by => 'me.id ASC' } )->hashref_array;
214 'login' => 'operator'
229 my $rs = $schema->resultset('User')->search(
232 prefetch => { user_role => [qw/role/] },
233 order_by => 'me.id DESC'
253 'name' => 'superuser'
273 my $expected_users = [
288 'login' => 'operator'
299 my $rs = $schema->resultset('User')->search( {}, { order_by => 'me.id ASC' } )->hashref_rs;
300 while ( my $row = $rs->next ) {
301 my $user = shift(@$expected_users);
302 is_deeply( $row, $user, "hashref_rs in while loop, user: " . $user->{login} );
307 my $first_row = $schema->resultset('User')->search( { login => 'root' } )->hashref_first;