Is unique
Definition
Return true if value is unique. Unique is dependant of your form implementation. Unique use Form#exist(String collection, String field, String value).
If you want to use your database modify the implementation you have choose.
Example: if you have an user with [email protected] in your database user and exist check with mongodb if in collection users at field email : [email protected]
exist will return true but unique return false because they are already an email with [email protected]
.
Usage
addRule("field -> unique: users, email")
Tests
@Test
public final void testRuleUniqueOk() throws Exception {
System.out.println("=== TEST FOR `unique` RULE ===\n");
UtilTest.testIt("unique: user, mail|email", "[email protected]", true);
UtilTest.testIt("unique: user, mail|email", "[email protected]", true);
UtilTest.testIt("unique: user, mail|email", "[email protected]", true);
}
@Test
public final void testRuleUniqueNotOk() throws Exception {
UtilTest.testIt("unique: user, mail|email", RandomUser.randoms.get(0).email, false);
UtilTest.testIt("unique: user, mail|email", RandomUser.randoms.get(1).email, false);
UtilTest.testIt("unique: user, mail|email", RandomUser.randoms.get(3).email, false);
UtilTest.testIt("unique: user, mail|email", "not email an email", false);
}