Commit 5660d2f4 authored by Steffen van Bergerem's avatar Steffen van Bergerem Committed by Benjamin Neff

Refactor comment creation in post interactions backbone model

closes #7186
parent ed5f2185
......@@ -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});
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment