@@ -64,13 +64,18 @@ describe("Validations", function() {
6464 var setupUnique = function ( ignoreCase , scope , msg ) {
6565 return function ( done ) {
6666 Product = db . define ( "product_unique" , {
67- name : String ,
67+ instock : { type : 'boolean' , required : true , defaultValue : false } ,
68+ name : String ,
6869 category : String
6970 } , {
71+ cache : false ,
7072 validations : {
71- name : [ ORM . validators . unique ( { ignoreCase : ignoreCase , scope : scope } , msg ) ]
73+ name : ORM . validators . unique ( { ignoreCase : ignoreCase , scope : scope } , msg ) ,
74+ instock : ORM . validators . required ( ) ,
75+ productId : ORM . validators . unique ( ) // this must be straight after a required & validated row.
7276 }
7377 } ) ;
78+ Product . hasOne ( 'product' , Product , { field : 'productId' , required : false , autoFetch : true } ) ;
7479
7580 return helper . dropSync ( Product , done ) ;
7681 } ;
@@ -102,6 +107,19 @@ describe("Validations", function() {
102107 } ) ;
103108 } ) ;
104109 } ) ;
110+
111+ // Technically this is covered by the tests above, but I'm putting it here for clarity's sake. 3 HOURS WASTED *sigh.
112+ it ( "should not leak required state from previous validation for association properties [regression test]" , function ( done ) {
113+ Product . create ( { name : 'pencil' , productId : null } , function ( err , product ) {
114+ should . not . exist ( err ) ;
115+
116+ Product . create ( { name : 'pencilcase' , productId : null } , function ( err , product ) {
117+ should . not . exist ( err ) ;
118+
119+ return done ( ) ;
120+ } ) ;
121+ } ) ;
122+ } ) ;
105123 } ) ;
106124
107125 describe ( "scope" , function ( ) {
0 commit comments