Use open session in view and populate model attrs

Open session in view was switched off accidentally a while ago. Also
the mapping changes recently meant that the changes to @Valid model
attributes were not being propagated correctly.

Fixes #946 and #947
This commit is contained in:
Dave Syer 2022-04-11 13:24:49 +00:00 committed by GitHub
parent e870b186fb
commit d381fb658c
5 changed files with 21 additions and 3 deletions

View file

@ -173,10 +173,16 @@ class OwnerControllerTests {
.andExpect(view().name("redirect:/owners/{ownerId}"));
}
@Test
void testProcessUpdateOwnerFormUnchangedSuccess() throws Exception {
mockMvc.perform(post("/owners/{ownerId}/edit", TEST_OWNER_ID)).andExpect(status().is3xxRedirection())
.andExpect(view().name("redirect:/owners/{ownerId}"));
}
@Test
void testProcessUpdateOwnerFormHasErrors() throws Exception {
mockMvc.perform(post("/owners/{ownerId}/edit", TEST_OWNER_ID).param("firstName", "Joe")
.param("lastName", "Bloggs").param("city", "London")).andExpect(status().isOk())
.param("lastName", "Bloggs").param("address", "").param("telephone", "")).andExpect(status().isOk())
.andExpect(model().attributeHasErrors("owner"))
.andExpect(model().attributeHasFieldErrors("owner", "address"))
.andExpect(model().attributeHasFieldErrors("owner", "telephone"))