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..4) {
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..4) {
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 );
40 my $group_3 = $employees->search({group_id=>3});
43 while (my $employee = $group_3->next) {
44 $employee->move_to_group($to_group, $to_pos);
46 $to_group = $to_group==1 ? 2 : 1;
48 foreach my $group_id (1..4) {
49 my $group_employees = $employees->search({group_id=>$group_id});
50 $group_employees->all();
51 ok( check_rs($group_employees), "group positions after move_to_group" );
54 my $employee = $employees->search({group_id=>4})->first;
55 $employee->position(2);
57 ok( check_rs($employees->search_rs({group_id=>4})), "overloaded update 1" );
58 $employee = $employees->search({group_id=>4})->first;
59 $employee->update({position=>3});
60 ok( check_rs($employees->search_rs({group_id=>4})), "overloaded update 2" );
61 $employee = $employees->search({group_id=>4})->first;
62 $employee->group_id(1);
65 check_rs($employees->search_rs({group_id=>1})) && check_rs($employees->search_rs({group_id=>4})),
68 $employee = $employees->search({group_id=>4})->first;
69 $employee->update({group_id=>2});
71 check_rs($employees->search_rs({group_id=>2})) && check_rs($employees->search_rs({group_id=>4})),
74 $employee = $employees->search({group_id=>4})->first;
75 $employee->group_id(1);
76 $employee->position(3);
79 check_rs($employees->search_rs({group_id=>1})) && check_rs($employees->search_rs({group_id=>4})),
82 $employee = $employees->search({group_id=>4})->first;
83 $employee->group_id(2);
84 $employee->position(undef);
87 check_rs($employees->search_rs({group_id=>2})) && check_rs($employees->search_rs({group_id=>4})),
90 $employee = $employees->search({group_id=>4})->first;
91 $employee->update({group_id=>1,position=>undef});
93 check_rs($employees->search_rs({group_id=>1})) && check_rs($employees->search_rs({group_id=>4})),
100 my $count = $rs->count();
101 my $position_column = $rs->result_class->position_column();
104 foreach my $position (1..$count) {
106 ($row) = $rs->search({ $position_column=>$position })->all();
107 $row->move_previous();
108 ok( check_rs($rs), "move_previous( $position )" );
110 ($row) = $rs->search({ $position_column=>$position })->all();
112 ok( check_rs($rs), "move_next( $position )" );
114 ($row) = $rs->search({ $position_column=>$position })->all();
116 ok( check_rs($rs), "move_first( $position )" );
118 ($row) = $rs->search({ $position_column=>$position })->all();
120 ok( check_rs($rs), "move_last( $position )" );
122 foreach my $to_position (1..$count) {
123 ($row) = $rs->search({ $position_column=>$position })->all();
124 $row->move_to($to_position);
125 ok( check_rs($rs), "move_to( $position => $to_position )" );
128 ($row) = $rs->search({ position=>$position })->all();
130 ok( !$row->previous_sibling(), 'no previous sibling' );
131 ok( !$row->first_sibling(), 'no first sibling' );
134 ok( $row->previous_sibling(), 'previous sibling' );
135 ok( $row->first_sibling(), 'first sibling' );
137 if ($position==$count) {
138 ok( !$row->next_sibling(), 'no next sibling' );
139 ok( !$row->last_sibling(), 'no last sibling' );
142 ok( $row->next_sibling(), 'next sibling' );
143 ok( $row->last_sibling(), 'last sibling' );
152 my $position_column = $rs->result_class->position_column();
153 my $expected_position = 0;
154 while (my $row = $rs->next()) {
155 $expected_position ++;
156 if ($row->get_column($position_column)!=$expected_position) {