1#!/usr/bin/env perl 2use strict; 3use warnings; 4 5use Jifty::Test::Dist tests => 4; 6 7use_ok('TestApp::Model::User'); 8 9# Create a superuser, which will be denied access in a bit 10my $system_user = TestApp::CurrentUser->superuser; 11ok($system_user, 'Found a system user'); 12 13# Associate a new rule that only names starting with bob can be created 14TestApp::Model::User->add_trigger( before_access => sub { 15 my ($self, $right, %args) = @_; 16 return 'ignore' unless $right eq 'create'; 17 unless ($args{name} =~ /^bob/) { 18 return 'deny'; 19 } 20 return 'ignore'; 21}); 22 23# Try creating non-bob, which will be denied 24my $o = TestApp::Model::User->new(current_user => $system_user); 25my ($id) = $o->create( name => 'nonbob', email => $$, password => $$ ); 26ok(!$id, 'User could not be created'); 27 28# Try creating bobette, which will be allowd 29($id) = $o->create( name => 'bobette', email => $$, password => $$ ); 30ok($id, 'User could be created'); 31