Merge remote-tracking branch 'parent/main' into upstream-20241119

This commit is contained in:
KMY 2024-11-19 08:49:55 +09:00
commit 055045981f
221 changed files with 2006 additions and 1127 deletions

View file

@ -7,10 +7,6 @@ RSpec.describe Api::BaseController do
def success
head 200
end
def failure
FakeService.new
end
end
it 'returns private cache control headers by default' do

View file

@ -8,9 +8,7 @@ RSpec.describe Auth::ChallengesController do
let(:password) { 'foobar12345' }
let(:user) { Fabricate(:user, password: password) }
before do
sign_in user
end
before { sign_in user }
describe 'POST #create' do
let(:return_to) { edit_user_registration_path }
@ -18,28 +16,24 @@ RSpec.describe Auth::ChallengesController do
context 'with correct password' do
before { post :create, params: { form_challenge: { return_to: return_to, current_password: password } } }
it 'redirects back' do
expect(response).to redirect_to(return_to)
end
it 'sets session' do
expect(session[:challenge_passed_at]).to_not be_nil
it 'redirects back and sets challenge passed at in session' do
expect(response)
.to redirect_to(return_to)
expect(session[:challenge_passed_at])
.to_not be_nil
end
end
context 'with incorrect password' do
before { post :create, params: { form_challenge: { return_to: return_to, current_password: 'hhfggjjd562' } } }
it 'renders challenge' do
expect(response).to render_template('auth/challenges/new')
end
it 'displays error' do
expect(response.body).to include 'Invalid password'
end
it 'does not set session' do
expect(session[:challenge_passed_at]).to be_nil
it 'renders challenge, displays error, does not set session' do
expect(response)
.to render_template('auth/challenges/new')
expect(response.body)
.to include 'Invalid password'
expect(session[:challenge_passed_at])
.to be_nil
end
end
end

View file

@ -23,12 +23,11 @@ RSpec.describe Auth::ConfirmationsController do
get :show, params: { confirmation_token: 'foobar' }
end
it 'redirects to login' do
expect(response).to redirect_to(new_user_session_path)
end
it 'queues up bootstrapping of home timeline' do
expect(BootstrapTimelineWorker).to have_received(:perform_async).with(user.account_id)
it 'redirects to login and queues worker' do
expect(response)
.to redirect_to(new_user_session_path)
expect(BootstrapTimelineWorker)
.to have_received(:perform_async).with(user.account_id)
end
end
@ -88,13 +87,13 @@ RSpec.describe Auth::ConfirmationsController do
get :show, params: { confirmation_token: 'foobar' }
end
it 'redirects to login and confirms email' do
expect(response).to redirect_to(new_user_session_path)
expect(user.reload.unconfirmed_email).to be_nil
end
it 'does not queue up bootstrapping of home timeline' do
expect(BootstrapTimelineWorker).to_not have_received(:perform_async)
it 'redirects to login, confirms email, does not queue worker' do
expect(response)
.to redirect_to(new_user_session_path)
expect(user.reload.unconfirmed_email)
.to be_nil
expect(BootstrapTimelineWorker)
.to_not have_received(:perform_async)
end
end
end

View file

@ -57,29 +57,30 @@ RSpec.describe Auth::PasswordsController do
post :update, params: { user: { password: password, password_confirmation: password, reset_password_token: token } }
end
it 'redirect to sign in' do
expect(response).to redirect_to '/auth/sign_in'
end
it 'resets the password' do
expect(response)
.to redirect_to '/auth/sign_in'
it 'changes password' do
this_user = User.find(user.id)
# Change password
expect(User.find(user.id))
.to be_present
.and be_valid_password(password)
expect(this_user).to_not be_nil
expect(this_user.valid_password?(password)).to be true
end
# Deactivate session
expect(user.session_activations.count)
.to eq 0
expect { session_activation.reload }
.to raise_error(ActiveRecord::RecordNotFound)
it 'deactivates all sessions' do
expect(user.session_activations.count).to eq 0
expect { session_activation.reload }.to raise_error(ActiveRecord::RecordNotFound)
end
# Revoke tokens
expect(Doorkeeper::AccessToken.active_for(user).count)
.to eq 0
it 'revokes all access tokens' do
expect(Doorkeeper::AccessToken.active_for(user).count).to eq 0
end
it 'removes push subscriptions' do
expect(Web::PushSubscription.where(user: user).or(Web::PushSubscription.where(access_token: access_token)).count).to eq 0
expect { web_push_subscription.reload }.to raise_error(ActiveRecord::RecordNotFound)
# Remove push subs
expect(Web::PushSubscription.where(user: user).or(Web::PushSubscription.where(access_token: access_token)).count)
.to eq 0
expect { web_push_subscription.reload }
.to raise_error(ActiveRecord::RecordNotFound)
end
end
@ -88,15 +89,13 @@ RSpec.describe Auth::PasswordsController do
post :update, params: { user: { password: password, password_confirmation: password, reset_password_token: 'some_invalid_value' } }
end
it 'renders reset password' do
expect(response).to render_template(:new)
end
it 'renders reset password and retains password' do
expect(response)
.to render_template(:new)
it 'retains password' do
this_user = User.find(user.id)
expect(this_user).to_not be_nil
expect(this_user.external_or_valid_password?(user.password)).to be true
expect(User.find(user.id))
.to be_present
.and be_external_or_valid_password(user.password)
end
end
end

View file

@ -6,25 +6,33 @@ RSpec.describe Auth::RegistrationsController do
render_views
shared_examples 'checks for enabled registrations' do |path|
it 'redirects if it is in single user mode while it is open for registration' do
Fabricate(:account)
Setting.registrations_mode = 'open'
allow(Rails.configuration.x).to receive(:single_user_mode).and_return(true)
context 'when in single user mode and open for registration' do
before do
Setting.registrations_mode = 'open'
allow(Rails.configuration.x).to receive(:single_user_mode).and_return(true)
end
get path
it 'redirects to root' do
Fabricate(:account)
get path
expect(response).to redirect_to '/'
expect(Rails.configuration.x).to have_received(:single_user_mode)
expect(response).to redirect_to '/'
expect(Rails.configuration.x).to have_received(:single_user_mode)
end
end
it 'redirects if it is not open for registration while it is not in single user mode' do
Setting.registrations_mode = 'none'
allow(Rails.configuration.x).to receive(:single_user_mode).and_return(false)
context 'when registrations closed and not in single user mode' do
before do
Setting.registrations_mode = 'none'
allow(Rails.configuration.x).to receive(:single_user_mode).and_return(false)
end
get path
it 'redirects to root' do
get path
expect(response).to redirect_to '/'
expect(Rails.configuration.x).to have_received(:single_user_mode)
expect(response).to redirect_to '/'
expect(Rails.configuration.x).to have_received(:single_user_mode)
end
end
end
@ -35,12 +43,12 @@ RSpec.describe Auth::RegistrationsController do
get :edit
end
it 'returns http success' do
expect(response).to have_http_status(200)
end
it 'returns http success and cache headers' do
expect(response)
.to have_http_status(200)
it 'returns private cache control header' do
expect(response.headers['Cache-Control']).to include('private, no-store')
expect(response.headers['Cache-Control'])
.to include('private, no-store')
end
end
@ -53,14 +61,13 @@ RSpec.describe Auth::RegistrationsController do
sign_in(user, scope: :user)
end
it 'returns http success' do
it 'returns http success and cache headers' do
put :update
expect(response).to have_http_status(200)
end
it 'returns private cache control headers' do
put :update
expect(response.headers['Cache-Control']).to include('private, no-store')
expect(response)
.to have_http_status(200)
expect(response.headers['Cache-Control'])
.to include('private, no-store')
end
it 'can update the user email' do
@ -174,16 +181,14 @@ RSpec.describe Auth::RegistrationsController do
post :create, params: { user: { account_attributes: { username: 'test' }, email: 'test@example.com', password: '12345678', password_confirmation: '12345678', agreement: 'true' } }
end
it 'redirects to setup' do
it 'redirects to setup and creates user' do
subject
expect(response).to redirect_to auth_setup_path
end
it 'creates user' do
subject
user = User.find_by(email: 'test@example.com')
expect(user).to_not be_nil
expect(user.locale).to eq(accept_language)
expect(response)
.to redirect_to auth_setup_path
expect(User.find_by(email: 'test@example.com'))
.to be_present
.and have_attributes(locale: eq(accept_language))
end
end
@ -254,17 +259,18 @@ RSpec.describe Auth::RegistrationsController do
post :create, params: { user: { account_attributes: { username: 'test' }, email: 'test@example.com', password: '12345678', password_confirmation: '12345678', agreement: 'true' } }
end
it 'redirects to setup' do
it 'redirects to setup and creates user' do
subject
expect(response).to redirect_to auth_setup_path
end
it 'creates user' do
subject
user = User.find_by(email: 'test@example.com')
expect(user).to_not be_nil
expect(user.locale).to eq(accept_language)
expect(user.approved).to be(false)
expect(response)
.to redirect_to auth_setup_path
expect(User.find_by(email: 'test@example.com'))
.to be_present
.and have_attributes(
locale: eq(accept_language),
approved: be(false)
)
end
end
@ -276,17 +282,17 @@ RSpec.describe Auth::RegistrationsController 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
it 'redirects to setup' do
it 'redirects to setup and creates user' do
subject
expect(response).to redirect_to auth_setup_path
end
it 'creates user' do
subject
user = User.find_by(email: 'test@example.com')
expect(user).to_not be_nil
expect(user.locale).to eq(accept_language)
expect(user.approved).to be(false)
expect(response).to redirect_to auth_setup_path
expect(User.find_by(email: 'test@example.com'))
.to be_present
.and have_attributes(
locale: eq(accept_language),
approved: be(false)
)
end
end
@ -300,17 +306,17 @@ RSpec.describe Auth::RegistrationsController 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
it 'redirects to setup' do
it 'redirects to setup and creates user' do
subject
expect(response).to redirect_to auth_setup_path
end
it 'creates user' do
subject
user = User.find_by(email: 'test@example.com')
expect(user).to_not be_nil
expect(user.locale).to eq(accept_language)
expect(user.approved).to be(true)
expect(response).to redirect_to auth_setup_path
expect(User.find_by(email: 'test@example.com'))
.to be_present
.and have_attributes(
locale: eq(accept_language),
approved: be(true)
)
end
end
@ -512,12 +518,11 @@ RSpec.describe Auth::RegistrationsController do
delete :destroy
end
it 'returns http not found' do
expect(response).to have_http_status(404)
end
it 'does not delete user' do
expect(User.find(user.id)).to_not be_nil
it 'returns http not found and keeps user' do
expect(response)
.to have_http_status(404)
expect(User.find(user.id))
.to_not be_nil
end
end
end

BIN
spec/fixtures/files/avatar-high.gif vendored Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 73 KiB

View file

@ -3,16 +3,6 @@
require 'rails_helper'
RSpec.describe AccountsHelper do
def set_not_embedded_view
params[:controller] = "not_#{StatusesHelper::EMBEDDED_CONTROLLER}"
params[:action] = "not_#{StatusesHelper::EMBEDDED_ACTION}"
end
def set_embedded_view
params[:controller] = StatusesHelper::EMBEDDED_CONTROLLER
params[:action] = StatusesHelper::EMBEDDED_ACTION
end
describe '#display_name' do
it 'uses the display name when it exists' do
account = Account.new(display_name: 'Display', username: 'Username')
@ -28,9 +18,8 @@ RSpec.describe AccountsHelper do
end
describe '#acct' do
it 'is fully qualified for embedded local accounts' do
it 'is fully qualified for local accounts' do
allow(Rails.configuration.x).to receive(:local_domain).and_return('local_domain')
set_embedded_view
account = Account.new(domain: nil, username: 'user')
acct = helper.acct(account)
@ -38,32 +27,12 @@ RSpec.describe AccountsHelper do
expect(acct).to eq '@user@local_domain'
end
it 'is fully qualified for embedded foreign accounts' do
set_embedded_view
it 'is fully qualified for remote accounts' do
account = Account.new(domain: 'foreign_server.com', username: 'user')
acct = helper.acct(account)
expect(acct).to eq '@user@foreign_server.com'
end
it 'is fully qualified for non embedded foreign accounts' do
set_not_embedded_view
account = Account.new(domain: 'foreign_server.com', username: 'user')
acct = helper.acct(account)
expect(acct).to eq '@user@foreign_server.com'
end
it 'is fully qualified for non embedded local accounts' do
allow(Rails.configuration.x).to receive(:local_domain).and_return('local_domain')
set_not_embedded_view
account = Account.new(domain: nil, username: 'user')
acct = helper.acct(account)
expect(acct).to eq '@user@local_domain'
end
end
end

View file

@ -261,11 +261,11 @@ RSpec.describe ApplicationHelper do
expect(helper.html_title).to be_html_safe
end
it 'removes extra new lines' do
it 'does not escape twice' do
Setting.site_title = 'Site Title'
helper.content_for(:page_title, "Test Value\n")
helper.content_for(:page_title, '"Test Value"'.html_safe)
expect(helper.html_title).to eq 'Test Value - Site Title'
expect(helper.html_title).to eq '"Test Value" - Site Title'
expect(helper.html_title).to be_html_safe
end
end

View file

@ -3,19 +3,20 @@
require 'rails_helper'
RSpec.describe SelfDestructHelper do
describe 'self_destruct?' do
describe '#self_destruct?' do
before { Rails.configuration.x.mastodon.self_destruct_value = destruct_value }
after { Rails.configuration.x.mastodon.self_destruct_value = nil }
context 'when SELF_DESTRUCT is unset' do
let(:destruct_value) { nil }
it 'returns false' do
expect(helper.self_destruct?).to be false
end
end
context 'when SELF_DESTRUCT is set to an invalid value' do
around do |example|
ClimateControl.modify SELF_DESTRUCT: 'true' do
example.run
end
end
let(:destruct_value) { 'true' }
it 'returns false' do
expect(helper.self_destruct?).to be false
@ -23,9 +24,10 @@ RSpec.describe SelfDestructHelper do
end
context 'when SELF_DESTRUCT is set to value signed for the wrong purpose' do
let(:destruct_value) { Rails.configuration.x.mastodon.self_destruct_value = Rails.application.message_verifier('foo').generate('example.com') }
around do |example|
ClimateControl.modify(
SELF_DESTRUCT: Rails.application.message_verifier('foo').generate('example.com'),
LOCAL_DOMAIN: 'example.com'
) do
example.run
@ -38,9 +40,10 @@ RSpec.describe SelfDestructHelper do
end
context 'when SELF_DESTRUCT is set to value signed for the wrong domain' do
let(:destruct_value) { Rails.configuration.x.mastodon.self_destruct_value = Rails.application.message_verifier(described_class::VERIFY_PURPOSE).generate('foo.com') }
around do |example|
ClimateControl.modify(
SELF_DESTRUCT: Rails.application.message_verifier('self-destruct').generate('foo.com'),
LOCAL_DOMAIN: 'example.com'
) do
example.run
@ -53,9 +56,10 @@ RSpec.describe SelfDestructHelper do
end
context 'when SELF_DESTRUCT is set to a correctly-signed value' do
let(:destruct_value) { Rails.configuration.x.mastodon.self_destruct_value = Rails.application.message_verifier(described_class::VERIFY_PURPOSE).generate('example.com') }
around do |example|
ClimateControl.modify(
SELF_DESTRUCT: Rails.application.message_verifier('self-destruct').generate('example.com'),
LOCAL_DOMAIN: 'example.com'
) do
example.run

View file

@ -107,28 +107,4 @@ RSpec.describe StatusesHelper do
end
end
end
describe '#stream_link_target' do
it 'returns nil if it is not an embedded view' do
set_not_embedded_view
expect(helper.stream_link_target).to be_nil
end
it 'returns _blank if it is an embedded view' do
set_embedded_view
expect(helper.stream_link_target).to eq '_blank'
end
end
def set_not_embedded_view
params[:controller] = "not_#{StatusesHelper::EMBEDDED_CONTROLLER}"
params[:action] = "not_#{StatusesHelper::EMBEDDED_ACTION}"
end
def set_embedded_view
params[:controller] = StatusesHelper::EMBEDDED_CONTROLLER
params[:action] = StatusesHelper::EMBEDDED_ACTION
end
end

View file

@ -0,0 +1,19 @@
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe DomainResource do
describe '#mx' do
subject { described_class.new(domain) }
let(:domain) { 'example.host' }
let(:exchange) { 'mx.host' }
before { configure_mx(domain: domain, exchange: exchange) }
it 'returns array of hostnames' do
expect(subject.mx)
.to eq([exchange])
end
end
end

View file

@ -63,6 +63,22 @@ RSpec.describe Mastodon::CLI::EmailDomainBlocks do
.and(change(EmailDomainBlock, :count).by(1))
end
end
context 'with --with-dns-records true' do
let(:domain) { 'host.example' }
let(:arguments) { [domain] }
let(:options) { { with_dns_records: true } }
before do
configure_mx(domain: domain, exchange: 'other.host')
end
it 'adds a new block for parent and children' do
expect { subject }
.to output_results('Added 2')
.and(change(EmailDomainBlock, :count).by(2))
end
end
end
describe '#remove' do

View file

@ -16,6 +16,7 @@ RSpec.describe SearchQueryTransformer do
['"2022-01-01"', '2022-01-01'],
['12345678', '12345678'],
['"12345678"', '12345678'],
['"2024-10-31T23:47:20Z"', '2024-10-31T23:47:20Z'],
].each do |value, parsed|
context "with #{operator}:#{value}" do
let(:query) { "#{operator}:#{value}" }
@ -34,7 +35,7 @@ RSpec.describe SearchQueryTransformer do
let(:query) { "#{operator}:\"abc\"" }
it 'raises an exception' do
expect { subject }.to raise_error(Mastodon::FilterValidationError, 'Invalid date abc')
expect { subject }.to raise_error(Date::Error)
end
end
end

View file

@ -7,7 +7,7 @@ RSpec.describe Account::Sensitizes do
describe '.sensitized' do
let(:sensitized_account) { Fabricate :account, sensitized_at: 2.days.ago }
before { Fabricate :account, sensitized_at: false }
before { Fabricate :account, sensitized_at: nil }
it 'returns an array of accounts who are sensitized' do
expect(Account.sensitized)

View file

@ -237,51 +237,26 @@ RSpec.describe Form::Import do
let(:import_file) { file }
let(:import_mode) { mode }
before do
subject.save
end
it 'creates the expected rows' do
expect(account.bulk_imports.first.rows.pluck(:data)).to match_array(expected_rows)
end
before { subject.save }
context 'with a BulkImport' do
let(:bulk_import) { account.bulk_imports.first }
it 'creates a non-nil bulk import' do
expect(bulk_import).to_not be_nil
end
it 'matches the subjects type' do
expect(bulk_import.type.to_sym).to eq subject.type.to_sym
end
it 'matches the subjects original filename' do
expect(bulk_import.original_filename).to eq subject.data.original_filename
end
it 'matches the subjects likely_mismatched? value' do
expect(bulk_import.likely_mismatched?).to eq subject.likely_mismatched?
end
it 'matches the subject overwrite value' do
expect(bulk_import.overwrite?).to eq !!subject.overwrite # rubocop:disable Style/DoubleNegation
end
it 'has zero processed items' do
expect(bulk_import.processed_items).to eq 0
end
it 'has zero imported items' do
expect(bulk_import.imported_items).to eq 0
end
it 'has a correct total_items value' do
expect(bulk_import.total_items).to eq bulk_import.rows.count
end
it 'defaults to unconfirmed true' do
expect(bulk_import.state_unconfirmed?).to be true
it 'creates a bulk import with correct values' do
expect(bulk_import)
.to be_present
.and have_attributes(
type: eq(subject.type),
original_filename: eq(subject.data.original_filename),
likely_mismatched?: eq(subject.likely_mismatched?),
overwrite?: eq(!!subject.overwrite), # rubocop:disable Style/DoubleNegation
processed_items: eq(0),
imported_items: eq(0),
total_items: eq(bulk_import.rows.count),
state_unconfirmed?: be(true)
)
expect(bulk_import.rows.pluck(:data))
.to match_array(expected_rows)
end
end
end

View file

@ -11,7 +11,11 @@ RSpec.describe List do
context 'when account has hit max list limit' do
let(:account) { Fabricate :account }
before { stub_const 'List::PER_ACCOUNT_LIMIT', 0 }
before do
stub_const 'List::PER_ACCOUNT_LIMIT', 1
Fabricate(:list, account: account)
end
context 'when creating a new list' do
it { is_expected.to_not allow_value(account).for(:account).against(:base).with_message(I18n.t('lists.errors.limit')) }

View file

@ -3,6 +3,60 @@
require 'rails_helper'
RSpec.describe SoftwareUpdate do
describe '#pending?' do
subject { described_class.new(version: update_version) }
before { allow(Mastodon::Version).to receive(:gem_version).and_return(Gem::Version.new(mastodon_version)) }
context 'when the runtime version is older than the update' do
let(:mastodon_version) { '4.0.0' }
let(:update_version) { '5.0.0' }
it { is_expected.to be_pending }
end
context 'when the runtime version is newer than the update' do
let(:mastodon_version) { '6.0.0' }
let(:update_version) { '5.0.0' }
it { is_expected.to_not be_pending }
end
context 'when the runtime version is same as the update' do
let(:mastodon_version) { '4.0.0' }
let(:update_version) { '4.0.0' }
it { is_expected.to_not be_pending }
end
end
describe '#outdated?' do
subject { described_class.new(version: update_version) }
before { allow(Mastodon::Version).to receive(:gem_version).and_return(Gem::Version.new(mastodon_version)) }
context 'when the runtime version is older than the update' do
let(:mastodon_version) { '4.0.0' }
let(:update_version) { '5.0.0' }
it { is_expected.to_not be_outdated }
end
context 'when the runtime version is newer than the update' do
let(:mastodon_version) { '6.0.0' }
let(:update_version) { '5.0.0' }
it { is_expected.to be_outdated }
end
context 'when the runtime version is same as the update' do
let(:mastodon_version) { '4.0.0' }
let(:update_version) { '4.0.0' }
it { is_expected.to be_outdated }
end
end
describe '.pending_to_a' do
before do
allow(Mastodon::Version).to receive(:gem_version).and_return(Gem::Version.new(mastodon_version))

View file

@ -630,4 +630,27 @@ RSpec.describe User do
end
end
end
describe '#applications_last_used' do
let!(:user) { Fabricate(:user) }
let!(:never_used_application) { Fabricate :application, owner: user }
let!(:application_one) { Fabricate :application, owner: user }
let!(:application_two) { Fabricate :application, owner: user }
before do
_other_user_token = Fabricate :access_token, last_used_at: 3.days.ago
_never_used_token = Fabricate :access_token, application: never_used_application, resource_owner_id: user.id, last_used_at: nil
_app_one_old_token = Fabricate :access_token, application: application_one, resource_owner_id: user.id, last_used_at: 5.days.ago
_app_one_new_token = Fabricate :access_token, application: application_one, resource_owner_id: user.id, last_used_at: 1.day.ago
_never_used_token = Fabricate :access_token, application: application_two, resource_owner_id: user.id, last_used_at: 5.days.ago
end
it 'returns a hash of unique applications with last used values' do
expect(user.applications_last_used)
.to include(application_one.id => be_within(1.0).of(1.day.ago))
.and include(application_two.id => be_within(1.0).of(5.days.ago))
.and not_include(never_used_application.id)
end
end
end

View file

@ -27,6 +27,7 @@ RSpec.describe SoftwareUpdateCheckService do
before do
Fabricate(:software_update, version: '3.5.0', type: 'major', urgent: false)
Fabricate(:software_update, version: '42.13.12', type: 'major', urgent: false)
Fabricate(:software_update, version: 'Malformed', type: 'major', urgent: false)
owner_user.settings.update('notification_emails.software_updates': 'all')
owner_user.save!
@ -50,7 +51,7 @@ RSpec.describe SoftwareUpdateCheckService do
end
it 'deletes outdated update records but keeps valid update records' do
expect { subject.call }.to change { SoftwareUpdate.pluck(:version).sort }.from(['3.5.0', '42.13.12']).to(['42.13.12'])
expect { subject.call }.to change { SoftwareUpdate.pluck(:version).sort }.from(['3.5.0', '42.13.12', 'Malformed']).to(['42.13.12'])
end
end
@ -85,7 +86,7 @@ RSpec.describe SoftwareUpdateCheckService do
end
it 'updates the list of known updates' do
expect { subject.call }.to change { SoftwareUpdate.pluck(:version).sort }.from(['3.5.0', '42.13.12']).to(['4.2.1', '4.3.0', '5.0.0'])
expect { subject.call }.to change { SoftwareUpdate.pluck(:version).sort }.from(['3.5.0', '42.13.12', 'Malformed']).to(['4.2.1', '4.3.0', '5.0.0'])
end
context 'when no update is urgent' do

View file

@ -2,13 +2,20 @@
RSpec.shared_examples 'AccountAvatar' do |fabricator|
describe 'static avatars', :attachment_processing do
describe 'when GIF' do
describe 'with a square GIF' do
it 'creates a png static style' do
account = Fabricate(fabricator, avatar: attachment_fixture('avatar.gif'))
expect(account.avatar_static_url).to_not eq account.avatar_original_url
end
end
describe 'with a higher-than-wide GIF' do
it 'creates a png static style' do
account = Fabricate(fabricator, avatar: attachment_fixture('avatar-high.gif'))
expect(account.avatar_static_url).to_not eq account.avatar_original_url
end
end
describe 'when non-GIF' do
it 'does not create extra static style' do
account = Fabricate(fabricator, avatar: attachment_fixture('attachment.jpg'))

View file

@ -8,5 +8,6 @@ RSpec.describe 'About page' do
expect(page)
.to have_css('noscript', text: /Mastodon/)
.and have_css('body', class: 'app-body')
end
end

View file

@ -11,6 +11,7 @@ RSpec.describe 'Home page' do
expect(page)
.to have_css('noscript', text: /Mastodon/)
.and have_css('body', class: 'app-body')
end
end
@ -20,6 +21,7 @@ RSpec.describe 'Home page' do
expect(page)
.to have_css('noscript', text: /Mastodon/)
.and have_css('body', class: 'app-body')
end
end
end

View file

@ -8,5 +8,6 @@ RSpec.describe 'Privacy policy page' do
expect(page)
.to have_css('noscript', text: /Mastodon/)
.and have_css('body', class: 'app-body')
end
end

View file

@ -13,6 +13,7 @@ RSpec.describe 'Tags' do
expect(page)
.to have_css('noscript', text: /Mastodon/)
.and have_css('body', class: 'app-body')
.and have_private_cache_control
end
end

View file

@ -18,7 +18,7 @@ RSpec.describe 'statuses/show.html.haml' do
assign(:descendant_threads, [])
end
it 'has valid opengraph tags' do
it 'has valid opengraph tags and twitter player tags' do
render
expect(header_tags)
@ -26,10 +26,6 @@ RSpec.describe 'statuses/show.html.haml' do
.and match(/<meta content="article" property="og:type">/)
.and match(/<meta content=".+" property="og:image">/)
.and match(%r{<meta content="http://.+" property="og:url">})
end
it 'has twitter player tag' do
render
expect(header_tags)
.to match(%r{<meta content="http://.+/media/.+/player" property="twitter:player">})

View file

@ -5,26 +5,45 @@ require 'rails_helper'
RSpec.describe ActivityPub::DeliveryWorker do
include RoutingHelper
subject { described_class.new }
let(:sender) { Fabricate(:account) }
let(:sender) { Fabricate(:account) }
let(:payload) { 'test' }
let(:url) { 'https://example.com/api' }
before do
allow(sender).to receive(:remote_followers_hash).with('https://example.com/api').and_return('somehash')
allow(sender).to receive(:remote_followers_hash).with(url).and_return('somehash')
allow(Account).to receive(:find).with(sender.id).and_return(sender)
end
describe 'perform' do
it 'performs a request' do
stub_request(:post, 'https://example.com/api').to_return(status: 200)
subject.perform(payload, sender.id, 'https://example.com/api', { synchronize_followers: true })
expect(a_request(:post, 'https://example.com/api').with(headers: { 'Collection-Synchronization' => "collectionId=\"#{account_followers_url(sender)}\", digest=\"somehash\", url=\"#{account_followers_synchronization_url(sender)}\"" })).to have_been_made.once
context 'with successful request' do
before { stub_request(:post, url).to_return(status: 200) }
it 'performs a request to synchronize collection' do
subject.perform(payload, sender.id, url, { synchronize_followers: true })
expect(request_to_url)
.to have_been_made.once
end
def request_to_url
a_request(:post, url)
.with(
headers: {
'Collection-Synchronization' => <<~VALUES.squish,
collectionId="#{account_followers_url(sender)}", digest="somehash", url="#{account_followers_synchronization_url(sender)}"
VALUES
}
)
end
end
it 'raises when request fails' do
stub_request(:post, 'https://example.com/api').to_return(status: 500)
expect { subject.perform(payload, sender.id, 'https://example.com/api') }.to raise_error Mastodon::UnexpectedResponseError
context 'with failing request' do
before { stub_request(:post, url).to_return(status: 500) }
it 'raises error' do
expect { subject.perform(payload, sender.id, url) }
.to raise_error Mastodon::UnexpectedResponseError
end
end
end
end