From c6d99bd14124cdd228fbf5fb7a31dc085c3e3e56 Mon Sep 17 00:00:00 2001 From: Robin Ward Date: Fri, 1 May 2015 16:35:52 -0400 Subject: [PATCH] Fixes routing in tests --- .../discourse/controllers/composer.js.es6 | 2 -- .../register-discourse-location.js.es6 | 4 +++- .../discourse-location.js.es6} | 16 ++++++++++------ app/assets/javascripts/discourse/lib/url.js | 2 +- .../discourse/mixins/add-category-class.js.es6 | 2 +- app/assets/javascripts/discourse/router.js.es6 | 10 +++++----- test/javascripts/models/store-test.js.es6 | 18 +++++++++--------- vendor/assets/javascripts/ember-qunit.js | 3 +-- 8 files changed, 30 insertions(+), 27 deletions(-) rename app/assets/javascripts/discourse/{routes/discourse_location.js => lib/discourse-location.js.es6} (94%) diff --git a/app/assets/javascripts/discourse/controllers/composer.js.es6 b/app/assets/javascripts/discourse/controllers/composer.js.es6 index 465eae404..fff3050c3 100644 --- a/app/assets/javascripts/discourse/controllers/composer.js.es6 +++ b/app/assets/javascripts/discourse/controllers/composer.js.es6 @@ -1,5 +1,3 @@ -import DiscourseController from 'discourse/controllers/controller'; - export default Ember.ObjectController.extend({ needs: ['modal', 'topic', 'composer-messages', 'application'], diff --git a/app/assets/javascripts/discourse/initializers/register-discourse-location.js.es6 b/app/assets/javascripts/discourse/initializers/register-discourse-location.js.es6 index e3ae8551a..2e1736975 100644 --- a/app/assets/javascripts/discourse/initializers/register-discourse-location.js.es6 +++ b/app/assets/javascripts/discourse/initializers/register-discourse-location.js.es6 @@ -1,8 +1,10 @@ +import DiscourseLocation from 'discourse/lib/discourse-location'; + export default { name: "register-discourse-location", after: 'inject-objects', initialize: function(container, application) { - application.register('location:discourse-location', Ember.DiscourseLocation); + application.register('location:discourse-location', DiscourseLocation); } }; diff --git a/app/assets/javascripts/discourse/routes/discourse_location.js b/app/assets/javascripts/discourse/lib/discourse-location.js.es6 similarity index 94% rename from app/assets/javascripts/discourse/routes/discourse_location.js rename to app/assets/javascripts/discourse/lib/discourse-location.js.es6 index 25af43558..41a415fcd 100644 --- a/app/assets/javascripts/discourse/routes/discourse_location.js +++ b/app/assets/javascripts/discourse/lib/discourse-location.js.es6 @@ -1,12 +1,14 @@ +import CloakedCollectionView from 'discourse/views/cloaked-collection'; + /** @module Discourse */ -var get = Ember.get, set = Ember.set; -var popstateFired = false; -var supportsHistoryState = window.history && 'state' in window.history; +const get = Ember.get, set = Ember.set; +let popstateFired = false; +const supportsHistoryState = window.history && 'state' in window.history; -var popstateCallbacks = []; +const popstateCallbacks = []; /** `Ember.DiscourseLocation` implements the location API using the browser's @@ -16,7 +18,7 @@ var popstateCallbacks = []; @namespace Discourse @extends Ember.Object */ -Ember.DiscourseLocation = Ember.Object.extend({ +const DiscourseLocation = Ember.Object.extend({ init: function() { set(this, 'location', get(this, 'location') || window.location); @@ -226,7 +228,7 @@ Ember.DiscourseLocation = Ember.Object.extend({ eject itself when the popState occurs. This results in better back button behavior. **/ -Discourse.CloakedCollectionView.reopen({ +CloakedCollectionView.reopen({ _watchForPopState: function() { var self = this, cb = function() { @@ -252,3 +254,5 @@ Discourse.CloakedCollectionView.reopen({ this.set('_callback', null); }.on('willDestroyElement') }); + +export default DiscourseLocation; diff --git a/app/assets/javascripts/discourse/lib/url.js b/app/assets/javascripts/discourse/lib/url.js index 70a04a711..25f6bb32f 100644 --- a/app/assets/javascripts/discourse/lib/url.js +++ b/app/assets/javascripts/discourse/lib/url.js @@ -295,7 +295,7 @@ Discourse.URL = Ember.Object.createWithMixins({ **/ router: function() { return Discourse.__container__.lookup('router:main'); - }.property(), + }.property().volatile(), /** @private diff --git a/app/assets/javascripts/discourse/mixins/add-category-class.js.es6 b/app/assets/javascripts/discourse/mixins/add-category-class.js.es6 index d0226ff7a..fb9c504bf 100644 --- a/app/assets/javascripts/discourse/mixins/add-category-class.js.es6 +++ b/app/assets/javascripts/discourse/mixins/add-category-class.js.es6 @@ -15,7 +15,7 @@ export default { if (categoryFullSlug) { $('body').addClass('category-' + categoryFullSlug); } - }.observes('categoryFullSlug'), + }.observes('categoryFullSlug').on('init'), _leaveView: function() { this._removeClasses(); }.on('willDestroyElement') }; diff --git a/app/assets/javascripts/discourse/router.js.es6 b/app/assets/javascripts/discourse/router.js.es6 index a7669926d..fc2a6f879 100644 --- a/app/assets/javascripts/discourse/router.js.es6 +++ b/app/assets/javascripts/discourse/router.js.es6 @@ -1,11 +1,13 @@ const rootURL = Discourse.BaseUri && Discourse.BaseUri !== "/" ? Discourse.BaseUri : undefined; -const Router = Ember.Router.extend({ +const BareRouter = Ember.Router.extend({ rootURL, location: Ember.testing ? 'none': 'discourse-location' }); export function mapRoutes() { + + var Router = BareRouter.extend(); const resources = {}; const paths = {}; @@ -29,7 +31,7 @@ export function mapRoutes() { } }); - Router.map(function() { + return Router.map(function() { var router = this; // Do the root resources first @@ -76,8 +78,6 @@ export function mapRoutes() { this.route('unknown', {path: '*path'}); }); - - return Router; } -export default Router; +export default BareRouter; diff --git a/test/javascripts/models/store-test.js.es6 b/test/javascripts/models/store-test.js.es6 index 6411f141f..f0dca5ad7 100644 --- a/test/javascripts/models/store-test.js.es6 +++ b/test/javascripts/models/store-test.js.es6 @@ -37,7 +37,7 @@ test('createRecord with a record as attributes returns that record from the map' test('find', function() { const store = createStore(); - store.find('widget', 123).then(function(w) { + return store.find('widget', 123).then(function(w) { equal(w.get('name'), 'Trout Lure'); equal(w.get('id'), 123); ok(!w.get('isNew'), 'found records are not new'); @@ -51,28 +51,28 @@ test('find', function() { test('find with object id', function() { const store = createStore(); - store.find('widget', {id: 123}).then(function(w) { + return store.find('widget', {id: 123}).then(function(w) { equal(w.get('firstObject.name'), 'Trout Lure'); }); }); test('find with query param', function() { const store = createStore(); - store.find('widget', {name: 'Trout Lure'}).then(function(w) { + return store.find('widget', {name: 'Trout Lure'}).then(function(w) { equal(w.get('firstObject.id'), 123); }); }); test('update', function() { const store = createStore(); - store.update('widget', 123, {name: 'hello'}).then(function(result) { + return store.update('widget', 123, {name: 'hello'}).then(function(result) { ok(result); }); }); test('findAll', function() { const store = createStore(); - store.findAll('widget').then(function(result) { + return store.findAll('widget').then(function(result) { equal(result.get('length'), 2); const w = result.findBy('id', 124); ok(!w.get('isNew'), 'found records are not new'); @@ -80,9 +80,9 @@ test('findAll', function() { }); }); -test('destroyRecord', function() { +test('destroyRecord', function(assert) { const store = createStore(); - store.find('widget', 123).then(function(w) { + return store.find('widget', 123).then(function(w) { store.destroyRecord('widget', w).then(function(result) { ok(result); }); @@ -91,7 +91,7 @@ test('destroyRecord', function() { test('find embedded', function() { const store = createStore(); - store.find('fruit', 1).then(function(f) { + return store.find('fruit', 1).then(function(f) { ok(f.get('farmer'), 'it has the embedded object'); ok(f.get('category'), 'categories are found automatically'); }); @@ -99,7 +99,7 @@ test('find embedded', function() { test('findAll embedded', function() { const store = createStore(); - store.findAll('fruit').then(function(fruits) { + return store.findAll('fruit').then(function(fruits) { equal(fruits.objectAt(0).get('farmer.name'), 'Old MacDonald'); equal(fruits.objectAt(0).get('farmer'), fruits.objectAt(1).get('farmer'), 'points at the same object'); equal(fruits.objectAt(2).get('farmer.name'), 'Luke Skywalker'); diff --git a/vendor/assets/javascripts/ember-qunit.js b/vendor/assets/javascripts/ember-qunit.js index 3bb231499..a6061f542 100644 --- a/vendor/assets/javascripts/ember-qunit.js +++ b/vendor/assets/javascripts/ember-qunit.js @@ -261,7 +261,6 @@ exports["default"] = function test(testName, callback) { function wrapper() { var context = testContext.get(); - resetViews(); var result = callback.call(context); @@ -279,4 +278,4 @@ exports["default"] = function test(testName, callback) { } },{"./test-context":6}]},{},[2]) (2) -}); \ No newline at end of file +});