Skip error/warn frames within CAG - saner callsite error messages this way
[dbsrgits/DBIx-Class.git] / t / 100extra_source.t
CommitLineData
2a4d9487 1use strict;
4783a9a4 2use warnings;
2a4d9487 3
4use Test::More;
4783a9a4 5use Test::Warn;
2a4d9487 6use lib qw(t/lib);
7use DBICTest;
8
9{
4783a9a4 10 package DBICTest::ArtistRS;
11 use strict;
12 use warnings;
13 use base qw/DBIx::Class::ResultSet/;
2a4d9487 14}
15
2a4d9487 16my $schema = DBICTest->init_schema();
17my $artist_source = $schema->source('Artist');
18
4783a9a4 19my $new_source = DBIx::Class::ResultSource::Table->new({
2a4d9487 20 %$artist_source,
4783a9a4 21 name => 'artist_preview',
22 resultset_class => 'DBICTest::ArtistRS',
23 _relationships => {}, # copying them as-is is bad taste
2a4d9487 24});
2a4d9487 25$new_source->add_column('other_col' => { data_type => 'integer', default_value => 1 });
26
2a4d9487 27{
28 $schema->register_extra_source( 'artist->extra' => $new_source );
29
4783a9a4 30 my $primary_source = $schema->source('DBICTest::Artist');
31 is($primary_source->source_name, 'Artist', 'original source still primary source');
32 ok(! $primary_source->has_column('other_col'), 'column definition did not leak to original source');
33 isa_ok($schema->resultset ('artist->extra'), 'DBICTest::ArtistRS');
2a4d9487 34}
35
4783a9a4 36warnings_are (sub {
5d779578 37 my $source = $schema->source('DBICTest::Artist');
38 $schema->register_source($source->source_name, $source);
4783a9a4 39}, [], 're-registering an existing source under the same name causes no warnings' );
40
41warnings_like (
42 sub {
43 my $new_source_name = 'Artist->preview(artist_preview)';
44 $schema->register_source( $new_source_name => $new_source );
45
46 my $primary_source = $schema->source('DBICTest::Artist');
47 is($primary_source->source_name, $new_source_name, 'new source is primary source');
48 ok($primary_source->has_column('other_col'), 'column correctly defined on new source');
49
50 isa_ok ($schema->resultset ($new_source_name), 'DBICTest::ArtistRS');
51
52 my $original_source = $schema->source('Artist');
53 ok(! $original_source->has_column('other_col'), 'column definition did not leak to original source');
54 isa_ok ($original_source->resultset, 'DBIx::Class::ResultSet');
55 isa_ok ($schema->resultset('Artist'), 'DBIx::Class::ResultSet');
56 },
57 [
dee99c24 58 qr/DBICTest::Artist already had a registered source which was replaced by this call/
4783a9a4 59 ],
60 'registering source to an existing result warns'
61);
62
63done_testing;