Add wait_for_ajax after using x-editable in tests.
authorTom Clegg <tom@curoverse.com>
Tue, 6 May 2014 22:27:01 +0000 (18:27 -0400)
committerTom Clegg <tom@curoverse.com>
Tue, 6 May 2014 22:27:01 +0000 (18:27 -0400)
apps/workbench/test/integration/folders_test.rb
apps/workbench/test/integration_helper.rb

index 8752dadbdac943eceefdb7396844f826d4cb5c02..dc51b7724d7832ee8e363206230b764224de2c92 100644 (file)
@@ -16,8 +16,7 @@ class FoldersTest < ActionDispatch::IntegrationTest
       find('.btn', text: 'Edit description').click
       find('.editable-input textarea').set('I just edited this.')
       find('.editable-submit').click
-      # Wait for editable popup to go away
-      page.assert_no_selector '.editable-submit'
+      wait_for_ajax
     end
     visit current_path
     assert(find?('.panel', text: 'I just edited this.'),
@@ -36,6 +35,7 @@ class FoldersTest < ActionDispatch::IntegrationTest
       find('.editable', text: 'Now I have a name.').click
       find('.editable-input input').set('Now I have a new name.')
       find('.glyphicon-ok').click
+      wait_for_ajax
       find('.editable', text: 'Now I have a new name.')
     end
     visit current_path
index 1784779664bc1074beb7df5888a7f0565d8e7107..a8788ceb53f6de95cffe0332eadb6dd6d312e808 100644 (file)
@@ -4,10 +4,24 @@ require 'capybara/poltergeist'
 require 'uri'
 require 'yaml'
 
+module WaitForAjax
+  Capybara.default_wait_time = 5
+  def wait_for_ajax
+    Timeout.timeout(Capybara.default_wait_time) do
+      loop until finished_all_ajax_requests?
+    end
+  end
+
+  def finished_all_ajax_requests?
+    page.evaluate_script('jQuery.active').zero?
+  end
+end
+
 class ActionDispatch::IntegrationTest
   # Make the Capybara DSL available in all integration tests
   include Capybara::DSL
   include ApiFixtureLoader
+  include WaitForAjax
 
   @@API_AUTHS = self.api_fixture('api_client_authorizations')