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