Fix the skip for DBD::Multi
[dbsrgits/DBIx-Class.git] / t / cdbi-t / 24-meta_info.t
CommitLineData
a9c8094b 1#!/usr/bin/perl -w
2
3use strict;
4use Test::More tests => 12;
5use Test::Warn;
6
7package Temp::DBI;
8use base qw(DBIx::Class::CDBICompat);
9Temp::DBI->columns(All => qw(id date));
10Temp::DBI->has_a( date => 'Time::Piece', inflate => sub {
11 Time::Piece->strptime(shift, "%Y-%m-%d")
12});
13
14
15package Temp::Person;
16use base 'Temp::DBI';
17Temp::Person->table('people');
18Temp::Person->columns(Info => qw(name pet));
19Temp::Person->has_a( pet => 'Temp::Pet' );
20
21package Temp::Pet;
22use base 'Temp::DBI';
23Temp::Pet->table('pets');
24Temp::Pet->columns(Info => qw(name));
25Temp::Pet->has_many(owners => 'Temp::Person');
26
27package main;
28
29{
30 my $pn_meta = Temp::Person->meta_info('has_a');
31 is_deeply [sort keys %$pn_meta], [qw/date pet/], "Person has Date and Pet";
32}
33
34{
35 my $pt_meta = Temp::Pet->meta_info;
36 is_deeply [keys %{$pt_meta->{has_a}}], [qw/date/], "Pet has Date";
37 is_deeply [keys %{$pt_meta->{has_many}}], [qw/owners/], "And owners";
38}
39
40{
41 my $pet = Temp::Person->meta_info( has_a => 'pet' );
42 is $pet->class, 'Temp::Person';
43 is $pet->foreign_class, 'Temp::Pet';
44 is $pet->accessor, 'pet';
45 is $pet->name, 'has_a';
46}
47
48{
49 my $owners = Temp::Pet->meta_info( has_many => 'owners' );
50 warning_like {
51 local $TODO = 'args is unlikely to ever work';
52
53 is_deeply $owners->args, {
54 foreign_key => 'pet',
55 mapping => [],
56 order_by => undef
57 };
58 } qr/^\Qargs() is unlikely to ever work/;
59}
60
61{
62 my $date = Temp::Pet->meta_info( has_a => 'date' );
63 is $date->class, 'Temp::DBI';
64 is $date->foreign_class, 'Time::Piece';
65 is $date->accessor, 'date';
66}