0
0
Fork 0

Update rubocop-rspec to version 2.22.0, fix RSpec/IndexedLet cop (#24698)

This commit is contained in:
Matt Jankowski 2023-06-14 10:44:37 -04:00 committed by GitHub
parent 24015ef0cc
commit 4c5aa0e470
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
25 changed files with 334 additions and 322 deletions

View file

@ -5,31 +5,31 @@ require 'rails_helper'
RSpec.describe AccountReachFinder do
let(:account) { Fabricate(:account) }
let(:follower1) { Fabricate(:account, protocol: :activitypub, inbox_url: 'https://example.com/inbox-1') }
let(:follower2) { Fabricate(:account, protocol: :activitypub, inbox_url: 'https://example.com/inbox-2') }
let(:follower3) { Fabricate(:account, protocol: :activitypub, inbox_url: 'https://foo.bar/users/a/inbox', shared_inbox_url: 'https://foo.bar/inbox') }
let(:ap_follower_example_com) { Fabricate(:account, protocol: :activitypub, inbox_url: 'https://example.com/inbox-1') }
let(:ap_follower_example_org) { Fabricate(:account, protocol: :activitypub, inbox_url: 'https://example.org/inbox-2') }
let(:ap_follower_with_shared) { Fabricate(:account, protocol: :activitypub, inbox_url: 'https://foo.bar/users/a/inbox', shared_inbox_url: 'https://foo.bar/inbox') }
let(:mentioned1) { Fabricate(:account, protocol: :activitypub, inbox_url: 'https://foo.bar/users/b/inbox', shared_inbox_url: 'https://foo.bar/inbox') }
let(:mentioned2) { Fabricate(:account, protocol: :activitypub, inbox_url: 'https://example.com/inbox-3') }
let(:mentioned3) { Fabricate(:account, protocol: :activitypub, inbox_url: 'https://example.com/inbox-4') }
let(:ap_mentioned_with_shared) { Fabricate(:account, protocol: :activitypub, inbox_url: 'https://foo.bar/users/b/inbox', shared_inbox_url: 'https://foo.bar/inbox') }
let(:ap_mentioned_example_com) { Fabricate(:account, protocol: :activitypub, inbox_url: 'https://example.com/inbox-3') }
let(:ap_mentioned_example_org) { Fabricate(:account, protocol: :activitypub, inbox_url: 'https://example.org/inbox-4') }
let(:unrelated_account) { Fabricate(:account, protocol: :activitypub, inbox_url: 'https://example.com/unrelated-inbox') }
before do
follower1.follow!(account)
follower2.follow!(account)
follower3.follow!(account)
ap_follower_example_com.follow!(account)
ap_follower_example_org.follow!(account)
ap_follower_with_shared.follow!(account)
Fabricate(:status, account: account).tap do |status|
status.mentions << Mention.new(account: follower1)
status.mentions << Mention.new(account: mentioned1)
status.mentions << Mention.new(account: ap_follower_example_com)
status.mentions << Mention.new(account: ap_mentioned_with_shared)
end
Fabricate(:status, account: account)
Fabricate(:status, account: account).tap do |status|
status.mentions << Mention.new(account: mentioned2)
status.mentions << Mention.new(account: mentioned3)
status.mentions << Mention.new(account: ap_mentioned_example_com)
status.mentions << Mention.new(account: ap_mentioned_example_org)
end
Fabricate(:status).tap do |status|
@ -39,11 +39,11 @@ RSpec.describe AccountReachFinder do
describe '#inboxes' do
it 'includes the preferred inbox URL of followers' do
expect(described_class.new(account).inboxes).to include(*[follower1, follower2, follower3].map(&:preferred_inbox_url))
expect(described_class.new(account).inboxes).to include(*[ap_follower_example_com, ap_follower_example_org, ap_follower_with_shared].map(&:preferred_inbox_url))
end
it 'includes the preferred inbox URL of recently-mentioned accounts' do
expect(described_class.new(account).inboxes).to include(*[mentioned1, mentioned2, mentioned3].map(&:preferred_inbox_url))
expect(described_class.new(account).inboxes).to include(*[ap_mentioned_with_shared, ap_mentioned_example_com, ap_mentioned_example_org].map(&:preferred_inbox_url))
end
it 'does not include the inbox of unrelated users' do

View file

@ -526,19 +526,25 @@ RSpec.describe FeedManager do
end
describe '#clear_from_home' do
let(:account) { Fabricate(:account) }
let(:account) { Fabricate(:account) }
let(:followed_account) { Fabricate(:account) }
let(:target_account) { Fabricate(:account) }
let(:status_1) { Fabricate(:status, account: followed_account) }
let(:status_2) { Fabricate(:status, account: target_account) }
let(:status_3) { Fabricate(:status, account: followed_account, mentions: [Fabricate(:mention, account: target_account)]) }
let(:status_4) { Fabricate(:status, mentions: [Fabricate(:mention, account: target_account)]) }
let(:status_5) { Fabricate(:status, account: followed_account, reblog: status_4) }
let(:status_6) { Fabricate(:status, account: followed_account, reblog: status_2) }
let(:status_7) { Fabricate(:status, account: followed_account) }
let(:target_account) { Fabricate(:account) }
let(:status_from_followed_account_first) { Fabricate(:status, account: followed_account) }
let(:status_from_target_account) { Fabricate(:status, account: target_account) }
let(:status_from_followed_account_mentions_target_account) { Fabricate(:status, account: followed_account, mentions: [Fabricate(:mention, account: target_account)]) }
let(:status_mentions_target_account) { Fabricate(:status, mentions: [Fabricate(:mention, account: target_account)]) }
let(:status_from_followed_account_reblogs_status_mentions_target_account) { Fabricate(:status, account: followed_account, reblog: status_mentions_target_account) }
let(:status_from_followed_account_reblogs_status_from_target_account) { Fabricate(:status, account: followed_account, reblog: status_from_target_account) }
let(:status_from_followed_account_next) { Fabricate(:status, account: followed_account) }
before do
[status_1, status_3, status_5, status_6, status_7].each do |status|
[
status_from_followed_account_first,
status_from_followed_account_mentions_target_account,
status_from_followed_account_reblogs_status_mentions_target_account,
status_from_followed_account_reblogs_status_from_target_account,
status_from_followed_account_next,
].each do |status|
redis.zadd("feed:home:#{account.id}", status.id, status.id)
end
end
@ -546,7 +552,7 @@ RSpec.describe FeedManager do
it 'correctly cleans the home timeline' do
described_class.instance.clear_from_home(account, target_account)
expect(redis.zrange("feed:home:#{account.id}", 0, -1)).to eq [status_1.id.to_s, status_7.id.to_s]
expect(redis.zrange("feed:home:#{account.id}", 0, -1)).to eq [status_from_followed_account_first.id.to_s, status_from_followed_account_next.id.to_s]
end
end
end

View file

@ -189,22 +189,22 @@ describe Mastodon::CLI::IpBlocks do
end
context 'with --force option' do
let!(:block1) { IpBlock.create(ip: '192.168.0.0/24', severity: :no_access) }
let!(:block2) { IpBlock.create(ip: '10.0.0.0/16', severity: :no_access) }
let!(:block3) { IpBlock.create(ip: '172.16.0.0/20', severity: :no_access) }
let!(:first_ip_range_block) { IpBlock.create(ip: '192.168.0.0/24', severity: :no_access) }
let!(:second_ip_range_block) { IpBlock.create(ip: '10.0.0.0/16', severity: :no_access) }
let!(:third_ip_range_block) { IpBlock.create(ip: '172.16.0.0/20', severity: :no_access) }
let(:arguments) { ['192.168.0.5', '10.0.1.50'] }
let(:options) { { force: true } }
it 'removes blocks for IP ranges that cover given IP(s)' do
cli.invoke(:remove, arguments, options)
expect(IpBlock.where(id: [block1.id, block2.id])).to_not exist
expect(IpBlock.where(id: [first_ip_range_block.id, second_ip_range_block.id])).to_not exist
end
it 'does not remove other IP ranges' do
cli.invoke(:remove, arguments, options)
expect(IpBlock.where(id: block3.id)).to exist
expect(IpBlock.where(id: third_ip_range_block.id)).to exist
end
end
@ -251,22 +251,22 @@ describe Mastodon::CLI::IpBlocks do
end
describe '#export' do
let(:block1) { IpBlock.create(ip: '192.168.0.0/24', severity: :no_access) }
let(:block2) { IpBlock.create(ip: '10.0.0.0/16', severity: :no_access) }
let(:block3) { IpBlock.create(ip: '127.0.0.1', severity: :sign_up_block) }
let(:first_ip_range_block) { IpBlock.create(ip: '192.168.0.0/24', severity: :no_access) }
let(:second_ip_range_block) { IpBlock.create(ip: '10.0.0.0/16', severity: :no_access) }
let(:third_ip_range_block) { IpBlock.create(ip: '127.0.0.1', severity: :sign_up_block) }
context 'when --format option is set to "plain"' do
let(:options) { { format: 'plain' } }
it 'exports blocked IPs with "no_access" severity in plain format' do
expect { cli.invoke(:export, nil, options) }.to output(
a_string_including("#{block1.ip}/#{block1.ip.prefix}\n#{block2.ip}/#{block2.ip.prefix}")
a_string_including("#{first_ip_range_block.ip}/#{first_ip_range_block.ip.prefix}\n#{second_ip_range_block.ip}/#{second_ip_range_block.ip.prefix}")
).to_stdout
end
it 'does not export bloked IPs with different severities' do
expect { cli.invoke(:export, nil, options) }.to_not output(
a_string_including("#{block3.ip}/#{block1.ip.prefix}")
a_string_including("#{third_ip_range_block.ip}/#{first_ip_range_block.ip.prefix}")
).to_stdout
end
end
@ -276,13 +276,13 @@ describe Mastodon::CLI::IpBlocks do
it 'exports blocked IPs with "no_access" severity in plain format' do
expect { cli.invoke(:export, nil, options) }.to output(
a_string_including("deny #{block1.ip}/#{block1.ip.prefix};\ndeny #{block2.ip}/#{block2.ip.prefix};")
a_string_including("deny #{first_ip_range_block.ip}/#{first_ip_range_block.ip.prefix};\ndeny #{second_ip_range_block.ip}/#{second_ip_range_block.ip.prefix};")
).to_stdout
end
it 'does not export bloked IPs with different severities' do
expect { cli.invoke(:export, nil, options) }.to_not output(
a_string_including("deny #{block3.ip}/#{block1.ip.prefix};")
a_string_including("deny #{third_ip_range_block.ip}/#{first_ip_range_block.ip.prefix};")
).to_stdout
end
end
@ -290,7 +290,7 @@ describe Mastodon::CLI::IpBlocks do
context 'when --format option is not provided' do
it 'exports blocked IPs in plain format by default' do
expect { cli.export }.to output(
a_string_including("#{block1.ip}/#{block1.ip.prefix}\n#{block2.ip}/#{block2.ip.prefix}")
a_string_including("#{first_ip_range_block.ip}/#{first_ip_range_block.ip.prefix}\n#{second_ip_range_block.ip}/#{second_ip_range_block.ip.prefix}")
).to_stdout
end
end