Skip to content

Commit 391495f

Browse files
committed
more more more tests baby!!!
1 parent b7e20ba commit 391495f

File tree

8 files changed

+96
-21
lines changed

8 files changed

+96
-21
lines changed

helpers/Mixins.cfm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ boolean function validateHasValue( any targetValue ){
7373
* @targetValue the value to check for nullness/emptyness
7474
*/
7575
boolean function validateIsNullOrEmpty( any targetValue ){
76-
return getValidationManager().getValidator( "Required", {} ).hasValue( argumentCollection = arguments );
76+
return !getValidationManager().getValidator( "Required", {} ).hasValue( argumentCollection = arguments );
7777
}
7878
7979
/**

models/delegates/Validatable.cfc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ component accessors="true" {
102102
* @targetValue the value to check for nullness/emptyness
103103
*/
104104
boolean function validateIsNullOrEmpty( any targetValue ){
105-
return variables.validationManager
105+
return !variables.validationManager
106106
.getValidator( "Required", {} )
107107
.hasValue( argumentCollection = arguments );
108108
}
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
component extends="coldbox.system.testing.BaseTestCase" appMapping="/root" {
2+
3+
this.unLoadColdBox = false;
4+
5+
/*********************************** LIFE CYCLE Methods ***********************************/
6+
7+
function beforeAll(){
8+
super.beforeAll();
9+
// do your own stuff here
10+
}
11+
12+
function afterAll(){
13+
// do your own stuff here
14+
super.afterAll();
15+
}
16+
17+
/*********************************** BDD SUITES ***********************************/
18+
19+
function run(){
20+
describe( "Validatable Spec", function(){
21+
beforeEach( function( currentSpec ){
22+
// Setup as a new ColdBox request, VERY IMPORTANT. ELSE EVERYTHING LOOKS LIKE THE SAME REQUEST.
23+
setup();
24+
delegate = getInstance( "Validatable@cbValidation" );
25+
delegate.injectPropertyMixin( "$parent", this );
26+
} );
27+
28+
it( "can be created", function(){
29+
expect( delegate ).toBeComponent()
30+
} );
31+
32+
it( "can validate if a target has value", function(){
33+
expect( delegate.validateHasValue( "test" ) ).toBeTrue();
34+
expect( delegate.validateHasValue( "" ) ).toBeFalse();
35+
} );
36+
37+
it( "can validate if a target is null or empty", function(){
38+
expect( delegate.validateIsNullOrEmpty( "" ) ).toBeTrue();
39+
expect( delegate.validateIsNullOrEmpty( javacast( "null", "" ) ) ).toBeTrue();
40+
expect( delegate.validateIsNullOrEmpty( "test" ) ).toBeFalse();
41+
} );
42+
43+
it( "can validate if a target can be asserted", function(){
44+
expect( delegate.assert( true ) ).toBeTrue();
45+
expect( () => delegate.assert( javacast( "null", "" ) ) ).toThrow();
46+
expect( () => delegate.assert( false ) ).toThrow();
47+
} );
48+
49+
it( "can validate", function(){
50+
var results = delegate.validate();
51+
expect( results.hasErrors() ).toBeFalse();
52+
});
53+
54+
it( "can validate or fail", function(){
55+
expect( () => delegate.validateOrFail() ).notToThrow();
56+
expect( () => delegate.validateOrFail(
57+
constraints = {
58+
"data" : { required : true }
59+
}
60+
) ).toThrow();
61+
});
62+
63+
it( "can self validate", function(){
64+
var results = delegate.isValid();
65+
expect( results ).toBeTrue();
66+
expect( delegate.getValidationResults().hasErrors() ).toBeFalse();
67+
});
68+
} );
69+
}
70+
71+
function getData(){
72+
return "";
73+
}
74+
75+
}

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,17 @@ component
2424
result = createMock( "cbvalidation.models.result.ValidationResult" ).init();
2525
} );
2626

27-
it( "can throw an exception if the target value is not a date", function(){
28-
expect( function(){
27+
it( "can invalidate if the target value is not a date", function(){
28+
expect(
2929
model.validate(
3030
validationResult: result,
3131
target : this,
3232
field : "testField",
3333
targetValue : "I am not a date",
3434
validationData : now(),
3535
rules : {}
36-
);
37-
} ).toThrow();
36+
)
37+
).toBeFalse();
3838
} );
3939

4040
it( "can validate true if the field under validation is after the target", function(){

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,17 @@ component extends="coldbox.system.testing.BaseModelTest" model="cbvalidation.mod
2121
result = createMock( "cbvalidation.models.result.ValidationResult" ).init();
2222
} );
2323

24-
it( "can throw an exception if the target value is not a date", function(){
25-
expect( function(){
24+
it( "can invalidate if the target value is not a date", function(){
25+
expect(
2626
model.validate(
2727
validationResult: result,
2828
target : this,
2929
field : "testField",
3030
targetValue : "I am not a date",
3131
validationData : now(),
3232
rules : {}
33-
);
34-
} ).toThrow();
33+
)
34+
).toBeFalse();
3535
} );
3636

3737
it( "can validate true if the field under validation is after the target", function(){

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,17 @@ component
2424
result = createMock( "cbvalidation.models.result.ValidationResult" ).init();
2525
} );
2626

27-
it( "can throw an exception if the target value is not a date", function(){
28-
expect( function(){
27+
it( "can invalidate if the target value is not a date", function(){
28+
expect(
2929
model.validate(
3030
validationResult: result,
3131
target : this,
3232
field : "testField",
3333
targetValue : "I am not a date",
3434
validationData : now(),
3535
rules : {}
36-
);
37-
} ).toThrow();
36+
)
37+
).toBeFalse();
3838
} );
3939

4040
it( "can validate true if the field under validation is before the target", function(){

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,17 @@ component extends="coldbox.system.testing.BaseModelTest" model="cbvalidation.mod
2121
result = createMock( "cbvalidation.models.result.ValidationResult" ).init();
2222
} );
2323

24-
it( "can throw an exception if the target value is not a date", function(){
25-
expect( function(){
24+
it( "can invalidate if the target value is not a date", function(){
25+
expect(
2626
model.validate(
2727
validationResult: result,
2828
target : this,
2929
field : "testField",
3030
targetValue : "I am not a date",
3131
validationData : now(),
3232
rules : {}
33-
);
34-
} ).toThrow();
33+
)
34+
).toBeFalse();
3535
} );
3636

3737
it( "can validate true if the field under validation is before the target", function(){

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,16 @@ component extends="coldbox.system.testing.BaseModelTest" model="cbvalidation.mod
2222
} );
2323

2424
it( "can throw an exception if the target value is not a date", function(){
25-
expect( function(){
25+
expect(
2626
model.validate(
2727
validationResult: result,
2828
target : this,
2929
field : "testField",
3030
targetValue : "I am not a date",
3131
validationData : now(),
3232
rules : {}
33-
);
34-
} ).toThrow();
33+
)
34+
).toBeFalse();
3535
} );
3636

3737
it( "can validate false if the field under validation is before the target", function(){

0 commit comments

Comments
 (0)