From bf9e7cc049d7a16cdd3718df82870bf5cc4809b9 Mon Sep 17 00:00:00 2001 From: Zizheng Tai Date: Sat, 26 Jan 2019 22:06:51 -0800 Subject: Add TemplateResponder trait for integration with actix-web --- testing/tests/actix_web.rs | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'testing') diff --git a/testing/tests/actix_web.rs b/testing/tests/actix_web.rs index d40830f..267736d 100644 --- a/testing/tests/actix_web.rs +++ b/testing/tests/actix_web.rs @@ -2,7 +2,7 @@ use actix_web::http::header::CONTENT_TYPE; use actix_web::test; use actix_web::HttpMessage; -use askama::Template; +use askama::{actix_web::TemplateResponder, Template}; use bytes::Bytes; #[derive(Template)] @@ -23,3 +23,21 @@ fn test_actix_web() { let bytes = srv.execute(response.body()).unwrap(); assert_eq!(bytes, Bytes::from_static("Hello, world!".as_ref())); } + +#[test] +fn test_actix_web_responder() { + let mut srv = test::TestServer::new(|app| { + app.handler(|_| { + let name = "world".to_owned(); + HelloTemplate { name: &name }.responder() + }) + }); + + let request = srv.get().finish().unwrap(); + let response = srv.execute(request.send()).unwrap(); + assert!(response.status().is_success()); + assert_eq!(response.headers().get(CONTENT_TYPE).unwrap(), "text/html"); + + let bytes = srv.execute(response.body()).unwrap(); + assert_eq!(bytes, Bytes::from_static("Hello, world!".as_ref())); +} -- cgit