diff --git a/app/assets/javascripts/discourse/models/site.js b/app/assets/javascripts/discourse/models/site.js index 46311444e..191363193 100644 --- a/app/assets/javascripts/discourse/models/site.js +++ b/app/assets/javascripts/discourse/models/site.js @@ -35,7 +35,9 @@ Discourse.Site = Discourse.Model.extend({ Discourse.Site.reopenClass({ instance: function() { - return Discourse.Site.create(PreloadStore.get('site')); + if ( this._site ) return this._site; + this._site = Discourse.Site.create(PreloadStore.get('site')); + return this._site; }, create: function(obj) { diff --git a/test/javascripts/models/nav_item_test.js b/test/javascripts/models/nav_item_test.js new file mode 100644 index 000000000..a6f5f930a --- /dev/null +++ b/test/javascripts/models/nav_item_test.js @@ -0,0 +1,22 @@ +/*global module:true test:true ok:true visit:true expect:true exists:true count:true equal:true */ + +module("Discourse.NavItem", { + setup: function() { + this.site = Discourse.Site.instance(); + this.originalCategories = Discourse.Site.instance().get('categories') || []; + this.site.set('categories', this.originalCategories.concat( [Discourse.Category.create({name: '确实是这样', id: 343434})] )); + }, + + teardown: function() { + this.site.set('categories', this.originalCategories); + } +}); + +test('href', function(){ + expect(4); + + equal(Discourse.NavItem.fromText('latest', {}).get('href'), '/latest', "latest"); + equal(Discourse.NavItem.fromText('categories', {}).get('href'), '/categories', "categories"); + equal(Discourse.NavItem.fromText('category/bug', {}).get('href'), '/category/bug', "English category name"); + equal(Discourse.NavItem.fromText('category/确实是这样', {}).get('href'), '/category/343434-category', "Chinese category name"); +});