diff --git a/Changelog.md b/Changelog.md
index 655040f8a..0024688c6 100644
--- a/Changelog.md
+++ b/Changelog.md
@@ -8,6 +8,7 @@
## Bug fixes
* Ignore invalid URLs for camo [#7922](https://github.com/diaspora/diaspora/pull/7922)
+* Unlinking a post did not update the participation icon without a reload [#7882](https://github.com/diaspora/diaspora/pull/7882)
## Features
* Add the ability to assign roles in the admin panel [#7868](https://github.com/diaspora/diaspora/pull/7868)
diff --git a/app/assets/javascripts/app/models/post/interactions.js b/app/assets/javascripts/app/models/post/interactions.js
index 5770b3291..2108393de 100644
--- a/app/assets/javascripts/app/models/post/interactions.js
+++ b/app/assets/javascripts/app/models/post/interactions.js
@@ -60,9 +60,13 @@ app.models.Post.Interactions = Backbone.Model.extend({
unlike : function() {
var self = this;
this.userLike().destroy({success : function() {
+ self.post.set({participation: false});
self.trigger('change');
self.set({"likes_count" : self.get("likes_count") - 1});
self.likes.trigger("change");
+ },
+ error: function(model, response) {
+ app.flashMessages.handleAjaxError(response);
}});
},
diff --git a/spec/javascripts/app/models/post/interacations_spec.js b/spec/javascripts/app/models/post/interacations_spec.js
index 019ca307a..599929eca 100644
--- a/spec/javascripts/app/models/post/interacations_spec.js
+++ b/spec/javascripts/app/models/post/interacations_spec.js
@@ -1,5 +1,6 @@
describe("app.models.Post.Interactions", function(){
var ajaxSuccess = {status: 200, responseText: "{\"id\": 1}"};
+ var ajaxNoContent = {status: 204};
beforeEach(function(){
this.post = factory.post();
@@ -9,7 +10,7 @@ describe("app.models.Post.Interactions", function(){
spec.content().append($("
"));
app.flashMessages = new app.views.FlashMessages({el: spec.content().find("#flash-container")});
- this.userLike = new app.models.Like({author : this.author});
+ this.userLike = new app.models.Like({author: this.author, id: "id01"});
});
describe("toggleLike", function(){
@@ -62,12 +63,41 @@ describe("app.models.Post.Interactions", function(){
});
describe("unlike", function(){
- it("calls destroy on the likes collection", function(){
+ beforeEach(function() {
this.interactions.likes.add(this.userLike);
- this.interactions.unlike();
+ this.post.set({participation: true});
+ spyOn(this.interactions, "userLike").and.returnValue(this.userLike);
+ });
+ it("calls delete on the likes collection for the post", function() {
+ expect(this.interactions.likes.length).toEqual(1);
+ this.interactions.unlike();
expect(this.interactions.likes.length).toEqual(0);
});
+
+ it("sets the participation flag for the post", function() {
+ expect(this.post.get("participation")).toBeTruthy();
+ this.interactions.unlike();
+ jasmine.Ajax.requests.mostRecent().respondWith(ajaxNoContent);
+ expect(this.post.get("participation")).toBeFalsy();
+ });
+
+ it("triggers a change on the likes collection", function() {
+ spyOn(this.interactions.likes, "trigger");
+ this.interactions.unlike();
+ jasmine.Ajax.requests.mostRecent().respondWith(ajaxNoContent);
+ expect(this.interactions.likes.trigger).toHaveBeenCalledWith("change");
+ });
+
+ it("displays a flash message on errors", function() {
+ spyOn(app.flashMessages, "handleAjaxError").and.callThrough();
+ this.interactions.unlike();
+ jasmine.Ajax.requests.mostRecent().respondWith({status: 400, responseText: "error message"});
+
+ expect(app.flashMessages.handleAjaxError).toHaveBeenCalled();
+ expect(app.flashMessages.handleAjaxError.calls.argsFor(0)[0].responseText).toBe("error message");
+ expect(spec.content().find(".flash-message")).toBeErrorFlashMessage("error message");
+ });
});
describe("reshare", function() {