diff --git a/app/views/templates/stream_element.jst b/app/views/templates/stream_element.jst index 89e217e8d08a8ec1560e2b58ef4abfaf40046ca3..dd2963b49ecf33f6c0bf91d8d4c3acb8eaebc52c 100644 --- a/app/views/templates/stream_element.jst +++ b/app/views/templates/stream_element.jst @@ -1,5 +1,5 @@ <div class="right controls"> - <% if(author.id != current_user.id) { %> + <% if(author.id != (!!current_user && current_user.id)) { %> <a href="#" rel=nofollow> <img src="/images/icons/ignoreuser.png" alt="Ignoreuser" class="block_user control_icon" title= "<%= Diaspora.I18n.t('ignore') %>" /> <img src="/images/deletelabel.png" class="delete control_icon hide_post" title="<%= Diaspora.I18n.t('stream.hide') %>" /> diff --git a/public/javascripts/app/views.js b/public/javascripts/app/views.js index e3581607fba635a8101169b024684c00a7341eaa..5864606c62185e256d722078d9f544bcb5e10846 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 35eb63d5c8e5d40ea844f60c36885c73b1cdb890..0fb51bb5735bbc5719101e774673317369887d27 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 0000000000000000000000000000000000000000..0da8de2f91526dd0cd9d1caf80406ad70b0216e9 --- /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 b9d0b8ea22b8314330e9a9838835db9c277bbdd1..93d670009cdc6122147a280001476f3b3ad3fed3 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 5430ea02539589994fc7e71e57e075464b13910b..754ad9e31ef91986cdb39adbed17f6823401cec9 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 e35d2a3bb37b1fb9de1af1b2911ae0abc20253a1..53e4855be6eda9de0f64b3c850490d6a336e15de 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 3ddeb5ede652bbb7a6577208fbff673374401a47..e4ff3b40266f2327b34ba5b913403db5c68f37d9 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 00d0873bc1b83b9e77111d48b34d48cc4e788a45..6704f9b7cae97be2805dd74452ffbea32d6364af 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 b0af4e9d4839aebe3681410326c292407ba80643..0ef2cdd8b43bf25a59be51486ed8c47d30dcea22 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 2217796d0a8b7a7af603d87b51d176c52fa21647..f7acdfa542f574b658507af8ba19902e3086f6bb 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 547aeee4d80ed8f93899274bef4caf880ed99405..dd0cdc9924be9da2b7ef45ac00fb5db0f112a6b8 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 92dd30341e3be095912ee3c04a5139c4ab1cf8ba..897e2c9a66123a182190cd093a59020eac1c2522 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