Skip to content

Commit

Permalink
DH DC don't render feedback view on public posts
Browse files Browse the repository at this point in the history
  • Loading branch information
dnsco committed Jan 13, 2012
1 parent 33772a2 commit dec3006
Show file tree
Hide file tree
Showing 13 changed files with 65 additions and 37 deletions.
2 changes: 1 addition & 1 deletion 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') %>" />
Expand Down
5 changes: 3 additions & 2 deletions public/javascripts/app/views.js
Expand Up @@ -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() {
Expand All @@ -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();
Expand Down
11 changes: 10 additions & 1 deletion public/javascripts/app/views/post_view.js
Expand Up @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions public/javascripts/app/views/reshare_feedback_view.js
@@ -0,0 +1,4 @@
app.views.ReshareFeedback = Backbone.View.extend({


});
2 changes: 1 addition & 1 deletion 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",
Expand Down
21 changes: 9 additions & 12 deletions spec/javascripts/app/views/header_view_spec.js
@@ -1,52 +1,49 @@
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);
})
})

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);
})
})

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");
})
Expand Down
2 changes: 1 addition & 1 deletion 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 : {
Expand Down
15 changes: 11 additions & 4 deletions spec/javascripts/app/views/post_view_spec.js
Expand Up @@ -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 : {
Expand All @@ -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();
Expand Down Expand Up @@ -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();
})
})

Expand Down
2 changes: 1 addition & 1 deletion 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();
Expand Down
3 changes: 1 addition & 2 deletions 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"];

Expand Down
11 changes: 0 additions & 11 deletions 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" })
Expand Down
20 changes: 20 additions & 0 deletions spec/javascripts/helpers/SpecHelper.js
Expand Up @@ -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) {
Expand All @@ -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) {
Expand Down
4 changes: 3 additions & 1 deletion spec/javascripts/helpers/factory.js
Expand Up @@ -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,
Expand Down Expand Up @@ -60,3 +60,5 @@ factory = {
return new app.models.Post(_.extend(defaultAttrs, overrides))
}
}

factory.author = factory.userAttrs

0 comments on commit dec3006

Please sign in to comment.