[Bps-public-commit] rt-extension-rest2 branch, dev, updated. 409245a6ed745abe4760733dc8874c0b10c8fcb4
Wallace Reis
wreis at bestpractical.com
Thu Feb 12 14:16:19 EST 2015
The branch, dev has been updated
via 409245a6ed745abe4760733dc8874c0b10c8fcb4 (commit)
via 0059391a7cf78d86d2b26087351724c6f40e18ca (commit)
via b2cd8a1b06e0ddc51312e137ab58ed7fec7e2d08 (commit)
from bb549d006e8fca3323a519879aec40411c92addf (commit)
Summary of changes:
lib/RT/Extension/REST2/Dispatcher.pm | 17 ++++++++------
t/acceptance/main.t | 43 ++++++++++++++++++++++++++++++++----
t/acceptance/not_found.t | 25 +++++++++++++++++++++
t/lib/RT/Extension/REST2/Test.pm | 2 ++
4 files changed, 76 insertions(+), 11 deletions(-)
create mode 100644 t/acceptance/not_found.t
- Log -----------------------------------------------------------------
commit b2cd8a1b06e0ddc51312e137ab58ed7fec7e2d08
Author: Wallace Reis <wreis at bestpractical.com>
Date: Wed Feb 11 21:34:56 2015 -0200
Tests for main endpoint
diff --git a/t/acceptance/main.t b/t/acceptance/main.t
index 29c92f8..9968bb9 100644
--- a/t/acceptance/main.t
+++ b/t/acceptance/main.t
@@ -4,9 +4,36 @@ use lib 't/lib';
use RT::Extension::REST2::Test tests => undef;
my $mech = RT::Extension::REST2::Test->mech;
-ok(my $res = $mech->get('/'));
-is($res->code, 401, 'Unauthorized');
-is($res->content, 'Authorization required');
-like($res->header('www-authenticate'), qr/example\.com\s+API/);
+
+my $rest_base_path = '/REST/2.0';
+
+{
+ ok(my $res = $mech->get($rest_base_path), "GET $rest_base_path");
+ is($res->code, 401, 'Unauthorized');
+ is($res->content, 'Authorization required');
+ like($res->header('content-type'), qr{text/plain});
+ like($res->header('www-authenticate'), qr/example\.com\s+REST\s+API/);
+}
+
+my $auth = RT::Extension::REST2::Test->authorization_header;
+
+{
+ foreach my $path (($rest_base_path, "${rest_base_path}/")) {
+ $mech->get_ok($path, ['Authorization' => $auth]);
+ my $res = $mech->response;
+ like($res->header('content-type'), qr{text/html});
+ my $content = $res->content;
+ # this is a temp solution as for main doc
+ # TODO: write an end user aimed documentation
+ like($content, qr/RT\-Extension\-REST2/);
+ like($content, qr/NAME/);
+ like($content, qr/INSTALLATION/);
+ like($content, qr/USAGE/);
+
+ ok($res = $mech->head($path, 'Authorization' => $auth),
+ "HEAD $path");
+ is($res->code, 200);
+ }
+}
done_testing;
diff --git a/t/lib/RT/Extension/REST2/Test.pm b/t/lib/RT/Extension/REST2/Test.pm
index fe97952..16abb5d 100644
--- a/t/lib/RT/Extension/REST2/Test.pm
+++ b/t/lib/RT/Extension/REST2/Test.pm
@@ -13,4 +13,6 @@ sub mech {
);
}
+sub authorization_header { return 'Basic cm9vdDpwYXNzd29yZA==' }
+
1;
commit 0059391a7cf78d86d2b26087351724c6f40e18ca
Author: Wallace Reis <wreis at bestpractical.com>
Date: Thu Feb 12 13:09:46 2015 -0200
Fix main endpoint dispatching
diff --git a/lib/RT/Extension/REST2/Dispatcher.pm b/lib/RT/Extension/REST2/Dispatcher.pm
index d64908f..cc78a99 100644
--- a/lib/RT/Extension/REST2/Dispatcher.pm
+++ b/lib/RT/Extension/REST2/Dispatcher.pm
@@ -5,16 +5,10 @@ use warnings;
use Web::Simple;
use Web::Machine;
use RT::Extension::REST2::PodViewer 'podview_as_html';
+use Web::Dispatch::HTTPMethods;
sub dispatch_request {
my ($self) = @_;
- sub (/) {
- return [
- 200,
- ['Content-Type' => 'text/html; charset=utf-8'],
- [ podview_as_html('RT::Extension::REST2') ]
- ];
- },
sub (/*/*) {
my $resource_name = ucfirst lc $_[1];
my $resource = "RT::Extension::REST2::Resource::${resource_name}";
@@ -27,6 +21,15 @@ sub dispatch_request {
return undef;
}
},
+ sub () {
+ my $main = [
+ 200,
+ ['Content-Type' => 'text/html; charset=utf-8'],
+ [ podview_as_html('RT::Extension::REST2') ]
+ ];
+ sub (~) { GET { $main } },
+ sub (/) { GET { $main } },
+ }
}
1;
commit 409245a6ed745abe4760733dc8874c0b10c8fcb4
Author: Wallace Reis <wreis at bestpractical.com>
Date: Thu Feb 12 14:24:24 2015 -0200
Tests for unsupported requests
diff --git a/t/acceptance/main.t b/t/acceptance/main.t
index 9968bb9..a80debc 100644
--- a/t/acceptance/main.t
+++ b/t/acceptance/main.t
@@ -36,4 +36,12 @@ my $auth = RT::Extension::REST2::Test->authorization_header;
}
}
+{
+ ok(my $res = $mech->post(
+ $rest_base_path, { param => 'value' }, 'Authorization' => $auth
+ ), "POST $rest_base_path");
+ is($res->code, 405);
+ like($res->header('allow'), qr/GET|HEAD|OPTIONS/);
+}
+
done_testing;
diff --git a/t/acceptance/not_found.t b/t/acceptance/not_found.t
new file mode 100644
index 0000000..a9eb01f
--- /dev/null
+++ b/t/acceptance/not_found.t
@@ -0,0 +1,25 @@
+use strict;
+use warnings;
+use lib 't/lib';
+use RT::Extension::REST2::Test tests => undef;
+
+my $mech = RT::Extension::REST2::Test->mech;
+
+my $auth = RT::Extension::REST2::Test->authorization_header;
+my $rest_base_path = '/REST/2.0';
+
+{
+ for (qw[/foobar /foo /ticket /queue /index.html /ticket.do/1 /1/1]) {
+ my $path = $rest_base_path . $_;
+ ok(my $res = $mech->get($path, 'Authorization' => $auth),
+ "GET $path");
+ is($res->code, 404);
+
+ ok($res = $mech->post(
+ $path, { param => 'value' }, 'Authorization' => $auth
+ ), "POST $path");
+ is($res->code, 404);
+ }
+}
+
+done_testing;
-----------------------------------------------------------------------
More information about the Bps-public-commit
mailing list