statuses_controller_spec.rb 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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