Added update_or_new to ResultSet.pm
[dbsrgits/DBIx-Class.git] / t / 100extra_source.t
CommitLineData
2a4d9487 1use strict;
2use warnings;
3
4use Test::More;
5use lib qw(t/lib);
6use DBICTest;
7
8{
9 package DBICTest::ResultSource::OtherSource;
10 use strict;
11 use warnings;
12 use base qw/DBIx::Class::ResultSource::Table/;
13}
14
15plan tests => 3;
16
17my $schema = DBICTest->init_schema();
18my $artist_source = $schema->source('Artist');
19
20my $new_source = DBICTest::ResultSource::OtherSource->new({
21 %$artist_source,
22 name => 'artist_preview',
23 _relationships => Storable::dclone( $artist_source->_relationships ),
24});
25
26$new_source->add_column('other_col' => { data_type => 'integer', default_value => 1 });
27
28my $warn = '';
fc38383e 29local $SIG{__WARN__} = sub { $warn = shift };
2a4d9487 30
31{
32 $schema->register_extra_source( 'artist->extra' => $new_source );
33
34 my $source = $schema->source('DBICTest::Artist');
35 is($source->source_name, 'Artist', 'original source still primary source');
36}
37
38{
39 my $new_source_name = 'Artist->preview(artist_preview)';
40 $schema->register_source( $new_source_name => $new_source );
41
42 ok(($warn =~ /DBICTest::Artist already has a source, use register_extra_source for additional sources/), 'registering extra source causes errors');
43
44 my $source = $schema->source('DBICTest::Artist');
45 is($source->source_name, $new_source_name, 'original source still primary source');
46}
47
481;