Skip to content

Commit 78eab3f

Browse files
authored
Issue #73 Discrete and Inlist Validations throw error if data element value is not simple value (#74)
* Issue #73 Discrete Validation throw error if data element value is not simple value * Issue #73 Discrete validation fix if value is not simple var name to test for consistency * Issue #73 InList Validation throw error if data element value is not simple Value
1 parent 9a2cb69 commit 78eab3f

File tree

4 files changed

+51
-0
lines changed

4 files changed

+51
-0
lines changed

models/validators/DiscreteValidator.cfc

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,25 @@ component extends="BaseValidator" accessors="true" singleton {
5555
return true;
5656
}
5757

58+
// check data element value and return error if it is not simple value.
59+
if ( !isSimpleValue( arguments.targetValue ) ) {
60+
var args = {
61+
message : "The '#arguments.field#' value is not a Simple value",
62+
field : arguments.field,
63+
validationType : getName(),
64+
rejectedValue : ( isSimpleValue( arguments.targetValue ) ? arguments.targetValue : "" ),
65+
validationData : arguments.validationData
66+
};
67+
var error = validationResult
68+
.newError( argumentCollection = args )
69+
.setErrorMetadata( {
70+
"operation" : operation,
71+
"operationValue" : operationValue
72+
} );
73+
validationResult.addError( error );
74+
return false;
75+
}
76+
5877
var r = false;
5978
if ( !isNull( arguments.targetValue ) ) {
6079
switch ( operation ) {

models/validators/InListValidator.cfc

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,24 @@ component extends="BaseValidator" accessors="true" singleton {
3636
return true;
3737
}
3838

39+
// check data element value and return error if it is not simple value.
40+
if ( !isSimpleValue( arguments.targetValue ) ) {
41+
var args = {
42+
message : "The '#arguments.field#' value is not a Simple value",
43+
field : arguments.field,
44+
validationType : getName(),
45+
rejectedValue : ( isSimpleValue( arguments.targetValue ) ? arguments.targetValue : "" ),
46+
validationData : arguments.validationData
47+
};
48+
var error = validationResult
49+
.newError( argumentCollection = args )
50+
.setErrorMetadata( {
51+
"inlist" : arguments.validationData
52+
} );
53+
validationResult.addError( error );
54+
return false;
55+
}
56+
3957
// Now check
4058
if ( listFindNoCase( arguments.validationData, arguments.targetValue ) ) {
4159
return true;

test-harness/tests/specs/validators/DiscreteValidatorTest.cfc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ component extends="coldbox.system.testing.BaseModelTest" model="cbvalidation.mod
4747
assertEquals( false, r );
4848
r = model.validate( result, this, "test", 4, "gte:4" );
4949
assertEquals( true, r );
50+
51+
// Validation check - if simple value
52+
r = model.validate( result, this, "test", [], "gte:1" );
53+
assertEquals( false, r );
5054
}
5155

5256
}

test-harness/tests/specs/validators/InListValidatorTest.cfc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,16 @@ component extends="coldbox.system.testing.BaseModelTest" model="cbvalidation.mod
3232
"luis,joe,alexia,vero"
3333
);
3434
assertEquals( true, r );
35+
36+
// not simple value
37+
r = model.validate(
38+
result,
39+
this,
40+
"test",
41+
[],
42+
"luis,joe,alexia,vero"
43+
);
44+
assertEquals( false, r );
3545
}
3646

3747
function getLuis(){

0 commit comments

Comments
 (0)