diff options
Diffstat (limited to 'spec')
-rw-r--r-- | spec/controllers/admin/reported_statuses_controller_spec.rb | 38 | ||||
-rw-r--r-- | spec/controllers/admin/statuses_controller_spec.rb | 107 | ||||
-rw-r--r-- | spec/models/form/status_batch_spec.rb | 52 |
3 files changed, 196 insertions, 1 deletions
diff --git a/spec/controllers/admin/reported_statuses_controller_spec.rb b/spec/controllers/admin/reported_statuses_controller_spec.rb index 80c69e8d1..297807d41 100644 --- a/spec/controllers/admin/reported_statuses_controller_spec.rb +++ b/spec/controllers/admin/reported_statuses_controller_spec.rb @@ -11,6 +11,42 @@ describe Admin::ReportedStatusesController do sign_in user, scope: :user end + describe 'POST #create' do + subject do + -> { post :create, params: { report_id: report, form_status_batch: { action: action, status_ids: status_ids } } } + end + + let(:action) { 'nsfw_on' } + let(:status_ids) { [status.id] } + let(:status) { Fabricate(:status, sensitive: !sensitive) } + let(:sensitive) { true } + let!(:media_attachment) { Fabricate(:media_attachment, status: status) } + + context 'updates sensitive column to true' do + it 'updates sensitive column' do + is_expected.to change { + status.reload.sensitive + }.from(false).to(true) + end + end + + context 'updates sensitive column to false' do + let(:action) { 'nsfw_off' } + let(:sensitive) { false } + + it 'updates sensitive column' do + is_expected.to change { + status.reload.sensitive + }.from(true).to(false) + end + end + + it 'redirects to report page' do + subject.call + expect(response).to redirect_to(admin_report_path(report)) + end + end + describe 'PATCH #update' do subject do -> { patch :update, params: { report_id: report, id: status, status: { sensitive: sensitive } } } @@ -48,7 +84,7 @@ describe Admin::ReportedStatusesController do allow(RemovalWorker).to receive(:perform_async) delete :destroy, params: { report_id: report, id: status } - expect(response).to redirect_to(admin_report_path(report)) + expect(response).to have_http_status(:success) expect(RemovalWorker). to have_received(:perform_async).with(status.id) end diff --git a/spec/controllers/admin/statuses_controller_spec.rb b/spec/controllers/admin/statuses_controller_spec.rb new file mode 100644 index 000000000..1515e299b --- /dev/null +++ b/spec/controllers/admin/statuses_controller_spec.rb @@ -0,0 +1,107 @@ +require 'rails_helper' + +describe Admin::StatusesController do + render_views + + let(:user) { Fabricate(:user, admin: true) } + let(:account) { Fabricate(:account) } + 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(:sensitive) { true } + + before do + sign_in user, scope: :user + end + + describe 'GET #index' do + it 'returns http success with no media' do + get :index, params: { account_id: account.id } + + statuses = assigns(:statuses).to_a + expect(statuses.size).to eq 2 + expect(response).to have_http_status(:success) + 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(response).to have_http_status(:success) + end + end + + describe 'POST #create' do + subject do + -> { post :create, params: { account_id: account.id, form_status_batch: { action: action, status_ids: status_ids } } } + end + + let(:action) { 'nsfw_on' } + let(:status_ids) { [media_attached_status.id] } + + context 'updates sensitive column to true' do + it 'updates sensitive column' do + is_expected.to change { + media_attached_status.reload.sensitive + }.from(false).to(true) + end + end + + context 'updates sensitive column to false' do + let(:action) { 'nsfw_off' } + let(:sensitive) { false } + + it 'updates sensitive column' do + is_expected.to change { + media_attached_status.reload.sensitive + }.from(true).to(false) + end + end + + it 'redirects to account statuses page' do + subject.call + expect(response).to redirect_to(admin_account_statuses_path(account.id)) + end + end + + describe 'PATCH #update' do + subject do + -> { patch :update, params: { account_id: account.id, id: media_attached_status, status: { sensitive: sensitive } } } + end + + context 'updates sensitive column to true' do + it 'updates sensitive column' do + is_expected.to change { + media_attached_status.reload.sensitive + }.from(false).to(true) + end + end + + context 'updates sensitive column to false' do + let(:sensitive) { false } + + it 'updates sensitive column' do + is_expected.to change { + media_attached_status.reload.sensitive + }.from(true).to(false) + end + end + + it 'redirects to account statuses page' do + subject.call + expect(response).to redirect_to(admin_account_statuses_path(account.id)) + end + end + + describe 'DELETE #destroy' do + it 'removes a status' do + allow(RemovalWorker).to receive(:perform_async) + + delete :destroy, params: { account_id: account.id, id: status } + expect(response).to have_http_status(:success) + expect(RemovalWorker). + to have_received(:perform_async).with(status.id) + end + end +end diff --git a/spec/models/form/status_batch_spec.rb b/spec/models/form/status_batch_spec.rb new file mode 100644 index 000000000..00c790a11 --- /dev/null +++ b/spec/models/form/status_batch_spec.rb @@ -0,0 +1,52 @@ +require 'rails_helper' + +describe Form::StatusBatch do + let(:form) { Form::StatusBatch.new(action: action, status_ids: status_ids) } + let(:status) { Fabricate(:status) } + + describe 'with nsfw action' do + let(:status_ids) { [status.id, nonsensitive_status.id, sensitive_status.id] } + let(:nonsensitive_status) { Fabricate(:status, sensitive: false) } + let(:sensitive_status) { Fabricate(:status, sensitive: true) } + let!(:shown_media_attachment) { Fabricate(:media_attachment, status: nonsensitive_status) } + let!(:hidden_media_attachment) { Fabricate(:media_attachment, status: sensitive_status) } + + context 'nsfw_on' do + let(:action) { 'nsfw_on' } + + it { expect(form.save).to be true } + it { expect { form.save }.to change { nonsensitive_status.reload.sensitive }.from(false).to(true) } + it { expect { form.save }.not_to change { sensitive_status.reload.sensitive } } + it { expect { form.save }.not_to change { status.reload.sensitive } } + end + + context 'nsfw_off' do + let(:action) { 'nsfw_off' } + + it { expect(form.save).to be true } + it { expect { form.save }.to change { sensitive_status.reload.sensitive }.from(true).to(false) } + it { expect { form.save }.not_to change { nonsensitive_status.reload.sensitive } } + it { expect { form.save }.not_to change { status.reload.sensitive } } + end + end + + describe 'with delete action' do + let(:status_ids) { [status.id] } + let(:action) { 'delete' } + let!(:another_status) { Fabricate(:status) } + + before do + allow(RemovalWorker).to receive(:perform_async) + end + + it 'call RemovalWorker' do + form.save + expect(RemovalWorker).to have_received(:perform_async).with(status.id) + end + + it 'do not call RemovalWorker' do + form.save + expect(RemovalWorker).not_to have_received(:perform_async).with(another_status.id) + end + end +end |