Created
July 26, 2010 21:32
-
-
Save dhoss/491289 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| my $chief = $rs->create( | |
| { | |
| name => 'grand chief', | |
| children => [ | |
| { | |
| name => 'subordinate 1', | |
| children => [ map { { name => 'rookie 1.' . $_ } } qw/1 2 3/, ], | |
| }, | |
| { | |
| name => 'subordinate 2', | |
| children => [ map { { name => 'rookie 2.' . $_ } } qw/1 2/, ], | |
| }, | |
| ] | |
| } | |
| ); | |
| ok( check_rs( $chief, [ undef, 1 ] ), "initial state" ); | |
| ok ( !defined $chief->parent, "chief has no parent"); | |
| ok( check_rs( my $first = $rs->find( { name => "subordinate 1" } ), [ 1, "1.1" ] ), "first subordinate" ); | |
| cmp_ok ( $first->parent->id, '==', $chief->id, 'first subordinate has chief as parent'); | |
| ok( check_rs( my $second = $rs->find( { name => "subordinate 2" } ), [ 1, "1.2" ] ), "second subordinate" ); | |
| cmp_ok( $second->parent->id, '==', $chief->id, 'second subordinate has chief as parent'); | |
| ok( check_rs( my $child1 = $rs->find( { path => "1.1.1" } ), [ "1.1", "1.1.1" ] ), "first child" ); | |
| cmp_ok( $child1->parent->id, '==', $first->id, "child 1 has subordinate 1 as a parent"); | |
| ok( check_rs( my $child2 = $rs->find( { path => "1.1.2" } ), [ "1.1", "1.1.2" ] ), "second child" ); | |
| cmp_ok( $child2->parent->id, '==', $first->id, "child 2 has subordinate 1 as a parent"); | |
| # move shit around | |
| $child1->update( { parent_id => $first->id } ); | |
| ok( check_rs( $rs->find( { path => 1.1 } ), [ 1, 1.1 ] ), 'promote a rookie to a subordinate' ); | |
| cmp_ok( $child1->parent->id, '==', $first->id, "child 1 has chief as a parent"); | |
| $child1->move_to(1); | |
| ok( check_rs( $rs->find( { path => 1.1 } ), [ 1, 1.1 ] ), 'make this same rookie 1st subordinate' ); | |
| warn "child1 path after FIRST move: ". $child1->path; | |
| $child1->move_to_group( undef, 1 ); | |
| ok( | |
| check_rs( $rs->find( { path => 1 } ), [ undef, 1 ] ), | |
| "promote him to FIRST chief (this time use move_to_group)" | |
| ); | |
| warn "child1 path after move to group: " . $child1->path; | |
| $child1->move_to(2); ## issues here | |
| warn "Child1 path after child1->move_to:" . $child1->path; | |
| ok( check_rs( $rs->find( { path => 2 } ), [ undef, 2 ] ), 'not that good - make 2nd chief' ); | |
| my $sub2id = $rs->find( { name => 'subordinate 2' } )->id; | |
| ##output: | |
| child1 path after FIRST move: 1.1.1 at t/basic.t line 52. | |
| BEGIN WORK | |
| SELECT path FROM nested me WHERE ( ( path > ? AND ( path != ? AND parent_id = ? ) ) ) ORDER BY path DESC LIMIT 1: '1.1.1', '1.1.1', '2' | |
| SELECT me.id, me.name, me.parent_id, me.path FROM nested me WHERE ( ( ( path BETWEEN ? AND ? ) AND parent_id = ? ) ) ORDER BY path ASC: '1.1.2', '1.1.3', '2' | |
| UPDATE nested SET path = ? WHERE ( id = ? ): '1.1.1', '4' | |
| SELECT me.id, me.name, me.parent_id, me.path FROM nested me WHERE ( path LIKE ? ): '1.1.2.%' | |
| UPDATE nested SET path = ? WHERE ( id = ? ): '1.1.2', '5' | |
| SELECT me.id, me.name, me.parent_id, me.path FROM nested me WHERE ( path LIKE ? ): '1.1.3.%' | |
| UPDATE nested SET path = ? WHERE ( id = ? ): '1.1.3', '3' | |
| SELECT path FROM nested me WHERE ( ( path IS NOT NULL AND parent_id IS NULL ) ) ORDER BY path DESC LIMIT 1: | |
| SELECT me.id, me.name, me.parent_id, me.path FROM nested me WHERE ( ( ( path BETWEEN ? AND ? ) AND parent_id IS NULL ) ) ORDER BY path DESC: '1.1.1', '1.1.1' | |
| UPDATE nested SET parent_id = ?, path = ? WHERE ( id = ? ): 'NULL', '1.1.1', '3' | |
| COMMIT | |
| SELECT me.id, me.name, me.parent_id, me.path FROM nested me WHERE ( me.path = ? ): '1' | |
| SELECT me.id, me.name, me.parent_id, me.path FROM nested me WHERE ( me.id = ? ): '1' | |
| child1 path after move to group: 1.1.1 at t/basic.t line 58. | |
| BEGIN WORK | |
| SELECT me.id, me.name, me.parent_id, me.path FROM nested me WHERE ( ( ( path BETWEEN ? AND ? ) AND parent_id IS NULL ) ) ORDER BY path ASC: '1.1.2', '1.1.2' | |
| UPDATE nested SET path = ? WHERE ( id = ? ): '1.1.2', '3' | |
| COMMIT | |
| Child1 path after child1->move_to:1.1.2 at t/basic.t line 60. | |
| SELECT me.id, me.name, me.parent_id, me.path FROM nested me WHERE ( me.path = ? ): '2' | |
| Can't call method "discard_changes" on an undefined value at t/basic.t line 91. | |
| line 91: | |
| $node->discard_changes; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment