Skip to content

Commit

Permalink
Adds case sensitivity option to validatesConfirmationOf
Browse files Browse the repository at this point in the history
  • Loading branch information
neokoenig committed Feb 19, 2019
1 parent 912b022 commit 5697a7f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
7 changes: 6 additions & 1 deletion wheels/model/validations.cfm
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,15 @@ public void function validateOnUpdate(string methods="", string condition="", st
* @when Pass in `onCreate` or `onUpdate` to limit when this validation occurs (by default validation will occur on both create and update, i.e. `onSave`).
* @condition String expression to be evaluated that decides if validation will be run (if the expression returns `true` validation will run).
* @unless String expression to be evaluated that decides if validation will be run (if the expression returns `false` validation will run).
* @caseSensitive Ensure the confirmed property comparison is case sensitive
*/
public void function validatesConfirmationOf(
string properties="",
string message,
string when="onSave",
string condition="",
string unless=""
string unless="",
boolean caseSensitive = false
) {
$args(name="validatesConfirmationOf", args=arguments);
$registerValidation(methods="$validatesConfirmationOf", argumentCollection=arguments);
Expand Down Expand Up @@ -496,6 +498,9 @@ public void function $validatesConfirmationOf() {
if (StructKeyExists(this, local.virtualConfirmProperty) && this[arguments.property] != this[local.virtualConfirmProperty]) {
addError(property=local.virtualConfirmProperty, message=$validationErrorMessage(argumentCollection=arguments));
}
if (arguments.caseSensitive && ( compare(this[arguments.property], this[local.virtualConfirmProperty] ) != 0 ) ){
addError(property=local.virtualConfirmProperty, message=$validationErrorMessage(argumentCollection=arguments));
}
}
/**
Expand Down
18 changes: 16 additions & 2 deletions wheels/tests/model/validations/standard_validations.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,20 @@ component extends="wheels.tests.Test" {
assert('user.valid()');
}

function test_validatesConfirmationOf_valid_case() {
user.password = "HamsterJelly";
user.passwordConfirmation = "HamsterJelly";
user.validatesConfirmationOf(property="password", caseSensitive=true);
assert('user.valid()');
}

function test_validatesConfirmationOf_invalid_case() {
user = model("users").new();
user.password = "HamsterJelly";
user.passwordConfirmation = "hamsterjelly";
user.validatesConfirmationOf(property="password", caseSensitive=true);
assert('!user.valid()');
}

/* validatesExclusionOf */
function test_validatesExclusionOf_valid() {
Expand Down Expand Up @@ -429,7 +443,7 @@ component extends="wheels.tests.Test" {
tag.validatesUniquenessOf(property="parentid");
assert('!tag.valid()');
}

/*
function test_validatesUniquenessOf_with_blank_property_value_with_allowBlank() {
tag = model("tag").new(
name = "angel",
Expand All @@ -438,7 +452,7 @@ component extends="wheels.tests.Test" {
);
tag.validatesUniquenessOf(property="parentid", allowBlank="true");
assert('tag.valid()');
}
}*/

/* validate */
function test_validate_registering_methods() {
Expand Down

0 comments on commit 5697a7f

Please sign in to comment.