Change config key re RT#40344
[catagits/Catalyst-Plugin-Cache.git] / t / currying_conf.t
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5
6 use Test::More 'no_plan';
7 use Test::Deep qw/superhashof cmp_deeply/;
8
9 use Scalar::Util qw/refaddr/;
10
11 use ok "Catalyst::Plugin::Cache";
12
13 {
14     package MockApp;
15     use base qw/Catalyst::Plugin::Cache/;
16
17     my %config = (
18         cache => {
19             profiles => {
20                 foo => {
21                     bah => "foo",
22                 },
23                 bar => bless( {}, "SomeClass" ),
24             },
25             ### as of 0.06, we need a specific backend
26             ### specified
27             backend => { 
28                 class   => 'SomeClass',
29             }
30         },
31     );
32     sub config { \%config };
33
34     package SomeClass;
35     ### backend must have a constructor
36     sub new { bless {}, shift };
37     sub get {}
38     sub set {}
39     sub remove {}
40 }
41
42 MockApp->setup;
43 my $c = bless {}, "MockApp";
44
45 MockApp->register_cache_backend( default => bless({}, "SomeClass") );
46
47 can_ok( $c, "curry_cache" );
48 can_ok( $c, "get_preset_curried" );
49
50 isa_ok( $c->cache, "Catalyst::Plugin::Cache::Curried" );
51
52 is( refaddr($c->cache), refaddr($c->cache), "default cache is memoized, so it is ==");
53
54 isa_ok( $c->cache("foo"), "Catalyst::Plugin::Cache::Curried", "cache('foo')" );
55
56 cmp_deeply( { @{ $c->cache("foo")->meta } }, superhashof({ bah => "foo" }), "meta is in place" ); 
57
58 is( refaddr( $c->cache("bar") ), refaddr( $c->cache("bar") ), "since bar is hard coded as an object it's always the same" );
59