BUGFIX: clicking on the Logo generates a javascript error

This commit is contained in:
Régis Hanol 2014-01-06 11:46:19 +01:00
parent eeb83adf71
commit 0dc0740408
3 changed files with 31 additions and 5 deletions

View File

@ -25,6 +25,19 @@ Discourse.ListController = Discourse.Controller.extend({
});
}.property("category"),
/**
Refresh our current topic list
@method refresh
**/
refresh: function() {
debugger;
var listTopicsController = this.get('controllers.listTopics');
listTopicsController.set('model.loaded', false);
this.load(this.get('filterMode')).then(function (topicList) {
listTopicsController.set('model', topicList);
});
},
/**
Load a list based on a filter

View File

@ -20,7 +20,6 @@ Discourse.URL = Em.Object.createWithMixins({
@param {String} path The path we are replacing our history state with.
**/
replaceState: function(path) {
if (window.history &&
window.history.pushState &&
window.history.replaceState &&
@ -48,7 +47,6 @@ Discourse.URL = Em.Object.createWithMixins({
@param {String} path The path we are routing to.
**/
routeTo: function(path) {
var oldPath = window.location.pathname;
path = path.replace(/https?\:\/\/[^\/]+/, '');
@ -120,7 +118,6 @@ Discourse.URL = Em.Object.createWithMixins({
@param {String} path the path we're navigating to
**/
navigatedToPost: function(oldPath, path) {
var newMatches = this.TOPIC_REGEXP.exec(path),
newTopicId = newMatches ? newMatches[2] : null;
@ -168,7 +165,6 @@ Discourse.URL = Em.Object.createWithMixins({
@param {String} path the path we're navigating to
**/
navigatedToHome: function(oldPath, path) {
var defaultFilter = "/" + Discourse.ListController.filters[0];
if (path === "/" && (oldPath === "/" || oldPath === defaultFilter)) {
@ -217,5 +213,4 @@ Discourse.URL = Em.Object.createWithMixins({
return Discourse.__container__.lookup('controller:' + name);
}
});

View File

@ -0,0 +1,18 @@
module("Discourse.URL");
test("navigatedToHome", function() {
var fakeListController = { refresh: function() { return true; } };
var mock = sinon.mock(fakeListController);
this.stub(Discourse.URL, "controllerFor").returns(fakeListController);
mock.expects("refresh").twice();
ok(Discourse.URL.navigatedToHome("/", "/"));
var defaultFilter = "/" + Discourse.ListController.filters[0];
ok(Discourse.URL.navigatedToHome(defaultFilter, "/"));
ok(!Discourse.URL.navigatedToHome("/old", "/new"));
// make sure we called the .refresh() method
mock.verify();
});