3 use Test::More tests => 25;
5 #-----------------------------------------------------------------------
6 # Make sure that we can set up columns properly
7 #-----------------------------------------------------------------------
10 use base 'DBIx::Class';
12 State->table('State');
13 State->columns(Essential => qw/Abbreviation Name/);
14 State->columns(Primary => 'Name');
15 State->columns(Weather => qw/Rain Snowfall/);
16 State->columns(Other => qw/Capital Population/);
17 #State->has_many(cities => "City");
20 my ($class, $column) = @_;
21 my $return = $column eq "Rain" ? "Rainfall" : $column;
26 my ($class, $column) = @_;
27 my $return = $column eq "Rain" ? "set_Rainfall" : "set_$column";
36 use base 'DBIx::Class';
39 City->columns(All => qw/Name State Population/);
40 City->has_a(State => 'State');
43 #-------------------------------------------------------------------------
45 use base 'DBIx::Class';
48 CD->columns('All' => qw/artist title length/);
50 #-------------------------------------------------------------------------
54 is(State->table, 'State', 'State table()');
55 is(State->primary_column, 'name', 'State primary()');
56 is_deeply [ State->columns('Primary') ] => [qw/name/],
57 'State Primary:' . join ", ", State->columns('Primary');
58 is_deeply [ sort State->columns('Essential') ] => [qw/abbreviation name/],
59 'State Essential:' . join ", ", State->columns('Essential');
60 is_deeply [ sort State->columns('All') ] =>
61 [ sort qw/name abbreviation rain snowfall capital population/ ],
62 'State All:' . join ", ", State->columns('All');
64 is(CD->primary_column, 'artist', 'CD primary()');
65 is_deeply [ CD->columns('Primary') ] => [qw/artist/],
66 'CD primary:' . join ", ", CD->columns('Primary');
67 is_deeply [ sort CD->columns('All') ] => [qw/artist length title/],
68 'CD all:' . join ", ", CD->columns('All');
69 is_deeply [ sort CD->columns('Essential') ] => [qw/artist/],
70 'CD essential:' . join ", ", CD->columns('Essential');
72 ok(State->find_column('Rain'), 'find_column Rain');
73 ok(State->find_column('rain'), 'find_column rain');
74 ok(!State->find_column('HGLAGAGlAG'), '!find_column HGLAGAGlAG');
78 can_ok +State => qw/Rainfall _Rainfall_accessor set_Rainfall
79 _set_Rainfall_accessor Snowfall _Snowfall_accessor set_Snowfall
80 _set_Snowfall_accessor/;
82 foreach my $method (qw/Rain _Rain_accessor rain snowfall/) {
83 ok !State->can($method), "State can't $method";
90 skip "No column objects", 1;
92 eval { my @grps = State->__grouper->groups_for("Huh"); };
93 ok $@, "Huh not in groups";
96 my @grps = sort State->__grouper->groups_for(State->_find_columns(qw/rain capital/));
97 is @grps, 2, "Rain and Capital = 2 groups";
98 @grps = sort @grps; # Because DBIx::Class is hash-based
99 is $grps[0], 'Other', " - Other";
100 is $grps[1], 'Weather', " - Weather";
104 local $SIG{__WARN__} = sub { };
105 eval { DBIx::Class->retrieve(1) };
106 like $@, qr/Can't retrieve unless primary columns are defined/, "Need primary key for retrieve";
109 #-----------------------------------------------------------------------
110 # Make sure that columns inherit properly
111 #-----------------------------------------------------------------------
115 @A::ISA = qw(DBIx::Class);
116 __PACKAGE__->columns(Primary => 'id');
120 __PACKAGE__->columns(All => qw(id b1));
124 __PACKAGE__->columns(All => qw(id c1 c2 c3));
127 is join (' ', sort A->columns), 'id', "A columns";
128 is join (' ', sort A::B->columns), 'b1 id', "A::B columns";
129 is join (' ', sort A::C->columns), 'c1 c2 c3 id', "A::C columns";