Commit 436934e8 authored by Steffen van Bergerem's avatar Steffen van Bergerem Committed by Benjamin Neff

Refactor reshares controller using reshare service

parent 44b616ed
......@@ -3,30 +3,22 @@ class ResharesController < ApplicationController
respond_to :json
def create
post = Post.where(:guid => params[:root_guid]).first
if post.is_a? Reshare
@reshare = current_user.build_post(:reshare, :root_guid => post.absolute_root.guid)
else
@reshare = current_user.build_post(:reshare, :root_guid => params[:root_guid])
end
if @reshare.save
current_user.dispatch_post(@reshare)
render :json => ExtremePostPresenter.new(@reshare, current_user), :status => 201
else
render text: I18n.t("reshares.create.error"), status: 422
end
reshare = reshare_service.create(params[:root_guid])
rescue ActiveRecord::RecordNotFound, ActiveRecord::RecordInvalid
render text: I18n.t("reshares.create.error"), status: 422
else
render json: ExtremePostPresenter.new(reshare, current_user), status: 201
end
def index
@reshares = target.reshares.includes(author: :profile)
render json: @reshares.as_api_response(:backbone)
render json: reshare_service.find_for_post(params[:post_id])
.includes(author: :profile)
.as_api_response(:backbone)
end
private
def target
@target ||= current_user.find_visible_shareable_by_id(Post, params[:post_id]) ||
raise(ActiveRecord::RecordNotFound.new)
def reshare_service
@reshare_service ||= ReshareService.new(current_user)
end
end
......@@ -31,8 +31,9 @@ describe ResharesController, :type => :controller do
}.to change(Reshare, :count).by(1)
end
it 'calls dispatch' do
expect(bob).to receive(:dispatch_post)
it "federates" do
allow_any_instance_of(Participation::Generator).to receive(:create!)
expect(Diaspora::Federation::Dispatcher).to receive(:defer_dispatch)
post_request!
end
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment