|
| 1 | +/** |
| 2 | + * ******************************************************************************* |
| 3 | + * ******************************************************************************* |
| 4 | + */ |
| 5 | +component extends="coldbox.system.testing.BaseModelTest" model="cbvalidation.models.validators.InstanceOfValidator" { |
| 6 | + |
| 7 | + // executes before all suites+specs in the run() method |
| 8 | + function beforeAll(){ |
| 9 | + super.setup(); |
| 10 | + model.init(); |
| 11 | + } |
| 12 | + |
| 13 | + // executes after all suites+specs in the run() method |
| 14 | + function afterAll(){ |
| 15 | + } |
| 16 | + |
| 17 | + /*********************************** BDD SUITES ***********************************/ |
| 18 | + |
| 19 | + function run( testResults, testBox ){ |
| 20 | + // all your suites go here. |
| 21 | + describe( "InstanceOf", function(){ |
| 22 | + beforeEach( function( currentSpec ){ |
| 23 | + result = createMock( "cbvalidation.models.result.ValidationResult" ).init(); |
| 24 | + } ); |
| 25 | + |
| 26 | + it( "validates true when expecting a User and receives a User", function(){ |
| 27 | + |
| 28 | + var user = createMock( "root.models.User" ).init(); |
| 29 | + |
| 30 | + expect( |
| 31 | + model.validate( |
| 32 | + validationResult: result, |
| 33 | + target : this, |
| 34 | + field : "testField", |
| 35 | + targetValue : user, |
| 36 | + validationData : "user", |
| 37 | + rules : {} |
| 38 | + ) |
| 39 | + ).toBeTrue(); |
| 40 | + } ); |
| 41 | + |
| 42 | + it( "validates false when expecting a Car and receives a User", function(){ |
| 43 | + |
| 44 | + var user = createMock( "root.models.User" ).init(); |
| 45 | + |
| 46 | + expect( |
| 47 | + model.validate( |
| 48 | + validationResult: result, |
| 49 | + target : this, |
| 50 | + field : "testField", |
| 51 | + targetValue : user, |
| 52 | + validationData : "car", |
| 53 | + rules : {} |
| 54 | + ) |
| 55 | + ).toBeFalse(); |
| 56 | + } ); |
| 57 | + |
| 58 | + it( "validates true when passed nothing", function(){ |
| 59 | + |
| 60 | + expect( |
| 61 | + model.validate( |
| 62 | + validationResult: result, |
| 63 | + target : this, |
| 64 | + field : "testField", |
| 65 | + targetValue : "", |
| 66 | + validationData : "car", |
| 67 | + rules : {} |
| 68 | + ) |
| 69 | + ).toBeTrue(); |
| 70 | + } ); |
| 71 | + |
| 72 | + it( "validates false when passed a non-object", function(){ |
| 73 | + |
| 74 | + expect( |
| 75 | + model.validate( |
| 76 | + validationResult: result, |
| 77 | + target : this, |
| 78 | + field : "testField", |
| 79 | + targetValue : "not an object", // not an object |
| 80 | + validationData : "car", |
| 81 | + rules : {} |
| 82 | + ) |
| 83 | + ).toBeFalse(); |
| 84 | + expect( |
| 85 | + model.validate( |
| 86 | + validationResult: result, |
| 87 | + target : this, |
| 88 | + field : "testField", |
| 89 | + targetValue : { "name": "not an object" }, // not an object |
| 90 | + validationData : "car", |
| 91 | + rules : {} |
| 92 | + ) |
| 93 | + ).toBeFalse(); |
| 94 | + expect( |
| 95 | + model.validate( |
| 96 | + validationResult: result, |
| 97 | + target : this, |
| 98 | + field : "testField", |
| 99 | + targetValue : [ 1, 2, 3 ], // not an object |
| 100 | + validationData : "car", |
| 101 | + rules : {} |
| 102 | + ) |
| 103 | + ).toBeFalse(); |
| 104 | + } ); |
| 105 | + } ); |
| 106 | + } |
| 107 | + |
| 108 | +} |
0 commit comments