2018-06-28 15:55:15 +00:00
|
|
|
#![feature(plugin, decl_macro, proc_macro_non_items)]
|
2016-12-26 03:32:32 +00:00
|
|
|
#![plugin(rocket_codegen)]
|
|
|
|
|
2018-08-07 02:58:07 +00:00
|
|
|
#[macro_use] extern crate rocket;
|
2016-12-26 03:32:32 +00:00
|
|
|
|
|
|
|
use rocket::request::Form;
|
|
|
|
|
|
|
|
#[derive(FromForm)]
|
|
|
|
struct FormData {
|
|
|
|
form_data: String,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[patch("/", data = "<form_data>")]
|
|
|
|
fn bug(form_data: Form<FormData>) -> &'static str {
|
2018-09-26 08:13:57 +00:00
|
|
|
assert_eq!("Form data", form_data.form_data);
|
2016-12-26 03:32:32 +00:00
|
|
|
"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
|
|
|
}
|