First stab at restructuring with tests_recursive() - no functional changes
[dbsrgits/DBIx-Class.git] / t / cdbi / mk_group_accessors.t
CommitLineData
7da06023 1use strict;
2use Test::More;
3
4BEGIN {
5 eval "use DBIx::Class::CDBICompat;";
6 plan skip_all => 'Class::Trigger and DBIx::ContextualFetch required' if $@;
7
8 eval "use DBD::SQLite";
9 plan skip_all => 'needs DBD::SQLite for testing' if $@;
10
11 plan 'no_plan';
12}
13
14INIT {
50891152 15 use lib 't/cdbi/testlib';
7da06023 16 require Film;
17}
18
19sub Film::get_test {
20 my $self = shift;
21 my $key = shift;
22 $self->{get_test}++;
23 return $self->{$key};
24}
25
26sub Film::set_test {
27 my($self, $key, $val) = @_;
28 $self->{set_test}++;
29 return $self->{$key} = $val;
30}
31
32
33my $film = Film->create({ Title => "No Wolf McQuade" });
34
35# Test mk_group_accessors() with a list of fields.
36{
37 Film->mk_group_accessors(test => qw(foo bar));
38 $film->foo(42);
39 is $film->foo, 42;
40
41 $film->bar(23);
42 is $film->bar, 23;
43}
44
45
46# An explicit accessor passed to mk_group_accessors should
47# ignore accessor/mutator_name_for.
48sub Film::accessor_name_for {
49 my($class, $col) = @_;
50 return "hlaglagh" if $col eq "wibble";
51 return $col;
52}
53
54sub Film::mutator_name_for {
55 my($class, $col) = @_;
56 return "hlaglagh" if $col eq "wibble";
57 return $col;
58}
59
60
61# Test with a mix of fields and field specs
62{
63 Film->mk_group_accessors(test => ("baz", [wibble_thing => "wibble"]));
64 $film->baz(42);
65 is $film->baz, 42;
66
67 $film->wibble_thing(23);
68 is $film->wibble_thing, 23;
69}