@@ -61,13 +61,42 @@ test("validatesFormatOf", function(){
6161} ) ;
6262
6363test ( "validatesInclusionOf" , function ( ) {
64+ Person . validateInclusionOf ( "thing" , [ "yes" , "no" , "maybe" ] ) ;
65+
66+ ok ( ! new Person ( { thing : "yes" } ) . errors ( ) , "no errors" ) ;
67+
68+ var errors = new Person ( { thing : "foobar" } ) . errors ( ) ;
69+
70+ ok ( errors , "there are errors" ) ;
71+ equals ( errors . thing . length , 1 , "one error on thing" ) ;
72+
73+ equals ( errors . thing [ 0 ] , "is not a valid option (perhaps out of range)" , "basic message" ) ;
74+
75+ Person . validateInclusionOf ( "otherThing" , [ "yes" , "no" , "maybe" ] , { message : "not a valid option" } ) ;
6476
77+ var errors2 = new Person ( { thing : "yes" , otherThing : "maybe not" } ) . errors ( ) ;
6578
66- } )
79+ equals ( errors2 . otherThing [ 0 ] , "not a valid option" , "can supply a custom message" ) ;
80+ } ) ;
6781
6882test ( "validatesLengthOf" , function ( ) {
83+ Person . validateLengthOf ( "thing" , 2 , 5 ) ;
84+
85+ ok ( ! new Person ( { thing : "yes" } ) . errors ( ) , "no errors" ) ;
6986
70- } )
87+ var errors = new Person ( { thing : "foobar" } ) . errors ( ) ;
88+
89+ ok ( errors , "there are errors" ) ;
90+ equals ( errors . thing . length , 1 , "one error on thing" ) ;
91+
92+ equals ( errors . thing [ 0 ] , "is too long (max=5)" , "basic message" ) ;
93+
94+ Person . validateLengthOf ( "otherThing" , 2 , 5 , { message : "invalid length" } ) ;
95+
96+ var errors2 = new Person ( { thing : "yes" , otherThing : "too long" } ) . errors ( ) ;
97+
98+ equals ( errors2 . otherThing [ 0 ] , "invalid length" , "can supply a custom message" ) ;
99+ } ) ;
71100
72101test ( "validatesPresenceOf" , function ( ) {
73102 $ . Model . extend ( "Task" , {
@@ -101,7 +130,22 @@ test("validatesPresenceOf", function(){
101130} )
102131
103132test ( "validatesRangeOf" , function ( ) {
104-
105- } )
133+ Person . validateRangeOf ( "thing" , 2 , 5 ) ;
134+
135+ ok ( ! new Person ( { thing : 4 } ) . errors ( ) , "no errors" ) ;
136+
137+ var errors = new Person ( { thing : 6 } ) . errors ( ) ;
138+
139+ ok ( errors , "there are errors" )
140+ equals ( errors . thing . length , 1 , "one error on thing" ) ;
141+
142+ equals ( errors . thing [ 0 ] , "is out of range [2,5]" , "basic message" ) ;
143+
144+ Person . validateRangeOf ( "otherThing" , 2 , 5 , { message : "value out of range" } ) ;
145+
146+ var errors2 = new Person ( { thing : 4 , otherThing : 6 } ) . errors ( ) ;
147+
148+ equals ( errors2 . otherThing [ 0 ] , "value out of range" , "can supply a custom message" ) ;
149+ } ) ;
106150
107151} )
0 commit comments