From 0dc0740408554f53e7ee3d50e83979f27c3cdeaf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9gis=20Hanol?= Date: Mon, 6 Jan 2014 11:46:19 +0100 Subject: [PATCH] BUGFIX: clicking on the Logo generates a javascript error --- .../controllers/list_controller.js.erb | 13 +++++++++++++ app/assets/javascripts/discourse/lib/url.js | 5 ----- test/javascripts/lib/url_test.js | 18 ++++++++++++++++++ 3 files changed, 31 insertions(+), 5 deletions(-) create mode 100644 test/javascripts/lib/url_test.js diff --git a/app/assets/javascripts/discourse/controllers/list_controller.js.erb b/app/assets/javascripts/discourse/controllers/list_controller.js.erb index 76e7f404c0c..d20ee2b2268 100644 --- a/app/assets/javascripts/discourse/controllers/list_controller.js.erb +++ b/app/assets/javascripts/discourse/controllers/list_controller.js.erb @@ -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 diff --git a/app/assets/javascripts/discourse/lib/url.js b/app/assets/javascripts/discourse/lib/url.js index 6071aace125..0303d947255 100644 --- a/app/assets/javascripts/discourse/lib/url.js +++ b/app/assets/javascripts/discourse/lib/url.js @@ -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); } - }); diff --git a/test/javascripts/lib/url_test.js b/test/javascripts/lib/url_test.js new file mode 100644 index 00000000000..9b8625bc024 --- /dev/null +++ b/test/javascripts/lib/url_test.js @@ -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(); +});