From 8f3cc6769c81a52c302e7609b6c227436348684a Mon Sep 17 00:00:00 2001 From: danielgrippi Date: Wed, 22 Feb 2012 18:02:08 -0800 Subject: [PATCH] update reshare count when resharing; return PostPresenter for reshare root in the success response --- app/controllers/likes_controller.rb | 12 ++++++++++-- spec/controllers/likes_controller_spec.rb | 2 +- spec/controllers/participations_controller_spec.rb | 2 +- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/app/controllers/likes_controller.rb b/app/controllers/likes_controller.rb index 071992f39..1caec8981 100644 --- a/app/controllers/likes_controller.rb +++ b/app/controllers/likes_controller.rb @@ -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 diff --git a/spec/controllers/likes_controller_spec.rb b/spec/controllers/likes_controller_spec.rb index 7680391ef..1b91262ca 100644 --- a/spec/controllers/likes_controller_spec.rb +++ b/spec/controllers/likes_controller_spec.rb @@ -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 diff --git a/spec/controllers/participations_controller_spec.rb b/spec/controllers/participations_controller_spec.rb index 134a003e1..63970b7a1 100644 --- a/spec/controllers/participations_controller_spec.rb +++ b/spec/controllers/participations_controller_spec.rb @@ -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