[Rt-commit] r2617 - in rt/branches/3.4-RELEASE/lib: RT t/regression
tla at bestpractical.com
tla at bestpractical.com
Tue Apr 12 21:52:54 EDT 2005
Author: tla
Date: Tue Apr 12 21:52:54 2005
New Revision: 2617
Modified:
rt/branches/3.4-RELEASE/lib/RT/SavedSearch.pm
rt/branches/3.4-RELEASE/lib/RT/SavedSearches.pm
rt/branches/3.4-RELEASE/lib/t/regression/20savedsearch.t
Log:
Added delete method & localized strings in SavedSearch
Made SavedSearches::LimitByPrivacy safe to call multiple times
Modified: rt/branches/3.4-RELEASE/lib/RT/SavedSearch.pm
==============================================================================
--- rt/branches/3.4-RELEASE/lib/RT/SavedSearch.pm (original)
+++ rt/branches/3.4-RELEASE/lib/RT/SavedSearch.pm Tue Apr 12 21:52:54 2005
@@ -85,6 +85,8 @@
Takes a privacy specification, an object ID, and a search ID. Loads
the given search ID if it belongs to the stated user or group.
+Returns a tuple of status and message, where status is true on
+success.
=begin testing
@@ -104,12 +106,15 @@
$self->{'Id'} = $self->{'Attribute'}->Id;
$self->{'Privacy'} = $privacy;
$self->{'Type'} = $self->{'Attribute'}->SubValue('SearchType');
+ return (1, $self->loc("Loaded search [_1]", $self->Name));
} else {
$RT::Logger->error("Could not load attribute " . $id
. " for object " . $privacy);
+ return (0, $self->loc("Search attribute load failure"));
}
} else {
$RT::Logger->error("Could not load object $privacy when loading search");
+ return (0, $self->loc("Could not load object for [_1]", $privacy));
}
}
@@ -118,7 +123,8 @@
Takes a privacy, an optional type, a name, and a hashref containing the
search parameters. Saves the given parameters to the appropriate user/
-group object, and loads the resulting search. Defaults are:
+group object, and loads the resulting search. Returns a tuple of status
+and message, where status is true on success. Defaults are:
Privacy: undef
Type: Ticket
Name: "new search"
@@ -150,9 +156,13 @@
$self->{'Id'} = $att_id;
$self->{'Privacy'} = $privacy;
$self->{'Type'} = $type;
+ return (1, $self->loc("Saved search [_1]", $name));
} else {
$RT::Logger->error("SavedSearch save failure: $att_msg");
+ return (0, $self->loc("Failed to create search attribute"));
}
+ } else {
+ return (0, $self->loc("Failed to load object for [_1]", $privacy));
}
}
@@ -167,12 +177,33 @@
my $self = shift;
my $params = shift;
- return(0, "No search loaded!") unless $self->Id;
- return(0, "Could not load search attribute")
+ return(0, $self->loc("No search loaded")) unless $self->Id;
+ return(0, $self->loc("Could not load search attribute"))
unless $self->{'Attribute'}->Id;
my ($status, $msg) = $self->{'Attribute'}->SetSubValues(%{$params});
- return ($status, $msg);
+ if ($status) {
+ # Update all the accessor variables.
+ return ($status, $self->loc("Search update: [_1]", $msg));
+}
+
+=head2 Delete
+
+Deletes the existing search. Returns a tuple of status and message,
+where status is true upon success.
+
+=cut
+
+sub Delete {
+ my $self = shift;
+
+ my ($status, $msg) = $self->{'Attribute'}->Delete;
+ if ($status) {
+ return (1, $self->loc("Deleted search"));
+ } else {
+ return (0, $self->loc("Delete failed: [_1]", $msg));
+ }
}
+
### Accessor methods
Modified: rt/branches/3.4-RELEASE/lib/RT/SavedSearches.pm
==============================================================================
--- rt/branches/3.4-RELEASE/lib/RT/SavedSearches.pm (original)
+++ rt/branches/3.4-RELEASE/lib/RT/SavedSearches.pm Tue Apr 12 21:52:54 2005
@@ -89,7 +89,7 @@
by RT::SavedSearch::Type(). The SavedSearches object will load the
searches belonging to that user or group that are of the type
specified. If no type is specified, all the searches belonging to the
-user/group will be loaded.
+user/group will be loaded. Repeated calls to the same object should DTRT.
=begin testing
@@ -107,6 +107,7 @@
my $object = $self->_GetObject($privacy);
if ($object) {
+ $self->{'objects'} = [];
my @search_atts = $object->Attributes->Named('SavedSearch');
foreach my $att (@search_atts) {
my $search = RT::SavedSearch->new($self->CurrentUser);
Modified: rt/branches/3.4-RELEASE/lib/t/regression/20savedsearch.t
==============================================================================
--- rt/branches/3.4-RELEASE/lib/t/regression/20savedsearch.t (original)
+++ rt/branches/3.4-RELEASE/lib/t/regression/20savedsearch.t Tue Apr 12 21:52:54 2005
@@ -67,46 +67,45 @@
\'<small>__LastUpdatedRelative__</small>\',
\'<small>__TimeLeft__</small>\'';
+my ($ret, $msg);
my $mysearch = RT::SavedSearch->new($curruser);
-$mysearch->Save(Privacy => 'RT::User-' . $searchuser->Id,
- Type => 'Ticket',
- Name => 'owned by me',
- SearchParams => {'Format' => $format,
- 'Query' => "Owner = '"
- . $searchuser->Name . "'"});
-is($mysearch->Type, 'Ticket', "mysearch was created");
+($ret, $msg) = $mysearch->Save(Privacy => 'RT::User-' . $searchuser->Id,
+ Type => 'Ticket',
+ Name => 'owned by me',
+ SearchParams => {'Format' => $format,
+ 'Query' => "Owner = '"
+ . $searchuser->Name
+ . "'"});
+ok($ret, "mysearch was created");
my $groupsearch = RT::SavedSearch->new($curruser);
-$groupsearch->Save(Privacy => 'RT::Group-' . $ingroup->Id,
- Type => 'Ticket',
- Name => 'search queue',
- SearchParams => {'Format' => $format,
- 'Query' => "Queue = '"
- . $queue->Name . "'"});
-is($groupsearch->Type, 'Ticket', "groupsearch was created");
-like($groupsearch->GetParameter('Query'), qr/Queue/,
- "Retrieved query of groupsearch");
+($ret, $msg) = $groupsearch->Save(Privacy => 'RT::Group-' . $ingroup->Id,
+ Type => 'Ticket',
+ Name => 'search queue',
+ SearchParams => {'Format' => $format,
+ 'Query' => "Queue = '"
+ . $queue->Name . "'"});
+ok($ret, "groupsearch was created");
my $othersearch = RT::SavedSearch->new($curruser);
-$othersearch->Save(Privacy => 'RT::Group-' . $outgroup->Id,
- Type => 'Ticket',
- Name => 'searchuser requested',
- SearchParams => {'Format' => $format,
- 'Query' =>
- "Requestor.Name LIKE 'search'"});
-is($othersearch->Id, 0, "othersearch NOT created");
+($ret, $msg) = $othersearch->Save(Privacy => 'RT::Group-' . $outgroup->Id,
+ Type => 'Ticket',
+ Name => 'searchuser requested',
+ SearchParams => {'Format' => $format,
+ 'Query' =>
+ "Requestor.Name LIKE 'search'"});
+ok(!$ret, "othersearch NOT created");
+like($msg, qr/Failed to load object for/, "...for the right reason");
$othersearch = RT::SavedSearch->new($RT::SystemUser);
-$othersearch->Save(Privacy => 'RT::Group-' . $outgroup->Id,
- Type => 'Ticket',
- Name => 'searchuser requested',
- SearchParams => {'Format' => $format,
- 'Query' =>
- "Requestor.Name LIKE 'search'"});
-is($othersearch->Type, 'Ticket', "othersearch created by systemuser");
-like($othersearch->GetParameter('Query'), qr/Requestor/,
- "Retrieved query of othersearch");
+($ret, $msg) = $othersearch->Save(Privacy => 'RT::Group-' . $outgroup->Id,
+ Type => 'Ticket',
+ Name => 'searchuser requested',
+ SearchParams => {'Format' => $format,
+ 'Query' =>
+ "Requestor.Name LIKE 'search'"});
+ok($ret, "othersearch created by systemuser");
# Now try to load some searches.
@@ -172,3 +171,10 @@
my $allsearches = RT::SavedSearches->new($curruser);
$allsearches->LimitToPrivacy('RT::User-'.$curruser->Id);
is($allsearches->Count, 2, "Found all searchuser's searches");
+
+# Delete a search.
+($ret, $msg) = $genericsearch->Delete;
+ok($ret, "Deleted genericsearch");
+$allsearches->LimitToPrivacy('RT::User-'.$curruser->Id);
+is($allsearches->Count, 1, "Found all searchuser's searches after deletion");
+
More information about the Rt-commit
mailing list