Skip to content

Commit

Permalink
Created test to ensure direct form submit binding triggers only once for
Browse files Browse the repository at this point in the history
non-remote data-confirm forms. See rails#196
  • Loading branch information
JangoSteve committed Oct 4, 2011
1 parent 03c9f0c commit 78cc23f
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion test/public/test/data-confirm.js
Expand Up @@ -5,6 +5,11 @@ module('data-confirm', {
'data-remote': 'true',
'data-confirm': 'Are you absolutely sure?',
text: 'my social security number'
}))
.append($('<form />', {
action: '/echo',
'data-confirm': 'true',
method: 'post'
}));

this.windowConfirm = window.confirm;
Expand Down Expand Up @@ -104,7 +109,7 @@ asyncTest('binding to confirm:complete event and returning false', 2, function()

asyncTest('clicking non-ajax link with data-confirm', 2, function() {
window.confirm = function(msg) {
ok(true, 'confirm dialog should be callsed');
ok(true, 'confirm dialog should be called');
return true;
};

Expand All @@ -122,3 +127,24 @@ asyncTest('clicking non-ajax link with data-confirm', 2, function() {
start();
}, 10);
});

asyncTest('submitting non-ajax form with data-confirm', 3, function() {
window.confirm = function(msg) {
ok(true, 'confirm dialog should be called');
return true;
};

$('form[data-confirm]')
.bind('submit', function() {
ok(true, 'direct submit binding should only be called once');
})
.bind('ajax:beforeSend', function() {
ok(false, 'ajax should not be called');
})
.bind('iframe:loaded', function() {
ok(true, 'should submit via non-ajax');
start();
})
.trigger('submit');

});

0 comments on commit 78cc23f

Please sign in to comment.