~cytrogen/masto-fe

a5b6f6da807ee057e3c9747b3b8eebb00f4c4c67 — Claire 2 years ago 05f9e39
Change /api/v1/statuses/:id/history to always return at least one item (#25510)

M app/controllers/api/v1/statuses/histories_controller.rb => app/controllers/api/v1/statuses/histories_controller.rb +5 -1
@@ 8,11 8,15 @@ class Api::V1::Statuses::HistoriesController < Api::BaseController

  def show
    cache_if_unauthenticated!
    render json: @status.edits.includes(:account, status: [:account]), each_serializer: REST::StatusEditSerializer
    render json: status_edits, each_serializer: REST::StatusEditSerializer
  end

  private

  def status_edits
    @status.edits.includes(:account, status: [:account]).to_a.presence || [@status.build_snapshot(at_time: @status.edited_at || @status.created_at)]
  end

  def set_status
    @status = Status.find(params[:status_id])
    authorize @status, :show?

M spec/controllers/api/v1/statuses/histories_controller_spec.rb => spec/controllers/api/v1/statuses/histories_controller_spec.rb +1 -0
@@ 23,6 23,7 @@ describe Api::V1::Statuses::HistoriesController do

      it 'returns http success' do
        expect(response).to have_http_status(200)
        expect(body_as_json.size).to_not be 0
      end
    end
  end