mirror of
https://git.kescher.at/CatCatNya/catstodon.git
synced 2024-11-26 05:31:36 +01:00
Autofix Rubocops RSpec/ScatteredLet (#23725)
This commit is contained in:
parent
aef0051fd0
commit
5179c47087
9 changed files with 56 additions and 83 deletions
|
@ -1629,19 +1629,6 @@ RSpec/RepeatedExampleGroupDescription:
|
||||||
- 'spec/controllers/admin/reports/actions_controller_spec.rb'
|
- 'spec/controllers/admin/reports/actions_controller_spec.rb'
|
||||||
- 'spec/policies/report_note_policy_spec.rb'
|
- 'spec/policies/report_note_policy_spec.rb'
|
||||||
|
|
||||||
# Offense count: 18
|
|
||||||
# This cop supports safe autocorrection (--autocorrect).
|
|
||||||
RSpec/ScatteredLet:
|
|
||||||
Exclude:
|
|
||||||
- 'spec/controllers/admin/domain_blocks_controller_spec.rb'
|
|
||||||
- 'spec/controllers/api/v1/admin/domain_blocks_controller_spec.rb'
|
|
||||||
- 'spec/controllers/api/v1/push/subscriptions_controller_spec.rb'
|
|
||||||
- 'spec/lib/activitypub/activity/create_spec.rb'
|
|
||||||
- 'spec/lib/vacuum/media_attachments_vacuum_spec.rb'
|
|
||||||
- 'spec/services/activitypub/process_status_update_service_spec.rb'
|
|
||||||
- 'spec/services/fan_out_on_write_service_spec.rb'
|
|
||||||
- 'spec/services/import_service_spec.rb'
|
|
||||||
|
|
||||||
# Offense count: 12
|
# Offense count: 12
|
||||||
RSpec/ScatteredSetup:
|
RSpec/ScatteredSetup:
|
||||||
Exclude:
|
Exclude:
|
||||||
|
|
|
@ -72,16 +72,15 @@ RSpec.describe Admin::DomainBlocksController, type: :controller do
|
||||||
|
|
||||||
describe 'PUT #update' do
|
describe 'PUT #update' do
|
||||||
let!(:remote_account) { Fabricate(:account, domain: 'example.com') }
|
let!(:remote_account) { Fabricate(:account, domain: 'example.com') }
|
||||||
let(:domain_block) { Fabricate(:domain_block, domain: 'example.com', severity: original_severity) }
|
let(:subject) do
|
||||||
|
post :update, params: { id: domain_block.id, domain_block: { domain: 'example.com', severity: new_severity } }
|
||||||
|
end
|
||||||
|
let(:domain_block) { Fabricate(:domain_block, domain: 'example.com', severity: original_severity) }
|
||||||
|
|
||||||
before do
|
before do
|
||||||
BlockDomainService.new.call(domain_block)
|
BlockDomainService.new.call(domain_block)
|
||||||
end
|
end
|
||||||
|
|
||||||
let(:subject) do
|
|
||||||
post :update, params: { id: domain_block.id, domain_block: { domain: 'example.com', severity: new_severity } }
|
|
||||||
end
|
|
||||||
|
|
||||||
context 'downgrading a domain suspension to silence' do
|
context 'downgrading a domain suspension to silence' do
|
||||||
let(:original_severity) { 'suspend' }
|
let(:original_severity) { 'suspend' }
|
||||||
let(:new_severity) { 'silence' }
|
let(:new_severity) { 'silence' }
|
||||||
|
|
|
@ -73,16 +73,15 @@ RSpec.describe Api::V1::Admin::DomainBlocksController, type: :controller do
|
||||||
|
|
||||||
describe 'PUT #update' do
|
describe 'PUT #update' do
|
||||||
let!(:remote_account) { Fabricate(:account, domain: 'example.com') }
|
let!(:remote_account) { Fabricate(:account, domain: 'example.com') }
|
||||||
let(:domain_block) { Fabricate(:domain_block, domain: 'example.com', severity: original_severity) }
|
let(:subject) do
|
||||||
|
post :update, params: { id: domain_block.id, domain: 'example.com', severity: new_severity }
|
||||||
|
end
|
||||||
|
let(:domain_block) { Fabricate(:domain_block, domain: 'example.com', severity: original_severity) }
|
||||||
|
|
||||||
before do
|
before do
|
||||||
BlockDomainService.new.call(domain_block)
|
BlockDomainService.new.call(domain_block)
|
||||||
end
|
end
|
||||||
|
|
||||||
let(:subject) do
|
|
||||||
post :update, params: { id: domain_block.id, domain: 'example.com', severity: new_severity }
|
|
||||||
end
|
|
||||||
|
|
||||||
context 'downgrading a domain suspension to silence' do
|
context 'downgrading a domain suspension to silence' do
|
||||||
let(:original_severity) { 'suspend' }
|
let(:original_severity) { 'suspend' }
|
||||||
let(:new_severity) { 'silence' }
|
let(:new_severity) { 'silence' }
|
||||||
|
|
|
@ -5,13 +5,7 @@ require 'rails_helper'
|
||||||
describe Api::V1::Push::SubscriptionsController do
|
describe Api::V1::Push::SubscriptionsController do
|
||||||
render_views
|
render_views
|
||||||
|
|
||||||
let(:user) { Fabricate(:user) }
|
let(:user) { Fabricate(:user) }
|
||||||
let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: 'push') }
|
|
||||||
|
|
||||||
before do
|
|
||||||
allow(controller).to receive(:doorkeeper_token) { token }
|
|
||||||
end
|
|
||||||
|
|
||||||
let(:create_payload) do
|
let(:create_payload) do
|
||||||
{
|
{
|
||||||
subscription: {
|
subscription: {
|
||||||
|
@ -23,7 +17,6 @@ describe Api::V1::Push::SubscriptionsController do
|
||||||
},
|
},
|
||||||
}.with_indifferent_access
|
}.with_indifferent_access
|
||||||
end
|
end
|
||||||
|
|
||||||
let(:alerts_payload) do
|
let(:alerts_payload) do
|
||||||
{
|
{
|
||||||
data: {
|
data: {
|
||||||
|
@ -41,6 +34,11 @@ describe Api::V1::Push::SubscriptionsController do
|
||||||
},
|
},
|
||||||
}.with_indifferent_access
|
}.with_indifferent_access
|
||||||
end
|
end
|
||||||
|
let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: 'push') }
|
||||||
|
|
||||||
|
before do
|
||||||
|
allow(controller).to receive(:doorkeeper_token) { token }
|
||||||
|
end
|
||||||
|
|
||||||
describe 'POST #create' do
|
describe 'POST #create' do
|
||||||
before do
|
before do
|
||||||
|
|
|
@ -753,10 +753,6 @@ RSpec.describe ActivityPub::Activity::Create do
|
||||||
|
|
||||||
context 'with an encrypted message' do
|
context 'with an encrypted message' do
|
||||||
let(:recipient) { Fabricate(:account) }
|
let(:recipient) { Fabricate(:account) }
|
||||||
let(:target_device) { Fabricate(:device, account: recipient) }
|
|
||||||
|
|
||||||
subject { described_class.new(json, sender, delivery: true, delivered_to_account_id: recipient.id) }
|
|
||||||
|
|
||||||
let(:object_json) do
|
let(:object_json) do
|
||||||
{
|
{
|
||||||
id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
|
id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
|
||||||
|
@ -778,6 +774,9 @@ RSpec.describe ActivityPub::Activity::Create do
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
let(:target_device) { Fabricate(:device, account: recipient) }
|
||||||
|
|
||||||
|
subject { described_class.new(json, sender, delivery: true, delivered_to_account_id: recipient.id) }
|
||||||
|
|
||||||
before do
|
before do
|
||||||
subject.perform
|
subject.perform
|
||||||
|
@ -833,13 +832,6 @@ RSpec.describe ActivityPub::Activity::Create do
|
||||||
|
|
||||||
context 'when sender replies to local status' do
|
context 'when sender replies to local status' do
|
||||||
let!(:local_status) { Fabricate(:status) }
|
let!(:local_status) { Fabricate(:status) }
|
||||||
|
|
||||||
subject { described_class.new(json, sender, delivery: true) }
|
|
||||||
|
|
||||||
before do
|
|
||||||
subject.perform
|
|
||||||
end
|
|
||||||
|
|
||||||
let(:object_json) do
|
let(:object_json) do
|
||||||
{
|
{
|
||||||
id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
|
id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
|
||||||
|
@ -849,6 +841,12 @@ RSpec.describe ActivityPub::Activity::Create do
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
subject { described_class.new(json, sender, delivery: true) }
|
||||||
|
|
||||||
|
before do
|
||||||
|
subject.perform
|
||||||
|
end
|
||||||
|
|
||||||
it 'creates status' do
|
it 'creates status' do
|
||||||
status = sender.statuses.first
|
status = sender.statuses.first
|
||||||
|
|
||||||
|
@ -859,13 +857,6 @@ RSpec.describe ActivityPub::Activity::Create do
|
||||||
|
|
||||||
context 'when sender targets a local user' do
|
context 'when sender targets a local user' do
|
||||||
let!(:local_account) { Fabricate(:account) }
|
let!(:local_account) { Fabricate(:account) }
|
||||||
|
|
||||||
subject { described_class.new(json, sender, delivery: true) }
|
|
||||||
|
|
||||||
before do
|
|
||||||
subject.perform
|
|
||||||
end
|
|
||||||
|
|
||||||
let(:object_json) do
|
let(:object_json) do
|
||||||
{
|
{
|
||||||
id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
|
id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
|
||||||
|
@ -875,6 +866,12 @@ RSpec.describe ActivityPub::Activity::Create do
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
subject { described_class.new(json, sender, delivery: true) }
|
||||||
|
|
||||||
|
before do
|
||||||
|
subject.perform
|
||||||
|
end
|
||||||
|
|
||||||
it 'creates status' do
|
it 'creates status' do
|
||||||
status = sender.statuses.first
|
status = sender.statuses.first
|
||||||
|
|
||||||
|
@ -885,13 +882,6 @@ RSpec.describe ActivityPub::Activity::Create do
|
||||||
|
|
||||||
context 'when sender cc\'s a local user' do
|
context 'when sender cc\'s a local user' do
|
||||||
let!(:local_account) { Fabricate(:account) }
|
let!(:local_account) { Fabricate(:account) }
|
||||||
|
|
||||||
subject { described_class.new(json, sender, delivery: true) }
|
|
||||||
|
|
||||||
before do
|
|
||||||
subject.perform
|
|
||||||
end
|
|
||||||
|
|
||||||
let(:object_json) do
|
let(:object_json) do
|
||||||
{
|
{
|
||||||
id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
|
id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
|
||||||
|
@ -901,6 +891,12 @@ RSpec.describe ActivityPub::Activity::Create do
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
subject { described_class.new(json, sender, delivery: true) }
|
||||||
|
|
||||||
|
before do
|
||||||
|
subject.perform
|
||||||
|
end
|
||||||
|
|
||||||
it 'creates status' do
|
it 'creates status' do
|
||||||
status = sender.statuses.first
|
status = sender.statuses.first
|
||||||
|
|
||||||
|
|
|
@ -2,12 +2,11 @@ require 'rails_helper'
|
||||||
|
|
||||||
RSpec.describe Vacuum::MediaAttachmentsVacuum do
|
RSpec.describe Vacuum::MediaAttachmentsVacuum do
|
||||||
let(:retention_period) { 7.days }
|
let(:retention_period) { 7.days }
|
||||||
|
|
||||||
subject { described_class.new(retention_period) }
|
|
||||||
|
|
||||||
let(:remote_status) { Fabricate(:status, account: Fabricate(:account, domain: 'example.com')) }
|
let(:remote_status) { Fabricate(:status, account: Fabricate(:account, domain: 'example.com')) }
|
||||||
let(:local_status) { Fabricate(:status) }
|
let(:local_status) { Fabricate(:status) }
|
||||||
|
|
||||||
|
subject { described_class.new(retention_period) }
|
||||||
|
|
||||||
describe '#perform' do
|
describe '#perform' do
|
||||||
let!(:old_remote_media) { Fabricate(:media_attachment, remote_url: 'https://example.com/foo.png', status: remote_status, created_at: (retention_period + 1.day).ago, updated_at: (retention_period + 1.day).ago) }
|
let!(:old_remote_media) { Fabricate(:media_attachment, remote_url: 'https://example.com/foo.png', status: remote_status, created_at: (retention_period + 1.day).ago, updated_at: (retention_period + 1.day).ago) }
|
||||||
let!(:old_local_media) { Fabricate(:media_attachment, status: local_status, created_at: (retention_period + 1.day).ago, updated_at: (retention_period + 1.day).ago) }
|
let!(:old_local_media) { Fabricate(:media_attachment, status: local_status, created_at: (retention_period + 1.day).ago, updated_at: (retention_period + 1.day).ago) }
|
||||||
|
|
|
@ -6,20 +6,6 @@ end
|
||||||
|
|
||||||
RSpec.describe ActivityPub::ProcessStatusUpdateService, type: :service do
|
RSpec.describe ActivityPub::ProcessStatusUpdateService, type: :service do
|
||||||
let!(:status) { Fabricate(:status, text: 'Hello world', account: Fabricate(:account, domain: 'example.com')) }
|
let!(:status) { Fabricate(:status, text: 'Hello world', account: Fabricate(:account, domain: 'example.com')) }
|
||||||
|
|
||||||
let(:alice) { Fabricate(:account) }
|
|
||||||
let(:bob) { Fabricate(:account) }
|
|
||||||
|
|
||||||
let(:mentions) { [] }
|
|
||||||
let(:tags) { [] }
|
|
||||||
let(:media_attachments) { [] }
|
|
||||||
|
|
||||||
before do
|
|
||||||
mentions.each { |a| Fabricate(:mention, status: status, account: a) }
|
|
||||||
tags.each { |t| status.tags << t }
|
|
||||||
media_attachments.each { |m| status.media_attachments << m }
|
|
||||||
end
|
|
||||||
|
|
||||||
let(:payload) do
|
let(:payload) do
|
||||||
{
|
{
|
||||||
'@context': 'https://www.w3.org/ns/activitystreams',
|
'@context': 'https://www.w3.org/ns/activitystreams',
|
||||||
|
@ -34,9 +20,21 @@ RSpec.describe ActivityPub::ProcessStatusUpdateService, type: :service do
|
||||||
],
|
],
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
let(:json) { Oj.load(Oj.dump(payload)) }
|
let(:json) { Oj.load(Oj.dump(payload)) }
|
||||||
|
|
||||||
|
let(:alice) { Fabricate(:account) }
|
||||||
|
let(:bob) { Fabricate(:account) }
|
||||||
|
|
||||||
|
let(:mentions) { [] }
|
||||||
|
let(:tags) { [] }
|
||||||
|
let(:media_attachments) { [] }
|
||||||
|
|
||||||
|
before do
|
||||||
|
mentions.each { |a| Fabricate(:mention, status: status, account: a) }
|
||||||
|
tags.each { |t| status.tags << t }
|
||||||
|
media_attachments.each { |m| status.media_attachments << m }
|
||||||
|
end
|
||||||
|
|
||||||
subject { described_class.new }
|
subject { described_class.new }
|
||||||
|
|
||||||
describe '#call' do
|
describe '#call' do
|
||||||
|
|
|
@ -2,6 +2,7 @@ require 'rails_helper'
|
||||||
|
|
||||||
RSpec.describe FanOutOnWriteService, type: :service do
|
RSpec.describe FanOutOnWriteService, type: :service do
|
||||||
let(:last_active_at) { Time.now.utc }
|
let(:last_active_at) { Time.now.utc }
|
||||||
|
let(:status) { Fabricate(:status, account: alice, visibility: visibility, text: 'Hello @bob #hoge') }
|
||||||
|
|
||||||
let!(:alice) { Fabricate(:user, current_sign_in_at: last_active_at).account }
|
let!(:alice) { Fabricate(:user, current_sign_in_at: last_active_at).account }
|
||||||
let!(:bob) { Fabricate(:user, current_sign_in_at: last_active_at, account_attributes: { username: 'bob' }).account }
|
let!(:bob) { Fabricate(:user, current_sign_in_at: last_active_at, account_attributes: { username: 'bob' }).account }
|
||||||
|
@ -9,8 +10,6 @@ RSpec.describe FanOutOnWriteService, type: :service do
|
||||||
|
|
||||||
subject { described_class.new }
|
subject { described_class.new }
|
||||||
|
|
||||||
let(:status) { Fabricate(:status, account: alice, visibility: visibility, text: 'Hello @bob #hoge') }
|
|
||||||
|
|
||||||
before do
|
before do
|
||||||
bob.follow!(alice)
|
bob.follow!(alice)
|
||||||
tom.follow!(alice)
|
tom.follow!(alice)
|
||||||
|
|
|
@ -183,15 +183,14 @@ RSpec.describe ImportService, type: :service do
|
||||||
subject { ImportService.new }
|
subject { ImportService.new }
|
||||||
|
|
||||||
let!(:nare) { Fabricate(:account, username: 'nare', domain: 'թութ.հայ', locked: false, protocol: :activitypub, inbox_url: 'https://թութ.հայ/inbox') }
|
let!(:nare) { Fabricate(:account, username: 'nare', domain: 'թութ.հայ', locked: false, protocol: :activitypub, inbox_url: 'https://թութ.հայ/inbox') }
|
||||||
|
let(:csv) { attachment_fixture('utf8-followers.txt') }
|
||||||
|
let(:import) { Import.create(account: account, type: 'following', data: csv) }
|
||||||
|
|
||||||
# Make sure to not actually go to the remote server
|
# Make sure to not actually go to the remote server
|
||||||
before do
|
before do
|
||||||
stub_request(:post, 'https://թութ.հայ/inbox').to_return(status: 200)
|
stub_request(:post, 'https://թութ.հայ/inbox').to_return(status: 200)
|
||||||
end
|
end
|
||||||
|
|
||||||
let(:csv) { attachment_fixture('utf8-followers.txt') }
|
|
||||||
let(:import) { Import.create(account: account, type: 'following', data: csv) }
|
|
||||||
|
|
||||||
it 'follows the listed account' do
|
it 'follows the listed account' do
|
||||||
expect(account.follow_requests.count).to eq 0
|
expect(account.follow_requests.count).to eq 0
|
||||||
subject.call(import)
|
subject.call(import)
|
||||||
|
@ -203,6 +202,9 @@ RSpec.describe ImportService, type: :service do
|
||||||
subject { ImportService.new }
|
subject { ImportService.new }
|
||||||
|
|
||||||
let(:csv) { attachment_fixture('bookmark-imports.txt') }
|
let(:csv) { attachment_fixture('bookmark-imports.txt') }
|
||||||
|
let(:local_account) { Fabricate(:account, username: 'foo', domain: '') }
|
||||||
|
let!(:remote_status) { Fabricate(:status, uri: 'https://example.com/statuses/1312') }
|
||||||
|
let!(:direct_status) { Fabricate(:status, uri: 'https://example.com/statuses/direct', visibility: :direct) }
|
||||||
|
|
||||||
around(:each) do |example|
|
around(:each) do |example|
|
||||||
local_before = Rails.configuration.x.local_domain
|
local_before = Rails.configuration.x.local_domain
|
||||||
|
@ -214,10 +216,6 @@ RSpec.describe ImportService, type: :service do
|
||||||
Rails.configuration.x.local_domain = local_before
|
Rails.configuration.x.local_domain = local_before
|
||||||
end
|
end
|
||||||
|
|
||||||
let(:local_account) { Fabricate(:account, username: 'foo', domain: '') }
|
|
||||||
let!(:remote_status) { Fabricate(:status, uri: 'https://example.com/statuses/1312') }
|
|
||||||
let!(:direct_status) { Fabricate(:status, uri: 'https://example.com/statuses/direct', visibility: :direct) }
|
|
||||||
|
|
||||||
before do
|
before do
|
||||||
service = double
|
service = double
|
||||||
allow(ActivityPub::FetchRemoteStatusService).to receive(:new).and_return(service)
|
allow(ActivityPub::FetchRemoteStatusService).to receive(:new).and_return(service)
|
||||||
|
|
Loading…
Reference in a new issue