Skip to content

Commit

Permalink
Autocomplete: Make it possible to change -postfix
Browse files Browse the repository at this point in the history
  • Loading branch information
judofyr committed Aug 23, 2011
1 parent 9242174 commit 7e9bd9b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/SolarBeam.pm
Expand Up @@ -37,8 +37,10 @@ sub search {
sub autocomplete {
my $callback = pop;
my ($self, $prefix, %options) = @_;
my $postfix = delete $options{'-postfix'} || '\w+';

$options{'regex.flag'} = 'case_insensitive';
$options{'regex'} = quotemeta($prefix) . '\w+';
$options{'regex'} = quotemeta($prefix) . $postfix;
my $options = { terms => \%options, -endpoint => 'terms' };

my $url = $self->build_url($options);
Expand Down
16 changes: 16 additions & 0 deletions t/search.t
Expand Up @@ -22,6 +22,22 @@ $mock->expect("/terms",

$sb->autocomplete('ost', fl => 'artifact.name', sub {});

$mock->expect("/terms",
wt => 'json',
terms => 'true',
'terms.fl' => 'artifact.name',
'terms.regex' => 'ost.*',
'terms.regex.flag' => 'case_insensitive'
);

$sb->autocomplete('ost',
-postfix => '.*',
fl => 'artifact.name',
sub { }
);

ok(!$sb->user_agent->{expect});

package UserAgentMock;
use Test::More;

Expand Down

0 comments on commit 7e9bd9b

Please sign in to comment.