File: is_ordered.t

package info (click to toggle)
libdbix-class-perl 0.082844-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 5,320 kB
  • sloc: perl: 27,215; sql: 322; sh: 29; makefile: 16
file content (89 lines) | stat: -rw-r--r-- 2,483 bytes parent folder | download | duplicates (5)
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
use strict;
use warnings;

use lib qw(t/lib);
use Test::More;
use DBICTest;

my $schema = DBICTest->init_schema();
my $rs = $schema->resultset('Artist');

ok !$rs->is_ordered, 'vanilla resultset is not ordered';

# Simple ordering with a single column
{
  my $ordered = $rs->search(undef, { order_by => 'artistid' });
  ok $ordered->is_ordered, 'Simple column ordering detected by is_ordered';
}

# Hashref order direction
{
  my $ordered = $rs->search(undef, { order_by => { -desc => 'artistid' } });
  ok $ordered->is_ordered, 'resultset with order direction is_ordered';
}

# Column ordering with literal SQL
{
  my $ordered = $rs->search(undef, { order_by => \'artistid DESC' });
  ok $ordered->is_ordered, 'resultset with literal SQL is_ordered';
}

# Multiple column ordering
{
  my $ordered = $rs->search(undef, { order_by => ['artistid', 'name'] });
  ok $ordered->is_ordered, 'ordering with multiple columns as arrayref is ordered';
}

# More complicated ordering
{
  my $ordered = $rs->search(undef, {
    order_by => [
      { -asc => 'artistid' },
      { -desc => 'name' },
    ]
  });
  ok $ordered->is_ordered, 'more complicated resultset ordering is_ordered';
}

# Empty multi-column ordering arrayref
{
  my $ordered = $rs->search(undef, { order_by => [] });
  ok !$ordered->is_ordered, 'ordering with empty arrayref is not ordered';
}

# Multi-column ordering syntax with empty hashref
{
  my $ordered = $rs->search(undef, { order_by => [{}] });
  ok !$ordered->is_ordered, 'ordering with [{}] is not ordered';
}

# Remove ordering after being set
{
  my $ordered = $rs->search(undef, { order_by => 'artistid' });
  ok $ordered->is_ordered, 'resultset with ordering applied works..';
  my $unordered = $ordered->search(undef, { order_by => undef });
  ok !$unordered->is_ordered, '..and is not ordered with ordering removed';
}

# Search without ordering
{
  my $ordered = $rs->search({ name => 'We Are Goth' }, { join => 'cds' });
  ok !$ordered->is_ordered, 'WHERE clause but no order_by is not ordered';
}

# Other functions without ordering
{
  # Join
  my $joined = $rs->search(undef, { join => 'cds' });
  ok !$joined->is_ordered, 'join but no order_by is not ordered';

  # Group By
  my $grouped = $rs->search(undef, { group_by => 'rank' });
  ok !$grouped->is_ordered, 'group_by but no order_by is not ordered';

  # Paging
  my $paged = $rs->search(undef, { page=> 5 });
  ok !$paged->is_ordered, 'paging but no order_by is not ordered';
}

done_testing;