@@ -9,6 +9,7 @@ module('call-remote-callbacks', {
99 teardown : function ( ) {
1010 $ ( document ) . undelegate ( 'form[data-remote]' , 'ajax:beforeSend' ) ;
1111 $ ( document ) . undelegate ( 'form[data-remote]' , 'ajax:before' ) ;
12+ $ ( document ) . undelegate ( 'form[data-remote]' , 'ajax:send' ) ;
1213 $ ( document ) . undelegate ( 'form[data-remote]' , 'ajax:complete' ) ;
1314 $ ( document ) . undelegate ( 'form[data-remote]' , 'ajax:success' ) ;
1415 $ ( document ) . unbind ( 'ajaxStop' ) ;
@@ -97,6 +98,9 @@ asyncTest('stopping the "ajax:beforeSend" event aborts the request', 1, function
9798 ok ( true , 'aborting request in ajax:beforeSend' ) ;
9899 return false ;
99100 } ) ;
101+ form . unbind ( 'ajax:send' ) . bind ( 'ajax:send' , function ( ) {
102+ ok ( false , 'ajax:send should not run' ) ;
103+ } ) ;
100104 form . unbind ( 'ajax:complete' ) . bind ( 'ajax:complete' , function ( ) {
101105 ok ( false , 'ajax:complete should not run' ) ;
102106 } ) ;
@@ -315,6 +319,9 @@ asyncTest('"ajax:beforeSend" can be observed and stopped with event delegation',
315319 } ) ;
316320
317321 submit ( function ( form ) {
322+ form . unbind ( 'ajax:send' ) . bind ( 'ajax:send' , function ( ) {
323+ ok ( false , 'ajax:send should not run' ) ;
324+ } ) ;
318325 form . unbind ( 'ajax:complete' ) . bind ( 'ajax:complete' , function ( ) {
319326 ok ( false , 'ajax:complete should not run' ) ;
320327 } ) ;
@@ -324,12 +331,15 @@ asyncTest('"ajax:beforeSend" can be observed and stopped with event delegation',
324331 } ) ;
325332} ) ;
326333
327- asyncTest ( '"ajax:beforeSend", "ajax:success" and "ajax:complete" are triggered' , 8 , function ( ) {
334+ asyncTest ( '"ajax:beforeSend", "ajax:send", "ajax: success" and "ajax:complete" are triggered' , 9 , function ( ) {
328335 submit ( function ( form ) {
329336 form . bind ( 'ajax:beforeSend' , function ( e , xhr , settings ) {
330337 ok ( xhr . setRequestHeader , 'first argument to "ajax:beforeSend" should be an XHR object' ) ;
331338 equal ( settings . url , '/echo' , 'second argument to "ajax:beforeSend" should be a settings object' ) ;
332339 } ) ;
340+ form . bind ( 'ajax:send' , function ( e , xhr ) {
341+ ok ( xhr . abort , 'first argument to "ajax:send" should be an XHR object' ) ;
342+ } ) ;
333343 form . bind ( 'ajax:success' , function ( e , data , status , xhr ) {
334344 ok ( data . REQUEST_METHOD , 'first argument to ajax:success should be a data object' ) ;
335345 equal ( status , 'success' , 'second argument to ajax:success should be a status string' ) ;
@@ -342,10 +352,11 @@ asyncTest('"ajax:beforeSend", "ajax:success" and "ajax:complete" are triggered',
342352 } ) ;
343353} ) ;
344354
345- asyncTest ( '"ajax:beforeSend", "ajax:error" and "ajax:complete" are triggered on error' , 6 , function ( ) {
355+ asyncTest ( '"ajax:beforeSend", "ajax:send", "ajax: error" and "ajax:complete" are triggered on error' , 7 , function ( ) {
346356 submit ( function ( form ) {
347357 form . attr ( 'action' , '/error' ) ;
348358 form . bind ( 'ajax:beforeSend' , function ( arg ) { ok ( true , 'ajax:beforeSend' ) } ) ;
359+ form . bind ( 'ajax:send' , function ( arg ) { ok ( true , 'ajax:send' ) } ) ;
349360 form . bind ( 'ajax:error' , function ( e , xhr , status , error ) {
350361 ok ( xhr . getResponseHeader , 'first argument to "ajax:error" should be an XHR object' ) ;
351362 equal ( status , 'error' , 'second argument to ajax:error should be a status string' ) ;
@@ -358,11 +369,14 @@ asyncTest('"ajax:beforeSend", "ajax:error" and "ajax:complete" are triggered on
358369} ) ;
359370
360371// IF THIS TEST IS FAILING, TRY INCREASING THE TIMEOUT AT THE BOTTOM TO > 100
361- asyncTest ( 'binding to ajax callbacks via .delegate() triggers handlers properly' , 3 , function ( ) {
372+ asyncTest ( 'binding to ajax callbacks via .delegate() triggers handlers properly' , 4 , function ( ) {
362373 $ ( document )
363374 . delegate ( 'form[data-remote]' , 'ajax:beforeSend' , function ( ) {
364375 ok ( true , 'ajax:beforeSend handler is triggered' ) ;
365376 } )
377+ . delegate ( 'form[data-remote]' , 'ajax:send' , function ( ) {
378+ ok ( true , 'ajax:send handler is triggered' ) ;
379+ } )
366380 . delegate ( 'form[data-remote]' , 'ajax:complete' , function ( ) {
367381 ok ( true , 'ajax:complete handler is triggered' ) ;
368382 } )
0 commit comments