Autofix Rubocop RSpec/LeadingSubject (#23670)

pull/53/head
Nick Schonning 2023-02-19 23:24:14 -05:00 committed by GitHub
parent 4ea1e0fceb
commit 4552685f6b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
78 changed files with 256 additions and 338 deletions

View File

@ -952,88 +952,6 @@ RSpec/InstanceVariable:
- 'spec/services/search_service_spec.rb'
- 'spec/services/unblock_domain_service_spec.rb'
# Offense count: 118
# This cop supports safe autocorrection (--autocorrect).
RSpec/LeadingSubject:
Exclude:
- 'spec/controllers/activitypub/collections_controller_spec.rb'
- 'spec/controllers/activitypub/followers_synchronizations_controller_spec.rb'
- 'spec/controllers/activitypub/inboxes_controller_spec.rb'
- 'spec/controllers/activitypub/outboxes_controller_spec.rb'
- 'spec/controllers/admin/invites_controller_spec.rb'
- 'spec/controllers/auth/registrations_controller_spec.rb'
- 'spec/controllers/well_known/webfinger_controller_spec.rb'
- 'spec/lib/activitypub/activity/accept_spec.rb'
- 'spec/lib/activitypub/activity/announce_spec.rb'
- 'spec/lib/activitypub/activity/create_spec.rb'
- 'spec/lib/activitypub/activity/reject_spec.rb'
- 'spec/lib/activitypub/activity/undo_spec.rb'
- 'spec/lib/activitypub/activity/update_spec.rb'
- 'spec/lib/activitypub/adapter_spec.rb'
- 'spec/lib/activitypub/dereferencer_spec.rb'
- 'spec/lib/activitypub/linked_data_signature_spec.rb'
- 'spec/lib/link_details_extractor_spec.rb'
- 'spec/lib/status_filter_spec.rb'
- 'spec/lib/status_reach_finder_spec.rb'
- 'spec/lib/suspicious_sign_in_detector_spec.rb'
- 'spec/lib/text_formatter_spec.rb'
- 'spec/lib/vacuum/backups_vacuum_spec.rb'
- 'spec/lib/vacuum/media_attachments_vacuum_spec.rb'
- 'spec/lib/vacuum/preview_cards_vacuum_spec.rb'
- 'spec/lib/vacuum/statuses_vacuum_spec.rb'
- 'spec/models/account/field_spec.rb'
- 'spec/models/account_spec.rb'
- 'spec/models/account_statuses_cleanup_policy_spec.rb'
- 'spec/models/account_statuses_filter_spec.rb'
- 'spec/models/concerns/account_interactions_spec.rb'
- 'spec/models/custom_emoji_filter_spec.rb'
- 'spec/models/custom_emoji_spec.rb'
- 'spec/models/home_feed_spec.rb'
- 'spec/models/media_attachment_spec.rb'
- 'spec/models/public_feed_spec.rb'
- 'spec/models/remote_follow_spec.rb'
- 'spec/models/setting_spec.rb'
- 'spec/models/status_spec.rb'
- 'spec/models/user_spec.rb'
- 'spec/models/web/push_subscription_spec.rb'
- 'spec/presenters/familiar_followers_presenter_spec.rb'
- 'spec/serializers/activitypub/note_spec.rb'
- 'spec/serializers/activitypub/update_poll_spec.rb'
- 'spec/serializers/rest/account_serializer_spec.rb'
- 'spec/services/activitypub/fetch_featured_collection_service_spec.rb'
- 'spec/services/activitypub/fetch_featured_tags_collection_service_spec.rb'
- 'spec/services/activitypub/fetch_remote_status_service_spec.rb'
- 'spec/services/activitypub/fetch_replies_service_spec.rb'
- 'spec/services/activitypub/process_account_service_spec.rb'
- 'spec/services/activitypub/process_collection_service_spec.rb'
- 'spec/services/activitypub/process_status_update_service_spec.rb'
- 'spec/services/activitypub/synchronize_followers_service_spec.rb'
- 'spec/services/after_block_domain_from_account_service_spec.rb'
- 'spec/services/app_sign_up_service_spec.rb'
- 'spec/services/authorize_follow_service_spec.rb'
- 'spec/services/block_domain_service_spec.rb'
- 'spec/services/block_service_spec.rb'
- 'spec/services/clear_domain_media_service_spec.rb'
- 'spec/services/delete_account_service_spec.rb'
- 'spec/services/fan_out_on_write_service_spec.rb'
- 'spec/services/favourite_service_spec.rb'
- 'spec/services/fetch_resource_service_spec.rb'
- 'spec/services/follow_service_spec.rb'
- 'spec/services/process_mentions_service_spec.rb'
- 'spec/services/purge_domain_service_spec.rb'
- 'spec/services/reblog_service_spec.rb'
- 'spec/services/reject_follow_service_spec.rb'
- 'spec/services/remove_from_follwers_service_spec.rb'
- 'spec/services/report_service_spec.rb'
- 'spec/services/suspend_account_service_spec.rb'
- 'spec/services/unallow_domain_service_spec.rb'
- 'spec/services/unblock_service_spec.rb'
- 'spec/services/unfollow_service_spec.rb'
- 'spec/services/unsuspend_account_service_spec.rb'
- 'spec/validators/blacklisted_email_validator_spec.rb'
- 'spec/workers/move_worker_spec.rb'
- 'spec/workers/unfollow_follow_worker_spec.rb'
# Offense count: 15
RSpec/LeakyConstantDeclaration:
Exclude:

View File

@ -35,11 +35,11 @@ RSpec.describe ActivityPub::CollectionsController, type: :controller do
describe 'GET #show' do
context 'when id is "featured"' do
context 'without signature' do
let(:remote_account) { nil }
subject(:body) { body_as_json }
subject(:response) { get :show, params: { id: 'featured', account_username: account.username } }
subject(:body) { body_as_json }
let(:remote_account) { nil }
it 'returns http success' do
expect(response).to have_http_status(200)

View File

@ -32,11 +32,11 @@ RSpec.describe ActivityPub::FollowersSynchronizationsController, type: :controll
end
context 'with signature from example.com' do
let(:remote_account) { Fabricate(:account, domain: 'example.com', uri: 'https://example.com/instance') }
subject(:body) { body_as_json }
subject(:response) { get :show, params: { account_username: account.username } }
subject(:body) { body_as_json }
let(:remote_account) { Fabricate(:account, domain: 'example.com', uri: 'https://example.com/instance') }
it 'returns http success' do
expect(response).to have_http_status(200)

View File

@ -22,10 +22,10 @@ RSpec.describe ActivityPub::InboxesController, type: :controller do
end
context 'for a specific account' do
let(:account) { Fabricate(:account) }
subject(:response) { post :create, params: { account_username: account.username }, body: '{}' }
let(:account) { Fabricate(:account) }
context 'when account is permanently suspended' do
before do
account.suspend!

View File

@ -33,11 +33,11 @@ RSpec.describe ActivityPub::OutboxesController, type: :controller do
describe 'GET #show' do
context 'without signature' do
let(:remote_account) { nil }
subject(:body) { body_as_json }
subject(:response) { get :show, params: { account_username: account.username, page: page } }
subject(:body) { body_as_json }
let(:remote_account) { nil }
context 'with page not requested' do
let(:page) { nil }

View File

@ -33,10 +33,10 @@ describe Admin::InvitesController do
end
describe 'DELETE #destroy' do
let!(:invite) { Fabricate(:invite, expires_at: nil) }
subject { delete :destroy, params: { id: invite.id } }
let!(:invite) { Fabricate(:invite, expires_at: nil) }
it 'expires invite' do
expect(subject).to redirect_to admin_invites_path
expect(invite.reload).to be_expired

View File

@ -95,18 +95,18 @@ RSpec.describe Auth::RegistrationsController, type: :controller do
before { request.env['devise.mapping'] = Devise.mappings[:user] }
context do
around do |example|
registrations_mode = Setting.registrations_mode
example.run
Setting.registrations_mode = registrations_mode
end
subject do
Setting.registrations_mode = 'open'
request.headers['Accept-Language'] = accept_language
post :create, params: { user: { account_attributes: { username: 'test' }, email: 'test@example.com', password: '12345678', password_confirmation: '12345678', agreement: 'true' } }
end
around do |example|
registrations_mode = Setting.registrations_mode
example.run
Setting.registrations_mode = registrations_mode
end
it 'redirects to setup' do
subject
expect(response).to redirect_to auth_setup_path
@ -121,18 +121,18 @@ RSpec.describe Auth::RegistrationsController, type: :controller do
end
context 'when user has not agreed to terms of service' do
around do |example|
registrations_mode = Setting.registrations_mode
example.run
Setting.registrations_mode = registrations_mode
end
subject do
Setting.registrations_mode = 'open'
request.headers['Accept-Language'] = accept_language
post :create, params: { user: { account_attributes: { username: 'test' }, email: 'test@example.com', password: '12345678', password_confirmation: '12345678', agreement: 'false' } }
end
around do |example|
registrations_mode = Setting.registrations_mode
example.run
Setting.registrations_mode = registrations_mode
end
it 'does not create user' do
subject
user = User.find_by(email: 'test@example.com')
@ -141,18 +141,18 @@ RSpec.describe Auth::RegistrationsController, type: :controller do
end
context 'approval-based registrations without invite' do
around do |example|
registrations_mode = Setting.registrations_mode
example.run
Setting.registrations_mode = registrations_mode
end
subject do
Setting.registrations_mode = 'approved'
request.headers['Accept-Language'] = accept_language
post :create, params: { user: { account_attributes: { username: 'test' }, email: 'test@example.com', password: '12345678', password_confirmation: '12345678', agreement: 'true' } }
end
around do |example|
registrations_mode = Setting.registrations_mode
example.run
Setting.registrations_mode = registrations_mode
end
it 'redirects to setup' do
subject
expect(response).to redirect_to auth_setup_path
@ -168,12 +168,6 @@ RSpec.describe Auth::RegistrationsController, type: :controller do
end
context 'approval-based registrations with expired invite' do
around do |example|
registrations_mode = Setting.registrations_mode
example.run
Setting.registrations_mode = registrations_mode
end
subject do
Setting.registrations_mode = 'approved'
request.headers['Accept-Language'] = accept_language
@ -181,6 +175,12 @@ RSpec.describe Auth::RegistrationsController, type: :controller do
post :create, params: { user: { account_attributes: { username: 'test' }, email: 'test@example.com', password: '12345678', password_confirmation: '12345678', invite_code: invite.code, agreement: 'true' } }
end
around do |example|
registrations_mode = Setting.registrations_mode
example.run
Setting.registrations_mode = registrations_mode
end
it 'redirects to setup' do
subject
expect(response).to redirect_to auth_setup_path
@ -196,14 +196,6 @@ RSpec.describe Auth::RegistrationsController, type: :controller do
end
context 'approval-based registrations with valid invite and required invite text' do
around do |example|
registrations_mode = Setting.registrations_mode
require_invite_text = Setting.require_invite_text
example.run
Setting.require_invite_text = require_invite_text
Setting.registrations_mode = registrations_mode
end
subject do
inviter = Fabricate(:user, confirmed_at: 2.days.ago)
Setting.registrations_mode = 'approved'
@ -213,6 +205,14 @@ RSpec.describe Auth::RegistrationsController, type: :controller do
post :create, params: { user: { account_attributes: { username: 'test' }, email: 'test@example.com', password: '12345678', password_confirmation: '12345678', invite_code: invite.code, agreement: 'true' } }
end
around do |example|
registrations_mode = Setting.registrations_mode
require_invite_text = Setting.require_invite_text
example.run
Setting.require_invite_text = require_invite_text
Setting.registrations_mode = registrations_mode
end
it 'redirects to setup' do
subject
expect(response).to redirect_to auth_setup_path

View File

@ -4,6 +4,10 @@ describe WellKnown::WebfingerController, type: :controller do
render_views
describe 'GET #show' do
subject do
get :show, params: { resource: resource }, format: :json
end
let(:alternate_domains) { [] }
let(:alice) { Fabricate(:account, username: 'alice') }
let(:resource) { nil }
@ -15,10 +19,6 @@ describe WellKnown::WebfingerController, type: :controller do
Rails.configuration.x.alternate_domains = tmp
end
subject do
get :show, params: { resource: resource }, format: :json
end
shared_examples 'a successful response' do
it 'returns http success' do
expect(response).to have_http_status(200)

View File

@ -42,6 +42,8 @@ RSpec.describe ActivityPub::Activity::Accept do
end
context 'given a relay' do
subject { described_class.new(json, sender) }
let!(:relay) { Fabricate(:relay, state: :pending, follow_activity_id: 'https://abc-123/456') }
let(:json) do
@ -59,8 +61,6 @@ RSpec.describe ActivityPub::Activity::Accept do
}.with_indifferent_access
end
subject { described_class.new(json, sender) }
it 'marks the relay as accepted' do
subject.perform
expect(relay.reload.accepted?).to be true

View File

@ -1,6 +1,8 @@
require 'rails_helper'
RSpec.describe ActivityPub::Activity::Announce do
subject { described_class.new(json, sender) }
let(:sender) { Fabricate(:account, followers_url: 'http://example.com/followers', uri: 'https://example.com/actor') }
let(:recipient) { Fabricate(:account) }
let(:status) { Fabricate(:status, account: recipient) }
@ -27,8 +29,6 @@ RSpec.describe ActivityPub::Activity::Announce do
}
end
subject { described_class.new(json, sender) }
describe '#perform' do
context 'when sender is followed by a local account' do
before do
@ -110,13 +110,13 @@ RSpec.describe ActivityPub::Activity::Announce do
end
context 'when the sender is relayed' do
subject { described_class.new(json, sender, relayed_through_actor: relay_account) }
let!(:relay_account) { Fabricate(:account, inbox_url: 'https://relay.example.com/inbox') }
let!(:relay) { Fabricate(:relay, inbox_url: 'https://relay.example.com/inbox') }
let(:object_json) { 'https://example.com/actor/hello-world' }
subject { described_class.new(json, sender, relayed_through_actor: relay_account) }
before do
stub_request(:get, 'https://example.com/actor/hello-world').to_return(body: Oj.dump(unknown_object_json))
end

View File

@ -752,6 +752,8 @@ RSpec.describe ActivityPub::Activity::Create do
end
context 'with an encrypted message' do
subject { described_class.new(json, sender, delivery: true, delivered_to_account_id: recipient.id) }
let(:recipient) { Fabricate(:account) }
let(:object_json) do
{
@ -776,8 +778,6 @@ RSpec.describe ActivityPub::Activity::Create do
end
let(:target_device) { Fabricate(:device, account: recipient) }
subject { described_class.new(json, sender, delivery: true, delivered_to_account_id: recipient.id) }
before do
subject.perform
end
@ -831,6 +831,8 @@ RSpec.describe ActivityPub::Activity::Create do
end
context 'when sender replies to local status' do
subject { described_class.new(json, sender, delivery: true) }
let!(:local_status) { Fabricate(:status) }
let(:object_json) do
{
@ -841,8 +843,6 @@ RSpec.describe ActivityPub::Activity::Create do
}
end
subject { described_class.new(json, sender, delivery: true) }
before do
subject.perform
end
@ -856,6 +856,8 @@ RSpec.describe ActivityPub::Activity::Create do
end
context 'when sender targets a local user' do
subject { described_class.new(json, sender, delivery: true) }
let!(:local_account) { Fabricate(:account) }
let(:object_json) do
{
@ -866,8 +868,6 @@ RSpec.describe ActivityPub::Activity::Create do
}
end
subject { described_class.new(json, sender, delivery: true) }
before do
subject.perform
end
@ -881,6 +881,8 @@ RSpec.describe ActivityPub::Activity::Create do
end
context 'when sender cc\'s a local user' do
subject { described_class.new(json, sender, delivery: true) }
let!(:local_account) { Fabricate(:account) }
let(:object_json) do
{
@ -891,8 +893,6 @@ RSpec.describe ActivityPub::Activity::Create do
}
end
subject { described_class.new(json, sender, delivery: true) }
before do
subject.perform
end

View File

@ -121,6 +121,8 @@ RSpec.describe ActivityPub::Activity::Reject do
end
context 'given a relay' do
subject { described_class.new(json, sender) }
let!(:relay) { Fabricate(:relay, state: :pending, follow_activity_id: 'https://abc-123/456') }
let(:json) do
@ -138,8 +140,6 @@ RSpec.describe ActivityPub::Activity::Reject do
}.with_indifferent_access
end
subject { described_class.new(json, sender) }
it 'marks the relay as rejected' do
subject.perform
expect(relay.reload.rejected?).to be true

View File

@ -1,6 +1,8 @@
require 'rails_helper'
RSpec.describe ActivityPub::Activity::Undo do
subject { described_class.new(json, sender) }
let(:sender) { Fabricate(:account, domain: 'example.com') }
let(:json) do
@ -13,8 +15,6 @@ RSpec.describe ActivityPub::Activity::Undo do
}.with_indifferent_access
end
subject { described_class.new(json, sender) }
describe '#perform' do
context 'with Announce' do
let(:status) { Fabricate(:status) }

View File

@ -1,14 +1,14 @@
require 'rails_helper'
RSpec.describe ActivityPub::Activity::Update do
subject { described_class.new(json, sender) }
let!(:sender) { Fabricate(:account) }
before do
sender.update!(uri: ActivityPub::TagManager.instance.uri_for(sender))
end
subject { described_class.new(json, sender) }
describe '#perform' do
context 'with an Actor object' do
let(:modified_sender) do

View File

@ -41,10 +41,10 @@ RSpec.describe ActivityPub::Adapter do
end
describe '#serializable_hash' do
let(:serializer_class) {}
subject { ActiveModelSerializers::SerializableResource.new(TestObject.new(foo: 'bar'), serializer: serializer_class, adapter: described_class).as_json }
let(:serializer_class) {}
context 'when serializer defines no context' do
let(:serializer_class) { TestWithBasicContextSerializer }

View File

@ -2,13 +2,13 @@ require 'rails_helper'
RSpec.describe ActivityPub::Dereferencer do
describe '#object' do
subject { described_class.new(uri, permitted_origin: permitted_origin, signature_actor: signature_actor).object }
let(:object) { { '@context': 'https://www.w3.org/ns/activitystreams', id: 'https://example.com/foo', type: 'Note', content: 'Hoge' } }
let(:permitted_origin) { 'https://example.com' }
let(:signature_actor) { nil }
let(:uri) { nil }
subject { described_class.new(uri, permitted_origin: permitted_origin, signature_actor: signature_actor).object }
before do
stub_request(:get, 'https://example.com/foo').to_return(body: Oj.dump(object), headers: { 'Content-Type' => 'application/activity+json' })
end

View File

@ -3,6 +3,8 @@ require 'rails_helper'
RSpec.describe ActivityPub::LinkedDataSignature do
include JsonLdHelper
subject { described_class.new(json) }
let!(:sender) { Fabricate(:account, uri: 'http://example.com/alice') }
let(:raw_json) do
@ -14,8 +16,6 @@ RSpec.describe ActivityPub::LinkedDataSignature do
let(:json) { raw_json.merge('signature' => signature) }
subject { described_class.new(json) }
before do
stub_jsonld_contexts!
end

View File

@ -1,12 +1,12 @@
require 'rails_helper'
RSpec.describe LinkDetailsExtractor do
subject { described_class.new(original_url, html, html_charset) }
let(:original_url) { '' }
let(:html) { '' }
let(:html_charset) { nil }
subject { described_class.new(original_url, html, html_charset) }
describe '#canonical_url' do
let(:original_url) { 'https://foo.com/article?bar=baz123' }

View File

@ -31,10 +31,10 @@ describe StatusFilter do
end
context 'with real account' do
let(:account) { Fabricate(:account) }
subject { described_class.new(status, account) }
let(:account) { Fabricate(:account) }
context 'when there are no connections' do
it { is_expected.to_not be_filtered }
end

View File

@ -5,13 +5,13 @@ require 'rails_helper'
describe StatusReachFinder do
describe '#inboxes' do
context 'for a local status' do
subject { described_class.new(status) }
let(:parent_status) { nil }
let(:visibility) { :public }
let(:alice) { Fabricate(:account, username: 'alice') }
let(:status) { Fabricate(:status, account: alice, thread: parent_status, visibility: visibility) }
subject { described_class.new(status) }
context 'when it contains mentions of remote accounts' do
let(:bob) { Fabricate(:account, username: 'bob', domain: 'foo.bar', protocol: :activitypub, inbox_url: 'https://foo.bar/inbox') }

View File

@ -2,12 +2,12 @@ require 'rails_helper'
RSpec.describe SuspiciousSignInDetector do
describe '#suspicious?' do
subject { described_class.new(user).suspicious?(request) }
let(:user) { Fabricate(:user, current_sign_in_at: 1.day.ago) }
let(:request) { double(remote_ip: remote_ip) }
let(:remote_ip) { nil }
subject { described_class.new(user).suspicious?(request) }
context 'when user has 2FA enabled' do
before do
user.update!(otp_required_for_login: true)

View File

@ -2,10 +2,10 @@ require 'rails_helper'
RSpec.describe TextFormatter do
describe '#to_s' do
let(:preloaded_accounts) { nil }
subject { described_class.new(text, preloaded_accounts: preloaded_accounts).to_s }
let(:preloaded_accounts) { nil }
context 'given text containing plain text' do
let(:text) { 'text' }

View File

@ -1,10 +1,10 @@
require 'rails_helper'
RSpec.describe Vacuum::BackupsVacuum do
let(:retention_period) { 7.days }
subject { described_class.new(retention_period) }
let(:retention_period) { 7.days }
describe '#perform' do
let!(:expired_backup) { Fabricate(:backup, created_at: (retention_period + 1.day).ago) }
let!(:current_backup) { Fabricate(:backup) }

View File

@ -1,12 +1,12 @@
require 'rails_helper'
RSpec.describe Vacuum::MediaAttachmentsVacuum do
subject { described_class.new(retention_period) }
let(:retention_period) { 7.days }
let(:remote_status) { Fabricate(:status, account: Fabricate(:account, domain: 'example.com')) }
let(:local_status) { Fabricate(:status) }
subject { described_class.new(retention_period) }
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_local_media) { Fabricate(:media_attachment, status: local_status, created_at: (retention_period + 1.day).ago, updated_at: (retention_period + 1.day).ago) }

View File

@ -1,10 +1,10 @@
require 'rails_helper'
RSpec.describe Vacuum::PreviewCardsVacuum do
let(:retention_period) { 7.days }
subject { described_class.new(retention_period) }
let(:retention_period) { 7.days }
describe '#perform' do
let!(:orphaned_preview_card) { Fabricate(:preview_card, created_at: 2.days.ago) }
let!(:old_preview_card) { Fabricate(:preview_card, updated_at: (retention_period + 1.day).ago) }

View File

@ -1,12 +1,12 @@
require 'rails_helper'
RSpec.describe Vacuum::StatusesVacuum do
subject { described_class.new(retention_period) }
let(:retention_period) { 7.days }
let(:remote_account) { Fabricate(:account, domain: 'example.com') }
subject { described_class.new(retention_period) }
describe '#perform' do
let!(:remote_status_old) { Fabricate(:status, account: remote_account, created_at: (retention_period + 2.days).ago) }
let!(:remote_status_recent) { Fabricate(:status, account: remote_account, created_at: (retention_period - 2.days).ago) }

View File

@ -2,10 +2,10 @@ require 'rails_helper'
RSpec.describe Account::Field, type: :model do
describe '#verified?' do
let(:account) { double('Account', local?: true) }
subject { described_class.new(account, 'name' => 'Foo', 'value' => 'Bar', 'verified_at' => verified_at) }
let(:account) { double('Account', local?: true) }
context 'when verified_at is set' do
let(:verified_at) { Time.now.utc.iso8601 }
@ -24,11 +24,11 @@ RSpec.describe Account::Field, type: :model do
end
describe '#mark_verified!' do
subject { described_class.new(account, original_hash) }
let(:account) { double('Account', local?: true) }
let(:original_hash) { { 'name' => 'Foo', 'value' => 'Bar' } }
subject { described_class.new(account, original_hash) }
before do
subject.mark_verified!
end
@ -43,10 +43,10 @@ RSpec.describe Account::Field, type: :model do
end
describe '#verifiable?' do
let(:account) { double('Account', local?: local) }
subject { described_class.new(account, 'name' => 'Foo', 'value' => value) }
let(:account) { double('Account', local?: local) }
context 'for local accounts' do
let(:local) { true }

View File

@ -2,10 +2,10 @@ require 'rails_helper'
RSpec.describe Account, type: :model do
context do
let(:bob) { Fabricate(:account, username: 'bob') }
subject { Fabricate(:account) }
let(:bob) { Fabricate(:account, username: 'bob') }
describe '#suspend!' do
it 'marks the account as suspended' do
subject.suspend!
@ -87,14 +87,14 @@ RSpec.describe Account, type: :model do
end
describe 'Local domain user methods' do
subject { Fabricate(:account, domain: nil, username: 'alice') }
around do |example|
before = Rails.configuration.x.local_domain
example.run
Rails.configuration.x.local_domain = before
end
subject { Fabricate(:account, domain: nil, username: 'alice') }
describe '#to_webfinger_s' do
it 'returns a webfinger string for the account' do
Rails.configuration.x.local_domain = 'example.com'
@ -243,13 +243,13 @@ RSpec.describe Account, type: :model do
end
describe '#favourited?' do
subject { Fabricate(:account) }
let(:original_status) do
author = Fabricate(:account, username: 'original')
Fabricate(:status, account: author)
end
subject { Fabricate(:account) }
context 'when the status is a reblog of another status' do
let(:original_reblog) do
author = Fabricate(:account, username: 'original_reblogger')
@ -281,13 +281,13 @@ RSpec.describe Account, type: :model do
end
describe '#reblogged?' do
subject { Fabricate(:account) }
let(:original_status) do
author = Fabricate(:account, username: 'original')
Fabricate(:status, account: author)
end
subject { Fabricate(:account) }
context 'when the status is a reblog of another status' do
let(:original_reblog) do
author = Fabricate(:account, username: 'original_reblogger')

View File

@ -132,11 +132,11 @@ RSpec.describe AccountStatusesCleanupPolicy, type: :model do
end
describe '#invalidate_last_inspected' do
subject { account_statuses_cleanup_policy.invalidate_last_inspected(status, action) }
let(:account_statuses_cleanup_policy) { Fabricate(:account_statuses_cleanup_policy, account: account) }
let(:status) { Fabricate(:status, id: 10, account: account) }
subject { account_statuses_cleanup_policy.invalidate_last_inspected(status, action) }
before do
account_statuses_cleanup_policy.record_last_inspected(42)
end
@ -231,11 +231,11 @@ RSpec.describe AccountStatusesCleanupPolicy, type: :model do
end
describe '#compute_cutoff_id' do
subject { account_statuses_cleanup_policy.compute_cutoff_id }
let!(:unrelated_status) { Fabricate(:status, created_at: 3.years.ago) }
let(:account_statuses_cleanup_policy) { Fabricate(:account_statuses_cleanup_policy, account: account) }
subject { account_statuses_cleanup_policy.compute_cutoff_id }
context 'when the account has posted multiple toots' do
let!(:very_old_status) { Fabricate(:status, created_at: 3.years.ago, account: account) }
let!(:old_status) { Fabricate(:status, created_at: 3.weeks.ago, account: account) }
@ -254,6 +254,8 @@ RSpec.describe AccountStatusesCleanupPolicy, type: :model do
end
describe '#statuses_to_delete' do
subject { account_statuses_cleanup_policy.statuses_to_delete }
let!(:unrelated_status) { Fabricate(:status, created_at: 3.years.ago) }
let!(:very_old_status) { Fabricate(:status, created_at: 3.years.ago, account: account) }
let!(:pinned_status) { Fabricate(:status, created_at: 1.year.ago, account: account) }
@ -275,8 +277,6 @@ RSpec.describe AccountStatusesCleanupPolicy, type: :model do
let(:account_statuses_cleanup_policy) { Fabricate(:account_statuses_cleanup_policy, account: account) }
subject { account_statuses_cleanup_policy.statuses_to_delete }
before do
4.times { faved4.increment_count!(:favourites_count) }
5.times { faved5.increment_count!(:favourites_count) }
@ -285,11 +285,11 @@ RSpec.describe AccountStatusesCleanupPolicy, type: :model do
end
context 'when passed a max_id' do
subject { account_statuses_cleanup_policy.statuses_to_delete(50, old_status.id).pluck(:id) }
let!(:old_status) { Fabricate(:status, created_at: 1.year.ago, account: account) }
let!(:slightly_less_old_status) { Fabricate(:status, created_at: 6.months.ago, account: account) }
subject { account_statuses_cleanup_policy.statuses_to_delete(50, old_status.id).pluck(:id) }
it 'returns statuses including max_id' do
expect(subject).to include(old_status.id)
end
@ -304,11 +304,11 @@ RSpec.describe AccountStatusesCleanupPolicy, type: :model do
end
context 'when passed a min_id' do
subject { account_statuses_cleanup_policy.statuses_to_delete(50, recent_status.id, old_status.id).pluck(:id) }
let!(:old_status) { Fabricate(:status, created_at: 1.year.ago, account: account) }
let!(:slightly_less_old_status) { Fabricate(:status, created_at: 6.months.ago, account: account) }
subject { account_statuses_cleanup_policy.statuses_to_delete(50, recent_status.id, old_status.id).pluck(:id) }
it 'returns statuses including min_id' do
expect(subject).to include(old_status.id)
end

View File

@ -3,12 +3,12 @@
require 'rails_helper'
RSpec.describe AccountStatusesFilter do
subject { described_class.new(account, current_account, params) }
let(:account) { Fabricate(:account) }
let(:current_account) { nil }
let(:params) { {} }
subject { described_class.new(account, current_account, params) }
def status!(visibility)
Fabricate(:status, account: account, visibility: visibility)
end

View File

@ -225,10 +225,10 @@ describe AccountInteractions do
end
describe '#mute_conversation!' do
let(:conversation) { Fabricate(:conversation) }
subject { account.mute_conversation!(conversation) }
let(:conversation) { Fabricate(:conversation) }
it 'creates and returns ConversationMute' do
expect do
expect(subject).to be_a ConversationMute
@ -237,10 +237,10 @@ describe AccountInteractions do
end
describe '#block_domain!' do
let(:domain) { 'example.com' }
subject { account.block_domain!(domain) }
let(:domain) { 'example.com' }
it 'creates and returns AccountDomainBlock' do
expect do
expect(subject).to be_a AccountDomainBlock
@ -303,10 +303,10 @@ describe AccountInteractions do
end
describe '#unmute_conversation!' do
let(:conversation) { Fabricate(:conversation) }
subject { account.unmute_conversation!(conversation) }
let(:conversation) { Fabricate(:conversation) }
context 'muting the conversation' do
it 'returns destroyed ConversationMute' do
account.conversation_mutes.create(conversation: conversation)
@ -323,10 +323,10 @@ describe AccountInteractions do
end
describe '#unblock_domain!' do
let(:domain) { 'example.com' }
subject { account.unblock_domain!(domain) }
let(:domain) { 'example.com' }
context 'blocking the domain' do
it 'returns destroyed AccountDomainBlock' do
account_domain_block = Fabricate(:account_domain_block, domain: domain)
@ -395,10 +395,10 @@ describe AccountInteractions do
end
describe '#domain_blocking?' do
let(:domain) { 'example.com' }
subject { account.domain_blocking?(domain) }
let(:domain) { 'example.com' }
context 'blocking the domain' do
it 'returns true' do
account_domain_block = Fabricate(:account_domain_block, domain: domain)
@ -433,10 +433,10 @@ describe AccountInteractions do
end
describe '#muting_conversation?' do
let(:conversation) { Fabricate(:conversation) }
subject { account.muting_conversation?(conversation) }
let(:conversation) { Fabricate(:conversation) }
context 'muting the conversation' do
it 'returns true' do
account.conversation_mutes.create(conversation: conversation)
@ -452,13 +452,13 @@ describe AccountInteractions do
end
describe '#muting_notifications?' do
subject { account.muting_notifications?(target_account) }
before do
mute = Fabricate(:mute, target_account: target_account, account: account, hide_notifications: hide)
account.mute_relationships << mute
end
subject { account.muting_notifications?(target_account) }
context 'muting notifications of target_account' do
let(:hide) { true }
@ -494,10 +494,10 @@ describe AccountInteractions do
end
describe '#favourited?' do
let(:status) { Fabricate(:status, account: account, favourites: favourites) }
subject { account.favourited?(status) }
let(:status) { Fabricate(:status, account: account, favourites: favourites) }
context 'favorited' do
let(:favourites) { [Fabricate(:favourite, account: account)] }
@ -516,10 +516,10 @@ describe AccountInteractions do
end
describe '#reblogged?' do
let(:status) { Fabricate(:status, account: account, reblogs: reblogs) }
subject { account.reblogged?(status) }
let(:status) { Fabricate(:status, account: account, reblogs: reblogs) }
context 'reblogged' do
let(:reblogs) { [Fabricate(:status, account: account)] }
@ -538,10 +538,10 @@ describe AccountInteractions do
end
describe '#pinned?' do
let(:status) { Fabricate(:status, account: account) }
subject { account.pinned?(status) }
let(:status) { Fabricate(:status, account: account) }
context 'pinned' do
it 'returns true' do
Fabricate(:status_pin, account: account, status: status)

View File

@ -4,12 +4,12 @@ require 'rails_helper'
RSpec.describe CustomEmojiFilter do
describe '#results' do
subject { described_class.new(params).results }
let!(:custom_emoji_0) { Fabricate(:custom_emoji, domain: 'a') }
let!(:custom_emoji_1) { Fabricate(:custom_emoji, domain: 'b') }
let!(:custom_emoji_2) { Fabricate(:custom_emoji, domain: nil, shortcode: 'hoge') }
subject { described_class.new(params).results }
context 'params have values' do
context 'local' do
let(:params) { { local: true } }

View File

@ -2,10 +2,10 @@ require 'rails_helper'
RSpec.describe CustomEmoji, type: :model do
describe '#search' do
let(:custom_emoji) { Fabricate(:custom_emoji, shortcode: shortcode) }
subject { described_class.search(search_term) }
let(:custom_emoji) { Fabricate(:custom_emoji, shortcode: shortcode) }
context 'shortcode is exact' do
let(:shortcode) { 'blobpats' }
let(:search_term) { 'blobpats' }
@ -26,10 +26,10 @@ RSpec.describe CustomEmoji, type: :model do
end
describe '#local?' do
let(:custom_emoji) { Fabricate(:custom_emoji, domain: domain) }
subject { custom_emoji.local? }
let(:custom_emoji) { Fabricate(:custom_emoji, domain: domain) }
context 'domain is nil' do
let(:domain) { nil }
@ -55,10 +55,10 @@ RSpec.describe CustomEmoji, type: :model do
end
describe '.from_text' do
let!(:emojo) { Fabricate(:custom_emoji) }
subject { described_class.from_text(text, nil) }
let!(:emojo) { Fabricate(:custom_emoji) }
context 'with plain text' do
let(:text) { 'Hello :coolcat:' }

View File

@ -1,10 +1,10 @@
require 'rails_helper'
RSpec.describe HomeFeed, type: :model do
let(:account) { Fabricate(:account) }
subject { described_class.new(account) }
let(:account) { Fabricate(:account) }
describe '#get' do
before do
Fabricate(:status, account: account, id: 1)

View File

@ -2,10 +2,10 @@ require 'rails_helper'
RSpec.describe MediaAttachment, type: :model do
describe 'local?' do
let(:media_attachment) { Fabricate(:media_attachment, remote_url: remote_url) }
subject { media_attachment.local? }
let(:media_attachment) { Fabricate(:media_attachment, remote_url: remote_url) }
context 'remote_url is blank' do
let(:remote_url) { '' }
@ -24,10 +24,10 @@ RSpec.describe MediaAttachment, type: :model do
end
describe 'needs_redownload?' do
let(:media_attachment) { Fabricate(:media_attachment, remote_url: remote_url, file: file) }
subject { media_attachment.needs_redownload? }
let(:media_attachment) { Fabricate(:media_attachment, remote_url: remote_url, file: file) }
context 'file is blank' do
let(:file) { nil }

View File

@ -40,6 +40,8 @@ RSpec.describe PublicFeed, type: :model do
end
context 'without local_only option' do
subject { described_class.new(viewer).get(20).map(&:id) }
let(:viewer) { nil }
let!(:local_account) { Fabricate(:account, domain: nil) }
@ -47,8 +49,6 @@ RSpec.describe PublicFeed, type: :model do
let!(:local_status) { Fabricate(:status, account: local_account) }
let!(:remote_status) { Fabricate(:status, account: remote_account) }
subject { described_class.new(viewer).get(20).map(&:id) }
context 'without a viewer' do
let(:viewer) { nil }
@ -75,13 +75,13 @@ RSpec.describe PublicFeed, type: :model do
end
context 'with a local_only option set' do
subject { described_class.new(viewer, local: true).get(20).map(&:id) }
let!(:local_account) { Fabricate(:account, domain: nil) }
let!(:remote_account) { Fabricate(:account, domain: 'test.com') }
let!(:local_status) { Fabricate(:status, account: local_account) }
let!(:remote_status) { Fabricate(:status, account: remote_account) }
subject { described_class.new(viewer, local: true).get(20).map(&:id) }
context 'without a viewer' do
let(:viewer) { nil }
@ -108,13 +108,13 @@ RSpec.describe PublicFeed, type: :model do
end
context 'with a remote_only option set' do
subject { described_class.new(viewer, remote: true).get(20).map(&:id) }
let!(:local_account) { Fabricate(:account, domain: nil) }
let!(:remote_account) { Fabricate(:account, domain: 'test.com') }
let!(:local_status) { Fabricate(:status, account: local_account) }
let!(:remote_status) { Fabricate(:status, account: remote_account) }
subject { described_class.new(viewer, remote: true).get(20).map(&:id) }
context 'without a viewer' do
let(:viewer) { nil }
@ -135,12 +135,12 @@ RSpec.describe PublicFeed, type: :model do
end
describe 'with an account passed in' do
subject { described_class.new(@account).get(20).map(&:id) }
before do
@account = Fabricate(:account)
end
subject { described_class.new(@account).get(20).map(&:id) }
it 'excludes statuses from accounts blocked by the account' do
blocked = Fabricate(:account)
@account.block!(blocked)

View File

@ -51,6 +51,8 @@ RSpec.describe RemoteFollow do
end
describe '#subscribe_address_for' do
subject { remote_follow.subscribe_address_for(account) }
before do
remote_follow.valid?
end
@ -58,8 +60,6 @@ RSpec.describe RemoteFollow do
let(:attrs) { { acct: 'gargron@quitter.no' } }
let(:account) { Fabricate(:account, username: 'alice') }
subject { remote_follow.subscribe_address_for(account) }
it 'returns subscribe address' do
expect(subject).to eq 'https://quitter.no/main/ostatussub?profile=https%3A%2F%2Fcb6e6126.ngrok.io%2Fusers%2Falice'
end

View File

@ -163,12 +163,12 @@ RSpec.describe Setting, type: :model do
end
describe '.default_settings' do
subject { described_class.default_settings }
before do
allow(RailsSettings::Default).to receive(:enabled?).and_return(enabled)
end
subject { described_class.default_settings }
context 'RailsSettings::Default.enabled? is false' do
let(:enabled) { false }

View File

@ -1,12 +1,12 @@
require 'rails_helper'
RSpec.describe Status, type: :model do
subject { Fabricate(:status, account: alice) }
let(:alice) { Fabricate(:account, username: 'alice') }
let(:bob) { Fabricate(:account, username: 'bob') }
let(:other) { Fabricate(:status, account: bob, text: 'Skulls for the skull god! The enemy\'s gates are sideways!') }
subject { Fabricate(:status, account: alice) }
describe '#local?' do
it 'returns true when no remote URI is set' do
expect(subject.local?).to be true
@ -204,11 +204,11 @@ RSpec.describe Status, type: :model do
end
describe '.mutes_map' do
subject { Status.mutes_map([status.conversation.id], account) }
let(:status) { Fabricate(:status) }
let(:account) { Fabricate(:account) }
subject { Status.mutes_map([status.conversation.id], account) }
it 'returns a hash' do
expect(subject).to be_a Hash
end
@ -220,11 +220,11 @@ RSpec.describe Status, type: :model do
end
describe '.favourites_map' do
subject { Status.favourites_map([status], account) }
let(:status) { Fabricate(:status) }
let(:account) { Fabricate(:account) }
subject { Status.favourites_map([status], account) }
it 'returns a hash' do
expect(subject).to be_a Hash
end
@ -236,11 +236,11 @@ RSpec.describe Status, type: :model do
end
describe '.reblogs_map' do
subject { Status.reblogs_map([status], account) }
let(:status) { Fabricate(:status) }
let(:account) { Fabricate(:account) }
subject { Status.reblogs_map([status], account) }
it 'returns a hash' do
expect(subject).to be_a Hash
end

View File

@ -142,10 +142,10 @@ RSpec.describe User, type: :model do
end
describe '#confirm' do
let(:new_email) { 'new-email@example.com' }
subject { user.confirm }
let(:new_email) { 'new-email@example.com' }
before do
allow(TriggerWebhookWorker).to receive(:perform_async)
end

View File

@ -1,6 +1,8 @@
require 'rails_helper'
RSpec.describe Web::PushSubscription, type: :model do
subject { described_class.new(data: data) }
let(:account) { Fabricate(:account) }
let(:policy) { 'all' }
@ -19,8 +21,6 @@ RSpec.describe Web::PushSubscription, type: :model do
}
end
subject { described_class.new(data: data) }
describe '#pushable?' do
let(:notification_type) { :mention }
let(:notification) { Fabricate(:notification, account: account, type: notification_type) }

View File

@ -4,12 +4,12 @@ require 'rails_helper'
RSpec.describe FamiliarFollowersPresenter do
describe '#accounts' do
subject { described_class.new(requested_accounts, account.id) }
let(:account) { Fabricate(:account) }
let(:familiar_follower) { Fabricate(:account) }
let(:requested_accounts) { Fabricate.times(2, :account) }
subject { described_class.new(requested_accounts, account.id) }
before do
familiar_follower.follow!(requested_accounts.first)
account.follow!(familiar_follower)

View File

@ -3,6 +3,8 @@
require 'rails_helper'
describe ActivityPub::NoteSerializer do
subject { JSON.parse(@serialization.to_json) }
let!(:account) { Fabricate(:account) }
let!(:other) { Fabricate(:account) }
let!(:parent) { Fabricate(:status, account: account, visibility: :public) }
@ -16,8 +18,6 @@ describe ActivityPub::NoteSerializer do
@serialization = ActiveModelSerializers::SerializableResource.new(parent, serializer: ActivityPub::NoteSerializer, adapter: ActivityPub::Adapter)
end
subject { JSON.parse(@serialization.to_json) }
it 'has a Note type' do
expect(subject['type']).to eql('Note')
end

View File

@ -3,6 +3,8 @@
require 'rails_helper'
describe ActivityPub::UpdatePollSerializer do
subject { JSON.parse(@serialization.to_json) }
let(:account) { Fabricate(:account) }
let(:poll) { Fabricate(:poll, account: account) }
let!(:status) { Fabricate(:status, account: account, poll: poll) }
@ -11,8 +13,6 @@ describe ActivityPub::UpdatePollSerializer do
@serialization = ActiveModelSerializers::SerializableResource.new(status, serializer: ActivityPub::UpdatePollSerializer, adapter: ActivityPub::Adapter)
end
subject { JSON.parse(@serialization.to_json) }
it 'has a Update type' do
expect(subject['type']).to eql('Update')
end

View File

@ -3,12 +3,12 @@
require 'rails_helper'
describe REST::AccountSerializer do
subject { JSON.parse(ActiveModelSerializers::SerializableResource.new(account, serializer: REST::AccountSerializer).to_json) }
let(:role) { Fabricate(:user_role, name: 'Role', highlighted: true) }
let(:user) { Fabricate(:user, role: role) }
let(:account) { user.account }
subject { JSON.parse(ActiveModelSerializers::SerializableResource.new(account, serializer: REST::AccountSerializer).to_json) }
context 'when the account is suspended' do
before do
account.suspend!

View File

@ -1,6 +1,8 @@
require 'rails_helper'
RSpec.describe ActivityPub::FetchFeaturedCollectionService, type: :service do
subject { described_class.new }
let(:actor) { Fabricate(:account, domain: 'example.com', uri: 'https://example.com/account', featured_collection_url: 'https://example.com/account/pinned') }
let!(:known_status) { Fabricate(:status, account: actor, uri: 'https://example.com/account/pinned/1') }
@ -56,8 +58,6 @@ RSpec.describe ActivityPub::FetchFeaturedCollectionService, type: :service do
}.with_indifferent_access
end
subject { described_class.new }
shared_examples 'sets pinned posts' do
before do
stub_request(:get, 'https://example.com/account/pinned/1').to_return(status: 200, body: Oj.dump(status_json_1))

View File

@ -1,6 +1,8 @@
require 'rails_helper'
RSpec.describe ActivityPub::FetchFeaturedTagsCollectionService, type: :service do
subject { described_class.new }
let(:collection_url) { 'https://example.com/account/tags' }
let(:actor) { Fabricate(:account, domain: 'example.com', uri: 'https://example.com/account') }
@ -21,8 +23,6 @@ RSpec.describe ActivityPub::FetchFeaturedTagsCollectionService, type: :service d
}.with_indifferent_access
end
subject { described_class.new }
shared_examples 'sets featured tags' do
before do
subject.call(actor, collection_url)

View File

@ -3,6 +3,8 @@ require 'rails_helper'
RSpec.describe ActivityPub::FetchRemoteStatusService, type: :service do
include ActionView::Helpers::TextHelper
subject { described_class.new }
let!(:sender) { Fabricate(:account, domain: 'foo.bar', uri: 'https://foo.bar') }
let!(:recipient) { Fabricate(:account) }
@ -18,8 +20,6 @@ RSpec.describe ActivityPub::FetchRemoteStatusService, type: :service do
}
end
subject { described_class.new }
before do
stub_request(:get, 'https://foo.bar/watch?v=12345').to_return(status: 404, body: '')
stub_request(:get, object[:id]).to_return(body: Oj.dump(object))

View File

@ -1,6 +1,8 @@
require 'rails_helper'
RSpec.describe ActivityPub::FetchRepliesService, type: :service do
subject { described_class.new }
let(:actor) { Fabricate(:account, domain: 'example.com', uri: 'http://example.com/account') }
let(:status) { Fabricate(:status, account: actor) }
let(:collection_uri) { 'http://example.com/replies/1' }
@ -28,8 +30,6 @@ RSpec.describe ActivityPub::FetchRepliesService, type: :service do
}.with_indifferent_access
end
subject { described_class.new }
describe '#call' do
context 'when the payload is a Collection with inlined replies' do
context 'when passing the collection itself' do

View File

@ -31,6 +31,8 @@ RSpec.describe ActivityPub::ProcessAccountService, type: :service do
end
context 'when account is not suspended' do
subject { described_class.new.call('alice', 'example.com', payload) }
let!(:account) { Fabricate(:account, username: 'alice', domain: 'example.com') }
let(:payload) do
@ -46,8 +48,6 @@ RSpec.describe ActivityPub::ProcessAccountService, type: :service do
allow(Admin::SuspensionWorker).to receive(:perform_async)
end
subject { described_class.new.call('alice', 'example.com', payload) }
it 'suspends account remotely' do
expect(subject.suspended?).to be true
expect(subject.suspension_origin_remote?).to be true
@ -60,6 +60,8 @@ RSpec.describe ActivityPub::ProcessAccountService, type: :service do
end
context 'when account is suspended' do
subject { described_class.new.call('alice', 'example.com', payload) }
let!(:account) { Fabricate(:account, username: 'alice', domain: 'example.com', display_name: '') }
let(:payload) do
@ -78,8 +80,6 @@ RSpec.describe ActivityPub::ProcessAccountService, type: :service do
account.suspend!(origin: suspension_origin)
end
subject { described_class.new.call('alice', 'example.com', payload) }
context 'locally' do
let(:suspension_origin) { :local }

View File

@ -1,6 +1,8 @@
require 'rails_helper'
RSpec.describe ActivityPub::ProcessCollectionService, type: :service do
subject { described_class.new }
let(:actor) { Fabricate(:account, domain: 'example.com', uri: 'http://example.com/account') }
let(:payload) do
@ -19,8 +21,6 @@ RSpec.describe ActivityPub::ProcessCollectionService, type: :service do
let(:json) { Oj.dump(payload) }
subject { described_class.new }
describe '#call' do
context 'when actor is suspended' do
before do

View File

@ -5,6 +5,8 @@ def poll_option_json(name, votes)
end
RSpec.describe ActivityPub::ProcessStatusUpdateService, type: :service do
subject { described_class.new }
let!(:status) { Fabricate(:status, text: 'Hello world', account: Fabricate(:account, domain: 'example.com')) }
let(:payload) do
{
@ -35,8 +37,6 @@ RSpec.describe ActivityPub::ProcessStatusUpdateService, type: :service do
media_attachments.each { |m| status.media_attachments << m }
end
subject { described_class.new }
describe '#call' do
it 'updates text' do
subject.call(status, json)

View File

@ -1,6 +1,8 @@
require 'rails_helper'
RSpec.describe ActivityPub::SynchronizeFollowersService, type: :service do
subject { described_class.new }
let(:actor) { Fabricate(:account, domain: 'example.com', uri: 'http://example.com/account', inbox_url: 'http://example.com/inbox') }
let(:alice) { Fabricate(:account, username: 'alice') }
let(:bob) { Fabricate(:account, username: 'bob') }
@ -25,8 +27,6 @@ RSpec.describe ActivityPub::SynchronizeFollowersService, type: :service do
}.with_indifferent_access
end
subject { described_class.new }
shared_examples 'synchronizes followers' do
before do
alice.follow!(actor)

View File

@ -1,11 +1,11 @@
require 'rails_helper'
RSpec.describe AfterBlockDomainFromAccountService, type: :service do
subject { AfterBlockDomainFromAccountService.new }
let!(:wolf) { Fabricate(:account, username: 'wolf', domain: 'evil.org', inbox_url: 'https://evil.org/inbox', protocol: :activitypub) }
let!(:alice) { Fabricate(:account, username: 'alice') }
subject { AfterBlockDomainFromAccountService.new }
before do
stub_jsonld_contexts!
allow(ActivityPub::DeliveryWorker).to receive(:perform_async)

View File

@ -1,12 +1,12 @@
require 'rails_helper'
RSpec.describe AppSignUpService, type: :service do
subject { described_class.new }
let(:app) { Fabricate(:application, scopes: 'read write') }
let(:good_params) { { username: 'alice', password: '12345678', email: 'good@email.com', agreement: true } }
let(:remote_ip) { IPAddr.new('198.0.2.1') }
subject { described_class.new }
describe '#call' do
it 'returns nil when registrations are closed' do
tmp = Setting.registrations_mode

View File

@ -1,10 +1,10 @@
require 'rails_helper'
RSpec.describe AuthorizeFollowService, type: :service do
let(:sender) { Fabricate(:account, username: 'alice') }
subject { AuthorizeFollowService.new }
let(:sender) { Fabricate(:account, username: 'alice') }
describe 'local' do
let(:bob) { Fabricate(:account, username: 'bob') }

View File

@ -1,14 +1,14 @@
require 'rails_helper'
RSpec.describe BlockDomainService, type: :service do
subject { BlockDomainService.new }
let!(:bad_account) { Fabricate(:account, username: 'badguy666', domain: 'evil.org') }
let!(:bad_status1) { Fabricate(:status, account: bad_account, text: 'You suck') }
let!(:bad_status2) { Fabricate(:status, account: bad_account, text: 'Hahaha') }
let!(:bad_attachment) { Fabricate(:media_attachment, account: bad_account, status: bad_status2, file: attachment_fixture('attachment.jpg')) }
let!(:already_banned_account) { Fabricate(:account, username: 'badguy', domain: 'evil.org', suspended: true, silenced: true) }
subject { BlockDomainService.new }
describe 'for a suspension' do
before do
subject.call(DomainBlock.create!(domain: 'evil.org', severity: :suspend))

View File

@ -1,10 +1,10 @@
require 'rails_helper'
RSpec.describe BlockService, type: :service do
let(:sender) { Fabricate(:account, username: 'alice') }
subject { BlockService.new }
let(:sender) { Fabricate(:account, username: 'alice') }
describe 'local' do
let(:bob) { Fabricate(:account, username: 'bob') }

View File

@ -1,13 +1,13 @@
require 'rails_helper'
RSpec.describe ClearDomainMediaService, type: :service do
subject { ClearDomainMediaService.new }
let!(:bad_account) { Fabricate(:account, username: 'badguy666', domain: 'evil.org') }
let!(:bad_status1) { Fabricate(:status, account: bad_account, text: 'You suck') }
let!(:bad_status2) { Fabricate(:status, account: bad_account, text: 'Hahaha') }
let!(:bad_attachment) { Fabricate(:media_attachment, account: bad_account, status: bad_status2, file: attachment_fixture('attachment.jpg')) }
subject { ClearDomainMediaService.new }
describe 'for a silence with reject media' do
before do
subject.call(DomainBlock.create!(domain: 'evil.org', severity: :silence, reject_media: true))

View File

@ -2,6 +2,8 @@ require 'rails_helper'
RSpec.describe DeleteAccountService, type: :service do
shared_examples 'common behavior' do
subject { described_class.new.call(account) }
let!(:status) { Fabricate(:status, account: account) }
let!(:mention) { Fabricate(:mention, account: local_follower) }
let!(:status_with_mention) { Fabricate(:status, account: account, mentions: [mention]) }
@ -23,8 +25,6 @@ RSpec.describe DeleteAccountService, type: :service do
let!(:account_note) { Fabricate(:account_note, account: account) }
subject { described_class.new.call(account) }
it 'deletes associated owned records' do
expect { subject }.to change {
[

View File

@ -1,6 +1,8 @@
require 'rails_helper'
RSpec.describe FanOutOnWriteService, type: :service do
subject { described_class.new }
let(:last_active_at) { Time.now.utc }
let(:status) { Fabricate(:status, account: alice, visibility: visibility, text: 'Hello @bob #hoge') }
@ -8,8 +10,6 @@ RSpec.describe FanOutOnWriteService, type: :service do
let!(:bob) { Fabricate(:user, current_sign_in_at: last_active_at, account_attributes: { username: 'bob' }).account }
let!(:tom) { Fabricate(:user, current_sign_in_at: last_active_at).account }
subject { described_class.new }
before do
bob.follow!(alice)
tom.follow!(alice)

View File

@ -1,10 +1,10 @@
require 'rails_helper'
RSpec.describe FavouriteService, type: :service do
let(:sender) { Fabricate(:account, username: 'alice') }
subject { FavouriteService.new }
let(:sender) { Fabricate(:account, username: 'alice') }
describe 'local' do
let(:bob) { Fabricate(:account) }
let(:status) { Fabricate(:status, account: bob) }

View File

@ -2,10 +2,10 @@ require 'rails_helper'
RSpec.describe FetchResourceService, type: :service do
describe '#call' do
let(:url) { 'http://example.com' }
subject { described_class.new.call(url) }
let(:url) { 'http://example.com' }
context 'with blank url' do
let(:url) { '' }

View File

@ -1,10 +1,10 @@
require 'rails_helper'
RSpec.describe FollowService, type: :service do
let(:sender) { Fabricate(:account, username: 'alice') }
subject { FollowService.new }
let(:sender) { Fabricate(:account, username: 'alice') }
context 'local account' do
describe 'locked account' do
let(:bob) { Fabricate(:account, locked: true, username: 'bob') }

View File

@ -1,10 +1,10 @@
require 'rails_helper'
RSpec.describe ProcessMentionsService, type: :service do
let(:account) { Fabricate(:account, username: 'alice') }
subject { ProcessMentionsService.new }
let(:account) { Fabricate(:account, username: 'alice') }
context 'when mentions contain blocked accounts' do
let(:non_blocked_account) { Fabricate(:account) }
let(:individually_blocked_account) { Fabricate(:account) }

View File

@ -1,13 +1,13 @@
require 'rails_helper'
RSpec.describe PurgeDomainService, type: :service do
subject { PurgeDomainService.new }
let!(:old_account) { Fabricate(:account, domain: 'obsolete.org') }
let!(:old_status1) { Fabricate(:status, account: old_account) }
let!(:old_status2) { Fabricate(:status, account: old_account) }
let!(:old_attachment) { Fabricate(:media_attachment, account: old_account, status: old_status2, file: attachment_fixture('attachment.jpg')) }
subject { PurgeDomainService.new }
describe 'for a suspension' do
before do
subject.call('obsolete.org')

View File

@ -4,12 +4,12 @@ RSpec.describe ReblogService, type: :service do
let(:alice) { Fabricate(:account, username: 'alice') }
context 'creates a reblog with appropriate visibility' do
subject { ReblogService.new }
let(:visibility) { :public }
let(:reblog_visibility) { :public }
let(:status) { Fabricate(:status, account: alice, visibility: visibility) }
subject { ReblogService.new }
before do
subject.call(alice, status, visibility: reblog_visibility)
end
@ -45,11 +45,11 @@ RSpec.describe ReblogService, type: :service do
end
context 'ActivityPub' do
subject { ReblogService.new }
let(:bob) { Fabricate(:account, username: 'bob', protocol: :activitypub, domain: 'example.com', inbox_url: 'http://example.com/inbox') }
let(:status) { Fabricate(:status, account: bob) }
subject { ReblogService.new }
before do
stub_request(:post, bob.inbox_url)
allow(ActivityPub::DistributionWorker).to receive(:perform_async)

View File

@ -1,10 +1,10 @@
require 'rails_helper'
RSpec.describe RejectFollowService, type: :service do
let(:sender) { Fabricate(:account, username: 'alice') }
subject { RejectFollowService.new }
let(:sender) { Fabricate(:account, username: 'alice') }
describe 'local' do
let(:bob) { Fabricate(:account) }

View File

@ -1,10 +1,10 @@
require 'rails_helper'
RSpec.describe RemoveFromFollowersService, type: :service do
let(:bob) { Fabricate(:account, username: 'bob') }
subject { RemoveFromFollowersService.new }
let(:bob) { Fabricate(:account, username: 'bob') }
describe 'local' do
let(:sender) { Fabricate(:account, username: 'alice') }

View File

@ -29,13 +29,13 @@ RSpec.describe ReportService, type: :service do
end
context 'when the reported status is a DM' do
let(:target_account) { Fabricate(:account) }
let(:status) { Fabricate(:status, account: target_account, visibility: :direct) }
subject do
-> { described_class.new.call(source_account, target_account, status_ids: [status.id]) }
end
let(:target_account) { Fabricate(:account) }
let(:status) { Fabricate(:status, account: target_account, visibility: :direct) }
context 'when it is addressed to the reporter' do
before do
status.mentions.create(account: source_account)
@ -85,13 +85,13 @@ RSpec.describe ReportService, type: :service do
end
context 'when other reports already exist for the same target' do
let!(:target_account) { Fabricate(:account) }
let!(:other_report) { Fabricate(:report, target_account: target_account) }
subject do
-> { described_class.new.call(source_account, target_account) }
end
let!(:target_account) { Fabricate(:account) }
let!(:other_report) { Fabricate(:report, target_account: target_account) }
before do
ActionMailer::Base.deliveries.clear
source_account.user.settings.notification_emails['report'] = true

View File

@ -2,11 +2,11 @@ require 'rails_helper'
RSpec.describe SuspendAccountService, type: :service do
shared_examples 'common behavior' do
subject { described_class.new.call(account) }
let!(:local_follower) { Fabricate(:user, current_sign_in_at: 1.hour.ago).account }
let!(:list) { Fabricate(:list, account: local_follower) }
subject { described_class.new.call(account) }
before do
allow(FeedManager.instance).to receive(:unmerge_from_home).and_return(nil)
allow(FeedManager.instance).to receive(:unmerge_from_list).and_return(nil)

View File

@ -1,6 +1,8 @@
require 'rails_helper'
RSpec.describe UnallowDomainService, type: :service do
subject { UnallowDomainService.new }
let!(:bad_account) { Fabricate(:account, username: 'badguy666', domain: 'evil.org') }
let!(:bad_status1) { Fabricate(:status, account: bad_account, text: 'You suck') }
let!(:bad_status2) { Fabricate(:status, account: bad_account, text: 'Hahaha') }
@ -8,8 +10,6 @@ RSpec.describe UnallowDomainService, type: :service do
let!(:already_banned_account) { Fabricate(:account, username: 'badguy', domain: 'evil.org', suspended: true, silenced: true) }
let!(:domain_allow) { Fabricate(:domain_allow, domain: 'evil.org') }
subject { UnallowDomainService.new }
context 'in limited federation mode' do
before do
allow(subject).to receive(:whitelist_mode?).and_return(true)

View File

@ -1,10 +1,10 @@
require 'rails_helper'
RSpec.describe UnblockService, type: :service do
let(:sender) { Fabricate(:account, username: 'alice') }
subject { UnblockService.new }
let(:sender) { Fabricate(:account, username: 'alice') }
describe 'local' do
let(:bob) { Fabricate(:account) }

View File

@ -1,10 +1,10 @@
require 'rails_helper'
RSpec.describe UnfollowService, type: :service do
let(:sender) { Fabricate(:account, username: 'alice') }
subject { UnfollowService.new }
let(:sender) { Fabricate(:account, username: 'alice') }
describe 'local' do
let(:bob) { Fabricate(:account, username: 'bob') }

View File

@ -2,11 +2,11 @@ require 'rails_helper'
RSpec.describe UnsuspendAccountService, type: :service do
shared_examples 'common behavior' do
subject { described_class.new.call(account) }
let!(:local_follower) { Fabricate(:user, current_sign_in_at: 1.hour.ago).account }
let!(:list) { Fabricate(:list, account: local_follower) }
subject { described_class.new.call(account) }
before do
allow(FeedManager.instance).to receive(:merge_into_home).and_return(nil)
allow(FeedManager.instance).to receive(:merge_into_list).and_return(nil)

View File

@ -4,6 +4,8 @@ require 'rails_helper'
RSpec.describe BlacklistedEmailValidator, type: :validator do
describe '#validate' do
subject { described_class.new.validate(user); errors }
let(:user) { double(email: 'info@mail.com', sign_up_ip: '1.2.3.4', errors: errors) }
let(:errors) { double(add: nil) }
@ -12,8 +14,6 @@ RSpec.describe BlacklistedEmailValidator, type: :validator do
allow_any_instance_of(described_class).to receive(:blocked_email_provider?) { blocked_email }
end
subject { described_class.new.validate(user); errors }
context 'when e-mail provider is blocked' do
let(:blocked_email) { true }

View File

@ -3,6 +3,8 @@
require 'rails_helper'
describe MoveWorker do
subject { described_class.new }
let(:local_follower) { Fabricate(:account) }
let(:blocking_account) { Fabricate(:account) }
let(:muting_account) { Fabricate(:account) }
@ -14,8 +16,6 @@ describe MoveWorker do
let(:block_service) { double }
subject { described_class.new }
before do
local_follower.follow!(source_account)
blocking_account.block!(source_account)

View File

@ -3,13 +3,13 @@
require 'rails_helper'
describe UnfollowFollowWorker do
subject { described_class.new }
let(:local_follower) { Fabricate(:account) }
let(:source_account) { Fabricate(:account) }
let(:target_account) { Fabricate(:account) }
let(:show_reblogs) { true }
subject { described_class.new }
before do
local_follower.follow!(source_account, reblogs: show_reblogs)
end