Fix busted get_column when using +select (and friends)
[dbsrgits/DBIx-Class.git] / t / 76select.t
index ca04b26..ca6a5e9 100644 (file)
@@ -8,7 +8,7 @@ use DBICTest;
 
 my $schema = DBICTest->init_schema();
 
-plan tests => 11;
+plan tests => 13;
 
 my $rs = $schema->resultset('CD')->search({},
     {
@@ -28,6 +28,16 @@ $rs = $schema->resultset('CD')->search({},
 lives_ok(sub { $rs->first->get_column('count') }, 'multiple +select/+as columns, 1st rscolumn present');
 lives_ok(sub { $rs->first->get_column('addedtitle') }, 'multiple +select/+as columns, 2nd rscolumn present');
 
+# Tests a regression in ResultSetColumn wrt +select
+my $rs = $schema->resultset('CD')->search(undef,
+    {
+        '+select'   => [ \'COUNT(*) AS year_count' ],
+               order_by => 'year_count'
+       }
+);
+my @counts = $rs->get_column('cdid')->all;
+ok(scalar(@counts), 'got rows from ->all using +select');
+
 $rs = $schema->resultset('CD')->search({},
     {
         '+select'   => [ \ 'COUNT(*)', 'title' ],
@@ -49,7 +59,6 @@ lives_ok(sub { $rs->first->get_column('addedtitle2') }, '+select/+as chained sea
 #
 # from doesn't seem to be useful without using a scalarref - there were no initial tests >:(
 #
-$schema->storage->debug (1);
 my $cds = $schema->resultset ('CD')->search ({}, { order_by => 'me.cdid'}); # make sure order is consistent
 cmp_ok ($cds->count, '>', 2, 'Initially populated with more than 2 CDs');
 
@@ -62,3 +71,5 @@ my $subsel = $cds->search ({}, {
 is ($subsel->count, 2, 'Subselect correctly limited the rs to 2 cds');
 is ($subsel->next->title, $cds->next->title, 'First CD title match');
 is ($subsel->next->title, $cds->next->title, 'Second CD title match');
+
+is($schema->resultset('CD')->current_source_alias, "me", '$rs->current_source_alias returns "me"');