window.app.user() doesn't return attributes nested in a key; added a comment_view spec
This commit is contained in:
parent
5b947db0d7
commit
3a76490640
11 changed files with 79 additions and 13 deletions
|
|
@ -90,13 +90,13 @@
|
|||
|
||||
- if current_user
|
||||
:javascript
|
||||
app.user({
|
||||
current_user: _.extend(#{current_user.person.as_api_response(:backbone).to_json}, {
|
||||
app.user(
|
||||
_.extend(#{current_user.person.as_api_response(:backbone).to_json}, {
|
||||
notifications_count : #{notification_count},
|
||||
unread_messages_count : #{unread_message_count},
|
||||
admin : #{current_user.admin?}
|
||||
})
|
||||
});
|
||||
);
|
||||
|
||||
= yield(:head)
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
<div class="right controls">
|
||||
<!-- need access to post -->
|
||||
<% if(author.id === current_user.id) { %>
|
||||
<% if(ownComment) { %>
|
||||
<a href="#" class="delete comment_delete" title="<%= Diaspora.I18n.t('delete') %>">
|
||||
<img alt="Deletelabel" src="/images/deletelabel.png" />
|
||||
<a/>
|
||||
|
|
|
|||
|
|
@ -5,9 +5,8 @@ var app = {
|
|||
views: {},
|
||||
|
||||
user: function(user) {
|
||||
if(user) { return this._user = user; }
|
||||
|
||||
return this._user || {current_user : false};
|
||||
if(user) { return this._user = user }
|
||||
return this._user
|
||||
},
|
||||
|
||||
initialize: function() {
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ app.views.Base = Backbone.View.extend({
|
|||
|
||||
defaultPresenter : function(){
|
||||
var modelJson = this.model ? this.model.toJSON() : {}
|
||||
return _.extend(modelJson, { current_user: app.user().current_user });
|
||||
return _.extend(modelJson, {current_user: app.user()});
|
||||
},
|
||||
|
||||
render : function() {
|
||||
|
|
|
|||
|
|
@ -15,5 +15,14 @@ app.views.Comment = app.views.Content.extend({
|
|||
$(this.el).attr("id", this.model.get("guid"));
|
||||
|
||||
return this;
|
||||
},
|
||||
|
||||
presenter : function() {
|
||||
return _.extend(this.defaultPresenter(), {ownComment: this.ownComment()})
|
||||
},
|
||||
|
||||
ownComment: function() {
|
||||
if(!app.user()){ return false }
|
||||
return this.model.get("author").diaspora_id == app.user().diaspora_id
|
||||
}
|
||||
});
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@ app.views.Post = app.views.StreamObject.extend({
|
|||
},
|
||||
|
||||
feedbackView : function(){
|
||||
if(!window.app.user().current_user ) { return null }
|
||||
if(!window.app.user()) { return null }
|
||||
return new app.views.Feedback({model : this.model});
|
||||
},
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
describe("app", function() {
|
||||
describe("user", function() {
|
||||
it("sets the user if given one and returns the current user", function() {
|
||||
expect(app.user()).toEqual({current_user : false});
|
||||
expect(app.user()).toBeFalsy()
|
||||
|
||||
app.user({name: "alice"});
|
||||
|
||||
|
|
|
|||
40
spec/javascripts/app/views/comment_view_spec.js
Normal file
40
spec/javascripts/app/views/comment_view_spec.js
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
describe("app.views.Comment", function(){
|
||||
beforeEach(function(){
|
||||
this.comment = factory.comment()
|
||||
this.view = new app.views.Comment({model : this.comment})
|
||||
})
|
||||
|
||||
describe("render", function(){
|
||||
it("has a delete link if the author is the current user", function(){
|
||||
loginAs(this.comment.get("author"))
|
||||
expect(this.view.render().$('.delete').length).toBe(1)
|
||||
})
|
||||
|
||||
it("doesn't have a delete link if the author is not the current user", function(){
|
||||
loginAs(_.extend(this.comment.get("author"), {diaspora_id : "notbob@bob.com"})
|
||||
expect(this.view.render().$('.delete').length).toBe(0)
|
||||
})
|
||||
|
||||
it("doesn't have a delete link if the user is logged out", function(){
|
||||
logout()
|
||||
expect(this.view.render().$('.delete').length).toBe(0)
|
||||
})
|
||||
})
|
||||
|
||||
describe("ownComment", function(){
|
||||
it("returns true if the author diaspora_id == the current user's diaspora_id", function(){
|
||||
loginAs(this.comment.get("author"))
|
||||
expect(this.view.ownComment()).toBe(true)
|
||||
})
|
||||
|
||||
it("returns false if the author diaspora_id != the current user's diaspora_id", function(){
|
||||
loginAs(_.extend(this.comment.get("author"), {diaspora_id : "notbob@bob.com"})
|
||||
expect(this.view.ownComment()).toBe(false);
|
||||
})
|
||||
|
||||
it("returns false if the user is not logged in", function(){
|
||||
logout()
|
||||
expect(this.view.ownComment()).toBe(false);
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
@ -7,7 +7,11 @@ describe("app.views.Header", function() {
|
|||
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(){ loginAs(_.extend(this.userAttrs, {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");
|
||||
|
|
|
|||
|
|
@ -52,11 +52,12 @@ window.stubView = function stubView(text){
|
|||
}
|
||||
|
||||
window.loginAs = function loginAs(attrs){
|
||||
return window.current_user = app.user({current_user: factory.userAttrs(attrs)})
|
||||
return window.current_user = app.user(factory.userAttrs(attrs))
|
||||
}
|
||||
|
||||
window.logout = function logout(){
|
||||
return window.current_user = app.user({current_user: null})
|
||||
this.app._user = undefined
|
||||
return window.current_user = app.user()
|
||||
}
|
||||
|
||||
spec.clearLiveEventBindings = function() {
|
||||
|
|
|
|||
|
|
@ -26,6 +26,7 @@ factory = {
|
|||
var defaultAttrs = {
|
||||
"name":"Awesome User" + id,
|
||||
"id": id,
|
||||
"diaspora_id": "bob@bob.com",
|
||||
"avatar":{
|
||||
"large":"http://localhost:3000/images/user/uma.jpg",
|
||||
"medium":"http://localhost:3000/images/user/uma.jpg",
|
||||
|
|
@ -57,6 +58,18 @@ factory = {
|
|||
}
|
||||
|
||||
return new app.models.Post(_.extend(defaultAttrs, overrides))
|
||||
},
|
||||
|
||||
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()
|
||||
}
|
||||
|
||||
return new app.models.Comment(_.extend(defaultAttrs, overrides))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue