6ec7fe1af07377f28854e77970e35578a171c522
[dbsrgits/DBIx-Class.git] / t / cdbi / columns_dont_override_custom_accessors.t
1 use strict;
2 use Test::More;
3 use lib 't/cdbi/testlib';
4
5 BEGIN {
6   eval "use DBIx::Class::CDBICompat;";
7   plan $@ ? (skip_all => "Class::Trigger and DBIx::ContextualFetch required: $@")
8           : (tests=> 5);
9 }
10
11 {
12     package Thing;
13
14     use base 'DBIC::Test::SQLite';
15
16     Thing->columns(TEMP => qw[foo bar]);
17     Thing->columns(All  => qw[thing_id yarrow flower]);
18     sub foo { 42 }
19     sub yarrow { "hock" }
20 }
21
22 is_deeply( [sort Thing->columns("TEMP")],
23            [sort qw(foo bar)],
24            "TEMP columns set"
25 );
26 my $thing = Thing->construct(
27     { thing_id => 23, foo => "this", bar => "that" }
28 );
29
30 is( $thing->id, 23 );
31 is( $thing->yarrow, "hock", 'custom accessor not overwritten by column' );
32 is( $thing->foo, 42, 'custom routine not overwritten by temp column' );
33 is( $thing->bar, "that", 'temp column accessor generated' );