mirror of https://github.com/rwf2/Rocket.git
Fix flash message display in todo example.
This commit is contained in:
parent
5593685455
commit
13d8e74655
|
@ -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")));
|
||||
})
|
||||
}
|
||||
|
|
|
@ -23,10 +23,10 @@
|
|||
<div class="ten columns">
|
||||
<input type="text" placeholder="enter a task description..."
|
||||
name="description" id="description" value="" autofocus
|
||||
class="u-full-width {% if msg %}field-{{msg.0}}{% endif %}" />
|
||||
{% if msg %}
|
||||
<small class="field-{{msg.0}}-msg">
|
||||
{{ msg.1 }}
|
||||
class="u-full-width {% if flash %}field-{{flash.0}}{% endif %}" />
|
||||
{% if flash %}
|
||||
<small class="field-{{flash.0}}-msg">
|
||||
{{ flash.1 }}
|
||||
</small>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
|
Loading…
Reference in New Issue