9a35e2476dcaf522c0fdec93d52bce0ac58a2ec8
[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
8 use Scalar::Util qw/refaddr/;
9
10 use ok "Catalyst::Plugin::Cache";
11
12 {
13     package MockApp;
14     use base qw/Catalyst::Plugin::Cache/;
15
16     my %config = (
17         cache => {
18             profiles => {
19                 foo => {
20                     bah => "foo",
21                 },
22                 bar => bless( {}, "SomeClass" ),
23             },
24         },
25     );
26     sub config { \%config };
27
28     package SomeClass;
29     sub get {}
30     sub set {}
31     sub remove {}
32 }
33
34 MockApp->setup;
35 my $c = bless {}, "MockApp";
36
37 MockApp->register_cache_backend( default => bless({}, "SomeClass") );
38
39 can_ok( $c, "curry_cache" );
40 can_ok( $c, "get_preset_curried" );
41
42 isa_ok( $c->cache, "Catalyst::Plugin::Cache::Curried" );
43
44 is( refaddr($c->cache), refaddr($c->cache), "default cache is memoized, so it is ==");
45
46 isa_ok( $c->cache("foo"), "Catalyst::Plugin::Cache::Curried", "cache('foo')" );
47
48 is_deeply( $c->cache("foo")->meta, [ bah => "foo" ], "meta is in place" ); 
49
50 is( refaddr( $c->cache("bar") ), refaddr( $c->cache("bar") ), "since bar is hard coded as an object it's always the same" );
51