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