闭社主体 forked from https://github.com/tootsuite/mastodon
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

77 lines
2.2 KiB

  1. require 'rails_helper'
  2. describe Admin::StatusesController do
  3. render_views
  4. let(:user) { Fabricate(:user, admin: true) }
  5. let(:account) { Fabricate(:account) }
  6. let!(:status) { Fabricate(:status, account: account) }
  7. let(:media_attached_status) { Fabricate(:status, account: account, sensitive: !sensitive) }
  8. let!(:media_attachment) { Fabricate(:media_attachment, account: account, status: media_attached_status) }
  9. let(:sensitive) { true }
  10. before do
  11. sign_in user, scope: :user
  12. end
  13. describe 'GET #index' do
  14. it 'returns http success with no media' do
  15. get :index, params: { account_id: account.id }
  16. statuses = assigns(:statuses).to_a
  17. expect(statuses.size).to eq 2
  18. expect(response).to have_http_status(200)
  19. end
  20. it 'returns http success with media' do
  21. get :index, params: { account_id: account.id , media: true }
  22. statuses = assigns(:statuses).to_a
  23. expect(statuses.size).to eq 1
  24. expect(response).to have_http_status(200)
  25. end
  26. end
  27. describe 'POST #create' do
  28. subject do
  29. -> { post :create, params: { :account_id => account.id, action => '', :form_status_batch => { status_ids: status_ids } } }
  30. end
  31. let(:action) { 'nsfw_on' }
  32. let(:status_ids) { [media_attached_status.id] }
  33. context 'when action is nsfw_on' do
  34. it 'updates sensitive column' do
  35. is_expected.to change {
  36. media_attached_status.reload.sensitive
  37. }.from(false).to(true)
  38. end
  39. end
  40. context 'when action is nsfw_off' do
  41. let(:action) { 'nsfw_off' }
  42. let(:sensitive) { false }
  43. it 'updates sensitive column' do
  44. is_expected.to change {
  45. media_attached_status.reload.sensitive
  46. }.from(true).to(false)
  47. end
  48. end
  49. context 'when action is delete' do
  50. let(:action) { 'delete' }
  51. it 'removes a status' do
  52. allow(RemovalWorker).to receive(:perform_async)
  53. subject.call
  54. expect(RemovalWorker).to have_received(:perform_async).with(status_ids.first)
  55. end
  56. end
  57. it 'redirects to account statuses page' do
  58. subject.call
  59. expect(response).to redirect_to(admin_account_statuses_path(account.id))
  60. end
  61. end
  62. end