querycounter role, test for that and a new schema hierarchy for additional Moose...
[dbsrgits/DBIx-Class.git] / t / 99schema_roles.t
1 use strict;
2 use warnings;
3 use lib qw(t/lib);
4 use Test::More;
5
6 BEGIN {
7     eval "use Moose";
8     plan $@
9         ? ( skip_all => 'needs Moose for testing' )
10         : ( tests => 11 );
11 }
12
13 =head1 NAME
14
15 DBICNGTest::Schema::ResultSet:Person; Example Resultset
16
17 =head1 DESCRIPTION
18
19 Tests for the various Schema roles you can either use or apply
20
21 =head1 TESTS
22
23 =head2 initialize database
24
25 create a schema and setup
26
27 =cut
28
29 use_ok 'DBICNGTest::Schema';
30
31 ok my $db_file = Path::Class::File->new(qw/t var DBIxClassNG.db/)
32     => 'created a path for the test database';
33
34 ok my $schema = DBICNGTest::Schema->connect_and_setup($db_file)
35     => 'Created a good Schema';
36
37 is ref $schema->source('Person'), 'DBIx::Class::ResultSource::Table'
38     => 'Found Expected Person Source';
39     
40 is $schema->resultset('Person')->count, 5
41     => 'Got the correct number of people';
42
43 is $schema->resultset('Gender')->count, 3
44     => 'Got the correct number of genders';
45
46
47 =head2 check query counter
48
49 Test the query counter role
50
51 =cut
52
53 use_ok 'DBIx::Class::Storage::DBI::Role::QueryCounter';
54 DBIx::Class::Storage::DBI::Role::QueryCounter->meta->apply($schema->storage);
55
56 is $schema->storage->query_count, 0
57     => 'Query Count is zero';
58     
59 is $schema->resultset('Person')->find(1)->name, 'john'
60     => 'Found John!';
61
62 is $schema->resultset('Person')->find(2)->name, 'dan'
63     => 'Found Dan!';
64
65 is $schema->storage->query_count, 2
66     => 'Query Count is zero';
67     
68     
69 =head2 cleanup
70
71 Cleanup after ourselves
72
73 =cut
74
75 unlink $db_file;
76
77
78 =head1 AUTHORS
79
80 See L<DBIx::Class> for more information regarding authors.
81
82 =head1 LICENSE
83
84 You may distribute this code under the same terms as Perl itself.
85
86 =cut