Merge pull request #599 from kmycode/upstream-20240218
Upstream 20240218
This commit is contained in:
commit
f9100f1d93
147 changed files with 3454 additions and 2567 deletions
|
@ -30,42 +30,48 @@ RSpec.describe Admin::Disputes::AppealsController do
|
|||
end
|
||||
|
||||
describe 'POST #approve' do
|
||||
subject { post :approve, params: { id: appeal.id } }
|
||||
|
||||
let(:current_user) { Fabricate(:user, role: UserRole.find_by(name: 'Admin')) }
|
||||
|
||||
before do
|
||||
post :approve, params: { id: appeal.id }
|
||||
end
|
||||
it 'redirects back to the strike page and notifies target account about approved appeal', :sidekiq_inline do
|
||||
emails = capture_emails { subject }
|
||||
|
||||
it 'unsuspends a suspended account' do
|
||||
expect(target_account.reload.suspended?).to be false
|
||||
end
|
||||
expect(response)
|
||||
.to redirect_to(disputes_strike_path(appeal.strike))
|
||||
|
||||
it 'redirects back to the strike page' do
|
||||
expect(response).to redirect_to(disputes_strike_path(appeal.strike))
|
||||
end
|
||||
expect(target_account.reload)
|
||||
.to_not be_suspended
|
||||
|
||||
it 'notifies target account about approved appeal', :sidekiq_inline do
|
||||
expect(UserMailer.deliveries.size).to eq(1)
|
||||
expect(UserMailer.deliveries.first.to.first).to eq(target_account.user.email)
|
||||
expect(UserMailer.deliveries.first.subject).to eq(I18n.t('user_mailer.appeal_approved.subject', date: I18n.l(appeal.created_at)))
|
||||
expect(emails.size)
|
||||
.to eq(1)
|
||||
expect(emails.first)
|
||||
.to have_attributes(
|
||||
to: contain_exactly(target_account.user.email),
|
||||
subject: eq(I18n.t('user_mailer.appeal_approved.subject', date: I18n.l(appeal.created_at)))
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'POST #reject' do
|
||||
subject { post :reject, params: { id: appeal.id } }
|
||||
|
||||
let(:current_user) { Fabricate(:user, role: UserRole.find_by(name: 'Admin')) }
|
||||
|
||||
before do
|
||||
post :reject, params: { id: appeal.id }
|
||||
end
|
||||
it 'redirects back to the strike page and notifies target account about rejected appeal', :sidekiq_inline do
|
||||
emails = capture_emails { subject }
|
||||
|
||||
it 'redirects back to the strike page' do
|
||||
expect(response).to redirect_to(disputes_strike_path(appeal.strike))
|
||||
end
|
||||
expect(response)
|
||||
.to redirect_to(disputes_strike_path(appeal.strike))
|
||||
|
||||
it 'notifies target account about rejected appeal', :sidekiq_inline do
|
||||
expect(UserMailer.deliveries.size).to eq(1)
|
||||
expect(UserMailer.deliveries.first.to.first).to eq(target_account.user.email)
|
||||
expect(UserMailer.deliveries.first.subject).to eq(I18n.t('user_mailer.appeal_rejected.subject', date: I18n.l(appeal.created_at)))
|
||||
expect(emails.size)
|
||||
.to eq(1)
|
||||
|
||||
expect(emails.first)
|
||||
.to have_attributes(
|
||||
to: contain_exactly(target_account.user.email),
|
||||
subject: eq(I18n.t('user_mailer.appeal_rejected.subject', date: I18n.l(appeal.created_at)))
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -5,6 +5,8 @@ require 'rails_helper'
|
|||
describe Admin::ResetsController do
|
||||
render_views
|
||||
|
||||
subject { post :create, params: { account_id: account.id } }
|
||||
|
||||
let(:account) { Fabricate(:account) }
|
||||
|
||||
before do
|
||||
|
@ -13,11 +15,11 @@ describe Admin::ResetsController do
|
|||
|
||||
describe 'POST #create', :sidekiq_inline do
|
||||
it 'redirects to admin accounts page' do
|
||||
expect do
|
||||
post :create, params: { account_id: account.id }
|
||||
end.to change(Devise.mailer.deliveries, :size).by(2)
|
||||
emails = capture_emails { subject }
|
||||
|
||||
expect(Devise.mailer.deliveries).to have_attributes(
|
||||
expect(emails.size)
|
||||
.to eq(2)
|
||||
expect(emails).to have_attributes(
|
||||
first: have_attributes(
|
||||
to: include(account.user.email),
|
||||
subject: I18n.t('devise.mailer.password_change.subject')
|
||||
|
|
|
@ -57,11 +57,9 @@ RSpec.describe Auth::SessionsController do
|
|||
post :create, params: { user: { email: 'pam_user1', password: '123456' } }
|
||||
end
|
||||
|
||||
it 'redirects to home' do
|
||||
it 'redirects to home and logs the user in' do
|
||||
expect(response).to redirect_to(root_path)
|
||||
end
|
||||
|
||||
it 'logs the user in' do
|
||||
expect(controller.current_user).to be_instance_of(User)
|
||||
end
|
||||
end
|
||||
|
@ -71,11 +69,9 @@ RSpec.describe Auth::SessionsController do
|
|||
post :create, params: { user: { email: 'pam_user1', password: 'WRONGPW' } }
|
||||
end
|
||||
|
||||
it 'shows a login error' do
|
||||
it 'shows a login error and does not log the user in' do
|
||||
expect(flash[:alert]).to match I18n.t('devise.failure.invalid', authentication_keys: I18n.t('activerecord.attributes.user.email'))
|
||||
end
|
||||
|
||||
it "doesn't log the user in" do
|
||||
expect(controller.current_user).to be_nil
|
||||
end
|
||||
end
|
||||
|
@ -92,11 +88,9 @@ RSpec.describe Auth::SessionsController do
|
|||
post :create, params: { user: { email: user.email, password: '123456' } }
|
||||
end
|
||||
|
||||
it 'redirects to home' do
|
||||
it 'redirects to home and logs the user in' do
|
||||
expect(response).to redirect_to(root_path)
|
||||
end
|
||||
|
||||
it 'logs the user in' do
|
||||
expect(controller.current_user).to eq user
|
||||
end
|
||||
end
|
||||
|
@ -110,16 +104,16 @@ RSpec.describe Auth::SessionsController do
|
|||
post :create, params: { user: { email: user.email, password: user.password } }
|
||||
end
|
||||
|
||||
it 'redirects to home' do
|
||||
it 'redirects to home and logs the user in' do
|
||||
expect(response).to redirect_to(root_path)
|
||||
end
|
||||
|
||||
it 'logs the user in' do
|
||||
expect(controller.current_user).to eq user
|
||||
end
|
||||
end
|
||||
|
||||
context 'when using a valid password on a previously-used account with a new IP address' do
|
||||
subject { post :create, params: { user: { email: user.email, password: user.password } } }
|
||||
|
||||
let(:previous_ip) { '1.2.3.4' }
|
||||
let(:current_ip) { '4.3.2.1' }
|
||||
|
||||
|
@ -127,21 +121,24 @@ RSpec.describe Auth::SessionsController do
|
|||
Fabricate(:login_activity, user: user, ip: previous_ip)
|
||||
allow(controller.request).to receive(:remote_ip).and_return(current_ip)
|
||||
user.update(current_sign_in_at: 1.month.ago)
|
||||
post :create, params: { user: { email: user.email, password: user.password } }
|
||||
end
|
||||
|
||||
it 'redirects to home' do
|
||||
expect(response).to redirect_to(root_path)
|
||||
end
|
||||
it 'logs the user in and sends suspicious email and redirects home', :sidekiq_inline do
|
||||
emails = capture_emails { subject }
|
||||
|
||||
it 'logs the user in' do
|
||||
expect(controller.current_user).to eq user
|
||||
end
|
||||
expect(response)
|
||||
.to redirect_to(root_path)
|
||||
|
||||
it 'sends a suspicious sign-in mail', :sidekiq_inline do
|
||||
expect(UserMailer.deliveries.size).to eq(1)
|
||||
expect(UserMailer.deliveries.first.to.first).to eq(user.email)
|
||||
expect(UserMailer.deliveries.first.subject).to eq(I18n.t('user_mailer.suspicious_sign_in.subject'))
|
||||
expect(controller.current_user)
|
||||
.to eq user
|
||||
|
||||
expect(emails.size)
|
||||
.to eq(1)
|
||||
expect(emails.first)
|
||||
.to have_attributes(
|
||||
to: contain_exactly(user.email),
|
||||
subject: eq(I18n.t('user_mailer.suspicious_sign_in.subject'))
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -150,11 +147,9 @@ RSpec.describe Auth::SessionsController do
|
|||
post :create, params: { user: { email: user.email.upcase, password: user.password } }
|
||||
end
|
||||
|
||||
it 'redirects to home' do
|
||||
it 'redirects to home and logs the user in' do
|
||||
expect(response).to redirect_to(root_path)
|
||||
end
|
||||
|
||||
it 'logs the user in' do
|
||||
expect(controller.current_user).to eq user
|
||||
end
|
||||
end
|
||||
|
@ -164,11 +159,9 @@ RSpec.describe Auth::SessionsController do
|
|||
post :create, params: { user: { email: user.email, password: 'wrongpw' } }
|
||||
end
|
||||
|
||||
it 'shows a login error' do
|
||||
it 'shows a login error and does not log the user in' do
|
||||
expect(flash[:alert]).to match I18n.t('devise.failure.invalid', authentication_keys: I18n.t('activerecord.attributes.user.email'))
|
||||
end
|
||||
|
||||
it "doesn't log the user in" do
|
||||
expect(controller.current_user).to be_nil
|
||||
end
|
||||
end
|
||||
|
@ -270,29 +263,28 @@ RSpec.describe Auth::SessionsController do
|
|||
travel_to '2023-12-20T10:00:00Z'
|
||||
end
|
||||
|
||||
it 'does not log the user in' do
|
||||
Auth::SessionsController::MAX_2FA_ATTEMPTS_PER_HOUR.times do
|
||||
post :create, params: { user: { otp_attempt: '1234' } }, session: { attempt_user_id: user.id, attempt_user_updated_at: user.updated_at.to_s }
|
||||
expect(controller.current_user).to be_nil
|
||||
it 'does not log the user in, sets a flash message, and sends a suspicious sign in email', :sidekiq_inline do
|
||||
emails = capture_emails do
|
||||
Auth::SessionsController::MAX_2FA_ATTEMPTS_PER_HOUR.times do
|
||||
post :create, params: { user: { otp_attempt: '1234' } }, session: { attempt_user_id: user.id, attempt_user_updated_at: user.updated_at.to_s }
|
||||
expect(controller.current_user).to be_nil
|
||||
end
|
||||
post :create, params: { user: { otp_attempt: user.current_otp } }, session: { attempt_user_id: user.id, attempt_user_updated_at: user.updated_at.to_s }
|
||||
end
|
||||
|
||||
post :create, params: { user: { otp_attempt: user.current_otp } }, session: { attempt_user_id: user.id, attempt_user_updated_at: user.updated_at.to_s }
|
||||
expect(controller.current_user)
|
||||
.to be_nil
|
||||
|
||||
expect(controller.current_user).to be_nil
|
||||
expect(flash[:alert]).to match I18n.t('users.rate_limited')
|
||||
end
|
||||
expect(flash[:alert])
|
||||
.to match I18n.t('users.rate_limited')
|
||||
|
||||
it 'sends a suspicious sign-in mail', :sidekiq_inline do
|
||||
Auth::SessionsController::MAX_2FA_ATTEMPTS_PER_HOUR.times do
|
||||
post :create, params: { user: { otp_attempt: '1234' } }, session: { attempt_user_id: user.id, attempt_user_updated_at: user.updated_at.to_s }
|
||||
expect(controller.current_user).to be_nil
|
||||
end
|
||||
|
||||
post :create, params: { user: { otp_attempt: user.current_otp } }, session: { attempt_user_id: user.id, attempt_user_updated_at: user.updated_at.to_s }
|
||||
|
||||
expect(UserMailer.deliveries.size).to eq(1)
|
||||
expect(UserMailer.deliveries.first.to.first).to eq(user.email)
|
||||
expect(UserMailer.deliveries.first.subject).to eq(I18n.t('user_mailer.failed_2fa.subject'))
|
||||
expect(emails.size)
|
||||
.to eq(1)
|
||||
expect(emails.first)
|
||||
.to have_attributes(
|
||||
to: contain_exactly(user.email),
|
||||
subject: eq(I18n.t('user_mailer.failed_2fa.subject'))
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -301,11 +293,9 @@ RSpec.describe Auth::SessionsController do
|
|||
post :create, params: { user: { otp_attempt: user.current_otp } }, session: { attempt_user_id: user.id, attempt_user_updated_at: user.updated_at.to_s }
|
||||
end
|
||||
|
||||
it 'redirects to home' do
|
||||
it 'redirects to home and logs the user in' do
|
||||
expect(response).to redirect_to(root_path)
|
||||
end
|
||||
|
||||
it 'logs the user in' do
|
||||
expect(controller.current_user).to eq user
|
||||
end
|
||||
end
|
||||
|
@ -318,11 +308,9 @@ RSpec.describe Auth::SessionsController do
|
|||
post :create, params: { user: { otp_attempt: user.current_otp } }, session: { attempt_user_id: user.id, attempt_user_updated_at: user.updated_at.to_s }
|
||||
end
|
||||
|
||||
it 'shows a login error' do
|
||||
it 'shows a login error and does not log the user in' do
|
||||
expect(flash[:alert]).to match I18n.t('users.invalid_otp_token')
|
||||
end
|
||||
|
||||
it "doesn't log the user in" do
|
||||
expect(controller.current_user).to be_nil
|
||||
end
|
||||
end
|
||||
|
@ -332,11 +320,9 @@ RSpec.describe Auth::SessionsController do
|
|||
post :create, params: { user: { otp_attempt: recovery_codes.first } }, session: { attempt_user_id: user.id, attempt_user_updated_at: user.updated_at.to_s }
|
||||
end
|
||||
|
||||
it 'redirects to home' do
|
||||
it 'redirects to home and logs the user in' do
|
||||
expect(response).to redirect_to(root_path)
|
||||
end
|
||||
|
||||
it 'logs the user in' do
|
||||
expect(controller.current_user).to eq user
|
||||
end
|
||||
end
|
||||
|
@ -346,11 +332,9 @@ RSpec.describe Auth::SessionsController do
|
|||
post :create, params: { user: { otp_attempt: 'wrongotp' } }, session: { attempt_user_id: user.id, attempt_user_updated_at: user.updated_at.to_s }
|
||||
end
|
||||
|
||||
it 'shows a login error' do
|
||||
it 'shows a login error and does not log the user in' do
|
||||
expect(flash[:alert]).to match I18n.t('users.invalid_otp_token')
|
||||
end
|
||||
|
||||
it "doesn't log the user in" do
|
||||
expect(controller.current_user).to be_nil
|
||||
end
|
||||
end
|
||||
|
@ -417,15 +401,11 @@ RSpec.describe Auth::SessionsController do
|
|||
post :create, params: { user: { credential: fake_credential } }, session: { attempt_user_id: user.id, attempt_user_updated_at: user.updated_at.to_s }
|
||||
end
|
||||
|
||||
it 'instructs the browser to redirect to home' do
|
||||
it 'instructs the browser to redirect to home, logs the user in, and updates the sign count' do
|
||||
expect(body_as_json[:redirect_path]).to eq(root_path)
|
||||
end
|
||||
|
||||
it 'logs the user in' do
|
||||
expect(controller.current_user).to eq user
|
||||
end
|
||||
|
||||
it 'updates the sign count' do
|
||||
expect(webauthn_credential.reload.sign_count).to eq(sign_count)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -10,19 +10,23 @@ RSpec.describe Disputes::AppealsController do
|
|||
let!(:admin) { Fabricate(:user, role: UserRole.find_by(name: 'Admin')) }
|
||||
|
||||
describe '#create' do
|
||||
subject { post :create, params: params }
|
||||
|
||||
context 'with valid params' do
|
||||
let(:current_user) { Fabricate(:user) }
|
||||
let(:strike) { Fabricate(:account_warning, target_account: current_user.account) }
|
||||
let(:params) { { strike_id: strike.id, appeal: { text: 'Foo' } } }
|
||||
|
||||
before do
|
||||
post :create, params: { strike_id: strike.id, appeal: { text: 'Foo' } }
|
||||
end
|
||||
it 'notifies staff about new appeal and redirects back to strike page', :sidekiq_inline do
|
||||
emails = capture_emails { subject }
|
||||
|
||||
it 'notifies staff about new appeal', :sidekiq_inline do
|
||||
expect(ActionMailer::Base.deliveries.first.to).to eq([admin.email])
|
||||
end
|
||||
|
||||
it 'redirects back to the strike page' do
|
||||
expect(emails.size)
|
||||
.to eq(1)
|
||||
expect(emails.first)
|
||||
.to have_attributes(
|
||||
to: contain_exactly(admin.email),
|
||||
subject: eq(I18n.t('admin_mailer.new_appeal.subject', username: current_user.account.acct, instance: Rails.configuration.x.local_domain))
|
||||
)
|
||||
expect(response).to redirect_to(disputes_strike_path(strike.id))
|
||||
end
|
||||
end
|
||||
|
@ -30,16 +34,12 @@ RSpec.describe Disputes::AppealsController do
|
|||
context 'with invalid params' do
|
||||
let(:current_user) { Fabricate(:user) }
|
||||
let(:strike) { Fabricate(:account_warning, target_account: current_user.account) }
|
||||
let(:params) { { strike_id: strike.id, appeal: { text: '' } } }
|
||||
|
||||
before do
|
||||
post :create, params: { strike_id: strike.id, appeal: { text: '' } }
|
||||
end
|
||||
it 'does not send email and renders strike show page', :sidekiq_inline do
|
||||
emails = capture_emails { subject }
|
||||
|
||||
it 'does not send email', :sidekiq_inline do
|
||||
expect(ActionMailer::Base.deliveries.size).to eq(0)
|
||||
end
|
||||
|
||||
it 'renders the strike show page' do
|
||||
expect(emails).to be_empty
|
||||
expect(response).to render_template('disputes/strikes/show')
|
||||
end
|
||||
end
|
||||
|
|
|
@ -13,17 +13,19 @@ RSpec.describe InstanceActorsController do
|
|||
end
|
||||
|
||||
it 'returns http success with correct media type, headers, and session values' do
|
||||
expect(response).to have_http_status(200)
|
||||
expect(response)
|
||||
.to have_http_status(200)
|
||||
.and have_attributes(
|
||||
media_type: eq('application/activity+json'),
|
||||
cookies: be_empty
|
||||
)
|
||||
|
||||
expect(response.media_type).to eq 'application/activity+json'
|
||||
|
||||
expect(response.cookies).to be_empty
|
||||
expect(response.headers['Set-Cookies']).to be_nil
|
||||
expect(response.headers)
|
||||
.to include('Cache-Control' => include('public'))
|
||||
.and not_include('Set-Cookies')
|
||||
|
||||
expect(session).to be_empty
|
||||
|
||||
expect(response.headers['Cache-Control']).to include 'public'
|
||||
|
||||
expect(body_as_json)
|
||||
.to include(:id, :type, :preferredUsername, :inbox, :publicKey, :inbox, :outbox, :url)
|
||||
end
|
||||
|
|
|
@ -957,13 +957,13 @@ RSpec.describe Account do
|
|||
end
|
||||
|
||||
it 'is valid if we are creating an instance actor account with a period' do
|
||||
account = Fabricate.build(:account, id: -99, actor_type: 'Application', locked: true, username: 'example.com')
|
||||
account = Fabricate.build(:account, id: described_class::INSTANCE_ACTOR_ID, actor_type: 'Application', locked: true, username: 'example.com')
|
||||
expect(account.valid?).to be true
|
||||
end
|
||||
|
||||
it 'is valid if we are creating a possibly-conflicting instance actor account' do
|
||||
_account = Fabricate(:account, username: 'examplecom')
|
||||
instance_account = Fabricate.build(:account, id: -99, actor_type: 'Application', locked: true, username: 'example.com')
|
||||
instance_account = Fabricate.build(:account, id: described_class::INSTANCE_ACTOR_ID, actor_type: 'Application', locked: true, username: 'example.com')
|
||||
expect(instance_account.valid?).to be true
|
||||
end
|
||||
|
||||
|
|
|
@ -91,20 +91,15 @@ RSpec.describe MediaAttachment, :paperclip_processing do
|
|||
end
|
||||
|
||||
it 'saves media attachment with correct file metadata' do
|
||||
expect(media.persisted?).to be true
|
||||
expect(media.file).to_not be_nil
|
||||
|
||||
# completes processing
|
||||
expect(media.processing_complete?).to be true
|
||||
|
||||
# sets type
|
||||
expect(media.type).to eq 'image'
|
||||
|
||||
# sets content type
|
||||
expect(media.file_content_type).to eq content_type
|
||||
|
||||
# sets file extension
|
||||
expect(media.file_file_name).to end_with extension
|
||||
expect(media)
|
||||
.to be_persisted
|
||||
.and be_processing_complete
|
||||
.and have_attributes(
|
||||
file: be_present,
|
||||
type: eq('image'),
|
||||
file_content_type: eq(content_type),
|
||||
file_file_name: end_with(extension)
|
||||
)
|
||||
|
||||
# Rack::Mime (used by PublicFileServerMiddleware) recognizes file extension
|
||||
expect(Rack::Mime.mime_type(extension, nil)).to eq content_type
|
||||
|
@ -112,17 +107,23 @@ RSpec.describe MediaAttachment, :paperclip_processing do
|
|||
|
||||
it 'saves media attachment with correct size metadata' do
|
||||
# strips original file name
|
||||
expect(media.file_file_name).to_not start_with '600x400'
|
||||
expect(media.file_file_name)
|
||||
.to_not start_with '600x400'
|
||||
|
||||
# sets meta for original
|
||||
expect(media.file.meta['original']['width']).to eq 600
|
||||
expect(media.file.meta['original']['height']).to eq 400
|
||||
expect(media.file.meta['original']['aspect']).to eq 1.5
|
||||
|
||||
# sets meta for thumbnail
|
||||
expect(media.file.meta['small']['width']).to eq 588
|
||||
expect(media.file.meta['small']['height']).to eq 392
|
||||
expect(media.file.meta['small']['aspect']).to eq 1.5
|
||||
# sets meta for original and thumbnail
|
||||
expect(media.file.meta.deep_symbolize_keys)
|
||||
.to include(
|
||||
original: include(
|
||||
width: eq(600),
|
||||
height: eq(400),
|
||||
aspect: eq(1.5)
|
||||
),
|
||||
small: include(
|
||||
width: eq(588),
|
||||
height: eq(392),
|
||||
aspect: eq(1.5)
|
||||
)
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
require 'rails_helper'
|
||||
|
||||
describe TagFeed, type: :service do
|
||||
describe TagFeed do
|
||||
describe '#get' do
|
||||
let(:account) { Fabricate(:account) }
|
||||
let(:tag_cats) { Fabricate(:tag, name: 'cats') }
|
||||
|
|
|
@ -164,12 +164,12 @@ RSpec.describe UserRole do
|
|||
end
|
||||
|
||||
describe '#everyone?' do
|
||||
it 'returns true when id is -99' do
|
||||
subject.id = -99
|
||||
it 'returns true when id matches the everyone id' do
|
||||
subject.id = described_class::EVERYONE_ROLE_ID
|
||||
expect(subject.everyone?).to be true
|
||||
end
|
||||
|
||||
it 'returns false when id is not -99' do
|
||||
it 'returns false when id does not match the everyone id' do
|
||||
subject.id = 123
|
||||
expect(subject.everyone?).to be false
|
||||
end
|
||||
|
|
|
@ -483,36 +483,35 @@ RSpec.describe User do
|
|||
end
|
||||
|
||||
describe '#mark_email_as_confirmed!' do
|
||||
subject(:user) { Fabricate(:user, confirmed_at: confirmed_at) }
|
||||
subject { user.mark_email_as_confirmed! }
|
||||
|
||||
before do
|
||||
ActionMailer::Base.deliveries.clear
|
||||
user.mark_email_as_confirmed!
|
||||
end
|
||||
|
||||
after { ActionMailer::Base.deliveries.clear }
|
||||
let!(:user) { Fabricate(:user, confirmed_at: confirmed_at) }
|
||||
|
||||
context 'when user is new' do
|
||||
let(:confirmed_at) { nil }
|
||||
|
||||
it 'confirms user' do
|
||||
expect(user.confirmed_at).to be_present
|
||||
end
|
||||
it 'confirms user and delivers welcome email', :sidekiq_inline do
|
||||
emails = capture_emails { subject }
|
||||
|
||||
it 'delivers mails', :sidekiq_inline do
|
||||
expect(ActionMailer::Base.deliveries.count).to eq 2
|
||||
expect(user.confirmed_at).to be_present
|
||||
expect(emails.size)
|
||||
.to eq(1)
|
||||
expect(emails.first)
|
||||
.to have_attributes(
|
||||
to: contain_exactly(user.email),
|
||||
subject: eq(I18n.t('user_mailer.welcome.subject'))
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when user is not new' do
|
||||
let(:confirmed_at) { Time.zone.now }
|
||||
|
||||
it 'confirms user' do
|
||||
expect(user.confirmed_at).to be_present
|
||||
end
|
||||
it 'confirms user but does not deliver welcome email' do
|
||||
emails = capture_emails { subject }
|
||||
|
||||
it 'does not deliver mail' do
|
||||
expect(ActionMailer::Base.deliveries.count).to eq 0
|
||||
expect(user.confirmed_at).to be_present
|
||||
expect(emails).to be_empty
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -82,6 +82,7 @@ RSpec.configure do |config|
|
|||
config.include Devise::Test::ControllerHelpers, type: :view
|
||||
config.include Devise::Test::IntegrationHelpers, type: :feature
|
||||
config.include Devise::Test::IntegrationHelpers, type: :request
|
||||
config.include ActionMailer::TestHelper
|
||||
config.include Paperclip::Shoulda::Matchers
|
||||
config.include ActiveSupport::Testing::TimeHelpers
|
||||
config.include Chewy::Rspec::Helpers
|
||||
|
|
|
@ -35,7 +35,7 @@ RSpec.describe 'Reports' do
|
|||
|
||||
it 'creates a report', :aggregate_failures do
|
||||
perform_enqueued_jobs do
|
||||
subject
|
||||
emails = capture_emails { subject }
|
||||
|
||||
expect(response).to have_http_status(200)
|
||||
expect(body_as_json).to match(
|
||||
|
@ -49,7 +49,13 @@ RSpec.describe 'Reports' do
|
|||
expect(target_account.targeted_reports).to_not be_empty
|
||||
expect(target_account.targeted_reports.first.comment).to eq 'reasons'
|
||||
|
||||
expect(ActionMailer::Base.deliveries.first.to).to eq([admin.email])
|
||||
expect(emails.size)
|
||||
.to eq(1)
|
||||
expect(emails.first)
|
||||
.to have_attributes(
|
||||
to: contain_exactly(admin.email),
|
||||
subject: eq(I18n.t('admin_mailer.new_report.subject', instance: Rails.configuration.x.local_domain, id: target_account.targeted_reports.first.id))
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -256,6 +256,16 @@ describe '/api/v1/statuses' do
|
|||
expect(response.headers['X-RateLimit-Remaining']).to eq '0'
|
||||
end
|
||||
end
|
||||
|
||||
context 'with missing thread' do
|
||||
let(:params) { { status: 'Hello world', in_reply_to_id: 0 } }
|
||||
|
||||
it 'returns http not found' do
|
||||
subject
|
||||
|
||||
expect(response).to have_http_status(404)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'DELETE /api/v1/statuses/:id' do
|
||||
|
|
24
spec/services/after_unallow_domain_service_spec.rb
Normal file
24
spec/services/after_unallow_domain_service_spec.rb
Normal file
|
@ -0,0 +1,24 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe AfterUnallowDomainService do
|
||||
describe '#call' do
|
||||
context 'with accounts for a domain' do
|
||||
let!(:account) { Fabricate(:account, domain: 'host.example') }
|
||||
let!(:test_account) { Fabricate(:account, domain: 'test.example') }
|
||||
let(:service_double) { instance_double(DeleteAccountService, call: true) }
|
||||
|
||||
before { allow(DeleteAccountService).to receive(:new).and_return(service_double) }
|
||||
|
||||
it 'calls the delete service for accounts from the relevant domain' do
|
||||
subject.call 'test.example'
|
||||
|
||||
expect(service_double)
|
||||
.to_not have_received(:call).with(account, reserve_username: false)
|
||||
expect(service_double)
|
||||
.to have_received(:call).with(test_account, reserve_username: false)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
40
spec/services/appeal_service_spec.rb
Normal file
40
spec/services/appeal_service_spec.rb
Normal file
|
@ -0,0 +1,40 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe AppealService do
|
||||
describe '#call' do
|
||||
let!(:admin) { Fabricate(:user, role: UserRole.find_by(name: 'Admin')) }
|
||||
|
||||
context 'with an existing strike' do
|
||||
let(:strike) { Fabricate(:account_warning) }
|
||||
let(:text) { 'Appeal text' }
|
||||
|
||||
it 'creates an appeal and notifies staff' do
|
||||
emails = capture_emails { subject.call(strike, text) }
|
||||
|
||||
expect(Appeal.last)
|
||||
.to have_attributes(
|
||||
strike: strike,
|
||||
text: text,
|
||||
account: strike.target_account
|
||||
)
|
||||
|
||||
expect(emails.size)
|
||||
.to eq(1)
|
||||
|
||||
expect(emails.first)
|
||||
.to have_attributes(
|
||||
to: contain_exactly(admin.email),
|
||||
subject: eq(
|
||||
I18n.t(
|
||||
'admin_mailer.new_appeal.subject',
|
||||
username: strike.target_account.acct,
|
||||
instance: Rails.configuration.x.local_domain
|
||||
)
|
||||
)
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
31
spec/services/create_featured_tag_service_spec.rb
Normal file
31
spec/services/create_featured_tag_service_spec.rb
Normal file
|
@ -0,0 +1,31 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe CreateFeaturedTagService do
|
||||
describe '#call' do
|
||||
let(:tag) { 'test' }
|
||||
|
||||
context 'with a local account' do
|
||||
let(:account) { Fabricate(:account, domain: nil) }
|
||||
|
||||
it 'creates a new featured tag and distributes' do
|
||||
expect { subject.call(account, tag) }
|
||||
.to change(FeaturedTag, :count).by(1)
|
||||
expect(ActivityPub::AccountRawDistributionWorker)
|
||||
.to have_enqueued_sidekiq_job(anything, account.id)
|
||||
end
|
||||
end
|
||||
|
||||
context 'with a remote account' do
|
||||
let(:account) { Fabricate(:account, domain: 'host.example') }
|
||||
|
||||
it 'creates a new featured tag and does not distributes' do
|
||||
expect { subject.call(account, tag) }
|
||||
.to change(FeaturedTag, :count).by(1)
|
||||
expect(ActivityPub::AccountRawDistributionWorker)
|
||||
.to_not have_enqueued_sidekiq_job
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -157,8 +157,6 @@ RSpec.describe NotifyService, type: :service do
|
|||
|
||||
describe 'email' do
|
||||
before do
|
||||
ActionMailer::Base.deliveries.clear
|
||||
|
||||
user.settings.update('notification_emails.follow': enabled)
|
||||
user.save
|
||||
end
|
||||
|
@ -167,7 +165,15 @@ RSpec.describe NotifyService, type: :service do
|
|||
let(:enabled) { true }
|
||||
|
||||
it 'sends email', :sidekiq_inline do
|
||||
expect { subject }.to change(ActionMailer::Base.deliveries, :count).by(1)
|
||||
emails = capture_emails { subject }
|
||||
|
||||
expect(emails.size)
|
||||
.to eq(1)
|
||||
expect(emails.first)
|
||||
.to have_attributes(
|
||||
to: contain_exactly(user.email),
|
||||
subject: eq(I18n.t('notification_mailer.follow.subject', name: sender.acct))
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -175,7 +181,9 @@ RSpec.describe NotifyService, type: :service do
|
|||
let(:enabled) { false }
|
||||
|
||||
it "doesn't send email" do
|
||||
expect { subject }.to_not change(ActionMailer::Base.deliveries, :count).from(0)
|
||||
emails = capture_emails { subject }
|
||||
|
||||
expect(emails).to be_empty
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
16
spec/services/process_hashtags_service_spec.rb
Normal file
16
spec/services/process_hashtags_service_spec.rb
Normal file
|
@ -0,0 +1,16 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe ProcessHashtagsService do
|
||||
describe '#call' do
|
||||
let(:status) { Fabricate(:status, visibility: :public, text: 'With tags #one #two') }
|
||||
|
||||
it 'applies the tags from the status text' do
|
||||
expect { subject.call(status) }
|
||||
.to change(Tag, :count).by(2)
|
||||
expect(status.reload.tags.map(&:name))
|
||||
.to contain_exactly('one', 'two')
|
||||
end
|
||||
end
|
||||
end
|
|
@ -158,13 +158,14 @@ RSpec.describe ReportService, type: :service do
|
|||
|
||||
before do
|
||||
Fabricate(:report, target_account: target_account)
|
||||
ActionMailer::Base.deliveries.clear
|
||||
source_account.user.settings['notification_emails.report'] = true
|
||||
source_account.user.save
|
||||
end
|
||||
|
||||
it 'does not send an e-mail' do
|
||||
expect { subject.call }.to_not change(ActionMailer::Base.deliveries, :count).from(0)
|
||||
emails = capture_emails { subject.call }
|
||||
|
||||
expect(emails).to be_empty
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -28,6 +28,6 @@ describe 'OCR', :paperclip_processing, :sidekiq_inline do
|
|||
|
||||
click_on('Detect text from picture')
|
||||
|
||||
expect(page).to have_css('#upload-modal__description', text: 'Hello Mastodon')
|
||||
expect(page).to have_css('#upload-modal__description', text: /Hello Mastodon\s*/, wait: 10)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -15,12 +15,17 @@ describe BackupWorker do
|
|||
let!(:other_backup) { Fabricate(:backup, user: backup.user) }
|
||||
|
||||
it 'sends the backup to the service and removes other backups', :sidekiq_inline do
|
||||
expect do
|
||||
worker.perform(backup.id)
|
||||
end.to change(UserMailer.deliveries, :size).by(1)
|
||||
emails = capture_emails { worker.perform(backup.id) }
|
||||
|
||||
expect(service).to have_received(:call).with(backup)
|
||||
expect { other_backup.reload }.to raise_error(ActiveRecord::RecordNotFound)
|
||||
expect(emails.size)
|
||||
.to eq(1)
|
||||
expect(emails.first)
|
||||
.to have_attributes(
|
||||
to: contain_exactly(backup.user.email),
|
||||
subject: I18n.t('user_mailer.backup_ready.subject')
|
||||
)
|
||||
end
|
||||
|
||||
context 'when sidekiq retries are exhausted' do
|
||||
|
|
|
@ -0,0 +1,60 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
describe Scheduler::AutoCloseRegistrationsScheduler do
|
||||
subject { described_class.new }
|
||||
|
||||
describe '#perform' do
|
||||
let(:moderator_activity_date) { Time.now.utc }
|
||||
|
||||
before do
|
||||
Fabricate(:user, role: UserRole.find_by(name: 'Owner'), current_sign_in_at: 10.years.ago)
|
||||
Fabricate(:user, role: UserRole.find_by(name: 'Moderator'), current_sign_in_at: moderator_activity_date)
|
||||
end
|
||||
|
||||
context 'when registrations are open' do
|
||||
before do
|
||||
Setting.registrations_mode = 'open'
|
||||
end
|
||||
|
||||
context 'when a moderator has logged in recently' do
|
||||
let(:moderator_activity_date) { Time.now.utc }
|
||||
|
||||
it 'does not change registrations mode' do
|
||||
expect { subject.perform }.to_not change(Setting, :registrations_mode)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when a moderator has not recently signed in' do
|
||||
let(:moderator_activity_date) { 1.year.ago }
|
||||
|
||||
it 'changes registrations mode from open to approved' do
|
||||
expect { subject.perform }.to change(Setting, :registrations_mode).from('open').to('approved')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'when registrations are closed' do
|
||||
before do
|
||||
Setting.registrations_mode = 'none'
|
||||
end
|
||||
|
||||
context 'when a moderator has logged in recently' do
|
||||
let(:moderator_activity_date) { Time.now.utc }
|
||||
|
||||
it 'does not change registrations mode' do
|
||||
expect { subject.perform }.to_not change(Setting, :registrations_mode)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when a moderator has not recently signed in' do
|
||||
let(:moderator_activity_date) { 1.year.ago }
|
||||
|
||||
it 'does not change registrations mode' do
|
||||
expect { subject.perform }.to_not change(Setting, :registrations_mode)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue