@@ -119,6 +119,21 @@ describe("Hook", function() {
119119 } ) ;
120120 } ) ;
121121
122+ it ( "should allow modification of instance" , function ( done ) {
123+ Person . beforeCreate ( function ( next ) {
124+ this . name = "Hook Worked" ;
125+ next ( ) ;
126+ } ) ;
127+
128+ Person . create ( [ { } ] , function ( err , people ) {
129+ should . not . exist ( err ) ;
130+ should . exist ( people ) ;
131+ should . equal ( people . length , 1 ) ;
132+ should . equal ( people [ 0 ] . name , "Hook Worked" ) ;
133+ done ( ) ;
134+ } ) ;
135+ } ) ;
136+
122137 describe ( "when setting properties" , function ( ) {
123138 before ( setup ( {
124139 beforeCreate : function ( ) {
@@ -217,6 +232,20 @@ describe("Hook", function() {
217232 return done ( ) ;
218233 } ) ;
219234 } ) ;
235+
236+ it ( "should allow modification of instance" , function ( done ) {
237+ Person . beforeSave ( function ( ) {
238+ this . name = "Hook Worked" ;
239+ } ) ;
240+
241+ Person . create ( [ { name : "John Doe" } ] , function ( err , people ) {
242+ should . not . exist ( err ) ;
243+ should . exist ( people ) ;
244+ should . equal ( people . length , 1 ) ;
245+ should . equal ( people [ 0 ] . name , "Hook Worked" ) ;
246+ done ( ) ;
247+ } ) ;
248+ } ) ;
220249
221250 describe ( "when setting properties" , function ( ) {
222251 before ( setup ( {
@@ -339,6 +368,21 @@ describe("Hook", function() {
339368 } ) ;
340369 } ) ;
341370
371+
372+ it ( "should allow modification of instance" , function ( done ) {
373+ Person . beforeValidation ( function ( ) {
374+ this . name = "Hook Worked" ;
375+ } ) ;
376+
377+ Person . create ( [ { name : "John Doe" } ] , function ( err , people ) {
378+ should . not . exist ( err ) ;
379+ should . exist ( people ) ;
380+ should . equal ( people . length , 1 ) ;
381+ should . equal ( people [ 0 ] . name , "Hook Worked" ) ;
382+ done ( ) ;
383+ } ) ;
384+ } ) ;
385+
342386 describe ( "if hook method has 1 argument" , function ( ) {
343387 var beforeValidation = false ;
344388 this . timeout ( 500 ) ;
@@ -589,4 +633,31 @@ describe("Hook", function() {
589633 } ) ;
590634 } ) ;
591635 } ) ;
636+
637+ describe ( "instance modifications" , function ( ) {
638+ before ( setup ( {
639+ beforeValidation : function ( ) {
640+ should . equal ( this . name , "John Doe" ) ;
641+ this . name = "beforeValidation" ;
642+ } ,
643+ beforeCreate : function ( ) {
644+ should . equal ( this . name , "beforeValidation" ) ;
645+ this . name = "beforeCreate" ;
646+ } ,
647+ beforeSave : function ( ) {
648+ should . equal ( this . name , "beforeCreate" ) ;
649+ this . name = "beforeSave" ;
650+ }
651+ } ) ) ;
652+
653+ it ( "should propagate down hooks" , function ( done ) {
654+ Person . create ( [ { name : "John Doe" } ] , function ( err , people ) {
655+ should . not . exist ( err ) ;
656+ should . exist ( people ) ;
657+ should . equal ( people . length , 1 ) ;
658+ should . equal ( people [ 0 ] . name , "beforeSave" ) ;
659+ done ( ) ;
660+ } ) ;
661+ } ) ;
662+ } ) ;
592663} ) ;
0 commit comments