diff --git a/app/assets/javascripts/app/router.js b/app/assets/javascripts/app/router.js index d795f0e7d..4f6568b2c 100644 --- a/app/assets/javascripts/app/router.js +++ b/app/assets/javascripts/app/router.js @@ -59,7 +59,7 @@ app.Router = Backbone.Router.extend({ $("#main_stream").html(app.page.render().el); $('#selected_aspect_contacts .content').html(streamFacesView.render().el); - this.hideInactiveStreamLists(); + this._hideInactiveStreamLists(); }, photos : function() { @@ -84,7 +84,7 @@ app.Router = Backbone.Router.extend({ ); $("#author_info").prepend(followedTagsAction.render().el) } - this.hideInactiveStreamLists(); + this._hideInactiveStreamLists(); }, aspects : function(){ @@ -107,10 +107,10 @@ app.Router = Backbone.Router.extend({ $("#main_stream").html(app.page.render().el); $('#selected_aspect_contacts .content').html(streamFacesView.render().el); - this.hideInactiveStreamLists(); + this._hideInactiveStreamLists(); }, - hideInactiveStreamLists: function() { + _hideInactiveStreamLists: function() { if(this.aspects_list && Backbone.history.fragment != "aspects") this.aspects_list.hideAspectsList(); diff --git a/spec/javascripts/app/router_spec.js b/spec/javascripts/app/router_spec.js index 6371f34e1..74afd9190 100644 --- a/spec/javascripts/app/router_spec.js +++ b/spec/javascripts/app/router_spec.js @@ -1,33 +1,27 @@ describe('app.Router', function () { describe('followed_tags', function() { + beforeEach(function() { + factory.preloads({tagFollowings: []}); + }); + it('decodes name before passing it into TagFollowingAction', function () { - var followed_tags = spyOn(app.router, 'followed_tags').andCallThrough(); - var tag_following_action = spyOn(app.views, 'TagFollowingAction').andCallFake(function(data) { + var followed_tags = spyOn(app.router, 'followed_tags').and.callThrough(); + var tag_following_action = spyOn(app.views, 'TagFollowingAction').and.callFake(function(data) { return {render: function() { return {el: ""}}}; }); - spyOn(window.history, 'pushState').andCallFake(function (data, title, url) { - var route = app.router._routeToRegExp("tags/:name"); - var args = app.router._extractParameters(route, url.replace(/^\//, "")); - app.router.followed_tags(args[0]); - }); - window.preloads = {tagFollowings: []}; - app.router.navigate('/tags/'+encodeURIComponent('օբյեկտիվ')); + + app.router.followed_tags(encodeURIComponent('օբյեկտիվ')); expect(followed_tags).toHaveBeenCalled(); expect(tag_following_action).toHaveBeenCalledWith({tagText: 'օբյեկտիվ'}); }); it('navigates to the downcase version of the corresponding tag', function () { - var followed_tags = spyOn(app.router, 'followed_tags').andCallThrough(); - var tag_following_action = spyOn(app.views, 'TagFollowingAction').andCallFake(function(data) { + var followed_tags = spyOn(app.router, 'followed_tags').and.callThrough(); + var tag_following_action = spyOn(app.views, 'TagFollowingAction').and.callFake(function(data) { return {render: function() { return {el: ""}}}; }); - spyOn(window.history, 'pushState').andCallFake(function (data, title, url) { - var route = app.router._routeToRegExp("tags/:name"); - var args = app.router._extractParameters(route, url.replace(/^\//, "")); - app.router.followed_tags(args[0]); - }); - window.preloads = {tagFollowings: []}; - app.router.navigate('/tags/'+encodeURIComponent('SomethingWithCapitalLetters')); + + app.router.followed_tags('SomethingWithCapitalLetters'); expect(followed_tags).toHaveBeenCalled(); expect(tag_following_action).toHaveBeenCalledWith({tagText: 'somethingwithcapitalletters'}); }); @@ -42,31 +36,28 @@ describe('app.Router', function () { router = new app.Router(); }); - it('calls hideInactiveStreamLists', function () { - var hideInactiveStreamLists = spyOn(router, 'hideInactiveStreamLists').andCallThrough(); - - router.stream(); - expect(hideInactiveStreamLists).toHaveBeenCalled(); - }); - it('hides the aspects list', function(){ - aspects = new app.collections.Aspects([{ name: 'Work', selected: true }]); - var aspectsListView = new app.views.AspectsList({collection: aspects}); - var hideAspectsList = spyOn(aspectsListView, 'hideAspectsList').andCallThrough(); + setFixtures('
'); + aspects = new app.collections.Aspects([ + { name: 'Work', selected: true }, + { name: 'Fun', selected: false } + ]); + var aspectsListView = new app.views.AspectsList({collection: aspects}).render(); router.aspects_list = aspectsListView; + expect(aspectsListView.$el.html()).not.toBe(""); router.stream(); - expect(hideAspectsList).toHaveBeenCalled(); + expect(aspectsListView.$el.html()).toBe(""); }); it('hides the followed tags view', function(){ tagFollowings = new app.collections.TagFollowings(); - var followedTagsView = new app.views.TagFollowingList({collection: tagFollowings}); - var hideFollowedTags = spyOn(followedTagsView, 'hideFollowedTags').andCallThrough(); + var followedTagsView = new app.views.TagFollowingList({collection: tagFollowings}).render(); router.followedTagsView = followedTagsView; + expect(followedTagsView.$el.html()).not.toBe(""); router.stream(); - expect(hideFollowedTags).toHaveBeenCalled(); + expect(followedTagsView.$el.html()).toBe(""); }); }); diff --git a/spec/javascripts/helpers/factory.js b/spec/javascripts/helpers/factory.js index 8f6be8b89..1f1ae657c 100644 --- a/spec/javascripts/helpers/factory.js +++ b/spec/javascripts/helpers/factory.js @@ -151,14 +151,23 @@ factory = { comment: function(overrides) { var defaultAttrs = { - "text" : "This is an awesome comment!", - "created_at" : "2012-01-03T19:53:13Z", - "author" : this.author(), - "guid" : this.guid(), - "id": this.id.next() - } + id: this.id.next(), + guid: this.guid(), + text: "This is an awesome comment!", + author: this.author(), + created_at: "2012-01-03T19:53:13Z" + }; return new app.models.Comment(_.extend(defaultAttrs, overrides)) + }, + + preloads: function(overrides) { + var defaults = { + aspect_ids: [] + }; + + window.gon = { preloads: {} }; + _.extend(window.gon.preloads, defaults, overrides); } } diff --git a/spec/javascripts/helpers/jasmine-jquery.js b/spec/javascripts/helpers/jasmine-jquery.js index 0096c4fc5..5e659195e 100644 --- a/spec/javascripts/helpers/jasmine-jquery.js +++ b/spec/javascripts/helpers/jasmine-jquery.js @@ -200,4 +200,4 @@ beforeEach(function() { afterEach(function() { jasmine.getFixtures().cleanUp(); -}); \ No newline at end of file +});