Remove useless use of Storable from t/100extra_source.t
[dbsrgits/DBIx-Class.git] / t / 100extra_source.t
1 use strict;
2 use warnings;
3
4 use Test::More;
5 use Test::Warn;
6 use lib qw(t/lib);
7 use DBICTest;
8
9 {
10   package DBICTest::ArtistRS;
11   use strict;
12   use warnings;
13   use base qw/DBIx::Class::ResultSet/;
14 }
15
16 my $schema = DBICTest->init_schema();
17 my $artist_source = $schema->source('Artist');
18
19 my $new_source = DBIx::Class::ResultSource::Table->new({
20   %$artist_source,
21   name            => 'artist_preview',
22   resultset_class => 'DBICTest::ArtistRS',
23   _relationships  => {}, # copying them as-is is bad taste
24 });
25 $new_source->add_column('other_col' => { data_type => 'integer', default_value => 1 });
26
27 {
28   $schema->register_extra_source( 'artist->extra' => $new_source );
29
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');
34 }
35
36 warnings_are (sub {
37   my $source = $schema->source('DBICTest::Artist');
38   $schema->register_source($source->source_name, $source);
39 }, [], 're-registering an existing source under the same name causes no warnings' );
40
41 warnings_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   [
58     qr/DBICTest::Artist already has a source, use register_extra_source for additional sources/
59   ],
60   'registering source to an existing result warns'
61 );
62
63 done_testing;