From 26c663f123032941cb3f61d6cd11869b86716d6d Mon Sep 17 00:00:00 2001
From: Peter Rabbitson <ribasushi@cpan.org>
Date: Tue, 3 Nov 2015 14:35:35 +0100
Subject: [PATCH] Adjust view-dependency tests to work on newer libsqlite

The test and mechanism behind it is largely useless in these cases, but old
sqlite installations will lurk around for ever, so keep the check while moving
it to xt/
---
 Changes                                        |  3 +++
 .../extra/sqlite_view_deps.t                   | 18 +++++++++++++++---
 2 files changed, 18 insertions(+), 3 deletions(-)
 rename t/105view_deps.t => xt/extra/sqlite_view_deps.t (83%)

diff --git a/Changes b/Changes
index b6c82cb33..13de347d8 100644
--- a/Changes
+++ b/Changes
@@ -29,6 +29,9 @@ Revision history for DBIx::Class
           immediately before the commit is attempted (RT#107159)
         - Fix several corner cases with Many2Many over custom relationships
         - Fix t/52leaks.t failures on compilerless systems (RT#104429)
+        - Fix t/105view_deps.t failing with libsqlite >= 3.009, where view
+          definitions are lazily-checked for correctness only at DML-time as
+          opposed to DDL-time (RT#1546088)
         - Fix t/storage/quote_names.t failures on systems with specified Oracle
           test credentials while missing the optional Math::Base36
         - Fix the Sybase ASE storage incorrectly attempting to retrieve an
diff --git a/t/105view_deps.t b/xt/extra/sqlite_view_deps.t
similarity index 83%
rename from t/105view_deps.t
rename to xt/extra/sqlite_view_deps.t
index bf470befe..39bb63252 100644
--- a/t/105view_deps.t
+++ b/xt/extra/sqlite_view_deps.t
@@ -64,10 +64,16 @@ can_ok( $view, $_ ) for qw/new from deploy_depends_on/;
     = ViewDepsBad->connect( DBICTest->_database ( quote_char => '"') );
   ok( $schema2, 'Connected to ViewDepsBad schema OK' );
 
+  my $lazy_view_validity = !(
+    $schema2->storage->_server_info->{normalized_dbms_version}
+      <
+    3.009
+  );
+
 #################### DEPLOY2
 
   warnings_exist { $schema2->deploy }
-    [qr/no such table: main.aba_name_artists/],
+    [ $lazy_view_validity ? () : 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?
@@ -97,9 +103,15 @@ can_ok( $view, $_ ) for qw/new from deploy_depends_on/;
     } grep { !/AbaNameArtistsAnd2010CDsWithManyTracks/ }
     @{ [ $schema2->sources ] };
 
+  $schema2->storage->dbh->do(q( DROP VIEW "aba_name_artists" ))
+    if $lazy_view_validity;
+
   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"
+    qr/no such table: (?:main\.)?aba_name_artists/,
+    sprintf(
+      "Query on AbaNameArtistsAnd2010CDsWithManyTracks throws, because the%s view does not exist",
+      $lazy_view_validity ? ' underlying' : ''
+    )
   ;
 }