Merge branch 'master' into topic/constructor_rewrite
[dbsrgits/DBIx-Class.git] / t / resultset / inflate_result_api.t
index d97e475..a6914d9 100644 (file)
@@ -2,6 +2,7 @@ use strict;
 use warnings;
 
 use Test::More;
+use Test::Deep;
 use lib qw(t/lib);
 use DBICTest;
 
@@ -42,12 +43,20 @@ $schema->resultset('CD')->create({
   },
 });
 
+$schema->resultset('CD')->create({ artist => 1, year => 1977, title => "fuzzy_1" });
+
 {
   package DBICTest::_IRCapture;
   sub inflate_result { [@_[2,3]] };
 }
 
-is_deeply(
+{
+  package DBICTest::_IRCaptureAround;
+  use base 'DBIx::Class::Row';
+  sub inflate_result { [@_[2,3]] };
+}
+
+cmp_structures(
   ([$schema->resultset ('CD')->search ({}, {
     result_class => 'DBICTest::_IRCapture',
     prefetch => { single_track => { cd => 'artist' } },
@@ -56,31 +65,31 @@ is_deeply(
   [
     [
       { cdid => 1, single_track => undef, artist => 1, genreid => 1, year => 1981, title => "Magnetic Fields" },
-      { single_track => [
+      { single_track => bless( [
         { trackid => undef, title => undef, position => undef, cd => undef, last_updated_at => undef, last_updated_on => undef },
-        {  cd => [
+        {  cd => bless ( [
           { cdid => undef, single_track => undef, artist => undef, genreid => undef, year => undef, title => undef },
           {
-            artist => [
+            artist => bless ( [
               { artistid => undef, name => undef, charfield => undef, rank => undef }
-            ]
+            ], $DBIx::Class::ResultSource::RowParser::Util::null_branch_class )
           }
-        ] }
-      ] }
+        ], $DBIx::Class::ResultSource::RowParser::Util::null_branch_class ) }
+      ], $DBIx::Class::ResultSource::RowParser::Util::null_branch_class ) }
     ],
     [
       { cdid => 2, single_track => undef, artist => 1, genreid => undef, year => 1976, title => "Oxygene" },
-      { single_track => [
+      { single_track => bless( [
         { trackid => undef, title => undef, position => undef, cd => undef, last_updated_at => undef, last_updated_on => undef },
-        {  cd => [
+        {  cd => bless ( [
           { cdid => undef, single_track => undef, artist => undef, genreid => undef, year => undef, title => undef },
           {
-            artist => [
+            artist => bless ( [
               { artistid => undef, name => undef, charfield => undef, rank => undef }
-            ]
+            ], $DBIx::Class::ResultSource::RowParser::Util::null_branch_class )
           }
-        ] }
-      ] }
+        ], $DBIx::Class::ResultSource::RowParser::Util::null_branch_class ) }
+      ], $DBIx::Class::ResultSource::RowParser::Util::null_branch_class ) }
     ],
     [
       { cdid => 3, single_track => 6, artist => 1, genreid => 1, year => 1978, title => "Equinoxe" },
@@ -96,11 +105,25 @@ is_deeply(
         ] }
       ] }
     ],
+    [
+      { cdid => 4, single_track => undef, artist => 1, genreid => undef, year => 1977, title => "fuzzy_1" },
+      { single_track => bless( [
+        { trackid => undef, title => undef, position => undef, cd => undef, last_updated_at => undef, last_updated_on => undef },
+        {  cd => bless ( [
+          { cdid => undef, single_track => undef, artist => undef, genreid => undef, year => undef, title => undef },
+          {
+            artist => bless ( [
+              { artistid => undef, name => undef, charfield => undef, rank => undef }
+            ], $DBIx::Class::ResultSource::RowParser::Util::null_branch_class )
+          }
+        ], $DBIx::Class::ResultSource::RowParser::Util::null_branch_class ) }
+      ], $DBIx::Class::ResultSource::RowParser::Util::null_branch_class ) }
+    ],
   ],
-  'Simple 1:1 descend with classic prefetch ok'
+  'Simple 1:1 descend with classic prefetch'
 );
 
-is_deeply(
+cmp_structures(
   [$schema->resultset ('CD')->search ({}, {
     result_class => 'DBICTest::_IRCapture',
     join => { single_track => { cd => 'artist' } },
@@ -116,7 +139,7 @@ is_deeply(
   [
     [
       { artist => 1, genreid => 1, year => 1981, title => "Magnetic Fields" },
-      { single_track => [
+      { single_track => bless( [
         undef,
         {  cd => [
           undef,
@@ -126,11 +149,11 @@ is_deeply(
             ]
           }
         ] }
-      ] }
+      ], $DBIx::Class::ResultSource::RowParser::Util::null_branch_class ) }
     ],
     [
       { artist => 1, genreid => undef, year => 1976, title => "Oxygene" },
-      { single_track => [
+      { single_track => bless( [
         undef,
         {  cd => [
           undef,
@@ -140,7 +163,7 @@ is_deeply(
             ]
           }
         ] }
-      ] }
+      ], $DBIx::Class::ResultSource::RowParser::Util::null_branch_class ) }
     ],
     [
       { artist => 1, genreid => 1, year => 1978, title => "Equinoxe" },
@@ -156,11 +179,25 @@ is_deeply(
         ] }
       ] }
     ],
+    [
+      { artist => 1, genreid => undef, year => 1977, title => "fuzzy_1" },
+      { single_track => bless( [
+        undef,
+        {  cd => [
+          undef,
+          {
+            artist => [
+              { artistid => undef }
+            ]
+          }
+        ] }
+      ], $DBIx::Class::ResultSource::RowParser::Util::null_branch_class ) }
+    ],
   ],
-  'Simple 1:1 descend with missing selectors ok'
+  'Simple 1:1 descend with missing selectors'
 );
 
-is_deeply(
+cmp_structures(
   ([$schema->resultset ('CD')->search ({}, {
     result_class => 'DBICTest::_IRCapture',
     prefetch => [ { single_track => { cd => { artist => { cds => 'tracks' } } } } ],
@@ -169,43 +206,43 @@ is_deeply(
   [
     [
       { cdid => 1, single_track => undef, artist => 1, genreid => 1, year => 1981, title => "Magnetic Fields" },
-      { single_track => [
+      { single_track => bless( [
         { trackid => undef, title => undef, position => undef, cd => undef, last_updated_at => undef, last_updated_on => undef },
         {  cd => [
           { cdid => undef, single_track => undef, artist => undef, genreid => undef, year => undef, title => undef },
           {
             artist => [
               { artistid => undef, name => undef, charfield => undef, rank => undef },
-              { cds => [ [
+              { cds => bless( [ [
                 { cdid => undef, single_track => undef, artist => undef, genreid => undef, year => undef, title => undef },
-                { tracks => [ [
+                { tracks => bless( [ [
                   { trackid => undef, title => undef, position => undef, cd => undef, last_updated_at => undef, last_updated_on => undef },
-                ] ] },
-              ]]},
+                ] ], $DBIx::Class::ResultSource::RowParser::Util::null_branch_class ) },
+              ] ], $DBIx::Class::ResultSource::RowParser::Util::null_branch_class ) },
             ],
           },
         ] },
-      ] },
+      ], $DBIx::Class::ResultSource::RowParser::Util::null_branch_class ) },
     ],
     [
       { cdid => 2, single_track => undef, artist => 1, genreid => undef, year => 1976, title => "Oxygene" },
-      { single_track => [
+      { single_track => bless( [
         { trackid => undef, title => undef, position => undef, cd => undef, last_updated_at => undef, last_updated_on => undef },
         {  cd => [
           { cdid => undef, single_track => undef, artist => undef, genreid => undef, year => undef, title => undef },
           {
             artist => [
               { artistid => undef, name => undef, charfield => undef, rank => undef },
-              { cds => [ [
+              { cds => bless( [ [
                 { cdid => undef, single_track => undef, artist => undef, genreid => undef, year => undef, title => undef },
-                { tracks => [ [
+                { tracks => bless( [ [
                   { trackid => undef, title => undef, position => undef, cd => undef, last_updated_at => undef, last_updated_on => undef },
-                ] ] },
-              ]]},
-            ]
-          }
-        ] }
-      ] }
+                ] ], $DBIx::Class::ResultSource::RowParser::Util::null_branch_class ) },
+              ] ], $DBIx::Class::ResultSource::RowParser::Util::null_branch_class ) },
+            ],
+          },
+        ] },
+      ], $DBIx::Class::ResultSource::RowParser::Util::null_branch_class ) },
     ],
     [
       { cdid => 3, single_track => 6, artist => 1, genreid => 1, year => 1978, title => "Equinoxe" },
@@ -218,6 +255,12 @@ is_deeply(
               { artistid => 1, name => 'JMJ', charfield => undef, rank => 13 },
               { cds => [
                 [
+                  { cdid => 4, single_track => undef, artist => 1, genreid => undef, year => 1977, title => "fuzzy_1" },
+                  { tracks => bless( [
+                    [ { trackid => undef, title => undef, position => undef, cd => undef, last_updated_at => undef, last_updated_on => undef } ],
+                  ], $DBIx::Class::ResultSource::RowParser::Util::null_branch_class ) },
+                ],
+                [
                   { cdid => 1, single_track => undef, artist => 1, genreid => 1, year => 1981, title => "Magnetic Fields" },
                   { tracks => [
                     [ { trackid => 1, title => 'm1', position => 1, cd => 1, last_updated_at => undef, last_updated_on => undef } ],
@@ -247,11 +290,31 @@ is_deeply(
         ] }
       ] }
     ],
+    [
+      { cdid => 4, single_track => undef, artist => 1, genreid => undef, year => 1977, title => "fuzzy_1" },
+      { single_track => bless( [
+        { trackid => undef, title => undef, position => undef, cd => undef, last_updated_at => undef, last_updated_on => undef },
+        {  cd => [
+          { cdid => undef, single_track => undef, artist => undef, genreid => undef, year => undef, title => undef },
+          {
+            artist => [
+              { artistid => undef, name => undef, charfield => undef, rank => undef },
+              { cds => bless( [ [
+                { cdid => undef, single_track => undef, artist => undef, genreid => undef, year => undef, title => undef },
+                { tracks => bless( [ [
+                  { trackid => undef, title => undef, position => undef, cd => undef, last_updated_at => undef, last_updated_on => undef },
+                ] ], $DBIx::Class::ResultSource::RowParser::Util::null_branch_class ) },
+              ] ], $DBIx::Class::ResultSource::RowParser::Util::null_branch_class ) },
+            ],
+          },
+        ] },
+      ], $DBIx::Class::ResultSource::RowParser::Util::null_branch_class ) },
+    ],
   ],
-  'Collapsing 1:1 ending in chained has_many with classic prefetch ok'
+  'Collapsing 1:1 ending in chained has_many with classic prefetch'
 );
 
-is_deeply (
+cmp_structures (
   ([$schema->resultset ('Artist')->search ({}, {
     result_class => 'DBICTest::_IRCapture',
     join => { cds => 'tracks' },
@@ -343,8 +406,24 @@ is_deeply (
         ]},
       ]},
     ],
+    [
+      { artistid => 1, name => 'JMJ', charfield => undef, rank => 13 },
+      { cds => [
+        { cdid => 4, single_track => undef, artist => 1, genreid => undef, year => 1977, title => "fuzzy_1" },
+        { tracks => bless( [
+          { trackid => undef, title => undef, position => undef, cd => undef, last_updated_at => undef, last_updated_on => undef },
+        ], $DBIx::Class::ResultSource::RowParser::Util::null_branch_class ) },
+      ]},
+    ],
   ],
-  'Non-Collapsing chained has_many ok'
+  'Non-Collapsing chained has_many'
 );
 
+sub cmp_structures {
+  my ($left, $right, $msg) = @_;
+
+  local $Test::Builder::Level = $Test::Builder::Level + 1;
+  cmp_deeply($left, $right, $msg||());
+}
+
 done_testing;