diff --git a/CHANGES.md b/CHANGES.md index 3955251d7..c0ba7dd26 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,6 +1,6 @@ # Changes -## 0.6.0 (...) +## 0.6.0 (2018-05-08) * Add route scopes #202 diff --git a/Cargo.toml b/Cargo.toml index a0bdf7088..fe63ef8a6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "actix-web" -version = "0.6.0-dev" +version = "0.6.0" authors = ["Nikolay Kim "] description = "Actix web is a simple, pragmatic and extremely fast web framework for Rust." readme = "README.md" diff --git a/src/scope.rs b/src/scope.rs index 74009841f..e5d160bbe 100644 --- a/src/scope.rs +++ b/src/scope.rs @@ -28,7 +28,7 @@ type NestedInfo = (Resource, Route, Vec>>); /// Scope prefix is always complete path segment, i.e `/app` would /// be converted to a `/app/` and it would not match `/app` path. /// -/// You can get variable path segments from HttpRequest::match_info()`. +/// You can get variable path segments from `HttpRequest::match_info()`. /// `Path` extractor also is able to extract scope level variable segments. /// /// ```rust @@ -50,6 +50,7 @@ type NestedInfo = (Resource, Route, Vec>>); /// * /{project_id}/path2 - `GET` requests /// * /{project_id}/path3 - `HEAD` requests /// +#[derive(Default)] pub struct Scope { filters: Vec>>, nested: Vec>, @@ -58,12 +59,7 @@ pub struct Scope { resources: ScopeResources, } -impl Default for Scope { - fn default() -> Scope { - Scope::new() - } -} - +#[cfg_attr(feature = "cargo-clippy", allow(new_without_default_derive))] impl Scope { pub fn new() -> Scope { Scope { @@ -319,7 +315,7 @@ impl Scope { /// middlewares get invoked on scope level. /// /// *Note* `Middleware::finish()` fires right after response get - /// prepared. It does not wait until body get sent to peer. + /// prepared. It does not wait until body get sent to the peer. pub fn middleware>(mut self, mw: M) -> Scope { Rc::get_mut(&mut self.middlewares) .expect("Can not use after configuration") @@ -333,7 +329,7 @@ impl RouteHandler for Scope { let path = unsafe { &*(&req.match_info()["tail"] as *const _) }; let path = if path == "" { "/" } else { path }; - // recognize paths + // recognize resources for &(ref pattern, ref resource) in self.resources.iter() { if pattern.match_with_params(path, req.match_info_mut()) { let default = unsafe { &mut *self.default.as_ref().get() }; @@ -777,6 +773,7 @@ mod tests { use application::App; use body::Body; use http::{Method, StatusCode}; + use httprequest::HttpRequest; use httpresponse::HttpResponse; use pred; use test::TestRequest; @@ -794,6 +791,27 @@ mod tests { assert_eq!(resp.as_msg().status(), StatusCode::OK); } + #[test] + fn test_scope_route() { + let mut app = App::new() + .scope("app", |scope| { + scope.route("/path1", Method::GET, |r: HttpRequest<_>| { + HttpResponse::Ok() + }) + }) + .finish(); + + let req = TestRequest::with_uri("/app/path1").finish(); + let resp = app.run(req); + assert_eq!(resp.as_msg().status(), StatusCode::OK); + + let req = TestRequest::with_uri("/app/path1") + .method(Method::POST) + .finish(); + let resp = app.run(req); + assert_eq!(resp.as_msg().status(), StatusCode::NOT_FOUND); + } + #[test] fn test_scope_filter() { let mut app = App::new()