I hate you all.
[dbsrgits/DBIx-Class.git] / t / 93single_accessor_object.t
1 use strict;
2 use warnings;  
3
4 use Test::More;
5 use lib qw(t/lib);
6 use DBICTest;
7
8 my $schema = DBICTest->init_schema();
9
10 plan tests => 7;
11
12 # Test various uses of passing an object to find, create, and update on a single
13 # rel accessor
14 {
15   my $artist = $schema->resultset("Artist")->find(1);
16
17   my $cd = $schema->resultset("CD")->find_or_create({
18     artist => $artist,
19     title  => "Object on a might_have",
20     year   => 2006,
21   });
22   ok(defined $cd, 'created a CD');
23   is($cd->get_column('artist'), $artist->id, 'artist matches CD');
24
25   my $liner_notes = $schema->resultset("LinerNotes")->find_or_create({
26     cd     => $cd,
27     notes  => "Creating using an object on a might_have is helpful.",
28   });
29   ok(defined $liner_notes, 'created liner notes');
30   is($liner_notes->liner_id, $cd->cdid, 'liner notes matches CD');
31   is($liner_notes->notes, "Creating using an object on a might_have is helpful.", 'liner notes are correct');
32
33   my $track = $cd->tracks->find_or_create({
34     position => 127,
35     title    => 'Single Accessor'
36   });
37   is($track->get_column('cd'), $cd->cdid, 'track matches CD before update');
38
39   my $another_cd = $schema->resultset("CD")->find(5);
40   $track->update({ disc => $another_cd });
41   is($track->get_column('cd'), $another_cd->cdid, 'track matches another CD after update');
42 }