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 joe@gmail.com in your database user and exist check with mongodb if in collection users at field email : joe@gmail.com exist will return true but unique return false because they are already an email with joe@gmail.com.

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", "jean@mail.com", true);
    UtilTest.testIt("unique: user, mail|email", "christian@gmail.com", true);
    UtilTest.testIt("unique: user, mail|email", "123@gmail.com", 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);
}

results matching ""

    No results matching ""