Fixed a bug where a sub class would re-run register_source and trigger carp. Minor...
[dbsrgits/DBIx-Class-Schema-ResultSetAccessors.git] / t / basic.t
CommitLineData
731e8b3e 1# DBIx::Class::Schema::ResultSetAccessors - check module loading and create testing directory
2
3use strict;
4use warnings;
5
6use lib qw(t/lib);
7
8use Test::More;
77c7c7a8 9use Test::Warn;
731e8b3e 10
11BEGIN {
12 use_ok('MyApp1::Schema');
13}
14
15ok my $schema1 = MyApp1::Schema->connect('dbi:SQLite:dbname=:memory:', '', ''),
16 'Got schema 1';
17
18isa_ok $schema1->resultset('Artist'), 'DBIx::Class::ResultSet';
867277b3 19can_ok $schema1, qw/cds artists liner_notes/;
731e8b3e 20isa_ok $schema1->artists, 'DBIx::Class::ResultSet'; # generic resultset
21isa_ok $schema1->cds, 'MyApp1::Schema::ResultSet::CD'; # custom ResultSet
22
23# overwrite the accessor name with resultset_accessor_name()
24can_ok $schema1, qw/source_resultset/;
25isa_ok $schema1->source_resultset, 'DBIx::Class::ResultSet';
26
77c7c7a8 27# test the warnings
28warning_like { warn_same_name() } qr/Schema method with the same name already exists/,
29 'Schema method with the same name already exists';
30
31sub warn_same_name {
731e8b3e 32 # must use required, because for some reason throws_ok cannot catch
33 # erros with "use"
34 require MyApp2::Schema;
77c7c7a8 35
36 # eval'ing this, otherwise an odd error is thrown
37 # "Can't call method "_count_select" on an undefined value"
38 # I presume it's due to the store not having the actual schema installed
39 # as we are connecting to an empty database
40 eval {
41 my $schema = MyApp2::Schema->connect('dbi:SQLite:dbname=:memory:', '', '');
42 };
43}
731e8b3e 44
45done_testing;