Properly handle empty group_by/order_by
[dbsrgits/DBIx-Class.git] / t / search / empty_attrs.t
diff --git a/t/search/empty_attrs.t b/t/search/empty_attrs.t
new file mode 100644 (file)
index 0000000..3b52487
--- /dev/null
@@ -0,0 +1,51 @@
+use strict;
+use warnings;
+
+use Test::More;
+
+use lib qw(t/lib);
+use DBICTest ':DiffSQL';
+
+my $schema = DBICTest->init_schema();
+
+my $rs = $schema->resultset('Artist')->search(
+  [ -and => [ {}, [] ], -or => [ {}, [] ] ],
+  {
+    select => [],
+    columns => {},
+    '+columns' => 'artistid',
+    join => [ {}, [ [ {}, {} ] ], {} ],
+    prefetch => [ [ [ {}, [] ], {} ], {}, [ {} ] ],
+    order_by => [],
+    group_by => [],
+    offset => 0,
+  }
+);
+
+is_same_sql_bind(
+  $rs->as_query,
+  '(SELECT me.artistid FROM artist me)',
+  [],
+);
+
+is_same_sql_bind(
+  $rs->count_rs->as_query,
+  '(SELECT COUNT(*) FROM artist me)',
+  [],
+);
+
+is_same_sql_bind(
+  $rs->as_subselect_rs->search({}, { columns => 'artistid' })->as_query,
+  '(SELECT me.artistid FROM (SELECT me.artistid FROM artist me) me)',
+  [],
+);
+
+{
+  local $TODO = 'Stupid misdesigned as_subselect_rs';
+  is_same_sql_bind(
+    $rs->as_subselect_rs->as_query,
+    $rs->as_subselect_rs->search({}, { columns => 'artistid' })->as_query,
+  );
+}
+
+done_testing;