0
0
Fork 0

Reduce RSpec/MultipleExpectations cop max to 8 (#25313)

This commit is contained in:
Matt Jankowski 2023-06-10 12:38:22 -04:00 committed by GitHub
parent b5675e265e
commit 62c996b52d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 172 additions and 106 deletions

View file

@ -245,17 +245,44 @@ RSpec.describe Form::Import do
expect(account.bulk_imports.first.rows.pluck(:data)).to match_array(expected_rows)
end
it 'creates a BulkImport with expected attributes' do
bulk_import = account.bulk_imports.first
expect(bulk_import).to_not be_nil
expect(bulk_import.type.to_sym).to eq subject.type.to_sym
expect(bulk_import.original_filename).to eq subject.data.original_filename
expect(bulk_import.likely_mismatched?).to eq subject.likely_mismatched?
expect(bulk_import.overwrite?).to eq !!subject.overwrite # rubocop:disable Style/DoubleNegation
expect(bulk_import.processed_items).to eq 0
expect(bulk_import.imported_items).to eq 0
expect(bulk_import.total_items).to eq bulk_import.rows.count
expect(bulk_import.unconfirmed?).to be true
context 'with a BulkImport' do
let(:bulk_import) { account.bulk_imports.first }
it 'creates a non-nil bulk import' do
expect(bulk_import).to_not be_nil
end
it 'matches the subjects type' do
expect(bulk_import.type.to_sym).to eq subject.type.to_sym
end
it 'matches the subjects original filename' do
expect(bulk_import.original_filename).to eq subject.data.original_filename
end
it 'matches the subjects likely_mismatched? value' do
expect(bulk_import.likely_mismatched?).to eq subject.likely_mismatched?
end
it 'matches the subject overwrite value' do
expect(bulk_import.overwrite?).to eq !!subject.overwrite # rubocop:disable Style/DoubleNegation
end
it 'has zero processed items' do
expect(bulk_import.processed_items).to eq 0
end
it 'has zero imported items' do
expect(bulk_import.imported_items).to eq 0
end
it 'has a correct total_items value' do
expect(bulk_import.total_items).to eq bulk_import.rows.count
end
it 'defaults to unconfirmed true' do
expect(bulk_import.unconfirmed?).to be true
end
end
end

View file

@ -99,73 +99,87 @@ RSpec.describe Notification do
]
end
it 'preloads target status' do
# mention
expect(subject[0].type).to eq :mention
expect(subject[0].association(:mention)).to be_loaded
expect(subject[0].mention.association(:status)).to be_loaded
context 'with a preloaded target status' do
it 'preloads mention' do
expect(subject[0].type).to eq :mention
expect(subject[0].association(:mention)).to be_loaded
expect(subject[0].mention.association(:status)).to be_loaded
end
# status
expect(subject[1].type).to eq :status
expect(subject[1].association(:status)).to be_loaded
it 'preloads status' do
expect(subject[1].type).to eq :status
expect(subject[1].association(:status)).to be_loaded
end
# reblog
expect(subject[2].type).to eq :reblog
expect(subject[2].association(:status)).to be_loaded
expect(subject[2].status.association(:reblog)).to be_loaded
it 'preloads reblog' do
expect(subject[2].type).to eq :reblog
expect(subject[2].association(:status)).to be_loaded
expect(subject[2].status.association(:reblog)).to be_loaded
end
# follow: nothing
expect(subject[3].type).to eq :follow
expect(subject[3].target_status).to be_nil
it 'preloads follow as nil' do
expect(subject[3].type).to eq :follow
expect(subject[3].target_status).to be_nil
end
# follow_request: nothing
expect(subject[4].type).to eq :follow_request
expect(subject[4].target_status).to be_nil
it 'preloads follow_request as nill' do
expect(subject[4].type).to eq :follow_request
expect(subject[4].target_status).to be_nil
end
# favourite
expect(subject[5].type).to eq :favourite
expect(subject[5].association(:favourite)).to be_loaded
expect(subject[5].favourite.association(:status)).to be_loaded
it 'preloads favourite' do
expect(subject[5].type).to eq :favourite
expect(subject[5].association(:favourite)).to be_loaded
expect(subject[5].favourite.association(:status)).to be_loaded
end
# poll
expect(subject[6].type).to eq :poll
expect(subject[6].association(:poll)).to be_loaded
expect(subject[6].poll.association(:status)).to be_loaded
it 'preloads poll' do
expect(subject[6].type).to eq :poll
expect(subject[6].association(:poll)).to be_loaded
expect(subject[6].poll.association(:status)).to be_loaded
end
end
it 'replaces to cached status' do
# mention
expect(subject[0].type).to eq :mention
expect(subject[0].target_status.association(:account)).to be_loaded
expect(subject[0].target_status).to eq mention.status
context 'with a cached status' do
it 'replaces mention' do
expect(subject[0].type).to eq :mention
expect(subject[0].target_status.association(:account)).to be_loaded
expect(subject[0].target_status).to eq mention.status
end
# status
expect(subject[1].type).to eq :status
expect(subject[1].target_status.association(:account)).to be_loaded
expect(subject[1].target_status).to eq status
it 'replaces status' do
expect(subject[1].type).to eq :status
expect(subject[1].target_status.association(:account)).to be_loaded
expect(subject[1].target_status).to eq status
end
# reblog
expect(subject[2].type).to eq :reblog
expect(subject[2].target_status.association(:account)).to be_loaded
expect(subject[2].target_status).to eq reblog.reblog
it 'replaces reblog' do
expect(subject[2].type).to eq :reblog
expect(subject[2].target_status.association(:account)).to be_loaded
expect(subject[2].target_status).to eq reblog.reblog
end
# follow: nothing
expect(subject[3].type).to eq :follow
expect(subject[3].target_status).to be_nil
it 'replaces follow' do
expect(subject[3].type).to eq :follow
expect(subject[3].target_status).to be_nil
end
# follow_request: nothing
expect(subject[4].type).to eq :follow_request
expect(subject[4].target_status).to be_nil
it 'replaces follow_request' do
expect(subject[4].type).to eq :follow_request
expect(subject[4].target_status).to be_nil
end
# favourite
expect(subject[5].type).to eq :favourite
expect(subject[5].target_status.association(:account)).to be_loaded
expect(subject[5].target_status).to eq favourite.status
it 'replaces favourite' do
expect(subject[5].type).to eq :favourite
expect(subject[5].target_status.association(:account)).to be_loaded
expect(subject[5].target_status).to eq favourite.status
end
# poll
expect(subject[6].type).to eq :poll
expect(subject[6].target_status.association(:account)).to be_loaded
expect(subject[6].target_status).to eq poll.status
it 'replaces poll' do
expect(subject[6].type).to eq :poll
expect(subject[6].target_status.association(:account)).to be_loaded
expect(subject[6].target_status).to eq poll.status
end
end
end
end