Explicit return of undef in the fall through case. Test for notFound now look for undef. Added POD.

This commit is contained in:
Colin Kuskie 2010-07-29 12:14:18 -07:00
parent 7e96b15141
commit c987747409
2 changed files with 17 additions and 5 deletions

View file

@ -563,11 +563,16 @@ sub definition {
=head2 dispatch ( $fragment )
Based on the URL and query parameters in the current request, call internal methods
like www_view, www_edit, etc.
like www_view, www_edit, etc. If no query parameter is present, then it returns the output
from the view method.
When this method returns undef, it means that the requested URL does not match this Asset's
URL.
=head3 $fragment
A URL.
A URL. If this URL is missing, then output from the view method is returned.
If the fragment does not match this Asset's URL, then it returns undef.
=cut
@ -582,6 +587,7 @@ sub dispatch {
if (! $fragment ) {
return $self->www_view;
}
return undef;
}

View file

@ -59,7 +59,7 @@ WebGUI::Test->addToCleanup( $tag );
#----------------------------------------------------------------------------
# Tests
plan tests => 9; # Increment this number for each test you create
plan tests => 10; # Increment this number for each test you create
#----------------------------------------------------------------------------
# Test dispatch
@ -82,12 +82,18 @@ is( $td->dispatch( '/foo' ), "bar", "overridden dispatch trumps ?func= query par
# Test func= can only be run on the exact asset we requested
my $output = $td->dispatch( '/bar' );
ok( $output, "dispatch returned something, maybe not found page?" );
is( $output, undef, "dispatch returned undef, meaning that it declined to handle the request for a func but the wrong URL" );
isnt( $output, "www_edit", "?func= dispatch cancelled because of unhandled fragment" );
# Test unhandled options
$session->request->setup_body( {
func => 'notAMethod',
} );
is( $td->dispatch, "www_view", "requests for non-existant methods return www_view method" );
$session->request->setup_body( { } );
$output = $td->dispatch( '/not-foo' );
ok( $output, "dispatch returned something, maybe not found page?" );
is( $output, undef, "dispatch returned undef, meaning that it declined to handle the request for the wrong URL" );
isnt( $output, "www_view", "?func= dispatch cancelled because of unhandled fragment" );
#vim:ft=perl