Skip to content
Extraits de code Groupes Projets
Valider 3a764906 rédigé par danielgrippi's avatar danielgrippi
Parcourir les fichiers

window.app.user() doesn't return attributes nested in a key; added a comment_view spec

parent 5b947db0
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
......@@ -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)
......
<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});
},
......
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"});
......
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))
}
}
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter