1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Merge pull request #31002 from ta1kt0me/call_ajax_without_beforeSend

Call Rails.ajax without beforeSend
This commit is contained in:
Guillermo Iguaran 2017-10-29 23:28:16 -05:00 committed by GitHub
commit ee44c1b6f1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 29 additions and 2 deletions

View file

@ -21,7 +21,7 @@ Rails.ajax = (options) ->
options.error?(response, xhr.statusText, xhr)
options.complete?(xhr, xhr.statusText)
unless options.beforeSend?(xhr, options)
if options.beforeSend? && !options.beforeSend(xhr, options)
return false
if xhr.readyState is XMLHttpRequest.OPENED

View file

@ -0,0 +1,27 @@
(function() {
module('call-ajax', {
setup: function() {
$('#qunit-fixture')
.append($('<a />', { href: '#' }))
}
})
asyncTest('call ajax without "ajax:beforeSend"', 1, function() {
var link = $('#qunit-fixture a')
link.bindNative('click', function() {
Rails.ajax({
type: 'get',
url: '/',
success: function() {
ok(true, 'calling request in ajax:success')
}
})
})
link.triggerNative('click')
setTimeout(function() { start() }, 13)
})
})()

View file

@ -1,6 +1,6 @@
<% @title = "rails-ujs test" %>
<%= test_to 'data-confirm', 'data-remote', 'data-disable', 'data-disable-with', 'call-remote', 'call-remote-callbacks', 'data-method', 'override', 'csrf-refresh', 'csrf-token' %>
<%= test_to 'data-confirm', 'data-remote', 'data-disable', 'data-disable-with', 'call-remote', 'call-remote-callbacks', 'data-method', 'override', 'csrf-refresh', 'csrf-token', 'call-ajax' %>
<h1 id="qunit-header"><%= @title %></h1>
<h2 id="qunit-banner"></h2>