diff --git a/lib/WebGUI/Asset.pm b/lib/WebGUI/Asset.pm index 8279fde74..38a2a6874 100644 --- a/lib/WebGUI/Asset.pm +++ b/lib/WebGUI/Asset.pm @@ -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; } diff --git a/t/Asset/dispatch.t b/t/Asset/dispatch.t index f7f6106c6..74d0f82d9 100644 --- a/t/Asset/dispatch.t +++ b/t/Asset/dispatch.t @@ -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