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::*;
|
2020-07-05 18:35:36 +00:00
|
|
|
use rocket::local::blocking::Client;
|
2017-01-05 20:51:00 +00:00
|
|
|
use rocket::http::{Status, ContentType};
|
|
|
|
|
2020-07-05 18:35:36 +00:00
|
|
|
#[test]
|
|
|
|
fn method_eval() {
|
|
|
|
let client = Client::new(rocket::ignite().mount("/", routes![bug])).unwrap();
|
2020-06-22 11:54:34 +00:00
|
|
|
let 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")
|
2020-07-05 18:35:36 +00:00
|
|
|
.dispatch();
|
2017-01-05 20:51:00 +00:00
|
|
|
|
2020-07-05 18:35:36 +00:00
|
|
|
assert_eq!(response.into_string(), Some("OK".into()));
|
2017-01-05 20:51:00 +00:00
|
|
|
}
|
|
|
|
|
2020-07-05 18:35:36 +00:00
|
|
|
#[test]
|
|
|
|
fn get_passes_through() {
|
|
|
|
let client = Client::new(rocket::ignite().mount("/", routes![bug])).unwrap();
|
2017-06-06 20:41:04 +00:00
|
|
|
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")
|
2020-07-05 18:35:36 +00:00
|
|
|
.dispatch();
|
2017-01-05 20:51:00 +00:00
|
|
|
|
|
|
|
assert_eq!(response.status(), Status::NotFound);
|
|
|
|
}
|
2016-12-31 04:33:51 +00:00
|
|
|
}
|