restored ability to 'unlike'

This commit is contained in:
danielgrippi 2012-01-05 14:57:40 -08:00 committed by Dennis Collinson
parent ae5fb67f71
commit 24950bd364
4 changed files with 9 additions and 6 deletions

View file

@ -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|

View file

@ -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 });
},

View file

@ -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

View file

@ -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();
})
})