Refactor comment creation in post interactions backbone model
closes #7186
This commit is contained in:
parent
ed5f218559
commit
5660d2f4a8
3 changed files with 23 additions and 2 deletions
|
|
@ -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});
|
||||
|
|
|
|||
Loading…
Reference in a new issue