diff --git a/app/views/templates/stream_element.jst b/app/views/templates/stream_element.jst index 89e217e8d..dd2963b49 100644 --- a/app/views/templates/stream_element.jst +++ b/app/views/templates/stream_element.jst @@ -1,5 +1,5 @@
- <% if(author.id != current_user.id) { %> + <% if(author.id != (!!current_user && current_user.id)) { %> Ignoreuser diff --git a/public/javascripts/app/views.js b/public/javascripts/app/views.js index e3581607f..5864606c6 100644 --- a/public/javascripts/app/views.js +++ b/public/javascripts/app/views.js @@ -5,7 +5,7 @@ app.views.Base = Backbone.View.extend({ defaultPresenter : function(){ var modelJson = this.model ? this.model.toJSON() : {} - return _.extend(modelJson, app.user()); + return _.extend(modelJson, { current_user: app.user().current_user }); }, render : function() { @@ -17,7 +17,8 @@ app.views.Base = Backbone.View.extend({ }, renderTemplate : function(){ - this.template = _.template($(this.template_name).html()); + var templateHTML = $(this.template_name).html(); //don't forget to regenerate your jasmine fixtures ;-) + this.template = _.template(templateHTML); var presenter = _.isFunction(this.presenter) ? this.presenter() : this.presenter $(this.el).html(this.template(presenter)); this.postRenderTemplate(); diff --git a/public/javascripts/app/views/post_view.js b/public/javascripts/app/views/post_view.js index 35eb63d5c..0fb51bb57 100644 --- a/public/javascripts/app/views/post_view.js +++ b/public/javascripts/app/views/post_view.js @@ -29,11 +29,20 @@ app.views.Post = app.views.StreamObject.extend({ //subviews this.commentStreamView = new app.views.CommentStream({ model : this.model}); this.likesInfoView = new app.views.LikesInfo({ model : this.model}); - this.feedbackView = window.app.user().current_user && new app.views.Feedback({model : this.model}); return this; }, + feedbackView : function(){ + if(!window.app.user().current_user ) { return null } + var feedbackViewClass = this.resharedContent() ? app.views.ReshareFeedback : app.views.Feedback + return new feedbackViewClass({model : this.model}); + }, + + resharedContent : function(){ + return this.model.get('root') + }, + postContentView: function(){ var normalizedClass = this.model.get("post_type").replace(/::/, "__"); var postClass = app.views[normalizedClass] || app.views.StatusMessage; diff --git a/public/javascripts/app/views/reshare_feedback_view.js b/public/javascripts/app/views/reshare_feedback_view.js new file mode 100644 index 000000000..0da8de2f9 --- /dev/null +++ b/public/javascripts/app/views/reshare_feedback_view.js @@ -0,0 +1,4 @@ +app.views.ReshareFeedback = Backbone.View.extend({ + + +}); diff --git a/spec/javascripts/app/views/feedback_view_spec.js b/spec/javascripts/app/views/feedback_view_spec.js index b9d0b8ea2..93d670009 100644 --- a/spec/javascripts/app/views/feedback_view_spec.js +++ b/spec/javascripts/app/views/feedback_view_spec.js @@ -1,6 +1,6 @@ describe("app.views.Feedback", function(){ beforeEach(function(){ - window.current_user = app.user({id : -1, name: "alice", avatar : {small : "http://avatar.com/photo.jpg"}}); + loginAs({id : -1, name: "alice", avatar : {small : "http://avatar.com/photo.jpg"}}); Diaspora.I18n.loadLocale({stream : { 'like' : "Like", diff --git a/spec/javascripts/app/views/header_view_spec.js b/spec/javascripts/app/views/header_view_spec.js index 5430ea025..754ad9e31 100644 --- a/spec/javascripts/app/views/header_view_spec.js +++ b/spec/javascripts/app/views/header_view_spec.js @@ -1,23 +1,20 @@ describe("app.views.Header", function() { beforeEach(function() { - // should be jasmine helper - window.current_user = app.user({name: "alice", avatar : {small : "http://avatar.com/photo.jpg"}}); + this.userAttrs = {name: "alice", avatar : {small : "http://avatar.com/photo.jpg"}} + + loginAs(this.userAttrs); spec.loadFixture("aspects_index"); this.view = new app.views.Header().render(); }); - - describe("render", function(){ - context("notifications badge", function(){ - it("displays a count when the current user has a notification", function(){ - window.current_user = _.extend(window.current_user, {notifications_count : 1}) +describe("render", function(){ context("notifications badge", function(){ it("displays a count when the current user has a notification", function(){ loginAs(_.extend(this.userAttrs, {notifications_count : 1})) this.view.render(); expect(this.view.$("#notification_badge .badge_count").hasClass('hidden')).toBe(false); expect(this.view.$("#notification_badge .badge_count").text()).toContain("1"); }) it("does not display a count when the current user has a notification", function(){ - window.current_user = _.extend(window.current_user, {notifications_count : 0}) + loginAs(_.extend(this.userAttrs, {notifications_count : 0})) this.view.render(); expect(this.view.$("#notification_badge .badge_count").hasClass('hidden')).toBe(true); }) @@ -25,14 +22,14 @@ describe("app.views.Header", function() { context("messages badge", function(){ it("displays a count when the current user has a notification", function(){ - window.current_user = _.extend(window.current_user, {unread_messages_count : 1}) + loginAs(_.extend(this.userAttrs, {unread_messages_count : 1})) this.view.render(); expect(this.view.$("#message_inbox_badge .badge_count").hasClass('hidden')).toBe(false); expect(this.view.$("#message_inbox_badge .badge_count").text()).toContain("1"); }) it("does not display a count when the current user has a notification", function(){ - window.current_user = _.extend(window.current_user, {unread_messages_count : 0}) + loginAs(_.extend(this.userAttrs, {unread_messages_count : 0})) this.view.render(); expect(this.view.$("#message_inbox_badge .badge_count").hasClass('hidden')).toBe(true); }) @@ -40,13 +37,13 @@ describe("app.views.Header", function() { context("admin link", function(){ it("displays if the current user is an admin", function(){ - window.current_user = _.extend(window.current_user, {admin : true}) + loginAs(_.extend(this.userAttrs, {admin : true})) this.view.render(); expect(this.view.$("#user_menu").html()).toContain("/admins"); }) it("does not display if the current user is not an admin", function(){ - window.current_user = _.extend(window.current_user, {admin : false}) + loginAs(_.extend(this.userAttrs, {admin : false})) this.view.render(); expect(this.view.$("#user_menu").html()).not.toContain("/admins"); }) diff --git a/spec/javascripts/app/views/likes_info_spec.js b/spec/javascripts/app/views/likes_info_spec.js index e35d2a3bb..53e4855be 100644 --- a/spec/javascripts/app/views/likes_info_spec.js +++ b/spec/javascripts/app/views/likes_info_spec.js @@ -1,6 +1,6 @@ describe("app.views.LikesInfo", function(){ beforeEach(function(){ - window.current_user = app.user({id : -1, name: "alice", avatar : {small : "http://avatar.com/photo.jpg"}}); + loginAs({id : -1, name: "alice", avatar : {small : "http://avatar.com/photo.jpg"}}); Diaspora.I18n.loadLocale({stream : { likes : { diff --git a/spec/javascripts/app/views/post_view_spec.js b/spec/javascripts/app/views/post_view_spec.js index 3ddeb5ede..e4ff3b402 100644 --- a/spec/javascripts/app/views/post_view_spec.js +++ b/spec/javascripts/app/views/post_view_spec.js @@ -2,7 +2,7 @@ describe("app.views.Post", function(){ describe("#render", function(){ beforeEach(function(){ - window.current_user = app.user({name: "alice", avatar : {small : "http://avatar.com/photo.jpg"}}); + loginAs({name: "alice", avatar : {small : "http://avatar.com/photo.jpg"}}); Diaspora.I18n.loadLocale({stream : { reshares : { @@ -18,6 +18,14 @@ describe("app.views.Post", function(){ this.reshare = this.collection.models[1]; }) + context("for a reshare", function(){ + it("should display ReshareFeedback", function(){ + spyOn(app.views, "ReshareFeedback").andReturn(stubView("these are special reshare actions")); + var view = new app.views.Post({model : this.reshare}).render(); + expect(view.$(".feedback").text().trim()).toBe("these are special reshare actions"); + }) + }) + it("displays a reshare count", function(){ this.statusMessage.set({reshares_count : 2}) var view = new app.views.Post({model : this.statusMessage}).render(); @@ -161,10 +169,9 @@ describe("app.views.Post", function(){ context("user not signed in", function(){ it("does not provide a Feedback view", function(){ - window.current_user = app.user(null); - + logout() var view = new app.views.Post({model : this.statusMessage}).render(); - expect(view.feedbackView).toBeFalsy(); + expect(view.feedbackView()).toBeFalsy(); }) }) diff --git a/spec/javascripts/app/views/publisher_view_spec.js b/spec/javascripts/app/views/publisher_view_spec.js index 00d0873bc..6704f9b7c 100644 --- a/spec/javascripts/app/views/publisher_view_spec.js +++ b/spec/javascripts/app/views/publisher_view_spec.js @@ -1,7 +1,7 @@ describe("app.views.Publisher", function() { beforeEach(function() { // should be jasmine helper - window.current_user = app.user({name: "alice", avatar : {small : "http://avatar.com/photo.jpg"}}); + loginAs({name: "alice", avatar : {small : "http://avatar.com/photo.jpg"}}); spec.loadFixture("aspects_index"); this.view = new app.views.Publisher(); diff --git a/spec/javascripts/app/views/stream_view_spec.js b/spec/javascripts/app/views/stream_view_spec.js index b0af4e9d4..0ef2cdd8b 100644 --- a/spec/javascripts/app/views/stream_view_spec.js +++ b/spec/javascripts/app/views/stream_view_spec.js @@ -1,7 +1,6 @@ describe("app.views.Stream", function(){ beforeEach(function(){ - // should be jasmine helper - window.current_user = app.user({name: "alice", avatar : {small : "http://avatar.com/photo.jpg"}}); + loginAs({name: "alice", avatar : {small : "http://avatar.com/photo.jpg"}}); this.posts = $.parseJSON(spec.readFixture("multi_stream_json"))["posts"]; diff --git a/spec/javascripts/app/views_spec.js b/spec/javascripts/app/views_spec.js index 2217796d0..f7acdfa54 100644 --- a/spec/javascripts/app/views_spec.js +++ b/spec/javascripts/app/views_spec.js @@ -1,15 +1,4 @@ describe("app.views.Base", function(){ - function stubView(text){ - var stubClass = Backbone.View.extend({ - render : function(){ - $(this.el).html(text) - return this - } - }) - - return new stubClass - } - describe("#render", function(){ beforeEach(function(){ var staticTemplateClass = app.views.Base.extend({ template_name : "#static-text-template" }) diff --git a/spec/javascripts/helpers/SpecHelper.js b/spec/javascripts/helpers/SpecHelper.js index 547aeee4d..dd0cdc992 100644 --- a/spec/javascripts/helpers/SpecHelper.js +++ b/spec/javascripts/helpers/SpecHelper.js @@ -40,6 +40,25 @@ afterEach(function() { var context = describe; var spec = {}; +window.stubView = function stubView(text){ + var stubClass = Backbone.View.extend({ + render : function(){ + $(this.el).html(text); + return this + } + }) + + return new stubClass +} + +window.loginAs = function loginAs(attrs){ + return window.current_user = app.user({current_user: factory.userAttrs(attrs)}) +} + +window.logout = function logout(){ + return window.current_user = app.user({current_user: null}) +} + spec.clearLiveEventBindings = function() { var events = jQuery.data(document, "events"); for (prop in events) { @@ -63,6 +82,7 @@ spec.loadFixture = function(fixtureName) { spec.loadFixtureCount++; }; + // Returns fixture markup as a string. Useful for fixtures that // represent the response text of ajax requests. spec.readFixture = function(fixtureName) { diff --git a/spec/javascripts/helpers/factory.js b/spec/javascripts/helpers/factory.js index 92dd30341..897e2c9a6 100644 --- a/spec/javascripts/helpers/factory.js +++ b/spec/javascripts/helpers/factory.js @@ -21,7 +21,7 @@ factory = { return _.extend(defaultAttrs, overrides) }, - author : function(overrides){ + userAttrs : function(overrides){ var id = this.id.next() var defaultAttrs = { "name":"Awesome User" + id, @@ -60,3 +60,5 @@ factory = { return new app.models.Post(_.extend(defaultAttrs, overrides)) } } + +factory.author = factory.userAttrs