aboutsummaryrefslogtreecommitdiffstats
path: root/testing
diff options
context:
space:
mode:
authorLibravatar Hajime Fukuda <hajime.fukuda@me.com>2018-01-17 22:49:27 +0900
committerLibravatar Dirkjan Ochtman <dirkjan@ochtman.nl>2018-01-19 12:48:17 +0100
commit8f216fed4c51f470777a004317ecc09869728fb7 (patch)
tree286114e076ab2f835b6b81c0128b7bc52a1b912e /testing
parentf376d96ee1bab82cf1cbb32fbdc0dbf969e5df9c (diff)
downloadaskama-8f216fed4c51f470777a004317ecc09869728fb7.tar.gz
askama-8f216fed4c51f470777a004317ecc09869728fb7.tar.bz2
askama-8f216fed4c51f470777a004317ecc09869728fb7.zip
infer Content-type from the file extension for iron integration
Diffstat (limited to 'testing')
-rw-r--r--testing/templates/hello.txt1
-rw-r--r--testing/tests/iron.rs20
2 files changed, 21 insertions, 0 deletions
diff --git a/testing/templates/hello.txt b/testing/templates/hello.txt
new file mode 100644
index 0000000..8149be7
--- /dev/null
+++ b/testing/templates/hello.txt
@@ -0,0 +1 @@
+Hello, {{ name }}!
diff --git a/testing/tests/iron.rs b/testing/tests/iron.rs
index 6f8868f..95c366c 100644
--- a/testing/tests/iron.rs
+++ b/testing/tests/iron.rs
@@ -11,10 +11,30 @@ struct HelloTemplate<'a> {
name: &'a str,
}
+#[derive(Template)]
+#[template(path = "hello.txt")]
+struct HelloTextTemplate<'a> {
+ name: &'a str,
+}
+
#[test]
fn test_iron() {
let rsp = Response::with((status::Ok, HelloTemplate { name: "world" }));
let mut buf = Vec::new();
let _ = rsp.body.unwrap().write_body(&mut buf);
assert_eq!(buf, b"Hello, world!");
+
+ let content_type = rsp.headers.get::<iron::headers::ContentType>().unwrap();
+ assert_eq!(format!("{}", content_type), "text/html; charset=utf-8");
+}
+
+#[test]
+fn test_iron_non_html() {
+ let rsp = Response::with((status::Ok, HelloTextTemplate { name: "world" }));
+ let mut buf = Vec::new();
+ let _ = rsp.body.unwrap().write_body(&mut buf);
+ assert_eq!(buf, b"Hello, world!");
+
+ let content_type = rsp.headers.get::<iron::headers::ContentType>();
+ assert_eq!(content_type, None);
}