Skip to content
Extraits de code Groupes Projets
Valider 5660d2f4 rédigé par Steffen van Bergerem's avatar Steffen van Bergerem Validation de Benjamin Neff
Parcourir les fichiers

Refactor comment creation in post interactions backbone model

closes #7186
parent ed5f2185
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
......@@ -22,6 +22,7 @@
* Show more information of recipients on conversation creation [#7129](https://github.com/diaspora/diaspora/pull/7129)
* Update notifications every 5 minutes and when opening the notification dropdown [#6952](https://github.com/diaspora/diaspora/pull/6952)
* Show browser notifications when receiving new unread notifications [#6952](https://github.com/diaspora/diaspora/pull/6952)
* Only clear comment textarea when comment submission was successful [#7186](https://github.com/diaspora/diaspora/pull/7186)
# 0.6.1.0
......
......@@ -100,12 +100,11 @@ app.models.Post.Interactions = Backbone.Model.extend({
if (options.error) { options.error(); }
}).done(function() {
self.post.set({participation: true});
self.set({"comments_count": self.get("comments_count") + 1});
self.trigger('change'); //updates after sync
if (options.success) { options.success(); }
});
this.trigger("change"); //updates count in an eager manner
app.instrument("track", "Comment");
},
......
......@@ -214,6 +214,13 @@ describe("app.models.Post.Interactions", function(){
expect(this.post.get("participation")).toBeTruthy();
});
it("increases the comments count", function() {
var commentsCount = this.interactions.get("comments_count");
this.interactions.comment("text");
jasmine.Ajax.requests.mostRecent().respondWith(ajaxSuccess);
expect(this.interactions.get("comments_count")).toBe(commentsCount + 1);
});
it("triggers a change on the model", function() {
spyOn(this.interactions, "trigger");
this.interactions.comment("text");
......@@ -237,6 +244,20 @@ describe("app.models.Post.Interactions", function(){
expect(this.post.get("participation")).toBeFalsy();
});
it("doesn't increase the comments count", function() {
var commentsCount = this.interactions.get("comments_count");
this.interactions.comment("text");
jasmine.Ajax.requests.mostRecent().respondWith({status: 400});
expect(this.interactions.get("comments_count")).toBe(commentsCount);
});
it("doesn't trigger a change on the model", function() {
spyOn(this.interactions, "trigger");
this.interactions.comment("text");
jasmine.Ajax.requests.mostRecent().respondWith({status: 400});
expect(this.interactions.trigger).not.toHaveBeenCalledWith("change");
});
it("calls the error function if one is given", function() {
var error = jasmine.createSpy();
this.interactions.comment("text", {error: error});
......
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