Skip to content

Commit 8a460ab

Browse files
lmajanogithub-actions[bot]
authored andcommitted
Apply cfformat changes
1 parent 05a58a8 commit 8a460ab

File tree

2 files changed

+31
-65
lines changed

2 files changed

+31
-65
lines changed

models/validators/RequiredIfValidator.cfc

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ component
3737
any validationData,
3838
struct rules
3939
){
40-
var isRequired = true;
41-
var errorMetadata = {};
40+
var isRequired = true;
41+
var errorMetadata = {};
4242

4343
// If you passed in simple data, simply check that the target field has a value
4444
if ( isSimpleValue( arguments.validationData ) && len( arguments.validationData ) ) {
@@ -61,22 +61,19 @@ component
6161
.reduce( function( result, key, value ){
6262
return ( arguments.value && arguments.result );
6363
}, true );
64-
// If passed a UDF/closure
65-
} else if (
66-
isCustomFunction( arguments.validationData ) ||
67-
isClosure( arguments.validationData )
68-
) {
69-
70-
// Validate against the UDF/closure
71-
var isRequired = arguments.validationData(
72-
isNull( arguments.targetValue ) ? javacast( "null", "" ) : arguments.targetValue,
73-
arguments.target,
74-
errorMetadata
75-
);
76-
77-
} else {
78-
79-
validationResult.addError(
64+
// If passed a UDF/closure
65+
} else if (
66+
isCustomFunction( arguments.validationData ) ||
67+
isClosure( arguments.validationData )
68+
) {
69+
// Validate against the UDF/closure
70+
var isRequired = arguments.validationData(
71+
isNull( arguments.targetValue ) ? javacast( "null", "" ) : arguments.targetValue,
72+
arguments.target,
73+
errorMetadata
74+
);
75+
} else {
76+
validationResult.addError(
8077
validationResult.newError(
8178
message = "The target for RequiredIf must be a simple field name or a struct of field to target value pairs.",
8279
field = arguments.field,
@@ -109,9 +106,9 @@ component
109106
validationData : arguments.validationData
110107
};
111108

112-
validationResult.addError(
113-
validationResult.newError( argumentCollection = args ).setErrorMetadata( errorMetadata )
114-
);
109+
validationResult.addError(
110+
validationResult.newError( argumentCollection = args ).setErrorMetadata( errorMetadata )
111+
);
115112
return false;
116113
}
117114

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

Lines changed: 13 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -106,78 +106,47 @@ component extends="coldbox.system.testing.BaseModelTest" model="cbvalidation.mod
106106

107107
expect( model.validate( result, mock, "testField", "", "name" ) ).toBeFalse();
108108

109-
expect(
110-
model.validate(
111-
result,
112-
mock,
113-
"testField",
114-
"",
115-
"missing"
116-
)
117-
).toBeTrue();
109+
expect( model.validate( result, mock, "testField", "", "missing" ) ).toBeTrue();
118110
} );
119-
it( "can accept a closure as validationData", function(){
111+
it( "can accept a closure as validationData", function(){
120112
var mock = createStub()
121113
.$( "getName", "luis" )
122114
.$( "getRole", "admin" )
123115
.$( "getMissing", javacast( "null", "" ) );
124116
var result = createMock( "cbvalidation.models.result.ValidationResult" ).init();
125117

126-
expect(
127-
model.validate(
128-
result,
129-
mock,
130-
"testField",
131-
"",
132-
isRequired1
133-
) ).toBeFalse();
118+
expect( model.validate( result, mock, "testField", "", isRequired1 ) ).toBeFalse();
134119

135-
expect(
136-
model.validate(
137-
result,
138-
mock,
139-
"testField",
140-
"",
141-
isRequired2
142-
)
143-
).toBeTrue();
120+
expect( model.validate( result, mock, "testField", "", isRequired2 ) ).toBeTrue();
144121
} );
145-
it( "can use custom error metadata", function(){
122+
it( "can use custom error metadata", function(){
146123
var mock = createStub()
147124
.$( "getName", "luis" )
148125
.$( "getRole", "admin" )
149126
.$( "getMissing", javacast( "null", "" ) );
150127
var result = createMock( "cbvalidation.models.result.ValidationResult" ).init();
151128

152-
expect(
153-
model.validate(
154-
result,
155-
mock,
156-
"testField",
157-
"",
158-
isRequired3
159-
) ).toBeFalse();
129+
expect( model.validate( result, mock, "testField", "", isRequired3 ) ).toBeFalse();
160130

161-
var errorMetadata = result.getErrors()[ 1 ].getErrorMetadata();
131+
var errorMetadata = result.getErrors()[ 1 ].getErrorMetadata();
162132

163-
expect( errorMetaData ).toHaveKey( "customMessage" );
164-
expect( errorMetaData.customMessage ).toBe( "This is custom data" );
165-
133+
expect( errorMetaData ).toHaveKey( "customMessage" );
134+
expect( errorMetaData.customMessage ).toBe( "This is custom data" );
166135
} );
167136
} );
168137
}
169138

170-
private function isRequired1( value, target, errorMetadata ){
139+
private function isRequired1( value, target, errorMetadata ){
171140
return true;
172141
}
173142

174-
private function isRequired2( value, target, errorMetadata ){
143+
private function isRequired2( value, target, errorMetadata ){
175144
return false;
176145
}
177146

178-
private function isRequired3( value, target, errorMetadata ){
147+
private function isRequired3( value, target, errorMetadata ){
179148
arguments.errorMetadata[ "customMessage" ] = "This is custom data";
180-
return true;
149+
return true;
181150
}
182151

183152
}

0 commit comments

Comments
 (0)