This is an automated email from the git hooks/post-receive script.

js pushed a commit to annotated tag 0.07
in repository libdancer-plugin-rest-perl.

commit 20c20147328c09129e959db272c5731aad7a7d9e
Author: Alexis Sukrieh <suk...@sukria.net>
Date:   Sat Apr 3 17:25:28 2010 +0200

    test script for resource
---
 t/03_resource.t | 84 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 84 insertions(+)

diff --git a/t/03_resource.t b/t/03_resource.t
new file mode 100644
index 0000000..f6a25e8
--- /dev/null
+++ b/t/03_resource.t
@@ -0,0 +1,84 @@
+use strict;
+use warnings;
+use Dancer::ModuleLoader;
+use Test::More import => ['!pass'];
+
+plan tests => 7;
+
+{
+    package Webservice;
+    use Dancer;
+    use Dancer::Plugin::REST;
+
+    resource user => 
+        'get' => \&on_get_user,
+        'create' => \&on_create_user,
+        'delete' => \&on_delete_user,
+        'update' => \&on_update_user;
+
+    my $users = {};
+    my $last_id = 0;
+
+    sub on_get_user {
+        my $id = params->{'id'};
+        { user => $users->{$id} };
+    }
+
+    sub on_create_user {
+        my $id = ++$last_id;
+        my $user = params('body');
+        $user->{id} = $id;
+        $users->{$id} = $user;
+
+        { user => $users->{$id} };
+    }
+
+    sub on_delete_user {
+        my $id = params->{'id'};
+        my $deleted = $users->{$id};
+        delete $users->{$id};
+        { user => $deleted };
+    }
+
+    sub on_update_user {
+        my $id = params->{'id'};
+        my $user = $users->{$id};
+        return { user => undef } unless defined $user;
+
+        $users->{$id} = { %$user, %{params('body')} };
+        { user => $users->{$id} };
+    }
+}
+
+use lib 't';
+use TestUtils;
+
+my $r = get_response_for_request(GET => '/user/1');
+is_deeply $r->{content}, {user => undef},
+    "user 1 is not defined";
+
+$r = get_response_for_request(POST => '/user', { name => 'Alexis' });
+is_deeply $r->{content}, { user => { id => 1, name => "Alexis" } },
+    "create user works";
+
+$r = get_response_for_request(GET => '/user/1');
+is_deeply $r->{content}, {user => { id => 1, name => 'Alexis'}},
+    "user 1 is defined";
+
+$r = get_response_for_request(PUT => '/user/1', { nick => 'sukria', name =>
+'Alexis Sukrieh' });
+is_deeply $r->{content}, {user => { id => 1, name => 'Alexis Sukrieh', nick => 
'sukria'}},
+    "user 1 is updated";
+
+$r = get_response_for_request(DELETE => '/user/1');
+is_deeply $r->{content}, {user => { id => 1, name => 'Alexis Sukrieh', nick => 
'sukria'}},
+    "user 1 is deleted";
+
+$r = get_response_for_request(GET => '/user/1');
+is_deeply $r->{content}, {user => undef},
+    "user 1 is not defined";
+
+$r = get_response_for_request(POST => '/user', { name => 'Franck Cuny' });
+is_deeply $r->{content}, { user => { id => 2, name => "Franck Cuny" } },
+    "id is correctly increased";
+

-- 
Alioth's /usr/local/bin/git-commit-notice on 
/srv/git.debian.org/git/pkg-perl/packages/libdancer-plugin-rest-perl.git

_______________________________________________
Pkg-perl-cvs-commits mailing list
Pkg-perl-cvs-commits@lists.alioth.debian.org
http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/pkg-perl-cvs-commits

Reply via email to