Commit | Line | Data |
93cec8c3 |
1 | # vim: filetype=perl |
2 | |
3 | sub run_tests { |
4 | |
5 | my $schema = shift; |
80010e2b |
6 | my $artists = $schema->resultset("Artist"); |
93cec8c3 |
7 | |
80010e2b |
8 | $artists->delete(); |
9 | $artists->create({ artistid=>1, name=>"Joe" }); |
10 | $artists->create({ artistid=>2, name=>"Bob" }); |
11 | $artists->create({ artistid=>3, name=>"Ted" }); |
12 | $artists->create({ artistid=>4, name=>"Ned" }); |
13 | $artists->create({ artistid=>5, name=>"Don" }); |
93cec8c3 |
14 | |
80010e2b |
15 | $artists = $artists->search(undef,{order_by=>'position'}); |
16 | |
17 | plan tests => 230; |
18 | |
19 | check_positions($schema); |
20 | |
21 | my $artist; |
22 | |
23 | foreach my $position (1..5) { |
24 | |
25 | $artist = $artists->find({ position=>$position }); |
26 | $artist->move_previous(); |
27 | check_positions($schema); |
28 | |
29 | $artist = $artists->find({ position=>$position }); |
30 | $artist->move_next(); |
31 | check_positions($schema); |
32 | |
33 | $artist = $artists->find({ position=>$position }); |
34 | $artist->move_first(); |
35 | check_positions($schema); |
36 | |
37 | $artist = $artists->find({ position=>$position }); |
38 | $artist->move_last(); |
39 | check_positions($schema); |
40 | |
41 | foreach my $to_position (1..5) { |
42 | |
43 | $artist = $artists->find({ position=>$position }); |
44 | $artist->move_to($to_position); |
45 | check_positions($schema); |
46 | |
47 | } |
48 | |
49 | } |
50 | |
51 | } |
52 | |
53 | sub check_positions { |
54 | my $schema = shift; |
55 | my $artists = $schema->resultset("Artist")->search(undef,{order_by=>'position'}); |
93cec8c3 |
56 | my $expected_position = 0; |
57 | while (my $artist = $artists->next()) { |
58 | $expected_position ++; |
59 | ok( ($artist->position()==$expected_position), 'default positions set as expected' ); |
60 | } |
61 | } |
62 | |
63 | 1; |