1
0
mirror of https://github.com/actix/actix-extras.git synced 2024-11-28 09:42:40 +01:00

update tests

This commit is contained in:
Nikolay Kim 2018-06-21 12:04:00 +06:00
parent 8e160ebda7
commit b7d813eeba
4 changed files with 26 additions and 20 deletions

View File

@ -312,8 +312,10 @@ impl<T: fmt::Display> fmt::Display for Form<T> {
/// let app = App::new().resource( /// let app = App::new().resource(
/// "/index.html", /// "/index.html",
/// |r| { /// |r| {
/// r.method(http::Method::GET).with(index).limit(4096); /// r.method(http::Method::GET)
/// }, // <- change form extractor configuration /// // register form handler and change form extractor configuration
/// .with_config(index, |cfg| {cfg.limit(4096);})
/// },
/// ); /// );
/// } /// }
/// ``` /// ```

View File

@ -171,12 +171,13 @@ where
/// fn main() { /// fn main() {
/// let app = App::new().resource("/index.html", |r| { /// let app = App::new().resource("/index.html", |r| {
/// r.method(http::Method::POST) /// r.method(http::Method::POST)
/// .with(index) /// .with_config(index, |cfg| {
/// .limit(4096) // <- change json extractor configuration /// cfg.limit(4096) // <- change json extractor configuration
/// .error_handler(|err, req| { // <- create custom error response /// .error_handler(|err, req| { // <- create custom error response
/// error::InternalError::from_response( /// error::InternalError::from_response(
/// err, HttpResponse::Conflict().finish()).into() /// err, HttpResponse::Conflict().finish()).into()
/// }); /// });
/// })
/// }); /// });
/// } /// }
/// ``` /// ```
@ -326,7 +327,7 @@ mod tests {
use http::header; use http::header;
use handler::Handler; use handler::Handler;
use with::{ExtractorConfig, With}; use with::With;
impl PartialEq for JsonPayloadError { impl PartialEq for JsonPayloadError {
fn eq(&self, other: &JsonPayloadError) -> bool { fn eq(&self, other: &JsonPayloadError) -> bool {
@ -409,7 +410,7 @@ mod tests {
#[test] #[test]
fn test_with_json() { fn test_with_json() {
let mut cfg = ExtractorConfig::<_, Json<MyObject>>::default(); let mut cfg = JsonConfig::default();
cfg.limit(4096); cfg.limit(4096);
let mut handler = With::new(|data: Json<MyObject>| data, cfg); let mut handler = With::new(|data: Json<MyObject>| data, cfg);

View File

@ -257,7 +257,7 @@ impl<S: 'static> Route<S> {
/// # extern crate actix_web; /// # extern crate actix_web;
/// # extern crate futures; /// # extern crate futures;
/// #[macro_use] extern crate serde_derive; /// #[macro_use] extern crate serde_derive;
/// use actix_web::{http, App, Error, Path}; /// use actix_web::{http, App, Error, Form};
/// use futures::Future; /// use futures::Future;
/// ///
/// #[derive(Deserialize)] /// #[derive(Deserialize)]
@ -318,7 +318,7 @@ impl<S: 'static> InnerHandler<S> {
#[inline] #[inline]
pub fn handle(&self, req: HttpRequest<S>) -> AsyncResult<HttpResponse> { pub fn handle(&self, req: HttpRequest<S>) -> AsyncResult<HttpResponse> {
// reason: handler is unique per thread, handler get called from async code only // reason: handler is unique per thread, handler get called from sync code only
let h = unsafe { &mut *self.0.as_ref().get() }; let h = unsafe { &mut *self.0.as_ref().get() };
h.handle(req) h.handle(req)
} }

View File

@ -152,14 +152,17 @@ fn test_form_extractor() {
fn test_form_extractor2() { fn test_form_extractor2() {
let mut srv = test::TestServer::new(|app| { let mut srv = test::TestServer::new(|app| {
app.resource("/{username}/index.html", |r| { app.resource("/{username}/index.html", |r| {
r.route() r.route().with_config(
.with(|form: Form<FormData>| format!("{}", form.username)) |form: Form<FormData>| format!("{}", form.username),
.error_handler(|err, _| { |cfg| {
cfg.error_handler(|err, _| {
error::InternalError::from_response( error::InternalError::from_response(
err, err,
HttpResponse::Conflict().finish(), HttpResponse::Conflict().finish(),
).into() ).into()
}); });
},
);
}); });
}); });