Skip to content
This repository has been archived by the owner on Dec 21, 2023. It is now read-only.

Commit

Permalink
Fix admin statuses order(mastodon#16937) (mastodon#16969)
Browse files Browse the repository at this point in the history
* Fix mastodon#16937

* Add test for statuses order
  • Loading branch information
tribela authored Nov 26, 2021
1 parent 3f382e3 commit 1c82647
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
2 changes: 1 addition & 1 deletion app/controllers/admin/statuses_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def index
@statuses = @account.statuses.where(visibility: [:public, :unlisted])

if params[:media]
@statuses.merge!(Status.joins(:media_attachments).merge(@account.media_attachments.reorder(nil)).group(:id)).reorder('statuses.id desc')
@statuses = @statuses.merge(Status.joins(:media_attachments).merge(@account.media_attachments.reorder(nil)).group(:id)).reorder('statuses.id desc')
end

@statuses = @statuses.preload(:media_attachments, :mentions).page(params[:page]).per(PER_PAGE)
Expand Down
9 changes: 7 additions & 2 deletions spec/controllers/admin/statuses_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
let!(:status) { Fabricate(:status, account: account) }
let(:media_attached_status) { Fabricate(:status, account: account, sensitive: !sensitive) }
let!(:media_attachment) { Fabricate(:media_attachment, account: account, status: media_attached_status) }
let(:last_media_attached_status) { Fabricate(:status, account: account, sensitive: !sensitive) }
let!(:last_media_attachment) { Fabricate(:media_attachment, account: account, status: last_media_attached_status) }
let!(:last_status) { Fabricate(:status, account: account) }
let(:sensitive) { true }

before do
Expand All @@ -19,15 +22,17 @@
get :index, params: { account_id: account.id }

statuses = assigns(:statuses).to_a
expect(statuses.size).to eq 2
expect(statuses.size).to eq 4
expect(statuses.first.id).to eq last_status.id
expect(response).to have_http_status(200)
end

it 'returns http success with media' do
get :index, params: { account_id: account.id, media: true }

statuses = assigns(:statuses).to_a
expect(statuses.size).to eq 1
expect(statuses.size).to eq 2
expect(statuses.first.id).to eq last_media_attached_status.id
expect(response).to have_http_status(200)
end
end
Expand Down

0 comments on commit 1c82647

Please sign in to comment.