Fix calling User->can() as a class method. RT#90715
[catagits/Catalyst-Authentication-Store-DBIx-Class.git] / t / 10-user-autoload.t
1 use strict;
2 use warnings;
3 use Test::More;
4 use Try::Tiny;
5 use Catalyst::Authentication::Store::DBIx::Class::User;
6
7 my $message = 'I exist';
8
9 {
10   package My::Test;
11
12   sub exists { $message }
13 }
14
15 my $class = 'Catalyst::Authentication::Store::DBIx::Class::User';
16 my $o = bless({
17   _user => bless({}, 'My::Test'),
18 }, $class);
19
20 is($o->exists, $message, 'AUTOLOAD proxies ok');
21
22 ok(my $meth = $o->can('exists'), 'can returns true');
23
24 is($o->$meth, $message, 'can returns right coderef');
25
26 is($o->can('non_existent_method'), undef, 'can on non existent method returns undef');
27
28 is($o->non_existent_method, undef, 'AUTOLOAD traps non existent method');
29
30 try {
31     is($class->can('non_existent_method'), undef, "can on non existent class method");
32 } catch {
33     my $e = $_;
34     fail('can on non existent class method');
35     diag("Got exception: $e");
36 };
37
38 try { 
39     is($class->non_existent_method, undef, 'AUTOLOAD traps non existent class method');
40 } catch {
41     my $e = $_;
42     fail('AUTOLOAD traps non existent class method');
43     diag("Got exception: $e");
44 };
45
46 done_testing;