[Bps-public-commit] rt-extension-rest2 branch, master, updated. 54644d5efc09d41d086db7a6569a2824b459bef5
Jim Brandt
jbrandt at bestpractical.com
Thu Sep 7 14:23:39 EDT 2017
The branch, master has been updated
via 54644d5efc09d41d086db7a6569a2824b459bef5 (commit)
via 599f7321d845b8a2d71db0b5626add5eb1534896 (commit)
via 17a1e2de86db66a018c384a46171d8c6be6806cd (commit)
via 5751d4c58361ca7d63952fcce3d1cfd269ab007c (commit)
via 8e4b8748505d06d0e91673eea0b1ee7c6c3dc6c1 (commit)
from 746bb0c6308d4d016209e8eb0689a90b347a25fc (commit)
Summary of changes:
lib/RT/Extension/REST2/Util.pm | 5 +----
t/organization.t | 44 ++++++++++++++++++++++++++++++++++++++++++
2 files changed, 45 insertions(+), 4 deletions(-)
- Log -----------------------------------------------------------------
commit 8e4b8748505d06d0e91673eea0b1ee7c6c3dc6c1
Author: Jim Brandt <jbrandt at bestpractical.com>
Date: Thu Sep 7 13:36:31 2017 -0400
Organization isn't always part of the uid
Make the Organization part of the uid optional to handle
formats like RT::User-test.
Also revert to capturing regex matches directly to the
class and id variables.
diff --git a/lib/RT/Extension/REST2/Util.pm b/lib/RT/Extension/REST2/Util.pm
index 143472b..675a3fb 100644
--- a/lib/RT/Extension/REST2/Util.pm
+++ b/lib/RT/Extension/REST2/Util.pm
@@ -34,10 +34,7 @@ sub expand_uid {
return if not defined $uid;
my $Organization = RT->Config->Get('Organization');
- my ($class, $id);
- if ($uid =~ /^([\w:]+)-\Q$Organization\E-(.+)$/) {
- ($class, $id) = ($1, $2);
- }
+ my ($class, $id) = $uid =~ /^([\w:]+)(?:-\Q$Organization\E)?-(.+)$/;
return unless $class and $id;
commit 5751d4c58361ca7d63952fcce3d1cfd269ab007c
Author: Jim Brandt <jbrandt at bestpractical.com>
Date: Thu Sep 7 13:39:00 2017 -0400
Add tests for expand_uid
diff --git a/t/organization.t b/t/organization.t
index a9fb831..b9bae67 100644
--- a/t/organization.t
+++ b/t/organization.t
@@ -3,6 +3,22 @@ use warnings;
use lib 't/lib';
use RT::Extension::REST2::Test tests => undef;
+use_ok('RT::Extension::REST2::Util', qw(expand_uid));
+
+{
+ my $base_url = RT::Extension::REST2->base_uri;
+ my $uid_parts = expand_uid('RT::User-test');
+
+ is($uid_parts->{'type'}, 'user', 'Got correct class');
+ is($uid_parts->{'id'}, 'test', 'Got correct id');
+ is($uid_parts->{'_url'}, $base_url . '/user/test', 'Got correct url');
+
+ $uid_parts = expand_uid('RT::CustomField-example.com-3');
+ is($uid_parts->{'type'}, 'customfield', 'Got correct class');
+ is($uid_parts->{'id'}, '3', 'Got correct id');
+ is($uid_parts->{'_url'}, $base_url . '/customfield/3', 'Got correct url');
+}
+
RT->Config->Set('Organization', 'name-with-dashes');
my $mech = RT::Extension::REST2::Test->mech;
commit 17a1e2de86db66a018c384a46171d8c6be6806cd
Author: Jim Brandt <jbrandt at bestpractical.com>
Date: Thu Sep 7 14:15:33 2017 -0400
Handle usernames with dashes
Make the uid match greedy to grab all remaining characters
at the end, including dashes that are part of a username.
diff --git a/lib/RT/Extension/REST2/Util.pm b/lib/RT/Extension/REST2/Util.pm
index 675a3fb..1a03364 100644
--- a/lib/RT/Extension/REST2/Util.pm
+++ b/lib/RT/Extension/REST2/Util.pm
@@ -34,7 +34,7 @@ sub expand_uid {
return if not defined $uid;
my $Organization = RT->Config->Get('Organization');
- my ($class, $id) = $uid =~ /^([\w:]+)(?:-\Q$Organization\E)?-(.+)$/;
+ my ($class, $id) = $uid =~ /^([\w:]+)(?:-\Q$Organization\E)?-(.+)$/g;
return unless $class and $id;
commit 599f7321d845b8a2d71db0b5626add5eb1534896
Author: Jim Brandt <jbrandt at bestpractical.com>
Date: Thu Sep 7 14:16:43 2017 -0400
Tests with a username with dashes
diff --git a/t/organization.t b/t/organization.t
index b9bae67..899b734 100644
--- a/t/organization.t
+++ b/t/organization.t
@@ -7,12 +7,18 @@ use_ok('RT::Extension::REST2::Util', qw(expand_uid));
{
my $base_url = RT::Extension::REST2->base_uri;
- my $uid_parts = expand_uid('RT::User-test');
+ my $uid_parts = expand_uid('RT::User-test');
is($uid_parts->{'type'}, 'user', 'Got correct class');
is($uid_parts->{'id'}, 'test', 'Got correct id');
is($uid_parts->{'_url'}, $base_url . '/user/test', 'Got correct url');
+ # User with dashes in the username
+ $uid_parts = expand_uid('RT::User-test-user');
+ is($uid_parts->{'type'}, 'user', 'Got correct class');
+ is($uid_parts->{'id'}, 'test-user', 'Got correct id');
+ is($uid_parts->{'_url'}, $base_url . '/user/test-user', 'Got correct url');
+
$uid_parts = expand_uid('RT::CustomField-example.com-3');
is($uid_parts->{'type'}, 'customfield', 'Got correct class');
is($uid_parts->{'id'}, '3', 'Got correct id');
commit 54644d5efc09d41d086db7a6569a2824b459bef5
Author: Jim Brandt <jbrandt at bestpractical.com>
Date: Thu Sep 7 14:23:06 2017 -0400
Re-run expand_uid tests with dashed org name
diff --git a/t/organization.t b/t/organization.t
index 899b734..c667791 100644
--- a/t/organization.t
+++ b/t/organization.t
@@ -5,6 +5,7 @@ use RT::Extension::REST2::Test tests => undef;
use_ok('RT::Extension::REST2::Util', qw(expand_uid));
+diag "Test expand_uid with default RT Organization of example.com";
{
my $base_url = RT::Extension::REST2->base_uri;
@@ -27,6 +28,27 @@ use_ok('RT::Extension::REST2::Util', qw(expand_uid));
RT->Config->Set('Organization', 'name-with-dashes');
+diag "Test expand_uid with Organization name with dashes";
+{
+ my $base_url = RT::Extension::REST2->base_uri;
+
+ my $uid_parts = expand_uid('RT::User-test');
+ is($uid_parts->{'type'}, 'user', 'Got correct class');
+ is($uid_parts->{'id'}, 'test', 'Got correct id');
+ is($uid_parts->{'_url'}, $base_url . '/user/test', 'Got correct url');
+
+ # User with dashes in the username
+ $uid_parts = expand_uid('RT::User-test-user');
+ is($uid_parts->{'type'}, 'user', 'Got correct class');
+ is($uid_parts->{'id'}, 'test-user', 'Got correct id');
+ is($uid_parts->{'_url'}, $base_url . '/user/test-user', 'Got correct url');
+
+ $uid_parts = expand_uid('RT::CustomField-name-with-dashes-3');
+ is($uid_parts->{'type'}, 'customfield', 'Got correct class');
+ is($uid_parts->{'id'}, '3', 'Got correct id');
+ is($uid_parts->{'_url'}, $base_url . '/customfield/3', 'Got correct url');
+}
+
my $mech = RT::Extension::REST2::Test->mech;
my $auth = RT::Extension::REST2::Test->authorization_header;
my $rest_base_path = '/REST/2.0';
-----------------------------------------------------------------------
More information about the Bps-public-commit
mailing list