File: 93single_accessor_object.t

package info (click to toggle)
libdbix-class-perl 0.08010-2
  • links: PTS, VCS
  • area: main
  • in suites: lenny
  • size: 2,052 kB
  • ctags: 1,064
  • sloc: perl: 10,536; sql: 225; makefile: 45
file content (42 lines) | stat: -rwxr-xr-x 1,304 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
use strict;
use warnings;  

use Test::More;
use lib qw(t/lib);
use DBICTest;

my $schema = DBICTest->init_schema();

plan tests => 7;

# Test various uses of passing an object to find, create, and update on a single
# rel accessor
{
  my $artist = $schema->resultset("Artist")->find(1);

  my $cd = $schema->resultset("CD")->find_or_create({
    artist => $artist,
    title  => "Object on a might_have",
    year   => 2006,
  });
  ok(defined $cd, 'created a CD');
  is($cd->get_column('artist'), $artist->id, 'artist matches CD');

  my $liner_notes = $schema->resultset("LinerNotes")->find_or_create({
    cd     => $cd,
    notes  => "Creating using an object on a might_have is helpful.",
  });
  ok(defined $liner_notes, 'created liner notes');
  is($liner_notes->liner_id, $cd->cdid, 'liner notes matches CD');
  is($liner_notes->notes, "Creating using an object on a might_have is helpful.", 'liner notes are correct');

  my $track = $cd->tracks->find_or_create({
    position => 127,
    title    => 'Single Accessor'
  });
  is($track->get_column('cd'), $cd->cdid, 'track matches CD before update');

  my $another_cd = $schema->resultset("CD")->find(5);
  $track->update({ disc => $another_cd });
  is($track->get_column('cd'), $another_cd->cdid, 'track matches another CD after update');
}