Fix calling User->can() as a class method. RT#90715
[catagits/Catalyst-Authentication-Store-DBIx-Class.git] / t / 10-user-autoload.t
CommitLineData
7afa5efd 1use strict;
2use warnings;
3use Test::More;
c30ad9df 4use Try::Tiny;
7afa5efd 5use Catalyst::Authentication::Store::DBIx::Class::User;
6
7my $message = 'I exist';
8
9{
10 package My::Test;
11
12 sub exists { $message }
13}
14
c30ad9df 15my $class = 'Catalyst::Authentication::Store::DBIx::Class::User';
7afa5efd 16my $o = bless({
17 _user => bless({}, 'My::Test'),
c30ad9df 18}, $class);
7afa5efd 19
20is($o->exists, $message, 'AUTOLOAD proxies ok');
21
22ok(my $meth = $o->can('exists'), 'can returns true');
23
7afa5efd 24is($o->$meth, $message, 'can returns right coderef');
25
057348d8 26is($o->can('non_existent_method'), undef, 'can on non existent method returns undef');
27
c30ad9df 28is($o->non_existent_method, undef, 'AUTOLOAD traps non existent method');
29
30try {
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
38try {
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
7afa5efd 46done_testing;