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.

107 lines
3.0 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, form_status_batch: { action: action, status_ids: status_ids } } }
  30. end
  31. let(:action) { 'nsfw_on' }
  32. let(:status_ids) { [media_attached_status.id] }
  33. context 'updates sensitive column to true' 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 'updates sensitive column to false' 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. it 'redirects to account statuses page' do
  50. subject.call
  51. expect(response).to redirect_to(admin_account_statuses_path(account.id))
  52. end
  53. end
  54. describe 'PATCH #update' do
  55. subject do
  56. -> { patch :update, params: { account_id: account.id, id: media_attached_status, status: { sensitive: sensitive } } }
  57. end
  58. context 'updates sensitive column to true' do
  59. it 'updates sensitive column' do
  60. is_expected.to change {
  61. media_attached_status.reload.sensitive
  62. }.from(false).to(true)
  63. end
  64. end
  65. context 'updates sensitive column to false' do
  66. let(:sensitive) { false }
  67. it 'updates sensitive column' do
  68. is_expected.to change {
  69. media_attached_status.reload.sensitive
  70. }.from(true).to(false)
  71. end
  72. end
  73. it 'redirects to account statuses page' do
  74. subject.call
  75. expect(response).to redirect_to(admin_account_statuses_path(account.id))
  76. end
  77. end
  78. describe 'DELETE #destroy' do
  79. it 'removes a status' do
  80. allow(RemovalWorker).to receive(:perform_async)
  81. delete :destroy, params: { account_id: account.id, id: status }
  82. expect(response).to have_http_status(200)
  83. expect(RemovalWorker).
  84. to have_received(:perform_async).with(status.id)
  85. end
  86. end
  87. end