| 114 | var Product = null, Supplier = null; |
| 115 | |
| 116 | var setupUnique = function (ignoreCase, scope, msg) { |
| 117 | return function (done) { |
| 118 | Supplier = db.define("supplier", { |
| 119 | name : String |
| 120 | }, { |
| 121 | cache: false |
| 122 | }); |
| 123 | helper.dropSync(Supplier, function(err){ |
| 124 | if (err) { |
| 125 | return done(err); |
| 126 | } |
| 127 | |
| 128 | Product = db.define("productUnique", { |
| 129 | instock : { type: 'boolean', required: true, defaultValue: false }, |
| 130 | name : String, |
| 131 | category : String |
| 132 | }, { |
| 133 | cache: false, |
| 134 | validations: { |
| 135 | name : ORM.validators.unique({ ignoreCase: ignoreCase, scope: scope }, msg), |
| 136 | instock : ORM.validators.required(), |
| 137 | productId : ORM.validators.unique() // this must be straight after a required & validated row. |
| 138 | } |
| 139 | }); |
| 140 | Product.hasOne('supplier', Supplier, { field: 'supplierId' }); |
| 141 | |
| 142 | return helper.dropSync(Product, done); |
| 143 | }); |
| 144 | }; |
| 145 | }; |
| 146 | |
| 147 | describe("simple", function () { |
| 148 | before(setupUnique(false, false)); |