2017-08-29 03:14:59 +00:00
|
|
|
#![feature(plugin, decl_macro, custom_derive)]
|
2016-12-26 03:32:32 +00:00
|
|
|
#![plugin(rocket_codegen)]
|
|
|
|
|
|
|
|
extern crate rocket;
|
|
|
|
|
|
|
|
use rocket::request::Form;
|
|
|
|
|
|
|
|
#[derive(FromForm)]
|
|
|
|
struct FormData {
|
|
|
|
form_data: String,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[patch("/", data = "<form_data>")]
|
|
|
|
fn bug(form_data: Form<FormData>) -> &'static str {
|
|
|
|
assert_eq!("Form data", &form_data.get().form_data);
|
|
|
|
"OK"
|
|
|
|
}
|
|
|
|
|
2017-01-05 20:51:00 +00:00
|
|
|
mod tests {
|
|
|
|
use super::*;
|
2017-06-06 20:41:04 +00:00
|
|
|
use rocket::local::Client;
|
2017-01-05 20:51:00 +00:00
|
|
|
use rocket::http::{Status, ContentType};
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn method_eval() {
|
2017-06-06 20:41:04 +00:00
|
|
|
let client = Client::new(rocket::ignite().mount("/", routes![bug])).unwrap();
|
|
|
|
let mut response = client.post("/")
|
2017-01-05 20:51:00 +00:00
|
|
|
.header(ContentType::Form)
|
2017-06-06 20:41:04 +00:00
|
|
|
.body("_method=patch&form_data=Form+data")
|
|
|
|
.dispatch();
|
2017-01-05 20:51:00 +00:00
|
|
|
|
2017-04-14 08:59:28 +00:00
|
|
|
assert_eq!(response.body_string(), Some("OK".into()));
|
2017-01-05 20:51:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn get_passes_through() {
|
2017-06-06 20:41:04 +00:00
|
|
|
let client = Client::new(rocket::ignite().mount("/", routes![bug])).unwrap();
|
|
|
|
let response = client.get("/")
|
2017-01-05 20:51:00 +00:00
|
|
|
.header(ContentType::Form)
|
2017-06-06 20:41:04 +00:00
|
|
|
.body("_method=patch&form_data=Form+data")
|
|
|
|
.dispatch();
|
2017-01-05 20:51:00 +00:00
|
|
|
|
|
|
|
assert_eq!(response.status(), Status::NotFound);
|
|
|
|
}
|
2016-12-31 04:33:51 +00:00
|
|
|
}
|