[Rt-commit] r3625 - in DBIx-SearchBuilder/trunk: . t

glasser at bestpractical.com glasser at bestpractical.com
Tue Aug 9 17:37:42 EDT 2005


Author: glasser
Date: Tue Aug  9 17:37:41 2005
New Revision: 3625

Modified:
   DBIx-SearchBuilder/trunk/   (props changed)
   DBIx-SearchBuilder/trunk/SearchBuilder.pm
   DBIx-SearchBuilder/trunk/t/01searches.t
Log:
 r39287 at tin-foil:  glasser | 2005-08-09 17:37:05 -0400
 Because SearchBuilder has the unfortunate historical feature of adding 
 % around LIKE values in Limits, add a MATCHES operators that... doesn't do that.
 (For Jifty::DBI, we will make LIKE do what MATCHES does here, and CONTAINS do
 what LIKE does here.)


Modified: DBIx-SearchBuilder/trunk/SearchBuilder.pm
==============================================================================
--- DBIx-SearchBuilder/trunk/SearchBuilder.pm	(original)
+++ DBIx-SearchBuilder/trunk/SearchBuilder.pm	Tue Aug  9 17:37:41 2005
@@ -645,6 +645,11 @@
 
 ENDSWITH is like LIKE, except it prepends a % to the beginning of the string
 
+=item "MATCHES"
+
+MATCHES is equivalent to the database's LIKE -- that is, it's actually LIKE, but
+doesn't surround the string in % signs as LIKE does.
+
 =back
 
 =item ENTRYAGGREGATOR 
@@ -694,7 +699,9 @@
         elsif ( $args{'OPERATOR'} =~ /ENDSWITH/i ) {
             $args{'VALUE'}    = "%" . $args{'VALUE'};
             $args{'OPERATOR'} = "LIKE";
-        }
+        } 
+	
+	$args{'OPERATOR'} =~ s/MATCHES/LIKE/i;  # MATCHES becomes LIKE, with no % stuff
 
         #if we're explicitly told not to to quote the value or
         # we're doing an IS or IS NOT (null), don't quote the operator.

Modified: DBIx-SearchBuilder/trunk/t/01searches.t
==============================================================================
--- DBIx-SearchBuilder/trunk/t/01searches.t	(original)
+++ DBIx-SearchBuilder/trunk/t/01searches.t	Tue Aug  9 17:37:41 2005
@@ -8,7 +8,7 @@
 BEGIN { require "t/utils.pl" }
 our (@AvailableDrivers);
 
-use constant TESTS_PER_DRIVER => 59;
+use constant TESTS_PER_DRIVER => 69;
 
 my $total = scalar(@AvailableDrivers) * TESTS_PER_DRIVER;
 plan tests => $total;
@@ -113,6 +113,30 @@
 	isa_ok( $first_rec, 'DBIx::SearchBuilder::Record', 'First returns record object' );
 	is( $first_rec->Login, 'glasser', 'login is correct' );
 
+	# MATCHES
+	$users_obj->CleanSlate;
+	is_deeply( $users_obj, $clean_obj, 'after CleanSlate looks like new object');
+	$users_obj->Limit( FIELD => 'Name', OPERATOR => 'MATCHES', VALUE => 'lass' );
+	is( $users_obj->Count, 0, "found no user matching 'lass' in the name" );
+
+	$users_obj->CleanSlate;
+	is_deeply( $users_obj, $clean_obj, 'after CleanSlate looks like new object');
+	$users_obj->Limit( FIELD => 'Name', OPERATOR => 'MATCHES', VALUE => '%lass' );
+	is( $users_obj->Count, 0, "found no user matching '%lass' in the name" );
+
+	$users_obj->CleanSlate;
+	is_deeply( $users_obj, $clean_obj, 'after CleanSlate looks like new object');
+	$users_obj->Limit( FIELD => 'Name', OPERATOR => 'MATCHES', VALUE => 'lass%' );
+	is( $users_obj->Count, 0, "found no user matching 'lass%' in the name" );
+
+	$users_obj->CleanSlate;
+	is_deeply( $users_obj, $clean_obj, 'after CleanSlate looks like new object');
+	$users_obj->Limit( FIELD => 'Name', OPERATOR => 'MATCHES', VALUE => '%lass%' );
+	is( $users_obj->Count, 1, "found one user matching '%lass%' in the name" );
+	$first_rec = $users_obj->First;
+	isa_ok( $first_rec, 'DBIx::SearchBuilder::Record', 'First returns record object' );
+	is( $first_rec->Login, 'glasser', 'login is correct' );
+
 	# STARTSWITH
 	$users_obj->CleanSlate;
 	is_deeply( $users_obj, $clean_obj, 'after CleanSlate looks like new object');


More information about the Rt-commit mailing list