5 use lib 't/cdbi/testlib';
8 #-----------------------------------------------------------------------
9 # Make sure that we can set up columns properly
10 #-----------------------------------------------------------------------
13 use base 'DBIC::Test::SQLite';
15 State->table('State');
16 State->columns(Essential => qw/Abbreviation Name/);
17 State->columns(Primary => 'Name');
18 State->columns(Weather => qw/Rain Snowfall/);
19 State->columns(Other => qw/Capital Population/);
20 #State->has_many(cities => "City");
22 sub accessor_name_for {
23 my ($class, $column) = @_;
24 my $return = $column eq "Rain" ? "Rainfall" : $column;
28 sub mutator_name_for {
29 my ($class, $column) = @_;
30 my $return = $column eq "Rain" ? "set_Rainfall" : "set_$column";
39 use base 'DBIC::Test::SQLite';
42 City->columns(All => qw/Name State Population/);
45 # Disable the `no such table' warning
46 local $SIG{__WARN__} = sub {
48 warn $warning unless ($warning =~ /\Qno such table: City(1)\E/);
51 City->has_a(State => 'State');
54 #-------------------------------------------------------------------------
56 use base 'DBIC::Test::SQLite';
59 CD->columns('All' => qw/artist title length/);
61 #-------------------------------------------------------------------------
65 is(State->table, 'State', 'State table()');
66 is(State->primary_column, 'name', 'State primary()');
67 is_deeply [ State->columns('Primary') ] => [qw/name/],
68 'State Primary:' . join ", ", State->columns('Primary');
69 is_deeply [ sort State->columns('Essential') ] => [qw/abbreviation name/],
70 'State Essential:' . join ", ", State->columns('Essential');
71 is_deeply [ sort State->columns('All') ] =>
72 [ sort qw/name abbreviation rain snowfall capital population/ ],
73 'State All:' . join ", ", State->columns('All');
75 is(CD->primary_column, 'artist', 'CD primary()');
76 is_deeply [ CD->columns('Primary') ] => [qw/artist/],
77 'CD primary:' . join ", ", CD->columns('Primary');
78 is_deeply [ sort CD->columns('All') ] => [qw/artist length title/],
79 'CD all:' . join ", ", CD->columns('All');
80 is_deeply [ sort CD->columns('Essential') ] => [qw/artist/],
81 'CD essential:' . join ", ", CD->columns('Essential');
83 ok(State->find_column('Rain'), 'find_column Rain');
84 ok(State->find_column('rain'), 'find_column rain');
85 ok(!State->find_column('HGLAGAGlAG'), '!find_column HGLAGAGlAG');
89 can_ok +State => qw/Rainfall _Rainfall_accessor set_Rainfall
90 _set_Rainfall_accessor Snowfall _Snowfall_accessor set_Snowfall
91 _set_Snowfall_accessor/;
93 foreach my $method (qw/Rain _Rain_accessor rain snowfall/) {
94 ok !State->can($method), "State can't $method";
101 skip "No column objects", 1;
103 eval { my @grps = State->__grouper->groups_for("Huh"); };
104 ok $@, "Huh not in groups";
107 my @grps = sort State->__grouper->groups_for(State->_find_columns(qw/rain capital/));
108 is @grps, 2, "Rain and Capital = 2 groups";
109 @grps = sort @grps; # Because the underlying API is hash-based
110 is $grps[0], 'Other', " - Other";
111 is $grps[1], 'Weather', " - Weather";
117 # @DieTest::ISA = qw(DBIx::Class);
118 # DieTest->load_components(qw/CDBICompat::Retrieve Core/);
120 # local $SIG{__WARN__} = sub { };
121 # eval { DieTest->retrieve(1) };
122 # like $@, qr/unless primary columns are defined/, "Need primary key for retrieve";
125 #-----------------------------------------------------------------------
126 # Make sure that columns inherit properly
127 #-----------------------------------------------------------------------
131 @A::ISA = qw(DBIx::Class);
132 __PACKAGE__->load_components(qw/CDBICompat Core/);
133 __PACKAGE__->table('dummy');
134 __PACKAGE__->columns(Primary => 'id');
138 __PACKAGE__->table('dummy2');
139 __PACKAGE__->columns(All => qw(id b1));
143 __PACKAGE__->table('dummy3');
144 __PACKAGE__->columns(All => qw(id c1 c2 c3));
147 is join (' ', sort A->columns), 'id', "A columns";
148 is join (' ', sort A::B->columns), 'b1 id', "A::B columns";
149 is join (' ', sort A::C->columns), 'c1 c2 c3 id', "A::C columns";