Update rubocop-rspec to version 3.6.0 (#34497)

This commit is contained in:
Matt Jankowski 2025-04-24 10:56:13 -04:00 committed by GitHub
parent 22ec828951
commit 6463415e06
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
41 changed files with 223 additions and 228 deletions

View File

@ -1,6 +1,6 @@
# This configuration was generated by # This configuration was generated by
# `rubocop --auto-gen-config --auto-gen-only-exclude --no-offense-counts --no-auto-gen-timestamp` # `rubocop --auto-gen-config --auto-gen-only-exclude --no-offense-counts --no-auto-gen-timestamp`
# using RuboCop version 1.75.2. # using RuboCop version 1.75.3.
# The point is for the user to remove these configuration records # The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base. # one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new # Note that changes in the inspected code, or installation of new

View File

@ -743,7 +743,7 @@ GEM
rspec-mocks (~> 3.0) rspec-mocks (~> 3.0)
sidekiq (>= 5, < 9) sidekiq (>= 5, < 9)
rspec-support (3.13.2) rspec-support (3.13.2)
rubocop (1.75.2) rubocop (1.75.3)
json (~> 2.3) json (~> 2.3)
language_server-protocol (~> 3.17.0.2) language_server-protocol (~> 3.17.0.2)
lint_roller (~> 1.1.0) lint_roller (~> 1.1.0)
@ -773,7 +773,7 @@ GEM
rack (>= 1.1) rack (>= 1.1)
rubocop (>= 1.75.0, < 2.0) rubocop (>= 1.75.0, < 2.0)
rubocop-ast (>= 1.38.0, < 2.0) rubocop-ast (>= 1.38.0, < 2.0)
rubocop-rspec (3.5.0) rubocop-rspec (3.6.0)
lint_roller (~> 1.1) lint_roller (~> 1.1)
rubocop (~> 1.72, >= 1.72.1) rubocop (~> 1.72, >= 1.72.1)
rubocop-rspec_rails (2.31.0) rubocop-rspec_rails (2.31.0)

View File

@ -23,7 +23,7 @@ RSpec.describe ApplicationController do
end end
end end
shared_examples 'respond_with_error' do |code| shared_examples 'error response' do |code|
it "returns http #{code} for http and renders template" do it "returns http #{code} for http and renders template" do
subject subject
@ -51,7 +51,7 @@ RSpec.describe ApplicationController do
post 'success' post 'success'
end end
include_examples 'respond_with_error', 422 it_behaves_like 'error response', 422
end end
describe 'helper_method :current_account' do describe 'helper_method :current_account' do
@ -123,7 +123,7 @@ RSpec.describe ApplicationController do
get 'routing_error' get 'routing_error'
end end
include_examples 'respond_with_error', 404 it_behaves_like 'error response', 404
end end
context 'with ActiveRecord::RecordNotFound' do context 'with ActiveRecord::RecordNotFound' do
@ -132,7 +132,7 @@ RSpec.describe ApplicationController do
get 'record_not_found' get 'record_not_found'
end end
include_examples 'respond_with_error', 404 it_behaves_like 'error response', 404
end end
context 'with ActionController::InvalidAuthenticityToken' do context 'with ActionController::InvalidAuthenticityToken' do
@ -141,7 +141,7 @@ RSpec.describe ApplicationController do
get 'invalid_authenticity_token' get 'invalid_authenticity_token'
end end
include_examples 'respond_with_error', 422 it_behaves_like 'error response', 422
end end
describe 'before_action :check_suspension' do describe 'before_action :check_suspension' do
@ -186,7 +186,7 @@ RSpec.describe ApplicationController do
get 'route_forbidden' get 'route_forbidden'
end end
include_examples 'respond_with_error', 403 it_behaves_like 'error response', 403
end end
describe 'not_found' do describe 'not_found' do
@ -201,7 +201,7 @@ RSpec.describe ApplicationController do
get 'route_not_found' get 'route_not_found'
end end
include_examples 'respond_with_error', 404 it_behaves_like 'error response', 404
end end
describe 'gone' do describe 'gone' do
@ -216,7 +216,7 @@ RSpec.describe ApplicationController do
get 'route_gone' get 'route_gone'
end end
include_examples 'respond_with_error', 410 it_behaves_like 'error response', 410
end end
describe 'unprocessable_entity' do describe 'unprocessable_entity' do
@ -231,6 +231,6 @@ RSpec.describe ApplicationController do
get 'route_unprocessable_entity' get 'route_unprocessable_entity'
end end
include_examples 'respond_with_error', 422 it_behaves_like 'error response', 422
end end
end end

View File

@ -5,7 +5,7 @@ require 'rails_helper'
RSpec.describe Auth::RegistrationsController do RSpec.describe Auth::RegistrationsController do
render_views render_views
shared_examples 'checks for enabled registrations' do |path| shared_examples 'registration mode based responses' do |path|
context 'when in single user mode and open for registration' do context 'when in single user mode and open for registration' do
before do before do
Setting.registrations_mode = 'open' Setting.registrations_mode = 'open'
@ -156,7 +156,7 @@ RSpec.describe Auth::RegistrationsController do
end end
end end
include_examples 'checks for enabled registrations', :new it_behaves_like 'registration mode based responses', :new
end end
describe 'POST #create' do describe 'POST #create' do
@ -378,7 +378,7 @@ RSpec.describe Auth::RegistrationsController do
end end
end end
include_examples 'checks for enabled registrations', :create it_behaves_like 'registration mode based responses', :create
end end
describe 'DELETE #destroy' do describe 'DELETE #destroy' do

View File

@ -59,10 +59,10 @@ RSpec.describe Localized do
sign_in(user) sign_in(user)
end end
include_examples 'default locale' it_behaves_like 'default locale'
end end
context 'with a user who has not signed in' do context 'with a user who has not signed in' do
include_examples 'default locale' it_behaves_like 'default locale'
end end
end end

View File

@ -35,7 +35,7 @@ RSpec.describe RelationshipsController do
describe 'PATCH #update' do describe 'PATCH #update' do
let(:alice) { Fabricate(:account, username: 'alice', domain: 'example.com') } let(:alice) { Fabricate(:account, username: 'alice', domain: 'example.com') }
shared_examples 'redirects back to followers page' do shared_examples 'general behavior for followed user' do
it 'redirects back to followers page' do it 'redirects back to followers page' do
alice.follow!(user.account) alice.follow!(user.account)
@ -49,7 +49,7 @@ RSpec.describe RelationshipsController do
context 'when select parameter is not provided' do context 'when select parameter is not provided' do
subject { patch :update } subject { patch :update }
include_examples 'redirects back to followers page' it_behaves_like 'general behavior for followed user'
end end
context 'when select parameter is provided' do context 'when select parameter is provided' do
@ -83,7 +83,7 @@ RSpec.describe RelationshipsController do
end end
end end
include_examples 'redirects back to followers page' it_behaves_like 'general behavior for followed user'
end end
end end
end end

View File

@ -162,7 +162,7 @@ RSpec.describe Settings::ImportsController do
] ]
end end
include_examples 'export failed rows', "Account address,Show boosts,Notify on new posts,Languages\nfoo@bar,true,false,\nuser@bar,false,true,\"fr, de\"\n" it_behaves_like 'export failed rows', "Account address,Show boosts,Notify on new posts,Languages\nfoo@bar,true,false,\nuser@bar,false,true,\"fr, de\"\n"
end end
context 'with blocks' do context 'with blocks' do
@ -175,7 +175,7 @@ RSpec.describe Settings::ImportsController do
] ]
end end
include_examples 'export failed rows', "foo@bar\nuser@bar\n" it_behaves_like 'export failed rows', "foo@bar\nuser@bar\n"
end end
context 'with mutes' do context 'with mutes' do
@ -188,7 +188,7 @@ RSpec.describe Settings::ImportsController do
] ]
end end
include_examples 'export failed rows', "Account address,Hide notifications\nfoo@bar,true\nuser@bar,false\n" it_behaves_like 'export failed rows', "Account address,Hide notifications\nfoo@bar,true\nuser@bar,false\n"
end end
context 'with domain blocks' do context 'with domain blocks' do
@ -201,7 +201,7 @@ RSpec.describe Settings::ImportsController do
] ]
end end
include_examples 'export failed rows', "bad.domain\nevil.domain\n" it_behaves_like 'export failed rows', "bad.domain\nevil.domain\n"
end end
context 'with bookmarks' do context 'with bookmarks' do
@ -214,7 +214,7 @@ RSpec.describe Settings::ImportsController do
] ]
end end
include_examples 'export failed rows', "https://foo.com/1\nhttps://foo.com/2\n" it_behaves_like 'export failed rows', "https://foo.com/1\nhttps://foo.com/2\n"
end end
context 'with lists' do context 'with lists' do
@ -227,7 +227,7 @@ RSpec.describe Settings::ImportsController do
] ]
end end
include_examples 'export failed rows', "Amigos,user@example.com\nFrenemies,user@org.org\n" it_behaves_like 'export failed rows', "Amigos,user@example.com\nFrenemies,user@org.org\n"
end end
end end

View File

@ -34,7 +34,7 @@ RSpec.describe Settings::TwoFactorAuthentication::ConfirmationsController do
get :new, session: { challenge_passed_at: Time.now.utc, new_otp_secret: 'thisisasecretforthespecofnewview' } get :new, session: { challenge_passed_at: Time.now.utc, new_otp_secret: 'thisisasecretforthespecofnewview' }
end end
include_examples 'renders expected page' it_behaves_like 'renders expected page'
end end
it 'redirects if a new otp_secret has not been set in the session' do it 'redirects if a new otp_secret has not been set in the session' do
@ -94,7 +94,7 @@ RSpec.describe Settings::TwoFactorAuthentication::ConfirmationsController do
.to include(I18n.t('otp_authentication.wrong_code')) .to include(I18n.t('otp_authentication.wrong_code'))
end end
include_examples 'renders expected page' it_behaves_like 'renders expected page'
end end
private private

View File

@ -12,7 +12,7 @@ RSpec.describe CacheBuster do
let(:purge_url) { 'https://example.com/test_purge' } let(:purge_url) { 'https://example.com/test_purge' }
describe '#bust' do describe '#bust' do
shared_examples 'makes_request' do shared_examples 'cache busting request' do
it 'makes an HTTP purging request' do it 'makes an HTTP purging request' do
method = http_method&.to_sym || :get method = http_method&.to_sym || :get
stub_request(method, purge_url).to_return(status: 200) stub_request(method, purge_url).to_return(status: 200)
@ -28,28 +28,28 @@ RSpec.describe CacheBuster do
end end
context 'when using default options' do context 'when using default options' do
include_examples 'makes_request' it_behaves_like 'cache busting request'
end end
context 'when specifying a secret header' do context 'when specifying a secret header' do
let(:secret_header) { 'X-Purge-Secret' } let(:secret_header) { 'X-Purge-Secret' }
let(:secret) { SecureRandom.hex(20) } let(:secret) { SecureRandom.hex(20) }
include_examples 'makes_request' it_behaves_like 'cache busting request'
end end
context 'when specifying a PURGE method' do context 'when specifying a PURGE method' do
let(:http_method) { 'purge' } let(:http_method) { 'purge' }
context 'when not using headers' do context 'when not using headers' do
include_examples 'makes_request' it_behaves_like 'cache busting request'
end end
context 'when specifying a secret header' do context 'when specifying a secret header' do
let(:secret_header) { 'X-Purge-Secret' } let(:secret_header) { 'X-Purge-Secret' }
let(:secret) { SecureRandom.hex(20) } let(:secret) { SecureRandom.hex(20) }
include_examples 'makes_request' it_behaves_like 'cache busting request'
end end
end end
end end

View File

@ -44,14 +44,14 @@ RSpec.describe Fasp::Request do
end end
describe '#get' do describe '#get' do
include_examples 'a provider request', :get it_behaves_like 'a provider request', :get
end end
describe '#post' do describe '#post' do
include_examples 'a provider request', :post it_behaves_like 'a provider request', :post
end end
describe '#delete' do describe '#delete' do
include_examples 'a provider request', :delete it_behaves_like 'a provider request', :delete
end end
end end

View File

@ -118,7 +118,7 @@ RSpec.describe LinkDetailsExtractor do
</html> </html>
HTML HTML
include_examples 'structured data' it_behaves_like 'structured data'
end end
context 'with the first tag is invalid JSON' do context 'with the first tag is invalid JSON' do
@ -136,7 +136,7 @@ RSpec.describe LinkDetailsExtractor do
</html> </html>
HTML HTML
include_examples 'structured data' it_behaves_like 'structured data'
end end
context 'with the first tag is null' do context 'with the first tag is null' do
@ -154,7 +154,7 @@ RSpec.describe LinkDetailsExtractor do
</html> </html>
HTML HTML
include_examples 'structured data' it_behaves_like 'structured data'
end end
context 'with preceding block of unsupported LD+JSON' do context 'with preceding block of unsupported LD+JSON' do
@ -194,7 +194,7 @@ RSpec.describe LinkDetailsExtractor do
</html> </html>
HTML HTML
include_examples 'structured data' it_behaves_like 'structured data'
end end
context 'with unsupported in same block LD+JSON' do context 'with unsupported in same block LD+JSON' do
@ -218,7 +218,7 @@ RSpec.describe LinkDetailsExtractor do
</html> </html>
HTML HTML
include_examples 'structured data' it_behaves_like 'structured data'
end end
context 'with author names as array' do context 'with author names as array' do

View File

@ -56,7 +56,7 @@ RSpec.describe Mastodon::CLI::IpBlocks do
end end
context 'with valid IP addresses' do context 'with valid IP addresses' do
include_examples 'ip address blocking' it_behaves_like 'ip address blocking'
end end
context 'when a specified IP address is already blocked' do context 'when a specified IP address is already blocked' do
@ -84,7 +84,7 @@ RSpec.describe Mastodon::CLI::IpBlocks do
.to('sign_up_requires_approval') .to('sign_up_requires_approval')
end end
include_examples 'ip address blocking' it_behaves_like 'ip address blocking'
end end
end end
@ -101,25 +101,25 @@ RSpec.describe Mastodon::CLI::IpBlocks do
context 'with --comment option' do context 'with --comment option' do
let(:options) { { severity: 'no_access', comment: 'Spam' } } let(:options) { { severity: 'no_access', comment: 'Spam' } }
include_examples 'ip address blocking' it_behaves_like 'ip address blocking'
end end
context 'with --duration option' do context 'with --duration option' do
let(:options) { { severity: 'no_access', duration: 10.days } } let(:options) { { severity: 'no_access', duration: 10.days } }
include_examples 'ip address blocking' it_behaves_like 'ip address blocking'
end end
context 'with "sign_up_requires_approval" severity' do context 'with "sign_up_requires_approval" severity' do
let(:options) { { severity: 'sign_up_requires_approval' } } let(:options) { { severity: 'sign_up_requires_approval' } }
include_examples 'ip address blocking' it_behaves_like 'ip address blocking'
end end
context 'with "sign_up_block" severity' do context 'with "sign_up_block" severity' do
let(:options) { { severity: 'sign_up_block' } } let(:options) { { severity: 'sign_up_block' } }
include_examples 'ip address blocking' it_behaves_like 'ip address blocking'
end end
context 'when a specified IP address fails to be blocked' do context 'when a specified IP address fails to be blocked' do

View File

@ -207,18 +207,18 @@ RSpec.describe Mastodon::RedisConfiguration do
end end
end end
include_examples 'setting a different driver' it_behaves_like 'setting a different driver'
include_examples 'setting a namespace' it_behaves_like 'setting a namespace'
include_examples 'sentinel support' it_behaves_like 'sentinel support'
end end
describe '#sidekiq' do describe '#sidekiq' do
subject { redis_environment.sidekiq } subject { redis_environment.sidekiq }
include_examples 'secondary configuration', 'SIDEKIQ' it_behaves_like 'secondary configuration', 'SIDEKIQ'
include_examples 'setting a different driver' it_behaves_like 'setting a different driver'
include_examples 'setting a namespace' it_behaves_like 'setting a namespace'
include_examples 'sentinel support', 'SIDEKIQ' it_behaves_like 'sentinel support', 'SIDEKIQ'
end end
describe '#cache' do describe '#cache' do
@ -256,8 +256,8 @@ RSpec.describe Mastodon::RedisConfiguration do
end end
end end
include_examples 'secondary configuration', 'CACHE' it_behaves_like 'secondary configuration', 'CACHE'
include_examples 'setting a different driver' it_behaves_like 'setting a different driver'
include_examples 'sentinel support', 'CACHE' it_behaves_like 'sentinel support', 'CACHE'
end end
end end

View File

@ -35,7 +35,7 @@ RSpec.describe NotificationMailer do
let(:notification) { Notification.create!(account: receiver.account, activity: mention) } let(:notification) { Notification.create!(account: receiver.account, activity: mention) }
let(:mail) { prepared_mailer_for(receiver.account).mention } let(:mail) { prepared_mailer_for(receiver.account).mention }
include_examples 'localized subject', 'notification_mailer.mention.subject', name: 'bob' it_behaves_like 'localized subject', 'notification_mailer.mention.subject', name: 'bob'
it 'renders the email' do it 'renders the email' do
expect(mail) expect(mail)
@ -47,8 +47,8 @@ RSpec.describe NotificationMailer do
.and have_standard_headers('mention').for(receiver) .and have_standard_headers('mention').for(receiver)
end end
include_examples 'delivery to non functional user' it_behaves_like 'delivery to non functional user'
include_examples 'delivery without status' it_behaves_like 'delivery without status'
end end
describe 'follow' do describe 'follow' do
@ -56,7 +56,7 @@ RSpec.describe NotificationMailer do
let(:notification) { Notification.create!(account: receiver.account, activity: follow) } let(:notification) { Notification.create!(account: receiver.account, activity: follow) }
let(:mail) { prepared_mailer_for(receiver.account).follow } let(:mail) { prepared_mailer_for(receiver.account).follow }
include_examples 'localized subject', 'notification_mailer.follow.subject', name: 'bob' it_behaves_like 'localized subject', 'notification_mailer.follow.subject', name: 'bob'
it 'renders the email' do it 'renders the email' do
expect(mail) expect(mail)
@ -66,7 +66,7 @@ RSpec.describe NotificationMailer do
.and have_standard_headers('follow').for(receiver) .and have_standard_headers('follow').for(receiver)
end end
include_examples 'delivery to non functional user' it_behaves_like 'delivery to non functional user'
end end
describe 'favourite' do describe 'favourite' do
@ -74,7 +74,7 @@ RSpec.describe NotificationMailer do
let(:notification) { Notification.create!(account: receiver.account, activity: favourite) } let(:notification) { Notification.create!(account: receiver.account, activity: favourite) }
let(:mail) { prepared_mailer_for(own_status.account).favourite } let(:mail) { prepared_mailer_for(own_status.account).favourite }
include_examples 'localized subject', 'notification_mailer.favourite.subject', name: 'bob' it_behaves_like 'localized subject', 'notification_mailer.favourite.subject', name: 'bob'
it 'renders the email' do it 'renders the email' do
expect(mail) expect(mail)
@ -86,8 +86,8 @@ RSpec.describe NotificationMailer do
.and have_standard_headers('favourite').for(receiver) .and have_standard_headers('favourite').for(receiver)
end end
include_examples 'delivery to non functional user' it_behaves_like 'delivery to non functional user'
include_examples 'delivery without status' it_behaves_like 'delivery without status'
end end
describe 'reblog' do describe 'reblog' do
@ -95,7 +95,7 @@ RSpec.describe NotificationMailer do
let(:notification) { Notification.create!(account: receiver.account, activity: reblog) } let(:notification) { Notification.create!(account: receiver.account, activity: reblog) }
let(:mail) { prepared_mailer_for(own_status.account).reblog } let(:mail) { prepared_mailer_for(own_status.account).reblog }
include_examples 'localized subject', 'notification_mailer.reblog.subject', name: 'bob' it_behaves_like 'localized subject', 'notification_mailer.reblog.subject', name: 'bob'
it 'renders the email' do it 'renders the email' do
expect(mail) expect(mail)
@ -107,8 +107,8 @@ RSpec.describe NotificationMailer do
.and have_standard_headers('reblog').for(receiver) .and have_standard_headers('reblog').for(receiver)
end end
include_examples 'delivery to non functional user' it_behaves_like 'delivery to non functional user'
include_examples 'delivery without status' it_behaves_like 'delivery without status'
end end
describe 'follow_request' do describe 'follow_request' do
@ -116,7 +116,7 @@ RSpec.describe NotificationMailer do
let(:notification) { Notification.create!(account: receiver.account, activity: follow_request) } let(:notification) { Notification.create!(account: receiver.account, activity: follow_request) }
let(:mail) { prepared_mailer_for(receiver.account).follow_request } let(:mail) { prepared_mailer_for(receiver.account).follow_request }
include_examples 'localized subject', 'notification_mailer.follow_request.subject', name: 'bob' it_behaves_like 'localized subject', 'notification_mailer.follow_request.subject', name: 'bob'
it 'renders the email' do it 'renders the email' do
expect(mail) expect(mail)
@ -126,7 +126,7 @@ RSpec.describe NotificationMailer do
.and have_standard_headers('follow_request').for(receiver) .and have_standard_headers('follow_request').for(receiver)
end end
include_examples 'delivery to non functional user' it_behaves_like 'delivery to non functional user'
end end
private private

View File

@ -29,10 +29,10 @@ RSpec.describe UserMailer do
.and(have_body_text(Rails.configuration.x.local_domain)) .and(have_body_text(Rails.configuration.x.local_domain))
end end
include_examples 'localized subject', it_behaves_like 'localized subject',
'devise.mailer.confirmation_instructions.subject', 'devise.mailer.confirmation_instructions.subject',
instance: Rails.configuration.x.local_domain instance: Rails.configuration.x.local_domain
include_examples 'delivery to memorialized user' it_behaves_like 'delivery to memorialized user'
end end
describe '#reconfirmation_instructions' do describe '#reconfirmation_instructions' do
@ -48,10 +48,10 @@ RSpec.describe UserMailer do
.and(have_body_text(Rails.configuration.x.local_domain)) .and(have_body_text(Rails.configuration.x.local_domain))
end end
include_examples 'localized subject', it_behaves_like 'localized subject',
'devise.mailer.confirmation_instructions.subject', 'devise.mailer.confirmation_instructions.subject',
instance: Rails.configuration.x.local_domain instance: Rails.configuration.x.local_domain
include_examples 'delivery to memorialized user' it_behaves_like 'delivery to memorialized user'
end end
describe '#reset_password_instructions' do describe '#reset_password_instructions' do
@ -66,9 +66,9 @@ RSpec.describe UserMailer do
.and(have_body_text('spec')) .and(have_body_text('spec'))
end end
include_examples 'localized subject', it_behaves_like 'localized subject',
'devise.mailer.reset_password_instructions.subject' 'devise.mailer.reset_password_instructions.subject'
include_examples 'delivery to memorialized user' it_behaves_like 'delivery to memorialized user'
end end
describe '#password_change' do describe '#password_change' do
@ -82,9 +82,9 @@ RSpec.describe UserMailer do
.and(have_body_text(I18n.t('devise.mailer.password_change.title'))) .and(have_body_text(I18n.t('devise.mailer.password_change.title')))
end end
include_examples 'localized subject', it_behaves_like 'localized subject',
'devise.mailer.password_change.subject' 'devise.mailer.password_change.subject'
include_examples 'delivery to memorialized user' it_behaves_like 'delivery to memorialized user'
end end
describe '#email_changed' do describe '#email_changed' do
@ -98,9 +98,9 @@ RSpec.describe UserMailer do
.and(have_body_text(I18n.t('devise.mailer.email_changed.title'))) .and(have_body_text(I18n.t('devise.mailer.email_changed.title')))
end end
include_examples 'localized subject', it_behaves_like 'localized subject',
'devise.mailer.email_changed.subject' 'devise.mailer.email_changed.subject'
include_examples 'delivery to memorialized user' it_behaves_like 'delivery to memorialized user'
end end
describe '#warning' do describe '#warning' do
@ -129,9 +129,9 @@ RSpec.describe UserMailer do
.and(have_body_text(I18n.t('devise.mailer.webauthn_credential.deleted.title'))) .and(have_body_text(I18n.t('devise.mailer.webauthn_credential.deleted.title')))
end end
include_examples 'localized subject', it_behaves_like 'localized subject',
'devise.mailer.webauthn_credential.deleted.subject' 'devise.mailer.webauthn_credential.deleted.subject'
include_examples 'delivery to memorialized user' it_behaves_like 'delivery to memorialized user'
end end
describe '#suspicious_sign_in' do describe '#suspicious_sign_in' do
@ -148,7 +148,7 @@ RSpec.describe UserMailer do
.and(have_body_text(I18n.t('user_mailer.suspicious_sign_in.explanation'))) .and(have_body_text(I18n.t('user_mailer.suspicious_sign_in.explanation')))
end end
include_examples 'localized subject', it_behaves_like 'localized subject',
'user_mailer.suspicious_sign_in.subject' 'user_mailer.suspicious_sign_in.subject'
end end
@ -166,7 +166,7 @@ RSpec.describe UserMailer do
.and(have_body_text(I18n.t('user_mailer.failed_2fa.explanation'))) .and(have_body_text(I18n.t('user_mailer.failed_2fa.explanation')))
end end
include_examples 'localized subject', it_behaves_like 'localized subject',
'user_mailer.failed_2fa.subject' 'user_mailer.failed_2fa.subject'
end end
@ -204,7 +204,7 @@ RSpec.describe UserMailer do
.and(have_body_text(I18n.t('devise.mailer.two_factor_enabled.explanation'))) .and(have_body_text(I18n.t('devise.mailer.two_factor_enabled.explanation')))
end end
include_examples 'delivery to memorialized user' it_behaves_like 'delivery to memorialized user'
end end
describe '#two_factor_disabled' do describe '#two_factor_disabled' do
@ -217,7 +217,7 @@ RSpec.describe UserMailer do
.and(have_body_text(I18n.t('devise.mailer.two_factor_disabled.explanation'))) .and(have_body_text(I18n.t('devise.mailer.two_factor_disabled.explanation')))
end end
include_examples 'delivery to memorialized user' it_behaves_like 'delivery to memorialized user'
end end
describe '#webauthn_enabled' do describe '#webauthn_enabled' do
@ -230,7 +230,7 @@ RSpec.describe UserMailer do
.and(have_body_text(I18n.t('devise.mailer.webauthn_enabled.explanation'))) .and(have_body_text(I18n.t('devise.mailer.webauthn_enabled.explanation')))
end end
include_examples 'delivery to memorialized user' it_behaves_like 'delivery to memorialized user'
end end
describe '#webauthn_disabled' do describe '#webauthn_disabled' do
@ -243,7 +243,7 @@ RSpec.describe UserMailer do
.and(have_body_text(I18n.t('devise.mailer.webauthn_disabled.explanation'))) .and(have_body_text(I18n.t('devise.mailer.webauthn_disabled.explanation')))
end end
include_examples 'delivery to memorialized user' it_behaves_like 'delivery to memorialized user'
end end
describe '#two_factor_recovery_codes_changed' do describe '#two_factor_recovery_codes_changed' do
@ -256,7 +256,7 @@ RSpec.describe UserMailer do
.and(have_body_text(I18n.t('devise.mailer.two_factor_recovery_codes_changed.explanation'))) .and(have_body_text(I18n.t('devise.mailer.two_factor_recovery_codes_changed.explanation')))
end end
include_examples 'delivery to memorialized user' it_behaves_like 'delivery to memorialized user'
end end
describe '#webauthn_credential_added' do describe '#webauthn_credential_added' do
@ -270,7 +270,7 @@ RSpec.describe UserMailer do
.and(have_body_text(I18n.t('devise.mailer.webauthn_credential.added.explanation'))) .and(have_body_text(I18n.t('devise.mailer.webauthn_credential.added.explanation')))
end end
include_examples 'delivery to memorialized user' it_behaves_like 'delivery to memorialized user'
end end
describe '#welcome' do describe '#welcome' do
@ -289,7 +289,7 @@ RSpec.describe UserMailer do
.and(have_body_text(I18n.t('user_mailer.welcome.explanation'))) .and(have_body_text(I18n.t('user_mailer.welcome.explanation')))
end end
include_examples 'delivery to memorialized user' it_behaves_like 'delivery to memorialized user'
end end
describe '#backup_ready' do describe '#backup_ready' do
@ -303,7 +303,7 @@ RSpec.describe UserMailer do
.and(have_body_text(I18n.t('user_mailer.backup_ready.explanation'))) .and(have_body_text(I18n.t('user_mailer.backup_ready.explanation')))
end end
include_examples 'delivery to memorialized user' it_behaves_like 'delivery to memorialized user'
end end
describe '#terms_of_service_changed' do describe '#terms_of_service_changed' do

View File

@ -3,8 +3,8 @@
require 'rails_helper' require 'rails_helper'
RSpec.describe Account do RSpec.describe Account do
include_examples 'Account::Search' it_behaves_like 'Account::Search'
include_examples 'Reviewable' it_behaves_like 'Reviewable'
context 'with an account record' do context 'with an account record' do
subject { Fabricate(:account) } subject { Fabricate(:account) }
@ -806,8 +806,8 @@ RSpec.describe Account do
end end
end end
include_examples 'AccountAvatar', :account it_behaves_like 'AccountAvatar', :account
include_examples 'AccountHeader', :account it_behaves_like 'AccountHeader', :account
describe '#increment_count!' do describe '#increment_count!' do
subject { Fabricate(:account) } subject { Fabricate(:account) }

View File

@ -3,7 +3,7 @@
require 'rails_helper' require 'rails_helper'
RSpec.describe CustomFilter do RSpec.describe CustomFilter do
include_examples 'Expireable' it_behaves_like 'Expireable'
describe 'Validations' do describe 'Validations' do
it { is_expected.to validate_presence_of(:title) } it { is_expected.to validate_presence_of(:title) }

View File

@ -3,7 +3,7 @@
require 'rails_helper' require 'rails_helper'
RSpec.describe Invite do RSpec.describe Invite do
include_examples 'Expireable' it_behaves_like 'Expireable'
describe 'Associations' do describe 'Associations' do
it { is_expected.to belong_to(:user).inverse_of(:invites) } it { is_expected.to belong_to(:user).inverse_of(:invites) }

View File

@ -3,7 +3,7 @@
require 'rails_helper' require 'rails_helper'
RSpec.describe IpBlock do RSpec.describe IpBlock do
include_examples 'Expireable' it_behaves_like 'Expireable'
describe 'Validations' do describe 'Validations' do
subject { Fabricate.build :ip_block } subject { Fabricate.build :ip_block }

View File

@ -3,7 +3,7 @@
require 'rails_helper' require 'rails_helper'
RSpec.describe LoginActivity do RSpec.describe LoginActivity do
include_examples 'BrowserDetection' it_behaves_like 'BrowserDetection'
describe 'Associations' do describe 'Associations' do
it { is_expected.to belong_to(:user).required } it { is_expected.to belong_to(:user).required }

View File

@ -3,7 +3,7 @@
require 'rails_helper' require 'rails_helper'
RSpec.describe Mute do RSpec.describe Mute do
include_examples 'Expireable' it_behaves_like 'Expireable'
describe 'Associations' do describe 'Associations' do
it { is_expected.to belong_to(:account).required } it { is_expected.to belong_to(:account).required }

View File

@ -3,7 +3,7 @@
require 'rails_helper' require 'rails_helper'
RSpec.describe Poll do RSpec.describe Poll do
include_examples 'Expireable' it_behaves_like 'Expireable'
describe '#reset_votes!' do describe '#reset_votes!' do
let(:poll) { Fabricate :poll, cached_tallies: [2, 3], votes_count: 5, voters_count: 5 } let(:poll) { Fabricate :poll, cached_tallies: [2, 3], votes_count: 5, voters_count: 5 }

View File

@ -3,7 +3,7 @@
require 'rails_helper' require 'rails_helper'
RSpec.describe PreviewCardProvider do RSpec.describe PreviewCardProvider do
include_examples 'Reviewable' it_behaves_like 'Reviewable'
describe 'scopes' do describe 'scopes' do
let(:trendable_and_reviewed) { Fabricate(:preview_card_provider, trendable: true, reviewed_at: 5.days.ago) } let(:trendable_and_reviewed) { Fabricate(:preview_card_provider, trendable: true, reviewed_at: 5.days.ago) }

View File

@ -3,7 +3,7 @@
require 'rails_helper' require 'rails_helper'
RSpec.describe PreviewCardTrend do RSpec.describe PreviewCardTrend do
include_examples 'RankedTrend' it_behaves_like 'RankedTrend'
describe 'Associations' do describe 'Associations' do
it { is_expected.to belong_to(:preview_card).required } it { is_expected.to belong_to(:preview_card).required }

View File

@ -3,7 +3,7 @@
require 'rails_helper' require 'rails_helper'
RSpec.describe SessionActivation do RSpec.describe SessionActivation do
include_examples 'BrowserDetection' it_behaves_like 'BrowserDetection'
describe '.active?' do describe '.active?' do
subject { described_class.active?(id) } subject { described_class.active?(id) }

View File

@ -9,7 +9,7 @@ RSpec.describe Status do
let(:bob) { Fabricate(:account, username: 'bob') } let(:bob) { Fabricate(:account, username: 'bob') }
let(:other) { Fabricate(:status, account: bob, text: 'Skulls for the skull god! The enemy\'s gates are sideways!') } let(:other) { Fabricate(:status, account: bob, text: 'Skulls for the skull god! The enemy\'s gates are sideways!') }
include_examples 'Status::Visibility' it_behaves_like 'Status::Visibility'
describe '#local?' do describe '#local?' do
it 'returns true when no remote URI is set' do it 'returns true when no remote URI is set' do

View File

@ -3,7 +3,7 @@
require 'rails_helper' require 'rails_helper'
RSpec.describe StatusTrend do RSpec.describe StatusTrend do
include_examples 'RankedTrend' it_behaves_like 'RankedTrend'
describe 'Associations' do describe 'Associations' do
it { is_expected.to belong_to(:account).required } it { is_expected.to belong_to(:account).required }

View File

@ -3,7 +3,7 @@
require 'rails_helper' require 'rails_helper'
RSpec.describe Tag do RSpec.describe Tag do
include_examples 'Reviewable' it_behaves_like 'Reviewable'
describe 'Validations' do describe 'Validations' do
describe 'name' do describe 'name' do

View File

@ -3,7 +3,7 @@
require 'rails_helper' require 'rails_helper'
RSpec.describe TagTrend do RSpec.describe TagTrend do
include_examples 'RankedTrend' it_behaves_like 'RankedTrend'
describe 'Associations' do describe 'Associations' do
it { is_expected.to belong_to(:tag).required } it { is_expected.to belong_to(:tag).required }

View File

@ -25,10 +25,10 @@ RSpec.describe Admin::Fasp::ProviderPolicy, type: :policy do
end end
permissions :index?, :create? do permissions :index?, :create? do
include_examples 'admin only', Fasp::Provider it_behaves_like 'admin only', Fasp::Provider
end end
permissions :show?, :create?, :update?, :destroy? do permissions :show?, :create?, :update?, :destroy? do
include_examples 'admin only', :fasp_provider it_behaves_like 'admin only', :fasp_provider
end end
end end

View File

@ -29,7 +29,7 @@ RSpec.describe 'Managing OAuth Tokens' do
access_grant.plaintext_token access_grant.plaintext_token
end end
shared_examples 'returns originally requested scopes' do shared_examples 'original scope request preservation' do
it 'returns all scopes requested for the given code' do it 'returns all scopes requested for the given code' do
subject subject
@ -41,26 +41,26 @@ RSpec.describe 'Managing OAuth Tokens' do
context 'with no scopes specified' do context 'with no scopes specified' do
let(:scope) { nil } let(:scope) { nil }
include_examples 'returns originally requested scopes' it_behaves_like 'original scope request preservation'
end end
context 'with scopes specified' do context 'with scopes specified' do
context 'when the scopes were requested for this code' do context 'when the scopes were requested for this code' do
let(:scope) { 'write' } let(:scope) { 'write' }
include_examples 'returns originally requested scopes' it_behaves_like 'original scope request preservation'
end end
context 'when the scope was not requested for the code' do context 'when the scope was not requested for the code' do
let(:scope) { 'follow' } let(:scope) { 'follow' }
include_examples 'returns originally requested scopes' it_behaves_like 'original scope request preservation'
end end
context 'when the scope does not belong to the application' do context 'when the scope does not belong to the application' do
let(:scope) { 'push' } let(:scope) { 'push' }
include_examples 'returns originally requested scopes' it_behaves_like 'original scope request preservation'
end end
end end
end end

View File

@ -130,14 +130,14 @@ RSpec.describe 'OmniAuth callbacks' do
end end
describe '#openid_connect', if: ENV['OIDC_ENABLED'] == 'true' && ENV['OIDC_SCOPE'].present? do describe '#openid_connect', if: ENV['OIDC_ENABLED'] == 'true' && ENV['OIDC_SCOPE'].present? do
include_examples 'omniauth provider callbacks', :openid_connect it_behaves_like 'omniauth provider callbacks', :openid_connect
end end
describe '#cas', if: ENV['CAS_ENABLED'] == 'true' do describe '#cas', if: ENV['CAS_ENABLED'] == 'true' do
include_examples 'omniauth provider callbacks', :cas it_behaves_like 'omniauth provider callbacks', :cas
end end
describe '#saml', if: ENV['SAML_ENABLED'] == 'true' do describe '#saml', if: ENV['SAML_ENABLED'] == 'true' do
include_examples 'omniauth provider callbacks', :saml it_behaves_like 'omniauth provider callbacks', :saml
end end
end end

View File

@ -68,7 +68,7 @@ RSpec.describe ActivityPub::FetchRemoteAccountService do
expect(account.domain).to eq 'example.com' expect(account.domain).to eq 'example.com'
end end
include_examples 'sets profile data' it_behaves_like 'sets profile data'
end end
context 'when WebFinger presents different domain than URI' do context 'when WebFinger presents different domain than URI' do
@ -91,7 +91,7 @@ RSpec.describe ActivityPub::FetchRemoteAccountService do
expect(account.domain).to eq 'iscool.af' expect(account.domain).to eq 'iscool.af'
end end
include_examples 'sets profile data' it_behaves_like 'sets profile data'
end end
context 'when WebFinger returns a different URI' do context 'when WebFinger returns a different URI' do

View File

@ -68,7 +68,7 @@ RSpec.describe ActivityPub::FetchRemoteActorService do
expect(account.domain).to eq 'example.com' expect(account.domain).to eq 'example.com'
end end
include_examples 'sets profile data' it_behaves_like 'sets profile data'
end end
context 'when WebFinger presents different domain than URI' do context 'when WebFinger presents different domain than URI' do
@ -91,7 +91,7 @@ RSpec.describe ActivityPub::FetchRemoteActorService do
expect(account.domain).to eq 'iscool.af' expect(account.domain).to eq 'iscool.af'
end end
include_examples 'sets profile data' it_behaves_like 'sets profile data'
end end
context 'when WebFinger returns a different URI' do context 'when WebFinger returns a different URI' do

View File

@ -115,7 +115,7 @@ RSpec.describe BulkImportRowService do
account.follow!(target_account) account.follow!(target_account)
end end
include_examples 'row import success and list addition' it_behaves_like 'row import success and list addition'
end end
context 'when the user already requested to follow the target account' do context 'when the user already requested to follow the target account' do
@ -123,17 +123,17 @@ RSpec.describe BulkImportRowService do
account.request_follow!(target_account) account.request_follow!(target_account)
end end
include_examples 'row import success and list addition' it_behaves_like 'row import success and list addition'
end end
context 'when the target account is neither followed nor requested' do context 'when the target account is neither followed nor requested' do
include_examples 'row import success and list addition' it_behaves_like 'row import success and list addition'
end end
context 'when the target account is the user themself' do context 'when the target account is the user themself' do
let(:target_account) { account } let(:target_account) { account }
include_examples 'row import success and list addition' it_behaves_like 'row import success and list addition'
end end
def add_target_account_to_list def add_target_account_to_list
@ -153,7 +153,7 @@ RSpec.describe BulkImportRowService do
end end
context 'when the list does not exist yet' do context 'when the list does not exist yet' do
include_examples 'common behavior' it_behaves_like 'common behavior'
end end
context 'when the list exists' do context 'when the list exists' do
@ -161,7 +161,7 @@ RSpec.describe BulkImportRowService do
Fabricate(:list, account: account, title: list_name) Fabricate(:list, account: account, title: list_name)
end end
include_examples 'common behavior' it_behaves_like 'common behavior'
it 'does not create a new list' do it 'does not create a new list' do
account.follow!(target_account) account.follow!(target_account)

View File

@ -71,7 +71,7 @@ RSpec.describe DeleteAccountService do
let!(:remote_alice) { Fabricate(:account, inbox_url: 'https://alice.com/inbox', domain: 'alice.com', protocol: :activitypub) } let!(:remote_alice) { Fabricate(:account, inbox_url: 'https://alice.com/inbox', domain: 'alice.com', protocol: :activitypub) }
let!(:remote_bob) { Fabricate(:account, inbox_url: 'https://bob.com/inbox', domain: 'bob.com', protocol: :activitypub) } let!(:remote_bob) { Fabricate(:account, inbox_url: 'https://bob.com/inbox', domain: 'bob.com', protocol: :activitypub) }
include_examples 'common behavior' do it_behaves_like 'common behavior' do
let(:account) { Fabricate(:account) } let(:account) { Fabricate(:account) }
let(:local_follower) { Fabricate(:account) } let(:local_follower) { Fabricate(:account) }
@ -88,7 +88,7 @@ RSpec.describe DeleteAccountService do
stub_request(:post, account.inbox_url).to_return(status: 201) stub_request(:post, account.inbox_url).to_return(status: 201)
end end
include_examples 'common behavior' do it_behaves_like 'common behavior' do
let(:account) { Fabricate(:account, inbox_url: 'https://bob.com/inbox', protocol: :activitypub, domain: 'bob.com') } let(:account) { Fabricate(:account, inbox_url: 'https://bob.com/inbox', protocol: :activitypub, domain: 'bob.com') }
let(:local_follower) { Fabricate(:account) } let(:local_follower) { Fabricate(:account) }

View File

@ -46,7 +46,7 @@ RSpec.describe SuspendAccountService do
json['type'] == 'Update' && json['actor'] == actor_id && json['object']['id'] == actor_id && json['object']['suspended'] json['type'] == 'Update' && json['actor'] == actor_id && json['object']['id'] == actor_id && json['object']['suspended']
end end
include_examples 'common behavior' do it_behaves_like 'common behavior' do
let!(:account) { Fabricate(:account) } let!(:account) { Fabricate(:account) }
let!(:remote_follower) { Fabricate(:account, uri: 'https://alice.com', inbox_url: 'https://alice.com/inbox', protocol: :activitypub, domain: 'alice.com') } let!(:remote_follower) { Fabricate(:account, uri: 'https://alice.com', inbox_url: 'https://alice.com/inbox', protocol: :activitypub, domain: 'alice.com') }
let!(:remote_reporter) { Fabricate(:account, uri: 'https://bob.com', inbox_url: 'https://bob.com/inbox', protocol: :activitypub, domain: 'bob.com') } let!(:remote_reporter) { Fabricate(:account, uri: 'https://bob.com', inbox_url: 'https://bob.com/inbox', protocol: :activitypub, domain: 'bob.com') }
@ -72,7 +72,7 @@ RSpec.describe SuspendAccountService do
json['type'] == 'Reject' && json['actor'] == ActivityPub::TagManager.instance.uri_for(followee) && json['object']['actor'] == account.uri json['type'] == 'Reject' && json['actor'] == ActivityPub::TagManager.instance.uri_for(followee) && json['object']['actor'] == account.uri
end end
include_examples 'common behavior' do it_behaves_like 'common behavior' do
let!(:account) { Fabricate(:account, domain: 'bob.com', uri: 'https://bob.com', inbox_url: 'https://bob.com/inbox', protocol: :activitypub) } let!(:account) { Fabricate(:account, domain: 'bob.com', uri: 'https://bob.com', inbox_url: 'https://bob.com/inbox', protocol: :activitypub) }
let!(:local_followee) { Fabricate(:account) } let!(:local_followee) { Fabricate(:account) }

View File

@ -3,7 +3,7 @@
require 'rails_helper' require 'rails_helper'
RSpec.describe UnsuspendAccountService do RSpec.describe UnsuspendAccountService do
shared_context 'with common context' do shared_context 'when account is unsuspended' do
subject { described_class.new.call(account) } subject { described_class.new.call(account) }
let!(:local_follower) { Fabricate(:user, current_sign_in_at: 1.hour.ago).account } let!(:local_follower) { Fabricate(:user, current_sign_in_at: 1.hour.ago).account }
@ -31,12 +31,13 @@ RSpec.describe UnsuspendAccountService do
stub_request(:post, 'https://bob.com/inbox').to_return(status: 201) stub_request(:post, 'https://bob.com/inbox').to_return(status: 201)
end end
let!(:account) { Fabricate(:account) }
it 'does not change the “suspended” flag' do it 'does not change the “suspended” flag' do
expect { subject }.to_not change(account, :suspended?) expect { subject }.to_not change(account, :suspended?)
end end
include_examples 'with common context' do include_context 'when account is unsuspended' do
let!(:account) { Fabricate(:account) }
let!(:remote_follower) { Fabricate(:account, uri: 'https://alice.com', inbox_url: 'https://alice.com/inbox', protocol: :activitypub, domain: 'alice.com') } let!(:remote_follower) { Fabricate(:account, uri: 'https://alice.com', inbox_url: 'https://alice.com/inbox', protocol: :activitypub, domain: 'alice.com') }
let!(:remote_reporter) { Fabricate(:account, uri: 'https://bob.com', inbox_url: 'https://bob.com/inbox', protocol: :activitypub, domain: 'bob.com') } let!(:remote_reporter) { Fabricate(:account, uri: 'https://bob.com', inbox_url: 'https://bob.com/inbox', protocol: :activitypub, domain: 'bob.com') }
@ -65,7 +66,7 @@ RSpec.describe UnsuspendAccountService do
end end
describe 'unsuspending a remote account' do describe 'unsuspending a remote account' do
include_examples 'with common context' do include_context 'when account is unsuspended' do
let!(:account) { Fabricate(:account, domain: 'bob.com', uri: 'https://bob.com', inbox_url: 'https://bob.com/inbox', protocol: :activitypub) } let!(:account) { Fabricate(:account, domain: 'bob.com', uri: 'https://bob.com', inbox_url: 'https://bob.com/inbox', protocol: :activitypub) }
let!(:resolve_account_service) { instance_double(ResolveAccountService) } let!(:resolve_account_service) { instance_double(ResolveAccountService) }

View File

@ -8,95 +8,82 @@ RSpec.describe Import::RowWorker do
let(:row) { Fabricate(:bulk_import_row, bulk_import: import) } let(:row) { Fabricate(:bulk_import_row, bulk_import: import) }
describe '#perform' do describe '#perform' do
before do before { allow(BulkImportRowService).to receive(:new).and_return(service_double) }
allow(BulkImportRowService).to receive(:new).and_return(service_double)
shared_context 'when service succeeds' do
let(:service_double) { instance_double(BulkImportRowService, call: true) }
end
shared_context 'when service fails' do
let(:service_double) { instance_double(BulkImportRowService, call: false) }
end
shared_context 'when service errors' do
let(:service_double) { instance_double(BulkImportRowService) }
before { allow(service_double).to receive(:call).and_raise('dummy error') }
end end
shared_examples 'clean failure' do shared_examples 'clean failure' do
let(:service_double) { instance_double(BulkImportRowService, call: false) } it 'calls service, increases processed items, preserves imported items, and keeps row' do
expect { subject.perform(row.id) }
it 'calls BulkImportRowService' do .to change { import.reload.processed_items }.by(+1)
subject.perform(row.id) .and not_change { import.reload.imported_items }
expect(service_double).to have_received(:call).with(row) .and(not_change { BulkImportRow.exists?(row.id) }.from(true))
end expect(service_double)
.to have_received(:call).with(row)
it 'increases the number of processed items' do
expect { subject.perform(row.id) }.to(change { import.reload.processed_items }.by(+1))
end
it 'does not increase the number of imported items' do
expect { subject.perform(row.id) }.to_not(change { import.reload.imported_items })
end
it 'does not delete the row' do
subject.perform(row.id)
expect(BulkImportRow.exists?(row.id)).to be true
end end
end end
shared_examples 'unclean failure' do shared_examples 'unclean failure' do
let(:service_double) { instance_double(BulkImportRowService) } it 'raises an error, preserves processed items, and keeps row' do
expect { subject.perform(row.id) }
before do .to raise_error(StandardError, 'dummy error')
allow(service_double).to receive(:call) do .and(not_change { import.reload.processed_items })
raise 'dummy error' .and(not_change { BulkImportRow.exists?(row.id) }.from(true))
end
end
it 'raises an error and does not change processed items count' do
expect { subject.perform(row.id) }.to raise_error(StandardError, 'dummy error').and(not_change { import.reload.processed_items })
end
it 'does not delete the row' do
expect { subject.perform(row.id) }.to raise_error(StandardError, 'dummy error').and(not_change { BulkImportRow.exists?(row.id) })
end end
end end
shared_examples 'clean success' do shared_examples 'clean success' do
let(:service_double) { instance_double(BulkImportRowService, call: true) } it 'calls service, increases processed items, increases imported items, and deletes row' do
expect { subject.perform(row.id) }
it 'calls BulkImportRowService' do .to change { import.reload.processed_items }.by(+1)
subject.perform(row.id) .and change { import.reload.imported_items }.by(+1)
.and(change { BulkImportRow.exists?(row.id) }.from(true).to(false))
expect(service_double).to have_received(:call).with(row) expect(service_double).to have_received(:call).with(row)
end end
it 'increases the number of processed items' do
expect { subject.perform(row.id) }.to(change { import.reload.processed_items }.by(+1))
end
it 'increases the number of imported items' do
expect { subject.perform(row.id) }.to(change { import.reload.imported_items }.by(+1))
end
it 'deletes the row' do
expect { subject.perform(row.id) }.to change { BulkImportRow.exists?(row.id) }.from(true).to(false)
end
end end
context 'when there are multiple rows to process' do context 'when there are multiple rows to process' do
let(:import) { Fabricate(:bulk_import, total_items: 2, processed_items: 0, imported_items: 0, state: :in_progress) } let(:import) { Fabricate(:bulk_import, total_items: 2, processed_items: 0, imported_items: 0, state: :in_progress) }
context 'with a clean failure' do context 'with a clean failure' do
include_examples 'clean failure' include_context 'when service fails'
it_behaves_like 'clean failure'
it 'does not mark the import as finished' do it 'does not mark the import as finished' do
expect { subject.perform(row.id) }.to_not(change { import.reload.state.to_sym }) expect { subject.perform(row.id) }
.to_not(change { import.reload.state.to_sym })
end end
end end
context 'with an unclean failure' do context 'with an unclean failure' do
include_examples 'unclean failure' include_context 'when service errors'
it_behaves_like 'unclean failure'
it 'does not mark the import as finished' do it 'does not mark the import as finished' do
expect { subject.perform(row.id) }.to raise_error(StandardError).and(not_change { import.reload.state.to_sym }) expect { subject.perform(row.id) }
.to raise_error(StandardError)
.and(not_change { import.reload.state.to_sym })
end end
end end
context 'with a clean success' do context 'with a clean success' do
include_examples 'clean success' include_context 'when service succeeds'
it_behaves_like 'clean success'
it 'does not mark the import as finished' do it 'does not mark the import as finished' do
expect { subject.perform(row.id) }.to_not(change { import.reload.state.to_sym }) expect { subject.perform(row.id) }
.to_not(change { import.reload.state.to_sym })
end end
end end
end end
@ -105,21 +92,28 @@ RSpec.describe Import::RowWorker do
let(:import) { Fabricate(:bulk_import, total_items: 2, processed_items: 1, imported_items: 0, state: :in_progress) } let(:import) { Fabricate(:bulk_import, total_items: 2, processed_items: 1, imported_items: 0, state: :in_progress) }
context 'with a clean failure' do context 'with a clean failure' do
include_examples 'clean failure' include_context 'when service fails'
it_behaves_like 'clean failure'
it 'marks the import as finished' do it 'marks the import as finished' do
expect { subject.perform(row.id) }.to change { import.reload.state.to_sym }.from(:in_progress).to(:finished) expect { subject.perform(row.id) }
.to change { import.reload.state.to_sym }.from(:in_progress).to(:finished)
end end
end end
context 'with an unclean failure' do
# NOTE: sidekiq retry logic may be a bit too difficult to test, so leaving this blind spot for now # NOTE: sidekiq retry logic may be a bit too difficult to test, so leaving this blind spot for now
include_context 'when service errors'
it_behaves_like 'unclean failure' it_behaves_like 'unclean failure'
end
context 'with a clean success' do context 'with a clean success' do
include_examples 'clean success' include_context 'when service succeeds'
it_behaves_like 'clean success'
it 'marks the import as finished' do it 'marks the import as finished' do
expect { subject.perform(row.id) }.to change { import.reload.state.to_sym }.from(:in_progress).to(:finished) expect { subject.perform(row.id) }
.to change { import.reload.state.to_sym }.from(:in_progress).to(:finished)
end end
end end
end end

View File

@ -113,27 +113,27 @@ RSpec.describe MoveWorker do
end end
shared_examples 'common tests' do shared_examples 'common tests' do
include_examples 'user note handling' it_behaves_like 'user note handling'
include_examples 'block and mute handling' it_behaves_like 'block and mute handling'
include_examples 'followers count handling' it_behaves_like 'followers count handling'
include_examples 'lists handling' it_behaves_like 'lists handling'
context 'when a local user already follows both source and target' do context 'when a local user already follows both source and target' do
before do before do
local_follower.request_follow!(target_account) local_follower.request_follow!(target_account)
end end
include_examples 'user note handling' it_behaves_like 'user note handling'
include_examples 'block and mute handling' it_behaves_like 'block and mute handling'
include_examples 'followers count handling' it_behaves_like 'followers count handling'
include_examples 'lists handling' it_behaves_like 'lists handling'
context 'when the local user already has the target in a list' do context 'when the local user already has the target in a list' do
before do before do
list.accounts << target_account list.accounts << target_account
end end
include_examples 'lists handling' it_behaves_like 'lists handling'
end end
end end
@ -142,17 +142,17 @@ RSpec.describe MoveWorker do
local_follower.follow!(target_account) local_follower.follow!(target_account)
end end
include_examples 'user note handling' it_behaves_like 'user note handling'
include_examples 'block and mute handling' it_behaves_like 'block and mute handling'
include_examples 'followers count handling' it_behaves_like 'followers count handling'
include_examples 'lists handling' it_behaves_like 'lists handling'
context 'when the local user already has the target in a list' do context 'when the local user already has the target in a list' do
before do before do
list.accounts << target_account list.accounts << target_account
end end
include_examples 'lists handling' it_behaves_like 'lists handling'
end end
end end
end end
@ -164,7 +164,7 @@ RSpec.describe MoveWorker do
expect(UnfollowFollowWorker).to have_enqueued_sidekiq_job(local_follower.id, source_account.id, target_account.id, false) expect(UnfollowFollowWorker).to have_enqueued_sidekiq_job(local_follower.id, source_account.id, target_account.id, false)
end end
include_examples 'common tests' it_behaves_like 'common tests'
end end
context 'when target account is local' do context 'when target account is local' do
@ -175,7 +175,7 @@ RSpec.describe MoveWorker do
expect(UnfollowFollowWorker).to have_enqueued_sidekiq_job(local_follower.id, source_account.id, target_account.id, true) expect(UnfollowFollowWorker).to have_enqueued_sidekiq_job(local_follower.id, source_account.id, target_account.id, true)
end end
include_examples 'common tests' it_behaves_like 'common tests'
end end
context 'when both target and source accounts are local' do context 'when both target and source accounts are local' do
@ -187,7 +187,7 @@ RSpec.describe MoveWorker do
expect(local_follower.following?(target_account)).to be true expect(local_follower.following?(target_account)).to be true
end end
include_examples 'common tests' it_behaves_like 'common tests'
it 'does not allow the moved account to follow themselves' do it 'does not allow the moved account to follow themselves' do
source_account.follow!(target_account) source_account.follow!(target_account)

View File

@ -108,7 +108,7 @@ RSpec.describe Scheduler::AccountsStatusesCleanupScheduler do
context 'when the budget is lower than the number of toots to delete' do context 'when the budget is lower than the number of toots to delete' do
it 'deletes the appropriate statuses' do it 'deletes the appropriate statuses' do
expect(Status.count).to be > (subject.compute_budget) # Data check expect(Status.count).to be > subject.compute_budget # Data check
expect { subject.perform } expect { subject.perform }
.to change(Status, :count).by(-subject.compute_budget) # Cleanable statuses .to change(Status, :count).by(-subject.compute_budget) # Cleanable statuses