问题
I'm finding that my ajax DELETE requests are not sending data parameters to the controller when I execute them through capybara-webkit. However, the data parameters do get sent (and the test passes) when I run the test suite by using selenium. My code looks like the following:
$(document).on 'click', 'a.delete_contact', ->
if confirm "Are you sure you want to delete this contact?"
id = $('a.delete_contact').data('id')
name = $('a.delete_contact').data('name')
$.ajax '/contacts',
type: 'DELETE'
dataType: 'html'
data: {'id' : id}
success: ->
$("li[data-cid='#{id}']").remove()
removeInitial(_.last(name.split(" "))[0])
show_notice("Contact successfully destroyed.", 'notice')
window.contactSelection.pop()
refreshSelectionView()
return false
Any ideas why this is failing in capybara-webkit?
回答1:
Apparently QtWebKit does not support an entity body with DELETE requests.
https://github.com/thoughtbot/capybara-webkit/issues/427#issuecomment-12200262
A capybara-webkit developer recommended this work-around: "[Send] a POST request with a parameter identifying the request as a DELETE. This mechanism is used by Rails to work around similar issues across browsers."
来源:https://stackoverflow.com/questions/16044184/ajax-delete-request-not-sending-data-parameters-in-capybara-webkit