From: André Walker Date: Mon, 8 Aug 2011 03:49:54 +0000 (-0300) Subject: test model Foo + small fixes X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=17f0d82d40416d9ecf3d0988115016380f87f0f0;p=catagits%2FCatalyst-Runtime.git test model Foo + small fixes --- diff --git a/t/lib/TestAppCustomContainer/NoSugarContainer.pm b/t/lib/TestAppCustomContainer/NoSugarContainer.pm index e30b08b..e65f1c9 100644 --- a/t/lib/TestAppCustomContainer/NoSugarContainer.pm +++ b/t/lib/TestAppCustomContainer/NoSugarContainer.pm @@ -16,7 +16,7 @@ sub BUILD { dependencies => [ depends_on( '/application_name' ), depends_on( '/config' ), - depends_on( 'model_Foo' ), + depends_on( '/model/Foo' ), ], ) ); @@ -60,7 +60,7 @@ sub BUILD { dependencies => [ depends_on( '/application_name' ), depends_on( '/config' ), - depends_on( 'model_Foo' ), + depends_on( '/model/Foo' ), ], ) ); diff --git a/t/lib/TestCustomContainer.pm b/t/lib/TestCustomContainer.pm index 815d5be..d18e7a9 100644 --- a/t/lib/TestCustomContainer.pm +++ b/t/lib/TestCustomContainer.pm @@ -38,10 +38,13 @@ sub BUILD { require Catalyst::Test; Catalyst::Test->import($self->app_name); - is(get('/container_class'), $self->container_class); - is(get('/container_isa'), $self->container_class); + is(get('/container_class'), $self->container_class, 'config is set properly'); + is(get('/container_isa'), $self->container_class, 'and container isa our container class'); { + # Foo ACCEPT_CONTEXT called twice - total: 2 + # TestAppCustomContainer::Role::HoldsFoo COMPONENT + # and in the block injection ok(my ($res, $c) = ctx_request('/get_model_baz'), 'request'); ok($res->is_success, 'request 2xx'); is($res->content, 'TestAppCustomContainer::Model::Baz', 'content is expected'); @@ -55,12 +58,14 @@ sub BUILD { isa_ok($foo, 'TestAppCustomContainer::Model::Foo'); is($foo->baz_got_it, 1, 'Baz accessed Foo once'); + # Foo ACCEPT_CONTEXT called - total: 3 ok(get('/get_model_baz'), 'another request'); is($baz->accept_context_called, 2, 'ACCEPT_CONTEXT called again'); is($foo->baz_got_it, 2, 'Baz accessed Foo again'); } { + # Foo ACCEPT_CONTEXT called twice - total: 5 ok(my ($res, $c) = ctx_request('/get_model_bar'), 'request'); ok($res->is_success, 'request 2xx'); is($res->content, 'TestAppCustomContainer::Model::Bar', 'content is expected'); @@ -76,11 +81,25 @@ sub BUILD { isa_ok($foo, 'TestAppCustomContainer::Model::Foo'); is($foo->bar_got_it, 1, 'Bar accessed Foo once'); + # Foo ACCEPT_CONTEXT *not* called - total: 5 ok(get('/get_model_bar'), 'another request'); is($bar->accept_context_called, 1, 'ACCEPT_CONTEXT not called again (lifecycle is Singleton)'); is($foo->bar_got_it, 1, 'Bar didn\'t access Foo again'); } + { + # Foo ACCEPT_CONTEXT called - total: 6 + ok(my ($res, $c) = ctx_request('/get_model_foo'), 'request'); + ok($res->is_success, 'request 2xx'); + is($res->content, 'TestAppCustomContainer::Model::Foo', 'content is expected'); + + ok(my $foo = $c->container->get_sub_container('component')->resolve(service => 'model_Foo'), 'fetching Foo'); + isa_ok($foo, 'TestAppCustomContainer::Model::Foo'); + is($foo->accept_context_called, 6, 'ACCEPT_CONTEXT called'); + is($foo->bar_got_it, 1, 'Bar accessed Foo once'); + is($foo->baz_got_it, 2, 'Baz accessed Foo twice'); + } + done_testing; }