From: Peter Rabbitson Date: Tue, 17 Aug 2010 05:18:06 +0000 (+0200) Subject: Remove useless use of Storable from t/100extra_source.t X-Git-Tag: v0.08124~28 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=4783a9a4721bc599e46de0ef2eed00a900325396;p=dbsrgits%2FDBIx-Class.git Remove useless use of Storable from t/100extra_source.t Cleanup needed before merging extended rels (Storable chokes on the coderefs). Rewrite the test while we are here. --- diff --git a/t/100extra_source.t b/t/100extra_source.t index 05d99b9..b917958 100644 --- a/t/100extra_source.t +++ b/t/100extra_source.t @@ -1,54 +1,63 @@ use strict; -use warnings; +use warnings; use Test::More; +use Test::Warn; use lib qw(t/lib); use DBICTest; { - package DBICTest::ResultSource::OtherSource; - use strict; - use warnings; - use base qw/DBIx::Class::ResultSource::Table/; + package DBICTest::ArtistRS; + use strict; + use warnings; + use base qw/DBIx::Class::ResultSet/; } -plan tests => 4; - my $schema = DBICTest->init_schema(); my $artist_source = $schema->source('Artist'); -my $new_source = DBICTest::ResultSource::OtherSource->new({ +my $new_source = DBIx::Class::ResultSource::Table->new({ %$artist_source, - name => 'artist_preview', - _relationships => Storable::dclone( $artist_source->_relationships ), + name => 'artist_preview', + resultset_class => 'DBICTest::ArtistRS', + _relationships => {}, # copying them as-is is bad taste }); - $new_source->add_column('other_col' => { data_type => 'integer', default_value => 1 }); -my $warn = ''; -local $SIG{__WARN__} = sub { $warn = shift }; - { $schema->register_extra_source( 'artist->extra' => $new_source ); - my $source = $schema->source('DBICTest::Artist'); - is($source->source_name, 'Artist', 'original source still primary source'); + my $primary_source = $schema->source('DBICTest::Artist'); + is($primary_source->source_name, 'Artist', 'original source still primary source'); + ok(! $primary_source->has_column('other_col'), 'column definition did not leak to original source'); + isa_ok($schema->resultset ('artist->extra'), 'DBICTest::ArtistRS'); } -{ +warnings_are (sub { my $source = $schema->source('DBICTest::Artist'); $schema->register_source($source->source_name, $source); - is($warn, '', "re-registering an existing source under the same name causes no errors"); -} - -{ - my $new_source_name = 'Artist->preview(artist_preview)'; - $schema->register_source( $new_source_name => $new_source ); - - ok(($warn =~ /DBICTest::Artist already has a source, use register_extra_source for additional sources/), 'registering extra source causes errors'); - - my $source = $schema->source('DBICTest::Artist'); - is($source->source_name, $new_source_name, 'original source still primary source'); -} - -1; +}, [], 're-registering an existing source under the same name causes no warnings' ); + +warnings_like ( + sub { + my $new_source_name = 'Artist->preview(artist_preview)'; + $schema->register_source( $new_source_name => $new_source ); + + my $primary_source = $schema->source('DBICTest::Artist'); + is($primary_source->source_name, $new_source_name, 'new source is primary source'); + ok($primary_source->has_column('other_col'), 'column correctly defined on new source'); + + isa_ok ($schema->resultset ($new_source_name), 'DBICTest::ArtistRS'); + + my $original_source = $schema->source('Artist'); + ok(! $original_source->has_column('other_col'), 'column definition did not leak to original source'); + isa_ok ($original_source->resultset, 'DBIx::Class::ResultSet'); + isa_ok ($schema->resultset('Artist'), 'DBIx::Class::ResultSet'); + }, + [ + qr/DBICTest::Artist already has a source, use register_extra_source for additional sources/ + ], + 'registering source to an existing result warns' +); + +done_testing;