File: 100extra_source.t

package info (click to toggle)
libdbix-class-perl 0.08123-1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 3,520 kB
  • ctags: 1,695
  • sloc: perl: 19,821; sql: 353; makefile: 10
file content (54 lines) | stat: -rw-r--r-- 1,500 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
use strict;
use warnings;  

use Test::More;
use lib qw(t/lib);
use DBICTest;

{
    package DBICTest::ResultSource::OtherSource;
    use strict;
    use warnings;
    use base qw/DBIx::Class::ResultSource::Table/;
}

plan tests => 4;

my $schema = DBICTest->init_schema();
my $artist_source = $schema->source('Artist');

my $new_source = DBICTest::ResultSource::OtherSource->new({
  %$artist_source,
  name           => 'artist_preview',
  _relationships => Storable::dclone( $artist_source->_relationships ),
});

$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 $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;