@@ -79,7 +79,7 @@ describe(Support.getTestDialectTeaser('InstanceValidator'), function() {
7979 } ) ;
8080 } ) ;
8181
82- it ( 'should enforce a unque constraint' , function ( ) {
82+ it ( 'should enforce a unique constraint' , function ( ) {
8383 var Model = this . sequelize . define ( 'model' , {
8484 uniqueName : { type : Sequelize . STRING , unique : true }
8585 } ) ;
@@ -103,6 +103,34 @@ describe(Support.getTestDialectTeaser('InstanceValidator'), function() {
103103 expect ( err . errors [ 0 ] . message ) . to . include ( 'must be unique' ) ;
104104 } ) ;
105105 } ) ;
106+
107+ it ( 'should allow a custom unique constraint error message' , function ( ) {
108+ var Model = this . sequelize . define ( 'model' , {
109+ uniqueName : {
110+ type : Sequelize . STRING ,
111+ unique : { msg : 'custom unique error message' }
112+ }
113+ } ) ;
114+ var records = [
115+ { uniqueName : 'unique name one' } ,
116+ { uniqueName : 'unique name two' }
117+ ] ;
118+ return Model . sync ( { force : true } )
119+ . then ( function ( ) {
120+ return Model . create ( records [ 0 ] ) ;
121+ } ) . then ( function ( instance ) {
122+ expect ( instance ) . to . be . ok ;
123+ return Model . create ( records [ 1 ] ) ;
124+ } ) . then ( function ( instance ) {
125+ expect ( instance ) . to . be . ok ;
126+ return expect ( Model . update ( records [ 0 ] , { where : { id : instance . id } } ) ) . to . be . rejected ;
127+ } ) . then ( function ( err ) {
128+ expect ( err ) . to . be . an . instanceOf ( Error ) ;
129+ expect ( err . errors ) . to . have . length ( 1 ) ;
130+ expect ( err . errors [ 0 ] . path ) . to . include ( 'uniqueName' ) ;
131+ expect ( err . errors [ 0 ] . message ) . to . equal ( 'custom unique error message' ) ;
132+ } ) ;
133+ } ) ;
106134 } ) ;
107135
108136 describe ( '#create' , function ( ) {
0 commit comments