Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: topic/SS_DBD_s…
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 116 lines (88 sloc) 3.009 kb
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 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115
#!/usr/bin/perl

use strict;
use warnings;

use Test::More;
use Test::Exception;
use Test::Warn;
use lib qw(t/lib);
use DBICTest;
use ViewDeps;
use ViewDepsBad;

BEGIN {
    require DBIx::Class;
    plan skip_all => 'Test needs ' .
        DBIx::Class::Optional::Dependencies->req_missing_for('deploy')
      unless DBIx::Class::Optional::Dependencies->req_ok_for('deploy');
}

use_ok('DBIx::Class::ResultSource::View');

#################### SANITY

my $view = DBIx::Class::ResultSource::View->new;

isa_ok( $view, 'DBIx::Class::ResultSource', 'A new view' );
isa_ok( $view, 'DBIx::Class', 'A new view also' );

can_ok( $view, $_ ) for qw/new from deploy_depends_on/;

#################### DEPS
{
  my $schema
    = ViewDeps->connect( DBICTest->_database (quote_char => '"') );
  ok( $schema, 'Connected to ViewDeps schema OK' );

#################### DEPLOY

  $schema->deploy;

#################### DOES ORDERING WORK?

  my $sqlt_object = $schema->{sqlt};

  is_deeply(
    [ map { $_->name } $sqlt_object->get_views ],
    [qw/
a_name_artists
track_number_fives
year_2010_cds
ab_name_artists
year_2010_cds_with_many_tracks
aba_name_artists
aba_name_artists_and_2010_cds_with_many_tracks
/],
    "SQLT view order triumphantly matches our order."
  );

#################### AND WHAT ABOUT USING THE SCHEMA?

  lives_ok( sub { $schema->resultset($_)->next }, "Query on $_ succeeds" )
    for grep {
    $schema->resultset($_)
      ->result_source->isa('DBIx::Class::ResultSource::View')
    } @{ [ $schema->sources ] };
}

#################### AND WHAT ABOUT A BAD DEPS CHAIN IN A VIEW?

{
  my $schema2
    = ViewDepsBad->connect( DBICTest->_database ( quote_char => '"') );
  ok( $schema2, 'Connected to ViewDepsBad schema OK' );

#################### DEPLOY2

  warnings_exist { $schema2->deploy }
    [qr/no such table: main.aba_name_artists/],
    "Deploying the bad schema produces a warning: aba_name_artists was not created.";

#################### DOES ORDERING WORK 2?

  my $sqlt_object2 = $schema2->{sqlt};

  is_deeply(
    [ map { $_->name } $sqlt_object2->get_views ],
    [qw/
a_name_artists
track_number_fives
year_2010_cds
ab_name_artists
year_2010_cds_with_many_tracks
aba_name_artists_and_2010_cds_with_many_tracks
aba_name_artists
/],
    "SQLT view order triumphantly matches our order."
  );

#################### AND WHAT ABOUT USING THE SCHEMA2?

  lives_ok( sub { $schema2->resultset($_)->next }, "Query on $_ succeeds" )
    for grep {
    $schema2->resultset($_)
      ->result_source->isa('DBIx::Class::ResultSource::View')
    } grep { !/AbaNameArtistsAnd2010CDsWithManyTracks/ }
    @{ [ $schema2->sources ] };

  throws_ok { $schema2->resultset('AbaNameArtistsAnd2010CDsWithManyTracks')->next }
    qr/no such table: aba_name_artists_and_2010_cds_with_many_tracks/,
    "Query on AbaNameArtistsAnd2010CDsWithManyTracks throws, because the table does not exist"
  ;
}

done_testing;
Something went wrong with that request. Please try again.