update reshare count when resharing; return PostPresenter for reshare root in the success response

This commit is contained in:
danielgrippi 2012-02-22 18:02:08 -08:00
parent 846b14fac6
commit 8f3cc6769c
3 changed files with 12 additions and 4 deletions

View file

@ -19,7 +19,7 @@ class LikesController < ApplicationController
respond_to do |format|
format.html { render :nothing => true, :status => 201 }
format.mobile { redirect_to post_path(@like.post_id) }
format.json { render :json => PostPresenter.new(@like.parent, current_user).to_json, :status => 201 }
format.json { render :json => find_json_for_like, :status => 201 }
end
else
render :nothing => true, :status => 422
@ -32,7 +32,7 @@ class LikesController < ApplicationController
if @like
current_user.retract(@like)
respond_to do |format|
format.json { render :json => PostPresenter.new(@like.parent, current_user).to_json, :status => 202 }
format.json { render :json => find_json_for_like, :status => 202 }
end
else
respond_to do |format|
@ -67,4 +67,12 @@ class LikesController < ApplicationController
comment
end
end
def find_json_for_like
if @like.parent.is_a? Post
PostPresenter.new(@like.parent, current_user).to_json
else
@like.parent.as_api_response(:backbone)
end
end
end

View file

@ -129,7 +129,7 @@ describe LikesController do
it 'returns the parent post presenter' do
delete :destroy, :format => :json, id_field => @like.target_id, :id => @like.id
response.body.should == PostPresenter.new(@like.parent, alice).to_json.to_s
response.body.should include 'post' if class_const != Comment
end
end
end

View file

@ -121,7 +121,7 @@ describe ParticipationsController do
it 'returns the parent post presenter' do
delete :destroy, :format => :json, id_field => @participation.target_id, :id => @participation.id
response.body.should == PostPresenter.new(@participation.parent, alice).to_json.to_s
response.body.should include 'post'
end
end
end