DEV: Fix pretenders leaking across acceptance test.

DEV: Fix pretenders leaking across acceptance test.

diff --git a/test/javascripts/acceptance/tag-hashtag-test.js.es6 b/test/javascripts/acceptance/tag-hashtag-test.js.es6
index 29b0b40..1e3e468 100644
--- a/test/javascripts/acceptance/tag-hashtag-test.js.es6
+++ b/test/javascripts/acceptance/tag-hashtag-test.js.es6
@@ -4,10 +4,6 @@ acceptance("Tag Hashtag", {
   loggedIn: true,
   settings: { tagging_enabled: true },
   pretend(server, helper) {
-    server.get("/tags/filter/search", () => {
-      return helper.response({ results: [{ text: "monkey", count: 1 }] });
-    });
-
     server.get("/tags/check", () => {
       return helper.response({
         valid: [{ value: "monkey", url: "/tags/monkey" }]
diff --git a/test/javascripts/acceptance/topic-edit-timer-test.js.es6 b/test/javascripts/acceptance/topic-edit-timer-test.js.es6
index 4521975..af8ab7e 100644
--- a/test/javascripts/acceptance/topic-edit-timer-test.js.es6
+++ b/test/javascripts/acceptance/topic-edit-timer-test.js.es6
@@ -14,13 +14,6 @@ acceptance("Topic - Edit timer", {
         category_id: null
       })
     );
-
-    server.put("/t/internationalization-localization/280/status", () =>
-      helper.response({
-        success: "OK",
-        topic_status_update: null
-      })
-    );
   }
 });
 
diff --git a/test/javascripts/acceptance/topic-test.js.es6 b/test/javascripts/acceptance/topic-test.js.es6
index 23dbf05..67f4cae 100644
--- a/test/javascripts/acceptance/topic-test.js.es6
+++ b/test/javascripts/acceptance/topic-test.js.es6
@@ -7,18 +7,6 @@ acceptance("Topic", {
     server.put("/posts/398/wiki", () => {
       return helper.response({});
     });
-
-    server.get("/topics/feature_stats.json", () => {
-      return helper.response({
-        pinned_in_category_count: 0,
-        pinned_globally_count: 0,
-        banner_count: 0
-      });
-    });
-
-    server.put("/t/280/make-banner", () => {
-      return helper.response({});
-    });
   }
 });
 
diff --git a/test/javascripts/helpers/create-pretender.js.es6 b/test/javascripts/helpers/create-pretender.js.es6
index 9837a53..64a70cc 100644
--- a/test/javascripts/helpers/create-pretender.js.es6
+++ b/test/javascripts/helpers/create-pretender.js.es6
@@ -85,6 +85,10 @@ export default function() {
       });
     });
 
+    this.get("/tags/filter/search", () => {
+      return response({ results: [{ text: "monkey", count: 1 }] });
+    });
+
     this.get(`/u/:username/emails.json`, () => {
       return response({ email: "eviltrout@example.com" });
     });
@@ -138,6 +142,25 @@ export default function() {
       return response({ topic_list: { topics: [] } });
     });
 
+    this.get("/topics/feature_stats.json", () => {
+      return response({
+        pinned_in_category_count: 0,
+        pinned_globally_count: 0,
+        banner_count: 0
+      });
+    });
+
+    this.put("/t/280/make-banner", () => {
+      return response({});
+    });
+
+    this.put("/t/internationalization-localization/280/status", () => {
+      return response({
+        success: "OK",
+        topic_status_update: null
+      });
+    });
+
     this.post("/clicks/track", success);
 
     this.get("/search", request => {
diff --git a/test/javascripts/helpers/qunit-helpers.js.es6 b/test/javascripts/helpers/qunit-helpers.js.es6
index 7799e08..652d3d1 100644
--- a/test/javascripts/helpers/qunit-helpers.js.es6
+++ b/test/javascripts/helpers/qunit-helpers.js.es6
@@ -57,17 +57,18 @@ function AcceptanceModal(option, _relatedTarget) {
 window.bootbox.$body = $("#ember-testing");
 $.fn.modal = AcceptanceModal;
 
-let _pretenderCallbacks = [];
+let _pretenderCallbacks = {};
 
-export function applyPretender(server, helper) {
-  _pretenderCallbacks.forEach(cb => cb(server, helper));
+export function applyPretender(name, server, helper) {
+  const cb = _pretenderCallbacks[name];
+  if (cb) cb(server, helper);
 }
 
 export function acceptance(name, options) {
   options = options || {};
 
   if (options.pretend) {
-    _pretenderCallbacks.push(options.pretend);
+    _pretenderCallbacks[name] = options.pretend;
   }
 
   QUnit.module("Acceptance: " + name, {
diff --git a/test/javascripts/test_helper.js b/test/javascripts/test_helper.js
index d94a88f..bbfaac9 100644
--- a/test/javascripts/test_helper.js
+++ b/test/javascripts/test_helper.js
@@ -88,7 +88,8 @@ var origDebounce = Ember.run.debounce,
   _DiscourseURL = require("discourse/lib/url", null, null, false).default,
   applyPretender = require("helpers/qunit-helpers", null, null, false)
     .applyPretender,
-  server;
+  server,
+  acceptanceModulePrefix = "Acceptance: ";
 
 function dup(obj) {
   return jQuery.extend(true, {}, obj);
@@ -105,13 +106,15 @@ function resetSite(siteSettings, extras) {
 QUnit.testStart(function(ctx) {
   server = pretender.default();
 
-  var helper = {
-    parsePostData: pretender.parsePostData,
-    response: pretender.response,
-    success: pretender.success
-  };
+  if (ctx.module.startsWith(acceptanceModulePrefix)) {
+    var helper = {
+      parsePostData: pretender.parsePostData,
+      response: pretender.response,
+      success: pretender.success
+    };
 
-  applyPretender(server, helper);
+    applyPretender(ctx.module.replace(acceptanceModulePrefix, ""), server, helper);
+  }
 
   // Allow our tests to change site settings and have them reset before the next test
   Discourse.SiteSettings = dup(Discourse.SiteSettingsOriginal);

GitHub sha: c80ab08e

1 Like