[Rt-commit] rt branch, 4.0/simple-search-cf-dashes, created. rt-4.0.5-135-gb42a867

Jim Brandt jbrandt at bestpractical.com
Fri May 4 14:52:25 EDT 2012


The branch, 4.0/simple-search-cf-dashes has been created
        at  b42a867f7280f79f7d43f382abaa8cc509e44002 (commit)

- Log -----------------------------------------------------------------
commit b42a867f7280f79f7d43f382abaa8cc509e44002
Author: Jim Brandt <jbrandt at bestpractical.com>
Date:   Fri May 4 14:31:12 2012 -0400

    Allow dashes in cf names in simple search.
    
    Added - (dash) to the regex that parses cfs in simple search.
    Was conservative and added just the dash. There may
    be other characters for cf names that could be allowed.

diff --git a/lib/RT/Search/Googleish.pm b/lib/RT/Search/Googleish.pm
index a125483..f6f5224 100644
--- a/lib/RT/Search/Googleish.pm
+++ b/lib/RT/Search/Googleish.pm
@@ -110,7 +110,7 @@ sub QueryToSQL {
                             (\w+)  # A straight word
                             (?:\.  # With an optional .foo
                                 ($RE{delimited}{-delim=>q['"]}
-                                |\w+
+                                |[\w-]+  # Allow \w + dashes
                                 ) # Which could be ."foo bar", too
                             )?
                         )
diff --git a/t/web/search_simple.t b/t/web/search_simple.t
index 1efc9a5..a1a3ce8 100644
--- a/t/web/search_simple.t
+++ b/t/web/search_simple.t
@@ -1,7 +1,7 @@
 use strict;
 use warnings;
 
-use RT::Test tests => 16;
+use RT::Test tests => 30;
 my ( $baseurl, $m ) = RT::Test->started_ok;
 
 RT::Test->create_tickets(
@@ -19,4 +19,58 @@ $m->content_contains( 'Show Results',   "has page menu" );
 $m->title_is( 'Found 1 ticket', 'title' );
 $m->content_contains( 'ticket foo', 'has ticket foo' );
 
+# Test searches on custom fields
+my $cf1 = RT::Test->load_or_create_custom_field(
+                      Name  => 'Location',
+                      Queue => 'General',
+                      Type  => 'FreeformSingle', );
+isa_ok( $cf1, 'RT::CustomField' );
+
+my $cf2 = RT::Test->load_or_create_custom_field(
+                      Name  => 'Server-name',
+                      Queue => 'General',
+                      Type  => 'FreeformSingle', );
+isa_ok( $cf2, 'RT::CustomField' );
+
+my $t = RT::Ticket->new(RT->SystemUser);
+
+{
+  my ($id,undef,$msg) = $t->Create(
+            Queue => 'General',
+            Subject => 'Test searching CFs');
+  ok( $id, "Created ticket - $msg" );
+}
+
+{
+  my ($status, $msg) = $t->AddCustomFieldValue(
+                           Field => $cf1->id,
+			   Value => 'Downtown');
+  ok( $status, "Added CF value - $msg" );
+}
+
+{
+  my ($status, $msg) = $t->AddCustomFieldValue(
+                           Field => $cf2->id,
+			   Value => 'Proxy');
+  ok( $status, "Added CF value - $msg" );
+}
+
+# Regular search
+my $search = 'cf.Location:Downtown';
+$m->get_ok("/Search/Simple.html?q=$search");
+$m->title_is( 'Found 1 ticket', 'Found 1 ticket' );
+$m->text_contains( 'Test searching CFs', "Found test CF ticket with $search" );
+
+# Case insensitive
+$search = "cf.Location:downtown";
+$m->get_ok("/Search/Simple.html?q=$search");
+$m->title_is( 'Found 1 ticket', 'Found 1 ticket' );
+$m->text_contains( 'Test searching CFs', "Found test CF ticket with $search" );
+
+# With dash in CF name
+$search = "cf.Server-name:Proxy";
+$m->get_ok("/Search/Simple.html?q=$search");
+$m->title_is( 'Found 1 ticket', 'Found 1 ticket' );
+$m->text_contains( 'Test searching CFs', "Found test CF ticket with $search" );
+
 # TODO more simple search tests

-----------------------------------------------------------------------


More information about the Rt-commit mailing list