Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Use ordered hash for point hints #46

Closed
wants to merge 2 commits into from

1 participant

Andrey Khozov
Andrey Khozov

No description provided.

Andrey Khozov

Replicated in a request #56, but without tests.

Andrey Khozov avkhozov closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Oct 16, 2012
  1. Andrey Khozov
  2. Andrey Khozov

    Improve tests.

    avkhozov authored
This page is out of date. Refresh to see the latest.
Showing with 29 additions and 3 deletions.
  1. +1 −1  lib/MongoDB/Cursor.pm
  2. +28 −2 t/cursor.t
2  lib/MongoDB/Cursor.pm
View
@@ -405,7 +405,7 @@ sub hint {
confess "cannot set hint after querying"
if $self->started_iterating;
confess 'not a hash reference'
- unless ref $index eq 'HASH';
+ unless ref $index eq 'HASH' || ref $index eq 'Tie::IxHash';
$self->_ensure_special;
$self->_query->{'$hint'} = $index;
30 t/cursor.t
View
@@ -19,7 +19,7 @@ if ($@) {
plan skip_all => $@;
}
else {
- plan tests => 74;
+ plan tests => 77;
}
my $db = $conn->get_database('test_database');
@@ -166,7 +166,7 @@ $cursor->reset;
$exp = $cursor->limit(-20)->explain;
is(20, $exp->{'n'});
-#hint
+# hint
$cursor->reset;
my $hinted = $cursor->hint({'x' => 1});
is($hinted, $cursor);
@@ -183,6 +183,32 @@ eval {
ok($@ =~ m/bad hint/);
+# ordered hint
+$cursor->reset;
+$hinted = $cursor->hint(Tie::IxHash->new('x' => 1));
+is($hinted, $cursor);
+
+$collection->drop;
+
+$collection->insert({'num' => 1, 'foo' => 1});
+
+$aok = 1;
+eval {
+ $collection->query->hint(Tie::IxHash->new('num' => 1, 'foo' => 1))->explain;
+ $aok = 0;
+};
+
+ok($@ =~ m/bad hint/);
+
+$collection->ensure_index(Tie::IxHash->new('num' => 1, 'foo' => 1));
+$aok = 1;
+eval {
+ $collection->find({num => 0, foo => 0})->hint(Tie::IxHash->new('num' => 1, 'foo' => 1))->explain;
+ $aok = 0;
+};
+
+ok($aok == 0);
+
# MongoDB::Cursor::slave_okay
$MongoDB::Cursor::slave_okay = 1;
$cursor = $collection->query->next;
Something went wrong with that request. Please try again.