diff options
author | Mike Greiling <mike@pixelcog.com> | 2017-03-17 14:09:29 -0500 |
---|---|---|
committer | Mike Greiling <mike@pixelcog.com> | 2017-03-20 22:12:01 -0500 |
commit | 96c7bd0378cb7a87c05913f0977916a46d01352d (patch) | |
tree | 44970c212c94fb137b11cd755ea983e85c5c34a5 | |
parent | 632497bd1b5d4bbe82f680eba3049c692dd54e0c (diff) | |
download | gitlab-ce-96c7bd0378cb7a87c05913f0977916a46d01352d.tar.gz |
fix wait_for_vue_resource to not rely on global Vue object
-rw-r--r-- | app/assets/javascripts/vue_shared/vue_resource_interceptor.js | 11 | ||||
-rw-r--r-- | spec/support/wait_for_vue_resource.rb | 2 |
2 files changed, 8 insertions, 5 deletions
diff --git a/app/assets/javascripts/vue_shared/vue_resource_interceptor.js b/app/assets/javascripts/vue_shared/vue_resource_interceptor.js index f1c1e553b16..d5f87588c28 100644 --- a/app/assets/javascripts/vue_shared/vue_resource_interceptor.js +++ b/app/assets/javascripts/vue_shared/vue_resource_interceptor.js @@ -1,20 +1,23 @@ -/* eslint-disable no-param-reassign, no-plusplus */ import Vue from 'vue'; import VueResource from 'vue-resource'; Vue.use(VueResource); +// Maintain a global counter for active requests +// see: spec/support/wait_for_vue_resource.rb Vue.http.interceptors.push((request, next) => { - Vue.activeResources = Vue.activeResources ? Vue.activeResources + 1 : 1; + window.activeVueResources = window.activeVueResources || 0; + window.activeVueResources += 1; next(() => { - Vue.activeResources--; + window.activeVueResources -= 1; }); }); +// Inject CSRF token so we don't break any tests. Vue.http.interceptors.push((request, next) => { - // needed in order to not break the tests. if ($.rails) { + // eslint-disable-next-line no-param-reassign request.headers['X-CSRF-Token'] = $.rails.csrfToken(); } next(); diff --git a/spec/support/wait_for_vue_resource.rb b/spec/support/wait_for_vue_resource.rb index 1029f84716f..4a4e2e16ee7 100644 --- a/spec/support/wait_for_vue_resource.rb +++ b/spec/support/wait_for_vue_resource.rb @@ -1,7 +1,7 @@ module WaitForVueResource def wait_for_vue_resource(spinner: true) Timeout.timeout(Capybara.default_max_wait_time) do - loop until page.evaluate_script('Vue.activeResources').zero? + loop until page.evaluate_script('window.activeVueResources').zero? end end end |