Commit | Line | Data |
c0329273 |
1 | BEGIN { do "./t/lib/ANFANG.pm" or die ( $@ || $! ) } |
2 | |
35f5c265 |
3 | use strict; |
4 | use warnings; |
5 | |
6 | use Test::More; |
c0329273 |
7 | |
35f5c265 |
8 | use DBICTest; |
9 | |
10 | my $schema = DBICTest->init_schema(); |
11 | |
12 | |
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' ); |
17 | |
18 | my $link = $bookmark->link; |
19 | |
20 | my $new_link = $schema->resultset("Link")->create({ |
21 | url => "http://bugsarereal.com", |
22 | title => "bugsarereal.com", |
23 | id => 9, |
24 | }); |
25 | |
26 | is( $bookmark->link->id, 1, 'Initial relation id' ); |
27 | |
28 | $bookmark->set_column( 'link', 9 ); |
29 | is( $bookmark->link->id, 9, 'Correct object re-selected after belongs_to set' ); |
30 | |
31 | $bookmark->discard_changes; |
32 | is( $bookmark->link->id, 1, 'Pulled the correct old object after belongs_to reset' ); |
33 | |
34 | |
35 | $bookmark->link($new_link); |
36 | is( $bookmark->get_column('link'), 9, 'Correct column set from related' ); |
37 | |
38 | $bookmark->discard_changes; |
39 | is( $bookmark->link->id, 1, 'Pulled the correct old object after belongs_to reset' ); |
40 | |
41 | |
42 | $bookmark->link(9); |
43 | is( $bookmark->link->id, 9, 'Correct object selected on deflated accessor set'); |
44 | |
45 | $bookmark->discard_changes; |
46 | is( $bookmark->link->id, 1, 'Pulled the correct old object after belongs_to reset' ); |
47 | |
48 | |
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' ); |
52 | |
53 | |
54 | # test with relname != colname |
55 | my $lyric = $schema->resultset('Lyrics')->create({ track_id => 5 }); |
56 | is( $lyric->track->id, 5, 'Initial relation id'); |
57 | |
58 | $lyric->track_id(6); |
59 | my $track6 = $lyric->track; |
60 | is( $track6->trackid, 6, 'Correct object re-selected after belongs_to set'); |
61 | |
62 | $lyric->discard_changes; |
63 | is( $lyric->track->trackid, 5, 'Pulled the correct old rel object after belongs_to reset'); |
64 | |
65 | $lyric->track($track6); |
66 | is( $lyric->track_id, 6, 'Correct column set from related'); |
67 | |
68 | $lyric->discard_changes; |
69 | is( $lyric->track->trackid, 5, 'Pulled the correct old rel object after belongs_to reset'); |
70 | |
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' ); |
74 | |
75 | done_testing; |