1 BEGIN { do "./t/lib/ANFANG.pm" or die ( $@ || $! ) }
10 my $schema = DBICTest->init_schema();
13 # test with relname == colname
14 my $bookmark = $schema->resultset("Bookmark")->find(1);
15 ok( $bookmark->has_column ('link'), 'Right column name' );
16 ok( $bookmark->has_relationship ('link'), 'Right rel name' );
18 my $link = $bookmark->link;
20 my $new_link = $schema->resultset("Link")->create({
21 url => "http://bugsarereal.com",
22 title => "bugsarereal.com",
26 is( $bookmark->link->id, 1, 'Initial relation id' );
28 $bookmark->set_column( 'link', 9 );
29 is( $bookmark->link->id, 9, 'Correct object re-selected after belongs_to set' );
31 $bookmark->discard_changes;
32 is( $bookmark->link->id, 1, 'Pulled the correct old object after belongs_to reset' );
35 $bookmark->link($new_link);
36 is( $bookmark->get_column('link'), 9, 'Correct column set from related' );
38 $bookmark->discard_changes;
39 is( $bookmark->link->id, 1, 'Pulled the correct old object after belongs_to reset' );
43 is( $bookmark->link->id, 9, 'Correct object selected on deflated accessor set');
45 $bookmark->discard_changes;
46 is( $bookmark->link->id, 1, 'Pulled the correct old object after belongs_to reset' );
49 $bookmark->update({ link => 9 });
50 is( $bookmark->link->id, 9, 'Correct relationship after update' );
51 is( $bookmark->get_from_storage->link->id, 9, 'Correct relationship after re-select' );
54 # test with relname != colname
55 my $lyric = $schema->resultset('Lyrics')->create({ track_id => 5 });
56 is( $lyric->track->id, 5, 'Initial relation id');
59 my $track6 = $lyric->track;
60 is( $track6->trackid, 6, 'Correct object re-selected after belongs_to set');
62 $lyric->discard_changes;
63 is( $lyric->track->trackid, 5, 'Pulled the correct old rel object after belongs_to reset');
65 $lyric->track($track6);
66 is( $lyric->track_id, 6, 'Correct column set from related');
68 $lyric->discard_changes;
69 is( $lyric->track->trackid, 5, 'Pulled the correct old rel object after belongs_to reset');
71 $lyric->update({ track => $track6 });
72 is( $lyric->track->trackid, 6, 'Correct relationship obj after update' );
73 is( $lyric->get_from_storage->track->trackid, 6, 'Correct relationship after re-select' );