Convert admin/account_moderation_notes spec controller->system (#33354)
				
					
				
			This commit is contained in:
		@@ -1,57 +0,0 @@
 | 
			
		||||
# frozen_string_literal: true
 | 
			
		||||
 | 
			
		||||
require 'rails_helper'
 | 
			
		||||
 | 
			
		||||
RSpec.describe Admin::AccountModerationNotesController do
 | 
			
		||||
  render_views
 | 
			
		||||
 | 
			
		||||
  let(:user) { Fabricate(:user, role: UserRole.find_by(name: 'Admin')) }
 | 
			
		||||
  let(:target_account) { Fabricate(:account) }
 | 
			
		||||
 | 
			
		||||
  before do
 | 
			
		||||
    sign_in user, scope: :user
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  describe 'POST #create' do
 | 
			
		||||
    subject { post :create, params: params }
 | 
			
		||||
 | 
			
		||||
    context 'when parameters are valid' do
 | 
			
		||||
      let(:params) { { account_moderation_note: { target_account_id: target_account.id, content: 'test content' } } }
 | 
			
		||||
 | 
			
		||||
      it 'successfully creates a note' do
 | 
			
		||||
        expect { subject }.to change(AccountModerationNote, :count).by(1)
 | 
			
		||||
        expect(response).to redirect_to admin_account_path(target_account.id)
 | 
			
		||||
      end
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    context 'when the content is too short' do
 | 
			
		||||
      let(:params) { { account_moderation_note: { target_account_id: target_account.id, content: '' } } }
 | 
			
		||||
 | 
			
		||||
      it 'fails to create a note' do
 | 
			
		||||
        expect { subject }.to_not change(AccountModerationNote, :count)
 | 
			
		||||
        expect(response).to render_template 'admin/accounts/show'
 | 
			
		||||
      end
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    context 'when the content is too long' do
 | 
			
		||||
      let(:params) { { account_moderation_note: { target_account_id: target_account.id, content: 'test' * AccountModerationNote::CONTENT_SIZE_LIMIT } } }
 | 
			
		||||
 | 
			
		||||
      it 'fails to create a note' do
 | 
			
		||||
        expect { subject }.to_not change(AccountModerationNote, :count)
 | 
			
		||||
        expect(response).to render_template 'admin/accounts/show'
 | 
			
		||||
      end
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  describe 'DELETE #destroy' do
 | 
			
		||||
    subject { delete :destroy, params: { id: note.id } }
 | 
			
		||||
 | 
			
		||||
    let!(:note) { Fabricate(:account_moderation_note, account: account, target_account: target_account) }
 | 
			
		||||
    let(:account) { Fabricate(:account) }
 | 
			
		||||
 | 
			
		||||
    it 'destroys note' do
 | 
			
		||||
      expect { subject }.to change(AccountModerationNote, :count).by(-1)
 | 
			
		||||
      expect(response).to redirect_to admin_account_path(target_account.id)
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
end
 | 
			
		||||
							
								
								
									
										43
									
								
								spec/system/admin/account_moderation_notes_spec.rb
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										43
									
								
								spec/system/admin/account_moderation_notes_spec.rb
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,43 @@
 | 
			
		||||
# frozen_string_literal: true
 | 
			
		||||
 | 
			
		||||
require 'rails_helper'
 | 
			
		||||
 | 
			
		||||
RSpec.describe 'Admin::AccountModerationNotes' do
 | 
			
		||||
  let(:current_user) { Fabricate(:user, role: UserRole.find_by(name: 'Admin')) }
 | 
			
		||||
  let(:target_account) { Fabricate(:account) }
 | 
			
		||||
 | 
			
		||||
  before { sign_in current_user }
 | 
			
		||||
 | 
			
		||||
  describe 'Managing account moderation note' do
 | 
			
		||||
    it 'saves and then deletes a record' do
 | 
			
		||||
      visit admin_account_path(target_account.id)
 | 
			
		||||
 | 
			
		||||
      fill_in 'account_moderation_note_content', with: ''
 | 
			
		||||
      expect { submit_form }
 | 
			
		||||
        .to not_change(AccountModerationNote, :count)
 | 
			
		||||
      expect(page)
 | 
			
		||||
        .to have_content(/error below/)
 | 
			
		||||
 | 
			
		||||
      fill_in 'account_moderation_note_content', with: 'Test message'
 | 
			
		||||
      expect { submit_form }
 | 
			
		||||
        .to change(AccountModerationNote, :count).by(1)
 | 
			
		||||
      expect(page)
 | 
			
		||||
        .to have_content(I18n.t('admin.account_moderation_notes.created_msg'))
 | 
			
		||||
 | 
			
		||||
      expect { delete_note }
 | 
			
		||||
        .to change(AccountModerationNote, :count).by(-1)
 | 
			
		||||
      expect(page)
 | 
			
		||||
        .to have_content(I18n.t('admin.account_moderation_notes.destroyed_msg'))
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    def submit_form
 | 
			
		||||
      click_on I18n.t('admin.account_moderation_notes.create')
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    def delete_note
 | 
			
		||||
      within('.report-notes__item__actions') do
 | 
			
		||||
        click_on I18n.t('admin.reports.notes.delete')
 | 
			
		||||
      end
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
end
 | 
			
		||||
		Reference in New Issue
	
	Block a user