Merge pull request #145 from opf/fix/rails3-cucumber-wait-for-ajax

merged anyhow. Maybe we want to add a sleep later but it is definitly not necessary.
pull/184/merge
Nils Kenneweg 12 years ago
commit 1ec8afbd00
  1. 10
      app/assets/javascripts/application.js
  2. 33
      features/step_definitions/web_steps.rb

@ -549,6 +549,16 @@ jQuery.viewportHeight = function() {
/* TODO: integrate with existing code and/or refactor */ /* TODO: integrate with existing code and/or refactor */
jQuery(document).ready(function($) { jQuery(document).ready(function($) {
document.ajaxActive = false;
$(document).ajaxStart(function () {
document.ajaxActive = true;
});
$(document).ajaxStop(function () {
document.ajaxActive = false;
});
var propagateOpenClose = function () { var propagateOpenClose = function () {
if ($(this).is(":visible")) { if ($(this).is(":visible")) {

@ -273,24 +273,27 @@ end
When /^I wait(?: (\d+) seconds)? for(?: the)? [Aa][Jj][Aa][Xx](?: requests?(?: to finish)?)?$/ do |timeout| When /^I wait(?: (\d+) seconds)? for(?: the)? [Aa][Jj][Aa][Xx](?: requests?(?: to finish)?)?$/ do |timeout|
ajax_done = lambda do ajax_done = lambda do
page.evaluate_script(%Q{ is_done = false
(function (){ while (!is_done) do
var done = true; is_done = page.evaluate_script(%Q{
(function (){
if (window.jQuery) { var done = true;
if (!window.jQuery.isReady || window.jQuery.active != 0) {
done = false; if (window.jQuery) {
if (document.ajaxActive) {
done = false;
}
} }
} if (window.Prototype && window.Ajax) {
if (window.Prototype && window.Ajax) { if (window.Ajax.activeRequestCount != 0) {
if (window.Ajax.activeRequestCount != 0) { done = false;
done = false; }
} }
}
return done; return done;
}()) }())
}.gsub("\n", '')) }.gsub("\n", ''))
end
end end
timeout = timeout.present? ? timeout = timeout.present? ?

Loading…
Cancel
Save