From f815c1c096fe60a8d638d125c3c1bb08c11c081a Mon Sep 17 00:00:00 2001 From: Josh Leeb-du Toit Date: Sun, 3 Jun 2018 17:48:12 +1000 Subject: [PATCH] Add test for default_resource scope propagation --- src/scope.rs | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/scope.rs b/src/scope.rs index 6651992d..6cc4929e 100644 --- a/src/scope.rs +++ b/src/scope.rs @@ -1188,4 +1188,27 @@ mod tests { let resp = app.run(req); assert_eq!(resp.as_msg().status(), StatusCode::NOT_FOUND); } + + #[test] + fn test_default_resource_propagation() { + let mut app = App::new() + .scope("/app1", |scope| { + scope.default_resource(|r| r.f(|_| HttpResponse::BadRequest())) + }) + .scope("/app2", |scope| scope) + .default_resource(|r| r.f(|_| HttpResponse::MethodNotAllowed())) + .finish(); + + let req = TestRequest::with_uri("/non-exist").finish(); + let resp = app.run(req); + assert_eq!(resp.as_msg().status(), StatusCode::METHOD_NOT_ALLOWED); + + let req = TestRequest::with_uri("/app1/non-exist").finish(); + let resp = app.run(req); + assert_eq!(resp.as_msg().status(), StatusCode::BAD_REQUEST); + + let req = TestRequest::with_uri("/app2/non-exist").finish(); + let resp = app.run(req); + assert_eq!(resp.as_msg().status(), StatusCode::METHOD_NOT_ALLOWED); + } }