Fix building on perls with no . in @INC
[dbsrgits/DBIx-Class.git] / t / relationship / set_column_on_fk.t
CommitLineData
c0329273 1BEGIN { do "./t/lib/ANFANG.pm" or die ( $@ || $! ) }
2
35f5c265 3use strict;
4use warnings;
5
6use Test::More;
c0329273 7
35f5c265 8use DBICTest;
9
10my $schema = DBICTest->init_schema();
11
12
13# test with relname == colname
14my $bookmark = $schema->resultset("Bookmark")->find(1);
15ok( $bookmark->has_column ('link'), 'Right column name' );
16ok( $bookmark->has_relationship ('link'), 'Right rel name' );
17
18my $link = $bookmark->link;
19
20my $new_link = $schema->resultset("Link")->create({
21 url => "http://bugsarereal.com",
22 title => "bugsarereal.com",
23 id => 9,
24});
25
26is( $bookmark->link->id, 1, 'Initial relation id' );
27
28$bookmark->set_column( 'link', 9 );
29is( $bookmark->link->id, 9, 'Correct object re-selected after belongs_to set' );
30
31$bookmark->discard_changes;
32is( $bookmark->link->id, 1, 'Pulled the correct old object after belongs_to reset' );
33
34
35$bookmark->link($new_link);
36is( $bookmark->get_column('link'), 9, 'Correct column set from related' );
37
38$bookmark->discard_changes;
39is( $bookmark->link->id, 1, 'Pulled the correct old object after belongs_to reset' );
40
41
42$bookmark->link(9);
43is( $bookmark->link->id, 9, 'Correct object selected on deflated accessor set');
44
45$bookmark->discard_changes;
46is( $bookmark->link->id, 1, 'Pulled the correct old object after belongs_to reset' );
47
48
49$bookmark->update({ link => 9 });
50is( $bookmark->link->id, 9, 'Correct relationship after update' );
51is( $bookmark->get_from_storage->link->id, 9, 'Correct relationship after re-select' );
52
53
54# test with relname != colname
55my $lyric = $schema->resultset('Lyrics')->create({ track_id => 5 });
56is( $lyric->track->id, 5, 'Initial relation id');
57
58$lyric->track_id(6);
59my $track6 = $lyric->track;
60is( $track6->trackid, 6, 'Correct object re-selected after belongs_to set');
61
62$lyric->discard_changes;
63is( $lyric->track->trackid, 5, 'Pulled the correct old rel object after belongs_to reset');
64
65$lyric->track($track6);
66is( $lyric->track_id, 6, 'Correct column set from related');
67
68$lyric->discard_changes;
69is( $lyric->track->trackid, 5, 'Pulled the correct old rel object after belongs_to reset');
70
71$lyric->update({ track => $track6 });
72is( $lyric->track->trackid, 6, 'Correct relationship obj after update' );
73is( $lyric->get_from_storage->track->trackid, 6, 'Correct relationship after re-select' );
74
75done_testing;