Skip to content

Commit

Permalink
Change /api/v1/statuses/:id/history to always return at least one item (
Browse files Browse the repository at this point in the history
  • Loading branch information
ClearlyClaire authored and skerit committed Jul 7, 2023
1 parent 55778c2 commit 2d2b67f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
6 changes: 5 additions & 1 deletion app/controllers/api/v1/statuses/histories_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

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

0 comments on commit 2d2b67f

Please sign in to comment.