summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/vue_shared
diff options
context:
space:
mode:
authorMike Greiling <mike@pixelcog.com>2017-03-17 14:09:29 -0500
committerMike Greiling <mike@pixelcog.com>2017-03-20 22:12:01 -0500
commit96c7bd0378cb7a87c05913f0977916a46d01352d (patch)
tree44970c212c94fb137b11cd755ea983e85c5c34a5 /app/assets/javascripts/vue_shared
parent632497bd1b5d4bbe82f680eba3049c692dd54e0c (diff)
downloadgitlab-ce-96c7bd0378cb7a87c05913f0977916a46d01352d.tar.gz
fix wait_for_vue_resource to not rely on global Vue object
Diffstat (limited to 'app/assets/javascripts/vue_shared')
-rw-r--r--app/assets/javascripts/vue_shared/vue_resource_interceptor.js11
1 files changed, 7 insertions, 4 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();