Rocket/lib/tests/form_method-issue-45.rs
Sergio Benitez 084481a84e Initial implementation of typed URIs.
This is a breaking change. All Rocket applications using code
generation must now additionally declare usage of the 'decl_macro'
feature.
2017-09-14 22:10:25 -07:00

46 lines
1.1 KiB
Rust

#![feature(plugin, decl_macro, custom_derive)]
#![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"
}
mod tests {
use super::*;
use rocket::local::Client;
use rocket::http::{Status, ContentType};
#[test]
fn method_eval() {
let client = Client::new(rocket::ignite().mount("/", routes![bug])).unwrap();
let mut response = client.post("/")
.header(ContentType::Form)
.body("_method=patch&form_data=Form+data")
.dispatch();
assert_eq!(response.body_string(), Some("OK".into()));
}
#[test]
fn get_passes_through() {
let client = Client::new(rocket::ignite().mount("/", routes![bug])).unwrap();
let response = client.get("/")
.header(ContentType::Form)
.body("_method=patch&form_data=Form+data")
.dispatch();
assert_eq!(response.status(), Status::NotFound);
}
}