diff --git a/examples/todo/src/tests.rs b/examples/todo/src/tests.rs index 286f73ae..5c2eadd7 100644 --- a/examples/todo/src/tests.rs +++ b/examples/todo/src/tests.rs @@ -138,9 +138,8 @@ fn test_bad_form_submissions() { .dispatch() .await; - let mut cookies = res.headers().get("Set-Cookie"); + assert!(!res.cookies().iter().any(|c| c.value().contains("error"))); assert_eq!(res.status(), Status::UnprocessableEntity); - assert!(!cookies.any(|value| value.contains("error"))); // Submit a form with an empty description. We look for 'error' in the // cookies which corresponds to flash message being set as an error. @@ -150,8 +149,18 @@ fn test_bad_form_submissions() { .dispatch() .await; - let mut cookies = res.headers().get("Set-Cookie"); - assert!(cookies.any(|value| value.contains("error"))); + // Check that the flash cookie set and that we're redirected to index. + assert!(res.cookies().iter().any(|c| c.value().contains("error"))); + assert_eq!(res.status(), Status::SeeOther); + + // The flash cookie should still be present and the error message should + // be rendered the index. + let body = client.get("/").dispatch().await.into_string().await.unwrap(); + assert!(body.contains("Description cannot be empty.")); + + // Check that the flash is cleared upon another visit to the index. + let body = client.get("/").dispatch().await.into_string().await.unwrap(); + assert!(!body.contains("Description cannot be empty.")); // Submit a form without a description. Expect a 422 but no flash error. let res = client.post("/todo") @@ -160,8 +169,7 @@ fn test_bad_form_submissions() { .dispatch() .await; - let mut cookies = res.headers().get("Set-Cookie"); + assert!(!res.cookies().iter().any(|c| c.value().contains("error"))); assert_eq!(res.status(), Status::UnprocessableEntity); - assert!(!cookies.any(|value| value.contains("error"))); }) } diff --git a/examples/todo/static/index.html.tera b/examples/todo/static/index.html.tera index 369ae364..a6f77f1d 100644 --- a/examples/todo/static/index.html.tera +++ b/examples/todo/static/index.html.tera @@ -23,10 +23,10 @@
- {% if msg %} - - {{ msg.1 }} + class="u-full-width {% if flash %}field-{{flash.0}}{% endif %}" /> + {% if flash %} + + {{ flash.1 }} {% endif %}