9 my $schema = DBICTest::init_schema();
13 my $employees = $schema->resultset('Employee');
17 $employees->create({ name=>'temp' });
19 $employees = $employees->search(undef,{order_by=>'position'});
20 ok( check_rs($employees), "intial positions" );
22 hammer_rs( $employees );
24 DBICTest::Employee->grouping_column('group_id');
26 foreach my $group_id (1..3) {
28 $employees->create({ name=>'temp', group_id=>$group_id });
31 $employees = $employees->search(undef,{order_by=>'group_id,position'});
33 foreach my $group_id (1..3) {
34 my $group_employees = $employees->search({group_id=>$group_id});
35 $group_employees->all();
36 ok( check_rs($group_employees), "group intial positions" );
37 hammer_rs( $group_employees );
43 my $count = $rs->count();
44 my $position_column = $rs->result_class->position_column();
46 foreach my $position (1..$count) {
48 ($row) = $rs->search({ $position_column=>$position })->all();
49 $row->move_previous();
50 ok( check_rs($rs), "move_previous( $position )" );
52 ($row) = $rs->search({ $position_column=>$position })->all();
54 ok( check_rs($rs), "move_next( $position )" );
56 ($row) = $rs->search({ $position_column=>$position })->all();
58 ok( check_rs($rs), "move_first( $position )" );
60 ($row) = $rs->search({ $position_column=>$position })->all();
62 ok( check_rs($rs), "move_last( $position )" );
64 foreach my $to_position (1..$count) {
65 ($row) = $rs->search({ $position_column=>$position })->all();
66 $row->move_to($to_position);
67 ok( check_rs($rs), "move_to( $position => $to_position )" );
70 ($row) = $rs->search({ position=>$position })->all();
72 ok( !$row->previous_sibling(), 'no previous sibling' );
73 ok( !$row->first_sibling(), 'no first sibling' );
76 ok( $row->previous_sibling(), 'previous sibling' );
77 ok( $row->first_sibling(), 'first sibling' );
79 if ($position==$count) {
80 ok( !$row->next_sibling(), 'no next sibling' );
81 ok( !$row->last_sibling(), 'no last sibling' );
84 ok( $row->next_sibling(), 'next sibling' );
85 ok( $row->last_sibling(), 'last sibling' );
94 my $position_column = $rs->result_class->position_column();
95 my $expected_position = 0;
96 while (my $row = $rs->next()) {
97 $expected_position ++;
98 if ($row->get_column($position_column)!=$expected_position) {