Skip to content

Commit

Permalink
Merge branch 'ajaxbefore.data-attr' of https://github.com/ronalchn/jq…
Browse files Browse the repository at this point in the history
…uery-ujs into ronalchn-ajaxbefore.data-attr
  • Loading branch information
JangoSteve committed Apr 3, 2012
2 parents 2e5b8c4 + 8b5c544 commit 298f69e
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 4 deletions.
7 changes: 3 additions & 4 deletions src/rails.js
Expand Up @@ -106,12 +106,11 @@

// Submits "remote" forms and links with ajax
handleRemote: function(element) {
var method, url, data,
crossDomain = element.data('cross-domain') || null,
dataType = element.data('type') || ($.ajaxSettings && $.ajaxSettings.dataType),
options;
var method, url, data, crossDomain, dataType, options;

if (rails.fire(element, 'ajax:before')) {
crossDomain = element.data('cross-domain') || null;
dataType = element.data('type') || ($.ajaxSettings && $.ajaxSettings.dataType);

if (element.is('form')) {
method = element.attr('method');
Expand Down
28 changes: 28 additions & 0 deletions test/public/test/call-remote-callbacks.js
Expand Up @@ -47,6 +47,34 @@ asyncTest('modifying form fields with "ajax:before" sends modified data in reque
});
});

asyncTest('modifying data("type") with "ajax:before" requests new dataType in request', 2, function(){
$('form[data-remote]').data('type','html')
.live('ajax:before', function() {
var form = $(this);
form.data('type','xml')
});

submit(function(form) {
form.bind('ajax:beforeSend', function(e, xhr, settings) {
equal(settings.dataType, 'xml', 'modified dataType should have been requested');
});
});
});

asyncTest('setting data("cross-domain",true) with "ajax:before" uses new setting in request', 2, function(){
$('form[data-remote]').data('cross-domain',false)
.live('ajax:before', function() {
var form = $(this);
form.data('cross-domain',true)
});

submit(function(form) {
form.bind('ajax:beforeSend', function(e, xhr, settings) {
equal(settings.crossDomain, true, 'setting modified in ajax:before should have forced cross-domain request');
});
});
});

asyncTest('stopping the "ajax:beforeSend" event aborts the request', 1, function() {
submit(function(form) {
form.bind('ajax:beforeSend', function() {
Expand Down

0 comments on commit 298f69e

Please sign in to comment.