Fixes routing in tests
This commit is contained in:
parent
ed398e65e0
commit
c6d99bd141
|
@ -1,5 +1,3 @@
|
|||
import DiscourseController from 'discourse/controllers/controller';
|
||||
|
||||
export default Ember.ObjectController.extend({
|
||||
needs: ['modal', 'topic', 'composer-messages', 'application'],
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
};
|
||||
|
|
|
@ -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;
|
|
@ -295,7 +295,7 @@ Discourse.URL = Ember.Object.createWithMixins({
|
|||
**/
|
||||
router: function() {
|
||||
return Discourse.__container__.lookup('router:main');
|
||||
}.property(),
|
||||
}.property().volatile(),
|
||||
|
||||
/**
|
||||
@private
|
||||
|
|
|
@ -15,7 +15,7 @@ export default {
|
|||
if (categoryFullSlug) {
|
||||
$('body').addClass('category-' + categoryFullSlug);
|
||||
}
|
||||
}.observes('categoryFullSlug'),
|
||||
}.observes('categoryFullSlug').on('init'),
|
||||
|
||||
_leaveView: function() { this._removeClasses(); }.on('willDestroyElement')
|
||||
};
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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');
|
||||
|
|
|
@ -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)
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue