From: André Walker Date: Mon, 8 Aug 2011 03:39:01 +0000 (-0300) Subject: more improving test - Bar X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Runtime.git;a=commitdiff_plain;h=e9af4f7db9d15b4bcb6c49481031c2afa0de22e4 more improving test - Bar --- diff --git a/t/lib/TestAppCustomContainer/NoSugarContainer.pm b/t/lib/TestAppCustomContainer/NoSugarContainer.pm index ecf423d..e30b08b 100644 --- a/t/lib/TestAppCustomContainer/NoSugarContainer.pm +++ b/t/lib/TestAppCustomContainer/NoSugarContainer.pm @@ -23,6 +23,7 @@ sub BUILD { $self->get_sub_container('model')->add_service( Catalyst::IOC::BlockInjection->new( name => 'Bar', + lifecycle => 'Singleton', dependencies => [ Bread::Board::Dependency->new( service_path => 'Foo', diff --git a/t/lib/TestCustomContainer.pm b/t/lib/TestCustomContainer.pm index 02fb9de..815d5be 100644 --- a/t/lib/TestCustomContainer.pm +++ b/t/lib/TestCustomContainer.pm @@ -54,6 +54,31 @@ sub BUILD { ok(my $foo = $c->container->get_sub_container('component')->resolve(service => 'model_Foo'), 'fetching Foo'); isa_ok($foo, 'TestAppCustomContainer::Model::Foo'); is($foo->baz_got_it, 1, 'Baz accessed Foo once'); + + 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'); + } + + { + 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'); + + ok(my $bar = $c->container->get_sub_container('component')->resolve(service => 'model_Bar'), 'fetching Bar'); + isa_ok($bar, 'TestAppCustomContainer::Model::Bar'); + + # FIXME - is this expected behavior? + is($bar->accept_context_called, 1, 'ACCEPT_CONTEXT called'); + isa_ok($bar->foo, 'TestAppCustomContainer::Model::Foo', 'Bar got Foo ok'); + + ok(my $foo = $c->container->get_sub_container('component')->resolve(service => 'model_Foo'), 'fetching Foo'); + isa_ok($foo, 'TestAppCustomContainer::Model::Foo'); + is($foo->bar_got_it, 1, 'Bar accessed Foo once'); + + 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'); } done_testing;