restored ability to 'unlike'
This commit is contained in:
parent
ae5fb67f71
commit
24950bd364
4 changed files with 9 additions and 6 deletions
|
|
@ -34,7 +34,7 @@ class LikesController < ApplicationController
|
|||
current_user.retract(@like)
|
||||
respond_to do |format|
|
||||
format.any { }
|
||||
format.json { render :nothing => true, :status => 204}
|
||||
format.json{ render :json => @like.parent.as_api_response(:backbone), :status => 202 }
|
||||
end
|
||||
else
|
||||
respond_to do |format|
|
||||
|
|
|
|||
|
|
@ -45,7 +45,10 @@ app.models.Post = Backbone.Model.extend({
|
|||
},
|
||||
|
||||
unlike : function() {
|
||||
this.get("user_like").destroy();
|
||||
var likeModel = new app.models.Like(this.get("user_like"));
|
||||
likeModel.url = this.likes.url + "/" + likeModel.id;
|
||||
|
||||
likeModel.destroy();
|
||||
this.set({ user_like : null });
|
||||
},
|
||||
|
||||
|
|
|
|||
|
|
@ -117,7 +117,7 @@ describe LikesController do
|
|||
expect {
|
||||
delete :destroy, :format => :json, id_field => @like.target_id, :id => @like.id
|
||||
}.should change(Like, :count).by(-1)
|
||||
response.status.should == 204
|
||||
response.status.should == 202
|
||||
end
|
||||
|
||||
it 'does not let a user destroy other likes' do
|
||||
|
|
|
|||
|
|
@ -59,12 +59,12 @@ describe("app.models.Post", function() {
|
|||
describe("unlike", function(){
|
||||
it("calls destroy on the likes collection", function(){
|
||||
var like = new app.models.Like();
|
||||
this.post.set({user_like : like})
|
||||
this.post.set({user_like : like.toJSON()})
|
||||
|
||||
spyOn(like, "destroy");
|
||||
spyOn(app.models.Like.prototype, "destroy");
|
||||
|
||||
this.post.unlike();
|
||||
expect(like.destroy).toHaveBeenCalled();
|
||||
expect(app.models.Like.prototype.destroy).toHaveBeenCalled();
|
||||
})
|
||||
})
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue