mirror of
https://github.com/kikobar/mastodon.git
synced 2024-11-16 20:22:18 +00:00
Reduce RSpec/MultipleExpectations
cop max to 8 (#25313)
This commit is contained in:
parent
b5675e265e
commit
62c996b52d
|
@ -394,7 +394,7 @@ RSpec/MessageSpies:
|
||||||
- 'spec/validators/status_length_validator_spec.rb'
|
- 'spec/validators/status_length_validator_spec.rb'
|
||||||
|
|
||||||
RSpec/MultipleExpectations:
|
RSpec/MultipleExpectations:
|
||||||
Max: 19
|
Max: 8
|
||||||
|
|
||||||
# Configuration parameters: AllowSubject.
|
# Configuration parameters: AllowSubject.
|
||||||
RSpec/MultipleMemoizedHelpers:
|
RSpec/MultipleMemoizedHelpers:
|
||||||
|
|
|
@ -48,10 +48,14 @@ describe Api::V1::Accounts::RelationshipsController do
|
||||||
expect(response).to have_http_status(200)
|
expect(response).to have_http_status(200)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'returns JSON with correct data' do
|
context 'when there is returned JSON data' do
|
||||||
json = body_as_json
|
let(:json) { body_as_json }
|
||||||
|
|
||||||
|
it 'returns an enumerable json' do
|
||||||
expect(json).to be_a Enumerable
|
expect(json).to be_a Enumerable
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'returns a correct first element' do
|
||||||
expect(json.first[:id]).to eq simon.id.to_s
|
expect(json.first[:id]).to eq simon.id.to_s
|
||||||
expect(json.first[:following]).to be true
|
expect(json.first[:following]).to be true
|
||||||
expect(json.first[:showing_reblogs]).to be true
|
expect(json.first[:showing_reblogs]).to be true
|
||||||
|
@ -59,7 +63,9 @@ describe Api::V1::Accounts::RelationshipsController do
|
||||||
expect(json.first[:muting]).to be false
|
expect(json.first[:muting]).to be false
|
||||||
expect(json.first[:requested]).to be false
|
expect(json.first[:requested]).to be false
|
||||||
expect(json.first[:domain_blocking]).to be false
|
expect(json.first[:domain_blocking]).to be false
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'returns a correct second element' do
|
||||||
expect(json.second[:id]).to eq lewis.id.to_s
|
expect(json.second[:id]).to eq lewis.id.to_s
|
||||||
expect(json.second[:following]).to be false
|
expect(json.second[:following]).to be false
|
||||||
expect(json.second[:showing_reblogs]).to be false
|
expect(json.second[:showing_reblogs]).to be false
|
||||||
|
@ -68,6 +74,7 @@ describe Api::V1::Accounts::RelationshipsController do
|
||||||
expect(json.second[:requested]).to be false
|
expect(json.second[:requested]).to be false
|
||||||
expect(json.second[:domain_blocking]).to be false
|
expect(json.second[:domain_blocking]).to be false
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
it 'returns JSON with correct data on cached requests too' do
|
it 'returns JSON with correct data on cached requests too' do
|
||||||
get :index, params: { id: [simon.id] }
|
get :index, params: { id: [simon.id] }
|
||||||
|
|
|
@ -56,18 +56,11 @@ describe Settings::TwoFactorAuthentication::ConfirmationsController do
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'when creation succeeds' do
|
describe 'when creation succeeds' do
|
||||||
|
let!(:otp_backup_codes) { user.generate_otp_backup_codes! }
|
||||||
|
|
||||||
it 'renders page with success' do
|
it 'renders page with success' do
|
||||||
otp_backup_codes = user.generate_otp_backup_codes!
|
prepare_user_otp_generation
|
||||||
expect_any_instance_of(User).to receive(:generate_otp_backup_codes!) do |value|
|
prepare_user_otp_consumption
|
||||||
expect(value).to eq user
|
|
||||||
otp_backup_codes
|
|
||||||
end
|
|
||||||
expect_any_instance_of(User).to receive(:validate_and_consume_otp!) do |value, code, options|
|
|
||||||
expect(value).to eq user
|
|
||||||
expect(code).to eq '123456'
|
|
||||||
expect(options).to eq({ otp_secret: 'thisisasecretforthespecofnewview' })
|
|
||||||
true
|
|
||||||
end
|
|
||||||
|
|
||||||
expect do
|
expect do
|
||||||
post :create,
|
post :create,
|
||||||
|
@ -80,6 +73,22 @@ describe Settings::TwoFactorAuthentication::ConfirmationsController do
|
||||||
expect(response).to have_http_status(200)
|
expect(response).to have_http_status(200)
|
||||||
expect(response).to render_template('settings/two_factor_authentication/recovery_codes/index')
|
expect(response).to render_template('settings/two_factor_authentication/recovery_codes/index')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def prepare_user_otp_generation
|
||||||
|
expect_any_instance_of(User).to receive(:generate_otp_backup_codes!) do |value|
|
||||||
|
expect(value).to eq user
|
||||||
|
otp_backup_codes
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def prepare_user_otp_consumption
|
||||||
|
expect_any_instance_of(User).to receive(:validate_and_consume_otp!) do |value, code, options|
|
||||||
|
expect(value).to eq user
|
||||||
|
expect(code).to eq '123456'
|
||||||
|
expect(options).to eq({ otp_secret: 'thisisasecretforthespecofnewview' })
|
||||||
|
true
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'when creation fails' do
|
describe 'when creation fails' do
|
||||||
|
|
|
@ -245,19 +245,46 @@ RSpec.describe Form::Import do
|
||||||
expect(account.bulk_imports.first.rows.pluck(:data)).to match_array(expected_rows)
|
expect(account.bulk_imports.first.rows.pluck(:data)).to match_array(expected_rows)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'creates a BulkImport with expected attributes' do
|
context 'with a BulkImport' do
|
||||||
bulk_import = account.bulk_imports.first
|
let(:bulk_import) { account.bulk_imports.first }
|
||||||
|
|
||||||
|
it 'creates a non-nil bulk import' do
|
||||||
expect(bulk_import).to_not be_nil
|
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
|
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
|
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?
|
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
|
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
|
expect(bulk_import.processed_items).to eq 0
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'has zero imported items' do
|
||||||
expect(bulk_import.imported_items).to eq 0
|
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
|
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
|
expect(bulk_import.unconfirmed?).to be true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
it_behaves_like 'on successful import', 'following', 'merge', 'imports.txt', (%w(user@example.com user@test.com).map { |acct| { 'acct' => acct } })
|
it_behaves_like 'on successful import', 'following', 'merge', 'imports.txt', (%w(user@example.com user@test.com).map { |acct| { 'acct' => acct } })
|
||||||
it_behaves_like 'on successful import', 'following', 'overwrite', 'imports.txt', (%w(user@example.com user@test.com).map { |acct| { 'acct' => acct } })
|
it_behaves_like 'on successful import', 'following', 'overwrite', 'imports.txt', (%w(user@example.com user@test.com).map { |acct| { 'acct' => acct } })
|
||||||
|
|
|
@ -99,74 +99,88 @@ RSpec.describe Notification do
|
||||||
]
|
]
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'preloads target status' do
|
context 'with a preloaded target status' do
|
||||||
# mention
|
it 'preloads mention' do
|
||||||
expect(subject[0].type).to eq :mention
|
expect(subject[0].type).to eq :mention
|
||||||
expect(subject[0].association(:mention)).to be_loaded
|
expect(subject[0].association(:mention)).to be_loaded
|
||||||
expect(subject[0].mention.association(:status)).to be_loaded
|
expect(subject[0].mention.association(:status)).to be_loaded
|
||||||
|
end
|
||||||
|
|
||||||
# status
|
it 'preloads status' do
|
||||||
expect(subject[1].type).to eq :status
|
expect(subject[1].type).to eq :status
|
||||||
expect(subject[1].association(:status)).to be_loaded
|
expect(subject[1].association(:status)).to be_loaded
|
||||||
|
end
|
||||||
|
|
||||||
# reblog
|
it 'preloads reblog' do
|
||||||
expect(subject[2].type).to eq :reblog
|
expect(subject[2].type).to eq :reblog
|
||||||
expect(subject[2].association(:status)).to be_loaded
|
expect(subject[2].association(:status)).to be_loaded
|
||||||
expect(subject[2].status.association(:reblog)).to be_loaded
|
expect(subject[2].status.association(:reblog)).to be_loaded
|
||||||
|
end
|
||||||
|
|
||||||
# follow: nothing
|
it 'preloads follow as nil' do
|
||||||
expect(subject[3].type).to eq :follow
|
expect(subject[3].type).to eq :follow
|
||||||
expect(subject[3].target_status).to be_nil
|
expect(subject[3].target_status).to be_nil
|
||||||
|
end
|
||||||
|
|
||||||
# follow_request: nothing
|
it 'preloads follow_request as nill' do
|
||||||
expect(subject[4].type).to eq :follow_request
|
expect(subject[4].type).to eq :follow_request
|
||||||
expect(subject[4].target_status).to be_nil
|
expect(subject[4].target_status).to be_nil
|
||||||
|
end
|
||||||
|
|
||||||
# favourite
|
it 'preloads favourite' do
|
||||||
expect(subject[5].type).to eq :favourite
|
expect(subject[5].type).to eq :favourite
|
||||||
expect(subject[5].association(:favourite)).to be_loaded
|
expect(subject[5].association(:favourite)).to be_loaded
|
||||||
expect(subject[5].favourite.association(:status)).to be_loaded
|
expect(subject[5].favourite.association(:status)).to be_loaded
|
||||||
|
end
|
||||||
|
|
||||||
# poll
|
it 'preloads poll' do
|
||||||
expect(subject[6].type).to eq :poll
|
expect(subject[6].type).to eq :poll
|
||||||
expect(subject[6].association(:poll)).to be_loaded
|
expect(subject[6].association(:poll)).to be_loaded
|
||||||
expect(subject[6].poll.association(:status)).to be_loaded
|
expect(subject[6].poll.association(:status)).to be_loaded
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
it 'replaces to cached status' do
|
context 'with a cached status' do
|
||||||
# mention
|
it 'replaces mention' do
|
||||||
expect(subject[0].type).to eq :mention
|
expect(subject[0].type).to eq :mention
|
||||||
expect(subject[0].target_status.association(:account)).to be_loaded
|
expect(subject[0].target_status.association(:account)).to be_loaded
|
||||||
expect(subject[0].target_status).to eq mention.status
|
expect(subject[0].target_status).to eq mention.status
|
||||||
|
end
|
||||||
|
|
||||||
# status
|
it 'replaces status' do
|
||||||
expect(subject[1].type).to eq :status
|
expect(subject[1].type).to eq :status
|
||||||
expect(subject[1].target_status.association(:account)).to be_loaded
|
expect(subject[1].target_status.association(:account)).to be_loaded
|
||||||
expect(subject[1].target_status).to eq status
|
expect(subject[1].target_status).to eq status
|
||||||
|
end
|
||||||
|
|
||||||
# reblog
|
it 'replaces reblog' do
|
||||||
expect(subject[2].type).to eq :reblog
|
expect(subject[2].type).to eq :reblog
|
||||||
expect(subject[2].target_status.association(:account)).to be_loaded
|
expect(subject[2].target_status.association(:account)).to be_loaded
|
||||||
expect(subject[2].target_status).to eq reblog.reblog
|
expect(subject[2].target_status).to eq reblog.reblog
|
||||||
|
end
|
||||||
|
|
||||||
# follow: nothing
|
it 'replaces follow' do
|
||||||
expect(subject[3].type).to eq :follow
|
expect(subject[3].type).to eq :follow
|
||||||
expect(subject[3].target_status).to be_nil
|
expect(subject[3].target_status).to be_nil
|
||||||
|
end
|
||||||
|
|
||||||
# follow_request: nothing
|
it 'replaces follow_request' do
|
||||||
expect(subject[4].type).to eq :follow_request
|
expect(subject[4].type).to eq :follow_request
|
||||||
expect(subject[4].target_status).to be_nil
|
expect(subject[4].target_status).to be_nil
|
||||||
|
end
|
||||||
|
|
||||||
# favourite
|
it 'replaces favourite' do
|
||||||
expect(subject[5].type).to eq :favourite
|
expect(subject[5].type).to eq :favourite
|
||||||
expect(subject[5].target_status.association(:account)).to be_loaded
|
expect(subject[5].target_status.association(:account)).to be_loaded
|
||||||
expect(subject[5].target_status).to eq favourite.status
|
expect(subject[5].target_status).to eq favourite.status
|
||||||
|
end
|
||||||
|
|
||||||
# poll
|
it 'replaces poll' do
|
||||||
expect(subject[6].type).to eq :poll
|
expect(subject[6].type).to eq :poll
|
||||||
expect(subject[6].target_status.association(:account)).to be_loaded
|
expect(subject[6].target_status.association(:account)).to be_loaded
|
||||||
expect(subject[6].target_status).to eq poll.status
|
expect(subject[6].target_status).to eq poll.status
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -152,24 +152,33 @@ RSpec.describe TranslateStatusService, type: :service do
|
||||||
describe 'status has poll' do
|
describe 'status has poll' do
|
||||||
let(:poll) { Fabricate(:poll, options: %w(Blue Green)) }
|
let(:poll) { Fabricate(:poll, options: %w(Blue Green)) }
|
||||||
|
|
||||||
|
context 'with source texts from the service' do
|
||||||
|
let!(:source_texts) { service.send(:source_texts) }
|
||||||
|
|
||||||
it 'returns formatted poll options' do
|
it 'returns formatted poll options' do
|
||||||
source_texts = service.send(:source_texts)
|
|
||||||
expect(source_texts.size).to eq 3
|
expect(source_texts.size).to eq 3
|
||||||
expect(source_texts.values).to eq %w(<p>Hello</p> Blue Green)
|
expect(source_texts.values).to eq %w(<p>Hello</p> Blue Green)
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'has a first key with content' do
|
||||||
expect(source_texts.keys.first).to eq :content
|
expect(source_texts.keys.first).to eq :content
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'has the first option in the second key with correct options' do
|
||||||
option1 = source_texts.keys.second
|
option1 = source_texts.keys.second
|
||||||
expect(option1).to be_a Poll::Option
|
expect(option1).to be_a Poll::Option
|
||||||
expect(option1.id).to eq '0'
|
expect(option1.id).to eq '0'
|
||||||
expect(option1.title).to eq 'Blue'
|
expect(option1.title).to eq 'Blue'
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'has the second option in the third key with correct options' do
|
||||||
option2 = source_texts.keys.third
|
option2 = source_texts.keys.third
|
||||||
expect(option2).to be_a Poll::Option
|
expect(option2).to be_a Poll::Option
|
||||||
expect(option2.id).to eq '1'
|
expect(option2.id).to eq '1'
|
||||||
expect(option2.title).to eq 'Green'
|
expect(option2.title).to eq 'Green'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
describe 'status has poll with custom emoji' do
|
describe 'status has poll with custom emoji' do
|
||||||
let(:poll) { Fabricate(:poll, options: ['Blue', 'Green :highfive:']) }
|
let(:poll) { Fabricate(:poll, options: ['Blue', 'Green :highfive:']) }
|
||||||
|
|
Loading…
Reference in a new issue