0
0
Fork 0

Remove usage of assigns in controller specs (#30195)

This commit is contained in:
Matt Jankowski 2024-09-03 11:23:16 -04:00 committed by GitHub
parent ae363f0555
commit 5b595b8a5a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
13 changed files with 66 additions and 51 deletions

View file

@ -40,15 +40,16 @@ RSpec.describe Admin::AccountsController do
expect(response)
.to have_http_status(200)
expect(assigns(:accounts))
.to have_attributes(
count: eq(1),
klass: be(Account)
)
expect(accounts_table_rows.size)
.to eq(1)
expect(AccountFilter)
.to have_received(:new)
.with(hash_including(params))
end
def accounts_table_rows
Nokogiri::Slop(response.body).css('table.accounts-table tr')
end
end
describe 'GET #show' do

View file

@ -13,7 +13,6 @@ RSpec.describe Admin::DomainAllowsController do
it 'assigns a new domain allow' do
get :new
expect(assigns(:domain_allow)).to be_instance_of(DomainAllow)
expect(response).to have_http_status(200)
end
end

View file

@ -13,7 +13,6 @@ RSpec.describe Admin::DomainBlocksController do
it 'assigns a new domain block' do
get :new
expect(assigns(:domain_block)).to be_instance_of(DomainBlock)
expect(response).to have_http_status(200)
end
end
@ -171,7 +170,6 @@ RSpec.describe Admin::DomainBlocksController do
it 'returns http success' do
get :edit, params: { id: domain_block.id }
expect(assigns(:domain_block)).to be_instance_of(DomainBlock)
expect(response).to have_http_status(200)
end
end

View file

@ -42,11 +42,8 @@ RSpec.describe Admin::ExportDomainBlocksController do
post :import, params: { admin_import: { data: fixture_file_upload('domain_blocks.csv') } }
end
it 'renders page with expected domain blocks' do
expect(assigns(:domain_blocks).map { |block| [block.domain, block.severity.to_sym] }).to contain_exactly(['bad.domain', :silence], ['worse.domain', :suspend], ['reject.media', :noop])
end
it 'returns http success' do
it 'renders page with expected domain blocks and returns http success' do
expect(mapped_batch_table_rows).to contain_exactly(['bad.domain', :silence], ['worse.domain', :suspend], ['reject.media', :noop])
expect(response).to have_http_status(200)
end
end
@ -56,14 +53,19 @@ RSpec.describe Admin::ExportDomainBlocksController do
post :import, params: { admin_import: { data: fixture_file_upload('domain_blocks_list.txt') } }
end
it 'renders page with expected domain blocks' do
expect(assigns(:domain_blocks).map { |block| [block.domain, block.severity.to_sym] }).to contain_exactly(['bad.domain', :suspend], ['worse.domain', :suspend], ['reject.media', :suspend])
end
it 'returns http success' do
it 'renders page with expected domain blocks and returns http success' do
expect(mapped_batch_table_rows).to contain_exactly(['bad.domain', :suspend], ['worse.domain', :suspend], ['reject.media', :suspend])
expect(response).to have_http_status(200)
end
end
def mapped_batch_table_rows
batch_table_rows.map { |row| [row.at_css('[id$=_domain]')['value'], row.at_css('[id$=_severity]')['value'].to_sym] }
end
def batch_table_rows
Nokogiri::Slop(response.body).css('body div.batch-table__row')
end
end
it 'displays error on no file selected' do

View file

@ -28,12 +28,15 @@ RSpec.describe Admin::InstancesController do
it 'renders instances' do
get :index, params: { page: 2 }
instances = assigns(:instances).to_a
expect(instances.size).to eq 1
expect(instances[0].domain).to eq 'less.popular'
expect(instance_directory_links.size).to eq(1)
expect(instance_directory_links.first.text.strip).to match('less.popular')
expect(response).to have_http_status(200)
end
def instance_directory_links
Nokogiri::Slop(response.body).css('div.directory__tag a')
end
end
describe 'GET #show' do

View file

@ -18,7 +18,8 @@ describe Admin::InvitesController do
it 'renders index page' do
expect(subject).to render_template :index
expect(assigns(:invites)).to include invite
expect(response.body)
.to include(invite.code)
end
end

View file

@ -13,39 +13,39 @@ describe Admin::ReportsController do
describe 'GET #index' do
it 'returns http success with no filters' do
specified = Fabricate(:report, action_taken_at: nil)
Fabricate(:report, action_taken_at: Time.now.utc)
specified = Fabricate(:report, action_taken_at: nil, comment: 'First report')
other = Fabricate(:report, action_taken_at: Time.now.utc, comment: 'Second report')
get :index
reports = assigns(:reports).to_a
expect(reports.size).to eq 1
expect(reports[0]).to eq specified
expect(response).to have_http_status(200)
expect(response.body)
.to include(specified.comment)
.and not_include(other.comment)
end
it 'returns http success with resolved filter' do
specified = Fabricate(:report, action_taken_at: Time.now.utc)
Fabricate(:report, action_taken_at: nil)
specified = Fabricate(:report, action_taken_at: Time.now.utc, comment: 'First report')
other = Fabricate(:report, action_taken_at: nil, comment: 'Second report')
get :index, params: { resolved: '1' }
reports = assigns(:reports).to_a
expect(reports.size).to eq 1
expect(reports[0]).to eq specified
expect(response).to have_http_status(200)
expect(response.body)
.to include(specified.comment)
.and not_include(other.comment)
end
end
describe 'GET #show' do
it 'renders report' do
report = Fabricate(:report)
report = Fabricate(:report, comment: 'A big problem')
get :show, params: { id: report }
expect(assigns(:report)).to eq report
expect(response).to have_http_status(200)
expect(response.body)
.to include(report.comment)
end
end