Fix t/54taint.t failures on perl-in-hell-in-space
[dbsrgits/DBIx-Class.git] / t / 105view_deps.t
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5
6 use Test::More;
7 use Test::Exception;
8 use Test::Warn;
9 use lib qw(t/lib);
10 use DBICTest;
11 use ViewDeps;
12 use ViewDepsBad;
13
14 BEGIN {
15     require DBIx::Class;
16     plan skip_all => 'Test needs ' .
17         DBIx::Class::Optional::Dependencies->req_missing_for('deploy')
18       unless DBIx::Class::Optional::Dependencies->req_ok_for('deploy');
19 }
20
21 use_ok('DBIx::Class::ResultSource::View');
22
23 #################### SANITY
24
25 my $view = DBIx::Class::ResultSource::View->new;
26
27 isa_ok( $view, 'DBIx::Class::ResultSource', 'A new view' );
28 isa_ok( $view, 'DBIx::Class', 'A new view also' );
29
30 can_ok( $view, $_ ) for qw/new from deploy_depends_on/;
31
32 #################### DEPS
33 {
34   my $schema
35     = ViewDeps->connect( DBICTest->_database (quote_char => '"') );
36   ok( $schema, 'Connected to ViewDeps schema OK' );
37
38 #################### DEPLOY
39
40   $schema->deploy;
41
42 #################### DOES ORDERING WORK?
43
44   my $sqlt_object = $schema->{sqlt};
45
46   is_deeply(
47     [ map { $_->name } $sqlt_object->get_views ],
48     [qw/
49       a_name_artists
50       track_number_fives
51       year_2010_cds
52       ab_name_artists
53       year_2010_cds_with_many_tracks
54       aba_name_artists
55       aba_name_artists_and_2010_cds_with_many_tracks
56     /],
57     "SQLT view order triumphantly matches our order."
58   );
59
60 #################### AND WHAT ABOUT USING THE SCHEMA?
61
62   lives_ok( sub { $schema->resultset($_)->next }, "Query on $_ succeeds" )
63     for grep {
64     $schema->resultset($_)
65       ->result_source->isa('DBIx::Class::ResultSource::View')
66     } @{ [ $schema->sources ] };
67 }
68
69 #################### AND WHAT ABOUT A BAD DEPS CHAIN IN A VIEW?
70
71 {
72   my $schema2
73     = ViewDepsBad->connect( DBICTest->_database ( quote_char => '"') );
74   ok( $schema2, 'Connected to ViewDepsBad schema OK' );
75
76 #################### DEPLOY2
77
78   warnings_exist { $schema2->deploy }
79     [qr/no such table: main.aba_name_artists/],
80     "Deploying the bad schema produces a warning: aba_name_artists was not created.";
81
82 #################### DOES ORDERING WORK 2?
83
84   my $sqlt_object2 = $schema2->{sqlt};
85
86   is_deeply(
87     [ map { $_->name } $sqlt_object2->get_views ],
88     [qw/
89       a_name_artists
90       track_number_fives
91       year_2010_cds
92       ab_name_artists
93       year_2010_cds_with_many_tracks
94       aba_name_artists_and_2010_cds_with_many_tracks
95       aba_name_artists
96     /],
97     "SQLT view order triumphantly matches our order."
98   );
99
100 #################### AND WHAT ABOUT USING THE SCHEMA2?
101
102   lives_ok( sub { $schema2->resultset($_)->next }, "Query on $_ succeeds" )
103     for grep {
104     $schema2->resultset($_)
105       ->result_source->isa('DBIx::Class::ResultSource::View')
106     } grep { !/AbaNameArtistsAnd2010CDsWithManyTracks/ }
107     @{ [ $schema2->sources ] };
108
109   throws_ok { $schema2->resultset('AbaNameArtistsAnd2010CDsWithManyTracks')->next }
110     qr/no such table: aba_name_artists_and_2010_cds_with_many_tracks/,
111     "Query on AbaNameArtistsAnd2010CDsWithManyTracks throws, because the table does not exist"
112   ;
113 }
114
115 done_testing;