Live app test, Cache::Store::Memory
[catagits/Catalyst-Plugin-Cache.git] / t / basic.t
index 89700b2..2cc7e1e 100644 (file)
--- a/t/basic.t
+++ b/t/basic.t
@@ -8,17 +8,16 @@ use Test::Exception;
 
 use ok "Catalyst::Plugin::Cache";
 
+use Catalyst::Plugin::Cache::Backend::Memory;
+
 {
     package MockApp;
     use base qw/Catalyst::Plugin::Cache/;
-
-    package MemoryCache;
-    use Storable qw/freeze thaw/;
     
-    sub new { bless {}, shift }
-    sub get { ${thaw($_[0]{$_[1]}) || return} };
-    sub set { $_[0]{$_[1]} = freeze(\$_[2]) };
-    sub delete { delete $_[0]{$_[1]} };
+    sub registered_plugins {}
+
+    my %config;
+    sub config { \%config };
 }
 
 MockApp->setup;
@@ -27,8 +26,8 @@ my $c = bless {}, "MockApp";
 can_ok( $c, "register_cache_backend" );
 can_ok( $c, "unregister_cache_backend" );
 
-MockApp->register_cache_backend( default => MemoryCache->new );
-MockApp->register_cache_backend( moose => MemoryCache->new );
+MockApp->register_cache_backend( default => Catalyst::Plugin::Cache::Backend::Memory->new );
+MockApp->register_cache_backend( moose => Catalyst::Plugin::Cache::Backend::Memory->new );
 
 can_ok( $c, "cache" );
 
@@ -56,22 +55,21 @@ dies_ok {
 
 
 can_ok( $c, "default_cache_backend" );
-is( $c->default_cache_backend, $c->cache, "cache with no args retrurns default" );
 
 can_ok( $c, "choose_cache_backend_wrapper" );
 can_ok( $c, "choose_cache_backend" );
 
 can_ok( $c, "cache_set" );
 can_ok( $c, "cache_get" );
-can_ok( $c, "cache_delete" );
+can_ok( $c, "cache_remove" );
 
 $c->cache_set( foo => "bar" );
 is( $c->cache_get("foo"), "bar", "set" );
 
-$c->cache_delete( "foo" );
-is( $c->cache_get("foo"), undef, "delete" );
+$c->cache_remove( "foo" );
+is( $c->cache_get("foo"), undef, "remove" );
 
-MockApp->register_cache_backend( elk => MemoryCache->new );
+MockApp->register_cache_backend( elk => Catalyst::Plugin::Cache::Backend::Memory->new );
 
 is( $c->choose_cache_backend_wrapper( key => "foo" ), $c->default_cache_backend, "choose default" );
 is( $c->choose_cache_backend_wrapper( key => "foo", backend => "elk" ), $c->get_cache_backend("elk"), "override choice" );
@@ -81,3 +79,8 @@ $c->cache_set( foo => "gorch", backend => "elk" );
 is( $c->cache_get("foo"), undef, "set to custom backend (get from non custom)" );
 is( $c->cache_get("foo", backend => "elk"), "gorch", "set to custom backend (get from custom)" );
 
+my $cache_elk = $c->cache( backend => "elk" );
+my $cache_norm = $c->cache();
+
+is( $cache_norm->get("foo"), undef, "default curried cache has no foo");
+is( $cache_elk->get("foo"), "gorch", "curried custom backend has foo" );