}
/**
+ * Check if an active user with the given email exits in database
+ *
* Please note that email is case insensitive, result for searching 'mail@email.com' or 'Mail@Email.com' will be the same
*/
public boolean doesEmailExist(DbSession dbSession, String email){
<select id="countByEmail" parameterType="String" resultType="long">
SELECT count(u.id)
FROM users u
- where lower(u.email)=#{email}
+ where lower(u.email)=#{email} AND u.active=${_true}
</select>
<select id="selectGroupByName" parameterType="string" resultType="Group">
@Test
public void exists_by_email() throws Exception {
- db.prepareDbUnit(getClass(), "exists_by_email.xml");
+ UserDto activeUser = newActiveUser();
+ UserDto disableUser = newUser(false);
- assertThat(underTest.doesEmailExist(session, "marius@lesbronzes.fr")).isTrue();
- assertThat(underTest.doesEmailExist(session, "Marius@LesBronzes.fr")).isTrue();
+ assertThat(underTest.doesEmailExist(session, activeUser.getEmail())).isTrue();
+ assertThat(underTest.doesEmailExist(session, disableUser.getEmail())).isFalse();
assertThat(underTest.doesEmailExist(session, "unknown")).isFalse();
}
private UserDto newActiveUser(){
- UserDto dto = UserTesting.newUserDto().setActive(true);
+ return newUser(true);
+ }
+
+ private UserDto newUser(boolean active){
+ UserDto dto = UserTesting.newUserDto().setActive(active);
underTest.insert(session, dto);
return dto;
}