Skip to content

Commit c703355

Browse files
committed
Apply cfformat changes
1 parent 18b08ba commit c703355

File tree

5 files changed

+136
-127
lines changed

5 files changed

+136
-127
lines changed

models/validators/MethodValidator.cfc

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@ component
4242
return true;
4343
}
4444

45+
// return true if no data to check, type needs a data element to be checked.
46+
if ( isNull( arguments.targetValue ) || isNullOrEmpty( arguments.targetValue ) ) {
47+
return true;
48+
}
49+
4550
// Validate via method
4651
if (
4752
invoke(
@@ -61,7 +66,9 @@ component
6166
validationData : arguments.validationData
6267
};
6368

64-
validationResult.addError( validationResult.newError( argumentCollection = args ).setErrorMetadata( errorMetadata ) );
69+
validationResult.addError(
70+
validationResult.newError( argumentCollection = args ).setErrorMetadata( errorMetadata )
71+
);
6572
return false;
6673
}
6774

models/validators/UDFValidator.cfc

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,13 @@ component
3535
any validationData,
3636
struct rules
3737
){
38-
39-
var errorMetadata = {};
38+
var errorMetadata = {};
4039

41-
// Validate against the UDF/closure
40+
// Validate against the UDF/closure
4241
var passed = arguments.validationData(
4342
isNull( arguments.targetValue ) ? javacast( "null", "" ) : arguments.targetValue,
44-
arguments.target,
45-
errorMetadata
43+
arguments.target,
44+
errorMetadata
4645
);
4746

4847
if ( passed ) {
@@ -57,7 +56,9 @@ component
5756
validationData : arguments.validationData
5857
};
5958

60-
validationResult.addError( validationResult.newError( argumentCollection = args ).setErrorMetadata( errorMetadata ) );
59+
validationResult.addError(
60+
validationResult.newError( argumentCollection = args ).setErrorMetadata( errorMetadata )
61+
);
6162

6263
return false;
6364
}

test-harness/tests/specs/ValidationIntegrations.cfc

Lines changed: 79 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,8 @@ component extends="coldbox.system.testing.BaseTestCase" appMapping="/root" {
7979
params = {
8080
username : "luis",
8181
password : "luis",
82-
email : "[email protected]",
83-
status : 1,
82+
email : "[email protected]",
83+
status : 1,
8484
bogus : now(),
8585
anotherBogus : now()
8686
},
@@ -146,82 +146,83 @@ component extends="coldbox.system.testing.BaseTestCase" appMapping="/root" {
146146
} );
147147
} );
148148
} );
149-
} );
150-
151-
152-
story( "I want to access error metadata in UDF and method validators", function(){
153-
given( "invalid data", function(){
154-
then( "it should allow access to custom udf metadata", function(){
155-
var e = this.request(
156-
route = "/main/validateOnly",
157-
params = {
158-
username : "luis",
159-
email : "[email protected]",
160-
password : "luis"
161-
},
162-
method = "post"
163-
);
164-
165-
var result = e.getPrivateValue( "result" );
166-
167-
expect( result.getErrors().len() ).toBe( 1 );
168-
expect( result.getErrors()[ 1 ].getValidationType() ).toBe( "UDF" );
169-
expect( result.getErrors()[ 1 ].getErrorMetaData() ).toHaveKey( "custom" );
170-
171-
} );
172-
then( "it should allow udf generated error messages based on metadata", function(){
173-
var e = this.request(
174-
route = "/main/validateOnly",
175-
params = {
176-
username : "luis",
177-
email : "[email protected]",
178-
password : "luis"
179-
},
180-
method = "post"
181-
);
182-
183-
var result = e.getPrivateValue( "result" );
184-
expect( result.getErrors()[ 1 ].getMessage() ).toBe( "This is a custom error message from within the udf" );
185-
} );
186-
then( "it should allow access to custom method metadata", function(){
187-
var e = this.request(
188-
route = "/main/validateOnly",
189-
params = {
190-
username : "luis",
191-
email : "[email protected]",
192-
password : "luis",
193-
status : 1,
194-
type : 4 // should not validate
195-
},
196-
method = "post"
197-
);
198-
199-
var result = e.getPrivateValue( "result" );
200-
201-
expect( result.getErrors().len() ).toBe( 1 );
202-
expect( result.getErrors()[ 1 ].getValidationType() ).toBe( "method" );
203-
expect( result.getErrors()[ 1 ].getErrorMetaData() ).toHaveKey( "custom" );
204-
205-
} );
206-
then( "it should allow method generated error messages based on metadata", function(){
207-
var e = this.request(
208-
route = "/main/validateOnly",
209-
params = {
210-
username : "luis",
211-
email : "[email protected]",
212-
password : "luis",
213-
status : 1,
214-
type : 4 // should not validate
215-
},
216-
method = "post"
217-
);
218-
219-
var result = e.getPrivateValue( "result" );
220-
expect( result.getErrors()[ 1 ].getMessage() ).toBe( "This is a custom error message from within the method" );
221-
222-
} );
223-
} );
224-
} );
149+
} );
150+
151+
152+
story( "I want to access error metadata in UDF and method validators", function(){
153+
given( "invalid data", function(){
154+
then( "it should allow access to custom udf metadata", function(){
155+
var e = this.request(
156+
route = "/main/validateOnly",
157+
params = {
158+
username : "luis",
159+
email : "[email protected]",
160+
password : "luis"
161+
},
162+
method = "post"
163+
);
164+
165+
var result = e.getPrivateValue( "result" );
166+
167+
expect( result.getErrors().len() ).toBe( 1 );
168+
expect( result.getErrors()[ 1 ].getValidationType() ).toBe( "UDF" );
169+
expect( result.getErrors()[ 1 ].getErrorMetaData() ).toHaveKey( "custom" );
170+
} );
171+
then( "it should allow udf generated error messages based on metadata", function(){
172+
var e = this.request(
173+
route = "/main/validateOnly",
174+
params = {
175+
username : "luis",
176+
email : "[email protected]",
177+
password : "luis"
178+
},
179+
method = "post"
180+
);
181+
182+
var result = e.getPrivateValue( "result" );
183+
expect( result.getErrors()[ 1 ].getMessage() ).toBe(
184+
"This is a custom error message from within the udf"
185+
);
186+
} );
187+
then( "it should allow access to custom method metadata", function(){
188+
var e = this.request(
189+
route = "/main/validateOnly",
190+
params = {
191+
username : "luis",
192+
email : "[email protected]",
193+
password : "luis",
194+
status : 1,
195+
type : 4 // should not validate
196+
},
197+
method = "post"
198+
);
199+
200+
var result = e.getPrivateValue( "result" );
201+
202+
expect( result.getErrors().len() ).toBe( 1 );
203+
expect( result.getErrors()[ 1 ].getValidationType() ).toBe( "method" );
204+
expect( result.getErrors()[ 1 ].getErrorMetaData() ).toHaveKey( "custom" );
205+
} );
206+
then( "it should allow method generated error messages based on metadata", function(){
207+
var e = this.request(
208+
route = "/main/validateOnly",
209+
params = {
210+
username : "luis",
211+
email : "[email protected]",
212+
password : "luis",
213+
status : 1,
214+
type : 4 // should not validate
215+
},
216+
method = "post"
217+
);
218+
219+
var result = e.getPrivateValue( "result" );
220+
expect( result.getErrors()[ 1 ].getMessage() ).toBe(
221+
"This is a custom error message from within the method"
222+
);
223+
} );
224+
} );
225+
} );
225226
}
226227

227228
}

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

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -97,33 +97,33 @@ component extends="coldbox.system.testing.BaseModelTest" model="cbvalidation.mod
9797
).toBeTrue();
9898
} );
9999

100-
it( "simply checks for existence when passing in a simple value", function() {
101-
var mock = createStub()
100+
it( "simply checks for existence when passing in a simple value", function(){
101+
var mock = createStub()
102102
.$( "getName", "luis" )
103103
.$( "getRole", "admin" )
104104
.$( "getMissing", javacast( "null", "" ) );
105105
var result = createMock( "cbvalidation.models.result.ValidationResult" ).init();
106106

107107
expect(
108-
model.validate(
109-
result,
110-
mock,
111-
"testField",
112-
"",
113-
"name"
114-
)
115-
).toBeFalse();
116-
117-
// expect(
118-
// model.validate(
119-
// result,
120-
// mock,
121-
// "testField",
122-
// "",
123-
// "missing"
124-
// )
125-
// ).toBeTrue();
126-
} );
108+
model.validate(
109+
result,
110+
mock,
111+
"testField",
112+
"",
113+
"name"
114+
)
115+
).toBeFalse();
116+
117+
// expect(
118+
// model.validate(
119+
// result,
120+
// mock,
121+
// "testField",
122+
// "",
123+
// "missing"
124+
// )
125+
// ).toBeTrue();
126+
} );
127127
} );
128128
}
129129

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

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -117,33 +117,33 @@ component extends="coldbox.system.testing.BaseModelTest" model="cbvalidation.mod
117117
).toBeTrue();
118118
} );
119119

120-
it( "simply checks for existence when passing in a simple value", function() {
121-
var mock = createStub()
120+
it( "simply checks for existence when passing in a simple value", function(){
121+
var mock = createStub()
122122
.$( "getName", "luis" )
123123
.$( "getRole", "admin" )
124124
.$( "getMissing", javacast( "null", "" ) );
125125
var result = createMock( "cbvalidation.models.result.ValidationResult" ).init();
126126

127127
expect(
128-
model.validate(
129-
result,
130-
mock,
131-
"testField",
132-
"",
133-
"name"
134-
)
135-
).toBeTrue();
136-
137-
expect(
138-
model.validate(
139-
result,
140-
mock,
141-
"testField",
142-
"",
143-
"missing"
144-
)
145-
).toBeFalse();
146-
} );
128+
model.validate(
129+
result,
130+
mock,
131+
"testField",
132+
"",
133+
"name"
134+
)
135+
).toBeTrue();
136+
137+
expect(
138+
model.validate(
139+
result,
140+
mock,
141+
"testField",
142+
"",
143+
"missing"
144+
)
145+
).toBeFalse();
146+
} );
147147
} );
148148
}
149149

0 commit comments

Comments
 (0)