[Jifty-commit] r1805 - in jifty/trunk/t/TestApp: lib/TestApp share/web/templates t

jifty-commit at lists.jifty.org jifty-commit at lists.jifty.org
Sun Aug 13 16:37:05 EDT 2006


Author: seanmil
Date: Sun Aug 13 16:37:01 2006
New Revision: 1805

Added:
   jifty/trunk/t/TestApp/share/web/templates/currentuser
   jifty/trunk/t/TestApp/t/11-current_user.t   (contents, props changed)
Modified:
   jifty/trunk/t/TestApp/lib/TestApp/Dispatcher.pm
   jifty/trunk/t/TestApp/lib/TestApp/Model/User.pm

Log:
* Add tests for current_user behavior

Modified: jifty/trunk/t/TestApp/lib/TestApp/Dispatcher.pm
==============================================================================
--- jifty/trunk/t/TestApp/lib/TestApp/Dispatcher.pm	(original)
+++ jifty/trunk/t/TestApp/lib/TestApp/Dispatcher.pm	Sun Aug 13 16:37:01 2006
@@ -49,4 +49,12 @@
     $after++;
 };
 
+on qr{/setuser/(.*)} => run {
+    my $name = $1;
+
+    my $current_user = TestApp::CurrentUser->new( name => $name );
+    Jifty->web->current_user( $current_user );
+    show '/index.html';
+};
+
 1;

Modified: jifty/trunk/t/TestApp/lib/TestApp/Model/User.pm
==============================================================================
--- jifty/trunk/t/TestApp/lib/TestApp/Model/User.pm	(original)
+++ jifty/trunk/t/TestApp/lib/TestApp/Model/User.pm	Sun Aug 13 16:37:01 2006
@@ -19,6 +19,9 @@
 use base qw/TestApp::Record/;
 
 # Your model-specific methods go here.
+sub current_user_can {
+    return 1;
+}
 
 1;
 

Added: jifty/trunk/t/TestApp/share/web/templates/currentuser
==============================================================================
--- (empty file)
+++ jifty/trunk/t/TestApp/share/web/templates/currentuser	Sun Aug 13 16:37:01 2006
@@ -0,0 +1,10 @@
+% if ( Jifty->web->current_user->id ) {
+Current user is <% Jifty->web->current_user->user_object->name %>
+%     if ( Jifty->web->current_user->is_superuser ) {
+The current user is a superuser.
+%     } else {
+The current user is not a superuser.
+%     }
+% } else {
+No current user set.
+% }

Added: jifty/trunk/t/TestApp/t/11-current_user.t
==============================================================================
--- (empty file)
+++ jifty/trunk/t/TestApp/t/11-current_user.t	Sun Aug 13 16:37:01 2006
@@ -0,0 +1,51 @@
+#!/usr/bin/env perl
+use warnings;
+use strict;
+
+=head1 DESCRIPTION
+
+Basic tests for CurrentUser.
+
+=cut
+
+use lib 't/lib';
+use Jifty::SubTest;
+
+use Jifty::Test tests => 19;
+use Jifty::Test::WWW::Mechanize;
+
+use_ok('TestApp::Model::User');
+use_ok('TestApp::CurrentUser');
+
+# Get a system user
+my $system_user = TestApp::CurrentUser->superuser;
+ok($system_user, "Found a system user");
+
+# Create two users
+my $o = TestApp::Model::User->new(current_user => $system_user);
+$o->create( name => 'A User', email => 'auser at example.com', tasty => 0 );
+ok($o->id, "New user has valid id set");
+ok(!$o->tasty, "User is not tasty");
+$o->create( name => 'Bob', email => 'bob at example.com', tasty => 1 );
+ok($o->id, "New user has valid id set");
+ok($o->tasty, "User is tasty");
+
+# Create a CurrentUser
+my $bob = TestApp::CurrentUser->new( name => 'Bob' );
+ok($bob->id, "CurrentUser has a valid id set");
+is($bob->id, $o->id, "The ids match");
+ok($bob->user_object->tasty, "The CurrentUser is tasty");
+ok($bob->is_superuser, "CurrentUser is a superuser");
+
+my $server = Jifty::Test->make_server;
+isa_ok($server, 'Jifty::Server');
+
+my $URL = $server->started_ok;
+my $mech = Jifty::Test::WWW::Mechanize->new();
+
+$mech->get_ok("$URL/currentuser", "Got currentuser page");
+$mech->content_contains("No current user set.", "Good, no current user yet");
+$mech->get_ok("$URL/setuser/Bob", "Setting currentuser to Bob");
+$mech->get_ok("$URL/currentuser", "Refetched currentuser page");
+$mech->content_contains("Current user is Bob", "Now the current_user is set");
+$mech->content_contains("The current user is a superuser", "... and the current_user is a superuser");


More information about the Jifty-commit mailing list