Merge commit '389a6cc4c0
' into upstream-20231108
This commit is contained in:
commit
08f86bcb8f
107 changed files with 970 additions and 703 deletions
|
@ -18,21 +18,8 @@ RSpec.describe Admin::AccountsController do
|
|||
end
|
||||
|
||||
it 'filters with parameters' do
|
||||
new = AccountFilter.method(:new)
|
||||
|
||||
expect(AccountFilter).to receive(:new) do |params|
|
||||
h = params.to_h
|
||||
|
||||
expect(h[:origin]).to eq 'local'
|
||||
expect(h[:by_domain]).to eq 'domain'
|
||||
expect(h[:status]).to eq 'active'
|
||||
expect(h[:username]).to eq 'username'
|
||||
expect(h[:display_name]).to eq 'display name'
|
||||
expect(h[:email]).to eq 'local-part@domain'
|
||||
expect(h[:ip]).to eq '0.0.0.42'
|
||||
|
||||
new.call({})
|
||||
end
|
||||
account_filter = instance_double(AccountFilter, results: Account.all)
|
||||
allow(AccountFilter).to receive(:new).and_return(account_filter)
|
||||
|
||||
get :index, params: {
|
||||
origin: 'local',
|
||||
|
@ -43,6 +30,18 @@ RSpec.describe Admin::AccountsController do
|
|||
email: 'local-part@domain',
|
||||
ip: '0.0.0.42',
|
||||
}
|
||||
|
||||
expect(AccountFilter).to have_received(:new) do |params|
|
||||
h = params.to_h
|
||||
|
||||
expect(h[:origin]).to eq 'local'
|
||||
expect(h[:by_domain]).to eq 'domain'
|
||||
expect(h[:status]).to eq 'active'
|
||||
expect(h[:username]).to eq 'username'
|
||||
expect(h[:display_name]).to eq 'display name'
|
||||
expect(h[:email]).to eq 'local-part@domain'
|
||||
expect(h[:ip]).to eq '0.0.0.42'
|
||||
end
|
||||
end
|
||||
|
||||
it 'paginates accounts' do
|
||||
|
|
|
@ -19,10 +19,6 @@ RSpec.describe Admin::Settings::BrandingController do
|
|||
end
|
||||
|
||||
describe 'PUT #update' do
|
||||
before do
|
||||
allow_any_instance_of(Form::AdminSettings).to receive(:valid?).and_return(true)
|
||||
end
|
||||
|
||||
around do |example|
|
||||
before = Setting.site_short_description
|
||||
Setting.site_short_description = nil
|
||||
|
|
|
@ -3,14 +3,14 @@
|
|||
require 'rails_helper'
|
||||
|
||||
describe Api::V1::StreamingController do
|
||||
around(:each) do |example|
|
||||
around do |example|
|
||||
before = Rails.configuration.x.streaming_api_base_url
|
||||
Rails.configuration.x.streaming_api_base_url = Rails.configuration.x.web_domain
|
||||
example.run
|
||||
Rails.configuration.x.streaming_api_base_url = before
|
||||
end
|
||||
|
||||
before(:each) do
|
||||
before do
|
||||
request.headers.merge! Host: Rails.configuration.x.web_domain
|
||||
end
|
||||
|
||||
|
@ -24,7 +24,7 @@ describe Api::V1::StreamingController do
|
|||
end
|
||||
|
||||
context 'with streaming api on different host' do
|
||||
before(:each) do
|
||||
before do
|
||||
Rails.configuration.x.streaming_api_base_url = "wss://streaming-#{Rails.configuration.x.web_domain}"
|
||||
@streaming_host = URI.parse(Rails.configuration.x.streaming_api_base_url).host
|
||||
end
|
||||
|
|
|
@ -53,7 +53,7 @@ RSpec.describe Api::V2::SearchController do
|
|||
|
||||
context 'without token' do
|
||||
describe 'GET #index' do
|
||||
let(:search_params) {}
|
||||
let(:search_params) { nil }
|
||||
|
||||
before do
|
||||
get :index, params: search_params
|
||||
|
|
|
@ -8,13 +8,11 @@ describe EmojisController do
|
|||
let(:emoji) { Fabricate(:custom_emoji) }
|
||||
|
||||
describe 'GET #show' do
|
||||
subject(:body) { JSON.parse(response.body, symbolize_names: true) }
|
||||
|
||||
let(:response) { get :show, params: { id: emoji.id, format: :json } }
|
||||
|
||||
it 'returns the right response' do
|
||||
expect(response).to have_http_status 200
|
||||
expect(body[:name]).to eq ':coolcat:'
|
||||
expect(body_as_json[:name]).to eq ':coolcat:'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -16,7 +16,7 @@ describe WellKnown::WebfingerController do
|
|||
let(:alice) { Fabricate(:account, username: 'alice') }
|
||||
let(:resource) { nil }
|
||||
|
||||
around(:each) do |example|
|
||||
around do |example|
|
||||
tmp = Rails.configuration.x.alternate_domains
|
||||
Rails.configuration.x.alternate_domains = alternate_domains
|
||||
example.run
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
Fabricator :access_token, from: 'Doorkeeper::AccessToken' do
|
||||
end
|
||||
Fabricator :access_token, from: 'Doorkeeper::AccessToken'
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
Fabricator(:conversation) do
|
||||
end
|
||||
Fabricator(:conversation)
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
Fabricator(:system_key) do
|
||||
end
|
||||
Fabricator(:system_key)
|
||||
|
|
|
@ -7,11 +7,7 @@ describe 'email confirmation flow when captcha is enabled' do
|
|||
let(:client_app) { nil }
|
||||
|
||||
before do
|
||||
# rubocop:disable RSpec/AnyInstance -- easiest way to deal with that that I know of
|
||||
allow_any_instance_of(Auth::ConfirmationsController).to receive(:captcha_enabled?).and_return(true)
|
||||
allow_any_instance_of(Auth::ConfirmationsController).to receive(:check_captcha!).and_return(true)
|
||||
allow_any_instance_of(Auth::ConfirmationsController).to receive(:render_captcha).and_return(nil)
|
||||
# rubocop:enable RSpec/AnyInstance
|
||||
allow(Auth::ConfirmationsController).to receive(:new).and_return(stubbed_controller)
|
||||
end
|
||||
|
||||
context 'when the user signed up through an app' do
|
||||
|
@ -40,4 +36,12 @@ describe 'email confirmation flow when captcha is enabled' do
|
|||
expect(page).to have_link(I18n.t('auth.confirmations.clicking_this_link'), href: client_app.confirmation_redirect_uri)
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def stubbed_controller
|
||||
Auth::ConfirmationsController.new.tap do |controller|
|
||||
allow(controller).to receive_messages(captcha_enabled?: true, check_captcha!: true, render_captcha: nil)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -18,13 +18,15 @@ RSpec.describe Admin::AccountModerationNotesHelper do
|
|||
let(:account) { Fabricate(:account) }
|
||||
|
||||
it 'calls #link_to' do
|
||||
expect(helper).to receive(:link_to).with(
|
||||
allow(helper).to receive(:link_to)
|
||||
|
||||
helper.admin_account_link_to(account)
|
||||
|
||||
expect(helper).to have_received(:link_to).with(
|
||||
admin_account_path(account.id),
|
||||
class: name_tag_classes(account),
|
||||
title: account.acct
|
||||
)
|
||||
|
||||
helper.admin_account_link_to(account)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -18,7 +18,7 @@ describe InstanceHelper do
|
|||
end
|
||||
|
||||
describe 'site_hostname' do
|
||||
around(:each) do |example|
|
||||
around do |example|
|
||||
before = Rails.configuration.x.local_domain
|
||||
example.run
|
||||
Rails.configuration.x.local_domain = before
|
||||
|
|
|
@ -3,8 +3,6 @@
|
|||
require 'rails_helper'
|
||||
|
||||
RSpec.describe AccountStatusesFilter do
|
||||
subject { described_class.new(account, current_account, params) }
|
||||
|
||||
let(:account) { Fabricate(:account) }
|
||||
let(:current_account) { nil }
|
||||
let(:params) { {} }
|
||||
|
@ -38,6 +36,8 @@ RSpec.describe AccountStatusesFilter do
|
|||
end
|
||||
|
||||
describe '#results' do
|
||||
subject { described_class.new(account, current_account, params).results }
|
||||
|
||||
let(:tag) { Fabricate(:tag) }
|
||||
|
||||
before do
|
||||
|
@ -61,7 +61,7 @@ RSpec.describe AccountStatusesFilter do
|
|||
let(:params) { { only_media: true } }
|
||||
|
||||
it 'returns only statuses with media' do
|
||||
expect(subject.results.all?(&:with_media?)).to be true
|
||||
expect(subject.all?(&:with_media?)).to be true
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -69,7 +69,7 @@ RSpec.describe AccountStatusesFilter do
|
|||
let(:params) { { tagged: tag.name } }
|
||||
|
||||
it 'returns only statuses with tag' do
|
||||
expect(subject.results.all? { |s| s.tags.include?(tag) }).to be true
|
||||
expect(subject.all? { |s| s.tags.include?(tag) }).to be true
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -77,7 +77,7 @@ RSpec.describe AccountStatusesFilter do
|
|||
let(:params) { { exclude_replies: true } }
|
||||
|
||||
it 'returns only statuses that are not replies' do
|
||||
expect(subject.results.none?(&:reply?)).to be true
|
||||
expect(subject.none?(&:reply?)).to be true
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -85,7 +85,7 @@ RSpec.describe AccountStatusesFilter do
|
|||
let(:params) { { exclude_reblogs: true } }
|
||||
|
||||
it 'returns only statuses that are not reblogs' do
|
||||
expect(subject.results.none?(&:reblog?)).to be true
|
||||
expect(subject.none?(&:reblog?)).to be true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -94,16 +94,12 @@ RSpec.describe AccountStatusesFilter do
|
|||
let(:current_account) { nil }
|
||||
let(:direct_status) { nil }
|
||||
|
||||
it 'returns only public statuses' do
|
||||
expect(subject.results.pluck(:visibility).uniq).to match_array %w(unlisted public_unlisted public)
|
||||
end
|
||||
it 'returns only public statuses, public replies, and public reblogs' do
|
||||
expect(results_unique_visibilities).to match_array %w(unlisted public_unlisted public)
|
||||
|
||||
it 'returns public replies' do
|
||||
expect(subject.results.pluck(:in_reply_to_id)).to_not be_empty
|
||||
end
|
||||
expect(results_in_reply_to_ids).to_not be_empty
|
||||
|
||||
it 'returns public reblogs' do
|
||||
expect(subject.results.pluck(:reblog_of_id)).to_not be_empty
|
||||
expect(results_reblog_of_ids).to_not be_empty
|
||||
end
|
||||
|
||||
it_behaves_like 'filter params'
|
||||
|
@ -117,23 +113,19 @@ RSpec.describe AccountStatusesFilter do
|
|||
end
|
||||
|
||||
it 'returns nothing' do
|
||||
expect(subject.results.to_a).to be_empty
|
||||
expect(subject.to_a).to be_empty
|
||||
end
|
||||
end
|
||||
|
||||
context 'when accessed by self' do
|
||||
let(:current_account) { account }
|
||||
|
||||
it 'returns everything' do
|
||||
expect(subject.results.pluck(:visibility).uniq).to match_array %w(direct private login unlisted public_unlisted public limited)
|
||||
end
|
||||
it 'returns all statuses, replies, and reblogs' do
|
||||
expect(results_unique_visibilities).to match_array %w(direct private login unlisted public_unlisted public limited)
|
||||
|
||||
it 'returns replies' do
|
||||
expect(subject.results.pluck(:in_reply_to_id)).to_not be_empty
|
||||
end
|
||||
expect(results_in_reply_to_ids).to_not be_empty
|
||||
|
||||
it 'returns reblogs' do
|
||||
expect(subject.results.pluck(:reblog_of_id)).to_not be_empty
|
||||
expect(results_reblog_of_ids).to_not be_empty
|
||||
end
|
||||
|
||||
it_behaves_like 'filter params'
|
||||
|
@ -146,23 +138,19 @@ RSpec.describe AccountStatusesFilter do
|
|||
current_account.follow!(account)
|
||||
end
|
||||
|
||||
it 'returns private statuses' do
|
||||
expect(subject.results.pluck(:visibility).uniq).to match_array %w(private login unlisted public_unlisted public)
|
||||
end
|
||||
it 'returns private statuses, replies, and reblogs' do
|
||||
expect(results_unique_visibilities).to match_array %w(private login unlisted public_unlisted public)
|
||||
|
||||
it 'returns replies' do
|
||||
expect(subject.results.pluck(:in_reply_to_id)).to_not be_empty
|
||||
end
|
||||
expect(results_in_reply_to_ids).to_not be_empty
|
||||
|
||||
it 'returns reblogs' do
|
||||
expect(subject.results.pluck(:reblog_of_id)).to_not be_empty
|
||||
expect(results_reblog_of_ids).to_not be_empty
|
||||
end
|
||||
|
||||
context 'when there is a direct status mentioning the non-follower' do
|
||||
let!(:direct_status) { status_with_mention!(:direct, current_account) }
|
||||
|
||||
it 'returns the direct status' do
|
||||
expect(subject.results.pluck(:id)).to include(direct_status.id)
|
||||
expect(results_ids).to include(direct_status.id)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -196,23 +184,19 @@ RSpec.describe AccountStatusesFilter do
|
|||
context 'when accessed by a non-follower' do
|
||||
let(:current_account) { Fabricate(:account) }
|
||||
|
||||
it 'returns only public statuses' do
|
||||
expect(subject.results.pluck(:visibility).uniq).to match_array %w(login unlisted public_unlisted public)
|
||||
end
|
||||
it 'returns only public statuses, replies, and reblogs' do
|
||||
expect(results_unique_visibilities).to match_array %w(login unlisted public_unlisted public)
|
||||
|
||||
it 'returns public replies' do
|
||||
expect(subject.results.pluck(:in_reply_to_id)).to_not be_empty
|
||||
end
|
||||
expect(results_in_reply_to_ids).to_not be_empty
|
||||
|
||||
it 'returns public reblogs' do
|
||||
expect(subject.results.pluck(:reblog_of_id)).to_not be_empty
|
||||
expect(results_reblog_of_ids).to_not be_empty
|
||||
end
|
||||
|
||||
context 'when there is a private status mentioning the non-follower' do
|
||||
let!(:private_status) { status_with_mention!(:private, current_account) }
|
||||
|
||||
it 'returns the private status' do
|
||||
expect(subject.results.pluck(:id)).to include(private_status.id)
|
||||
expect(results_ids).to include(private_status.id)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -224,7 +208,7 @@ RSpec.describe AccountStatusesFilter do
|
|||
end
|
||||
|
||||
it 'does not return reblog of blocked account' do
|
||||
expect(subject.results.pluck(:id)).to_not include(reblog.id)
|
||||
expect(results_ids).to_not include(reblog.id)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -238,7 +222,7 @@ RSpec.describe AccountStatusesFilter do
|
|||
end
|
||||
|
||||
it 'does not return reblog of blocked domain' do
|
||||
expect(subject.results.pluck(:id)).to_not include(reblog.id)
|
||||
expect(results_ids).to_not include(reblog.id)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -252,7 +236,7 @@ RSpec.describe AccountStatusesFilter do
|
|||
end
|
||||
|
||||
it 'returns the reblog from the non-blocked domain' do
|
||||
expect(subject.results.pluck(:id)).to include(reblog.id)
|
||||
expect(results_ids).to include(reblog.id)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -264,7 +248,7 @@ RSpec.describe AccountStatusesFilter do
|
|||
end
|
||||
|
||||
it 'does not return reblog of muted account' do
|
||||
expect(subject.results.pluck(:id)).to_not include(reblog.id)
|
||||
expect(results_ids).to_not include(reblog.id)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -276,11 +260,29 @@ RSpec.describe AccountStatusesFilter do
|
|||
end
|
||||
|
||||
it 'does not return reblog of blocked-by account' do
|
||||
expect(subject.results.pluck(:id)).to_not include(reblog.id)
|
||||
expect(results_ids).to_not include(reblog.id)
|
||||
end
|
||||
end
|
||||
|
||||
it_behaves_like 'filter params'
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def results_unique_visibilities
|
||||
subject.pluck(:visibility).uniq
|
||||
end
|
||||
|
||||
def results_in_reply_to_ids
|
||||
subject.pluck(:in_reply_to_id)
|
||||
end
|
||||
|
||||
def results_reblog_of_ids
|
||||
subject.pluck(:reblog_of_id)
|
||||
end
|
||||
|
||||
def results_ids
|
||||
subject.pluck(:id)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -53,7 +53,7 @@ RSpec.describe ActivityPub::Adapter do
|
|||
describe '#serializable_hash' do
|
||||
subject { ActiveModelSerializers::SerializableResource.new(TestObject.new(foo: 'bar'), serializer: serializer_class, adapter: described_class).as_json }
|
||||
|
||||
let(:serializer_class) {}
|
||||
let(:serializer_class) { nil }
|
||||
|
||||
context 'when serializer defines no context' do
|
||||
let(:serializer_class) { TestWithBasicContextSerializer }
|
||||
|
|
|
@ -4,9 +4,51 @@ require 'rails_helper'
|
|||
require 'mastodon/cli/maintenance'
|
||||
|
||||
describe Mastodon::CLI::Maintenance do
|
||||
let(:cli) { described_class.new }
|
||||
|
||||
describe '.exit_on_failure?' do
|
||||
it 'returns true' do
|
||||
expect(described_class.exit_on_failure?).to be true
|
||||
end
|
||||
end
|
||||
|
||||
describe '#fix_duplicates' do
|
||||
context 'when the database version is too old' do
|
||||
before do
|
||||
allow(ActiveRecord::Migrator).to receive(:current_version).and_return(2000_01_01_000000) # Earlier than minimum
|
||||
end
|
||||
|
||||
it 'Exits with error message' do
|
||||
expect { cli.invoke :fix_duplicates }.to output(
|
||||
a_string_including('is too old')
|
||||
).to_stdout.and raise_error(SystemExit)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when the database version is too new and the user does not continue' do
|
||||
before do
|
||||
allow(ActiveRecord::Migrator).to receive(:current_version).and_return(2100_01_01_000000) # Later than maximum
|
||||
allow(cli.shell).to receive(:yes?).with('Continue anyway? (Yes/No)').and_return(false).once
|
||||
end
|
||||
|
||||
it 'Exits with error message' do
|
||||
expect { cli.invoke :fix_duplicates }.to output(
|
||||
a_string_including('more recent')
|
||||
).to_stdout.and raise_error(SystemExit)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when Sidekiq is running' do
|
||||
before do
|
||||
allow(ActiveRecord::Migrator).to receive(:current_version).and_return(2022_01_01_000000) # Higher than minimum, lower than maximum
|
||||
allow(Sidekiq::ProcessSet).to receive(:new).and_return [:process]
|
||||
end
|
||||
|
||||
it 'Exits with error message' do
|
||||
expect { cli.invoke :fix_duplicates }.to output(
|
||||
a_string_including('Sidekiq is running')
|
||||
).to_stdout.and raise_error(SystemExit)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -29,12 +29,16 @@ describe WebfingerResource do
|
|||
allow(recognized).to receive(:[]).with(:username).and_return('alice')
|
||||
allow(recognized).to receive(:[]).with(:action).and_return('create')
|
||||
|
||||
expect(Rails.application.routes).to receive(:recognize_path).with(resource).and_return(recognized).at_least(:once)
|
||||
allow(Rails.application.routes).to receive(:recognize_path).with(resource).and_return(recognized)
|
||||
|
||||
expect do
|
||||
described_class.new(resource).username
|
||||
end.to raise_error(ActiveRecord::RecordNotFound)
|
||||
expect(recognized).to have_received(:[]).exactly(3).times
|
||||
|
||||
expect(Rails.application.routes).to have_received(:recognize_path)
|
||||
.with(resource)
|
||||
.at_least(:once)
|
||||
end
|
||||
|
||||
it 'raises with a string that doesnt start with URL' do
|
||||
|
|
|
@ -78,13 +78,15 @@ RSpec.describe Admin::AccountAction do
|
|||
end
|
||||
|
||||
it 'calls process_email!' do
|
||||
expect(account_action).to receive(:process_email!)
|
||||
allow(account_action).to receive(:process_email!)
|
||||
subject
|
||||
expect(account_action).to have_received(:process_email!)
|
||||
end
|
||||
|
||||
it 'calls process_reports!' do
|
||||
expect(account_action).to receive(:process_reports!)
|
||||
allow(account_action).to receive(:process_reports!)
|
||||
subject
|
||||
expect(account_action).to have_received(:process_reports!)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -120,8 +120,11 @@ RSpec.describe Remotable do
|
|||
end
|
||||
|
||||
it 'does not try to write attribute' do
|
||||
expect(foo).to_not receive('[]=').with(attribute_name, url)
|
||||
allow(foo).to receive('[]=').with(attribute_name, url)
|
||||
|
||||
foo.hoge_remote_url = url
|
||||
|
||||
expect(foo).to_not have_received('[]=').with(attribute_name, url)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -131,8 +134,11 @@ RSpec.describe Remotable do
|
|||
end
|
||||
|
||||
it 'does not try to write attribute' do
|
||||
expect(foo).to receive('[]=').with(attribute_name, url)
|
||||
allow(foo).to receive('[]=').with(attribute_name, url)
|
||||
|
||||
foo.hoge_remote_url = url
|
||||
|
||||
expect(foo).to have_received('[]=').with(attribute_name, url)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -146,10 +152,13 @@ RSpec.describe Remotable do
|
|||
let(:code) { 500 }
|
||||
|
||||
it 'does not assign file' do
|
||||
expect(foo).to_not receive(:public_send).with("#{hoge}=", any_args)
|
||||
expect(foo).to_not receive(:public_send).with("#{hoge}_file_name=", any_args)
|
||||
allow(foo).to receive(:public_send)
|
||||
allow(foo).to receive(:public_send)
|
||||
|
||||
foo.hoge_remote_url = url
|
||||
|
||||
expect(foo).to_not have_received(:public_send).with("#{hoge}=", any_args)
|
||||
expect(foo).to_not have_received(:public_send).with("#{hoge}_file_name=", any_args)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -165,13 +174,13 @@ RSpec.describe Remotable do
|
|||
|
||||
allow(ResponseWithLimit).to receive(:new).with(anything, anything).and_return(response_with_limit)
|
||||
|
||||
expect(foo).to receive(:public_send).with("download_#{hoge}!", url)
|
||||
|
||||
allow(foo).to receive(:public_send)
|
||||
foo.hoge_remote_url = url
|
||||
expect(foo).to have_received(:public_send).with("download_#{hoge}!", url)
|
||||
|
||||
expect(foo).to receive(:public_send).with("#{hoge}=", response_with_limit)
|
||||
|
||||
allow(foo).to receive(:public_send)
|
||||
foo.download_hoge!(url)
|
||||
expect(foo).to have_received(:public_send).with("#{hoge}=", response_with_limit)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -193,10 +202,13 @@ RSpec.describe Remotable do
|
|||
let(:error_class) { error_class }
|
||||
|
||||
it 'calls Rails.logger.debug' do
|
||||
expect(Rails.logger).to receive(:debug) do |&block|
|
||||
allow(Rails.logger).to receive(:debug)
|
||||
|
||||
foo.hoge_remote_url = url
|
||||
|
||||
expect(Rails.logger).to have_received(:debug) do |&block|
|
||||
expect(block.call).to match(/^Error fetching remote #{hoge}: /)
|
||||
end
|
||||
foo.hoge_remote_url = url
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -21,12 +21,17 @@ RSpec.describe FollowRequest do
|
|||
end
|
||||
|
||||
it 'calls Account#follow!, MergeWorker.perform_async, and #destroy!' do
|
||||
expect(account).to receive(:follow!).with(target_account, reblogs: true, notify: false, uri: follow_request.uri, languages: nil, bypass_limit: true) do
|
||||
allow(account).to receive(:follow!) do
|
||||
account.active_relationships.create!(target_account: target_account)
|
||||
end
|
||||
expect(MergeWorker).to receive(:perform_async).with(target_account.id, account.id)
|
||||
expect(follow_request).to receive(:destroy!)
|
||||
allow(MergeWorker).to receive(:perform_async)
|
||||
allow(follow_request).to receive(:destroy!)
|
||||
|
||||
follow_request.authorize!
|
||||
|
||||
expect(account).to have_received(:follow!).with(target_account, reblogs: true, notify: false, uri: follow_request.uri, languages: nil, bypass_limit: true)
|
||||
expect(MergeWorker).to have_received(:perform_async).with(target_account.id, account.id)
|
||||
expect(follow_request).to have_received(:destroy!)
|
||||
end
|
||||
|
||||
it 'correctly passes show_reblogs when true' do
|
||||
|
|
|
@ -7,8 +7,11 @@ RSpec.describe Identity do
|
|||
let(:auth) { Fabricate(:identity, user: Fabricate(:user)) }
|
||||
|
||||
it 'calls .find_or_create_by' do
|
||||
expect(described_class).to receive(:find_or_create_by).with(uid: auth.uid, provider: auth.provider)
|
||||
allow(described_class).to receive(:find_or_create_by)
|
||||
|
||||
described_class.find_for_oauth(auth)
|
||||
|
||||
expect(described_class).to have_received(:find_or_create_by).with(uid: auth.uid, provider: auth.provider)
|
||||
end
|
||||
|
||||
it 'returns an instance of Identity' do
|
||||
|
|
|
@ -74,9 +74,13 @@ RSpec.describe SessionActivation do
|
|||
let(:options) { { user: Fabricate(:user), session_id: '1' } }
|
||||
|
||||
it 'calls create! and purge_old' do
|
||||
expect(described_class).to receive(:create!).with(**options)
|
||||
expect(described_class).to receive(:purge_old)
|
||||
allow(described_class).to receive(:create!).with(**options)
|
||||
allow(described_class).to receive(:purge_old)
|
||||
|
||||
described_class.activate(**options)
|
||||
|
||||
expect(described_class).to have_received(:create!).with(**options)
|
||||
expect(described_class).to have_received(:purge_old)
|
||||
end
|
||||
|
||||
it 'returns an instance of SessionActivation' do
|
||||
|
|
|
@ -23,8 +23,11 @@ RSpec.describe Setting do
|
|||
let(:rails_initialized) { false }
|
||||
|
||||
it 'calls RailsSettings::Base#[]' do
|
||||
expect(RailsSettings::Base).to receive(:[]).with(key)
|
||||
allow(RailsSettings::Base).to receive(:[]).with(key)
|
||||
|
||||
described_class[key]
|
||||
|
||||
expect(RailsSettings::Base).to have_received(:[]).with(key)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -38,8 +41,11 @@ RSpec.describe Setting do
|
|||
let(:cache_value) { 'cache-value' }
|
||||
|
||||
it 'calls not RailsSettings::Base#[]' do
|
||||
expect(RailsSettings::Base).to_not receive(:[]).with(key)
|
||||
allow(RailsSettings::Base).to receive(:[]).with(key)
|
||||
|
||||
described_class[key]
|
||||
|
||||
expect(RailsSettings::Base).to_not have_received(:[]).with(key)
|
||||
end
|
||||
|
||||
context 'when Rails.cache does not exists' do
|
||||
|
@ -56,8 +62,11 @@ RSpec.describe Setting do
|
|||
let(:records) { [Fabricate(:setting, var: key, value: nil)] }
|
||||
|
||||
it 'calls RailsSettings::Settings.object' do
|
||||
expect(RailsSettings::Settings).to receive(:object).with(key)
|
||||
allow(RailsSettings::Settings).to receive(:object).with(key)
|
||||
|
||||
described_class[key]
|
||||
|
||||
expect(RailsSettings::Settings).to have_received(:object).with(key)
|
||||
end
|
||||
|
||||
context 'when RailsSettings::Settings.object returns truthy' do
|
||||
|
|
|
@ -60,7 +60,7 @@ RSpec.describe UserRole do
|
|||
end
|
||||
|
||||
describe '#permissions_as_keys=' do
|
||||
let(:input) {}
|
||||
let(:input) { nil }
|
||||
|
||||
before do
|
||||
subject.permissions_as_keys = input
|
||||
|
|
|
@ -102,7 +102,7 @@ RSpec.describe User do
|
|||
end
|
||||
|
||||
describe 'blacklist' do
|
||||
around(:each) do |example|
|
||||
around do |example|
|
||||
old_blacklist = Rails.configuration.x.email_blacklist
|
||||
|
||||
Rails.configuration.x.email_domains_blacklist = 'mvrht.com'
|
||||
|
@ -169,7 +169,7 @@ RSpec.describe User do
|
|||
let(:user) { Fabricate(:user, confirmed_at: nil, unconfirmed_email: new_email) }
|
||||
|
||||
context 'when the user is already approved' do
|
||||
around(:example) do |example|
|
||||
around do |example|
|
||||
registrations_mode = Setting.registrations_mode
|
||||
Setting.registrations_mode = 'approved'
|
||||
|
||||
|
@ -193,7 +193,7 @@ RSpec.describe User do
|
|||
end
|
||||
|
||||
context 'when the user does not require explicit approval' do
|
||||
around(:example) do |example|
|
||||
around do |example|
|
||||
registrations_mode = Setting.registrations_mode
|
||||
Setting.registrations_mode = 'open'
|
||||
|
||||
|
@ -213,7 +213,7 @@ RSpec.describe User do
|
|||
end
|
||||
|
||||
context 'when the user requires explicit approval but is not approved' do
|
||||
around(:example) do |example|
|
||||
around do |example|
|
||||
registrations_mode = Setting.registrations_mode
|
||||
Setting.registrations_mode = 'approved'
|
||||
|
||||
|
@ -237,7 +237,7 @@ RSpec.describe User do
|
|||
describe '#approve!' do
|
||||
subject { user.approve! }
|
||||
|
||||
around(:example) do |example|
|
||||
around do |example|
|
||||
registrations_mode = Setting.registrations_mode
|
||||
Setting.registrations_mode = 'approved'
|
||||
|
||||
|
@ -338,7 +338,7 @@ RSpec.describe User do
|
|||
end
|
||||
|
||||
describe 'whitelist' do
|
||||
around(:each) do |example|
|
||||
around do |example|
|
||||
old_whitelist = Rails.configuration.x.email_domains_whitelist
|
||||
|
||||
Rails.configuration.x.email_domains_whitelist = 'mastodon.space'
|
||||
|
|
|
@ -142,13 +142,13 @@ RSpec.configure do |config|
|
|||
search_data_manager.remove_indexes
|
||||
end
|
||||
|
||||
config.before(:each) do |example|
|
||||
config.before do |example|
|
||||
unless example.metadata[:paperclip_processing]
|
||||
allow_any_instance_of(Paperclip::Attachment).to receive(:post_process).and_return(true) # rubocop:disable RSpec/AnyInstance
|
||||
end
|
||||
end
|
||||
|
||||
config.after :each do
|
||||
config.after do
|
||||
Rails.cache.clear
|
||||
redis.del(redis.keys)
|
||||
end
|
||||
|
|
|
@ -171,12 +171,10 @@ describe 'Caching behavior' do
|
|||
let(:user) { Fabricate(:user, role: UserRole.find_by(name: 'Moderator')) }
|
||||
|
||||
before do
|
||||
# rubocop:disable Style/NumericLiterals
|
||||
status = Fabricate(:status, account: alice, id: 110224538612341312)
|
||||
Fabricate(:status, account: alice, id: 110224538643211312, visibility: :private)
|
||||
status = Fabricate(:status, account: alice, id: '110224538612341312')
|
||||
Fabricate(:status, account: alice, id: '110224538643211312', visibility: :private)
|
||||
Fabricate(:invite, code: 'abcdef')
|
||||
Fabricate(:poll, status: status, account: alice, id: 12345)
|
||||
# rubocop:enable Style/NumericLiterals
|
||||
Fabricate(:poll, status: status, account: alice, id: '12345')
|
||||
|
||||
user.account.follow!(alice)
|
||||
end
|
||||
|
|
|
@ -3,13 +3,7 @@
|
|||
require 'rails_helper'
|
||||
|
||||
describe ActivityPub::DeviceSerializer do
|
||||
let(:serialization) do
|
||||
JSON.parse(
|
||||
ActiveModelSerializers::SerializableResource.new(
|
||||
record, serializer: described_class
|
||||
).to_json
|
||||
)
|
||||
end
|
||||
let(:serialization) { serialized_record_json(record, described_class) }
|
||||
let(:record) { Fabricate(:device) }
|
||||
|
||||
describe 'type' do
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
require 'rails_helper'
|
||||
|
||||
describe ActivityPub::NoteSerializer do
|
||||
subject { JSON.parse(@serialization.to_json) }
|
||||
subject { serialized_record_json(parent, described_class, adapter: ActivityPub::Adapter) }
|
||||
|
||||
let(:visibility) { :public }
|
||||
let(:searchability) { :public }
|
||||
|
@ -18,10 +18,9 @@ describe ActivityPub::NoteSerializer do
|
|||
let!(:referred) { nil }
|
||||
let!(:referred2) { nil }
|
||||
|
||||
before(:each) do
|
||||
before do
|
||||
parent.references << referred if referred.present?
|
||||
parent.references << referred2 if referred2.present?
|
||||
@serialization = ActiveModelSerializers::SerializableResource.new(parent, serializer: described_class, adapter: ActivityPub::Adapter)
|
||||
end
|
||||
|
||||
it 'has the expected shape' do
|
||||
|
|
|
@ -3,13 +3,7 @@
|
|||
require 'rails_helper'
|
||||
|
||||
describe ActivityPub::OneTimeKeySerializer do
|
||||
let(:serialization) do
|
||||
JSON.parse(
|
||||
ActiveModelSerializers::SerializableResource.new(
|
||||
record, serializer: described_class
|
||||
).to_json
|
||||
)
|
||||
end
|
||||
let(:serialization) { serialized_record_json(record, described_class) }
|
||||
let(:record) { Fabricate(:one_time_key) }
|
||||
|
||||
describe 'type' do
|
||||
|
|
|
@ -3,13 +3,7 @@
|
|||
require 'rails_helper'
|
||||
|
||||
describe ActivityPub::UndoLikeSerializer do
|
||||
let(:serialization) do
|
||||
JSON.parse(
|
||||
ActiveModelSerializers::SerializableResource.new(
|
||||
record, serializer: described_class
|
||||
).to_json
|
||||
)
|
||||
end
|
||||
let(:serialization) { serialized_record_json(record, described_class) }
|
||||
let(:record) { Fabricate(:favourite) }
|
||||
|
||||
describe 'type' do
|
||||
|
|
|
@ -3,16 +3,12 @@
|
|||
require 'rails_helper'
|
||||
|
||||
describe ActivityPub::UpdatePollSerializer do
|
||||
subject { JSON.parse(@serialization.to_json) }
|
||||
subject { serialized_record_json(status, described_class, adapter: ActivityPub::Adapter) }
|
||||
|
||||
let(:account) { Fabricate(:account) }
|
||||
let(:poll) { Fabricate(:poll, account: account) }
|
||||
let!(:status) { Fabricate(:status, account: account, poll: poll) }
|
||||
|
||||
before(:each) do
|
||||
@serialization = ActiveModelSerializers::SerializableResource.new(status, serializer: described_class, adapter: ActivityPub::Adapter)
|
||||
end
|
||||
|
||||
it 'has a Update type' do
|
||||
expect(subject['type']).to eql('Update')
|
||||
end
|
||||
|
|
|
@ -3,13 +3,7 @@
|
|||
require 'rails_helper'
|
||||
|
||||
describe ActivityPub::VoteSerializer do
|
||||
let(:serialization) do
|
||||
JSON.parse(
|
||||
ActiveModelSerializers::SerializableResource.new(
|
||||
record, serializer: described_class
|
||||
).to_json
|
||||
)
|
||||
end
|
||||
let(:serialization) { serialized_record_json(record, described_class) }
|
||||
let(:record) { Fabricate(:poll_vote) }
|
||||
|
||||
describe 'type' do
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
require 'rails_helper'
|
||||
|
||||
describe REST::AccountSerializer do
|
||||
subject { JSON.parse(ActiveModelSerializers::SerializableResource.new(account, serializer: described_class).to_json) }
|
||||
subject { serialized_record_json(account, described_class) }
|
||||
|
||||
let(:role) { Fabricate(:user_role, name: 'Role', highlighted: true) }
|
||||
let(:user) { Fabricate(:user, role: role) }
|
||||
|
|
|
@ -3,13 +3,7 @@
|
|||
require 'rails_helper'
|
||||
|
||||
describe REST::EncryptedMessageSerializer do
|
||||
let(:serialization) do
|
||||
JSON.parse(
|
||||
ActiveModelSerializers::SerializableResource.new(
|
||||
record, serializer: described_class
|
||||
).to_json
|
||||
)
|
||||
end
|
||||
let(:serialization) { serialized_record_json(record, described_class) }
|
||||
let(:record) { Fabricate(:encrypted_message) }
|
||||
|
||||
describe 'account' do
|
||||
|
|
|
@ -3,13 +3,7 @@
|
|||
require 'rails_helper'
|
||||
|
||||
describe REST::InstanceSerializer do
|
||||
let(:serialization) do
|
||||
JSON.parse(
|
||||
ActiveModelSerializers::SerializableResource.new(
|
||||
record, serializer: described_class
|
||||
).to_json
|
||||
)
|
||||
end
|
||||
let(:serialization) { serialized_record_json(record, described_class) }
|
||||
let(:record) { InstancePresenter.new }
|
||||
|
||||
describe 'usage' do
|
||||
|
|
|
@ -3,13 +3,7 @@
|
|||
require 'rails_helper'
|
||||
|
||||
describe REST::Keys::ClaimResultSerializer do
|
||||
let(:serialization) do
|
||||
JSON.parse(
|
||||
ActiveModelSerializers::SerializableResource.new(
|
||||
record, serializer: described_class
|
||||
).to_json
|
||||
)
|
||||
end
|
||||
let(:serialization) { serialized_record_json(record, described_class) }
|
||||
let(:record) { Keys::ClaimService::Result.new(Account.new(id: 123), 456) }
|
||||
|
||||
describe 'account' do
|
||||
|
|
|
@ -3,13 +3,7 @@
|
|||
require 'rails_helper'
|
||||
|
||||
describe REST::Keys::DeviceSerializer do
|
||||
let(:serialization) do
|
||||
JSON.parse(
|
||||
ActiveModelSerializers::SerializableResource.new(
|
||||
record, serializer: described_class
|
||||
).to_json
|
||||
)
|
||||
end
|
||||
let(:serialization) { serialized_record_json(record, described_class) }
|
||||
let(:record) { Device.new(name: 'Device name') }
|
||||
|
||||
describe 'name' do
|
||||
|
|
|
@ -3,13 +3,7 @@
|
|||
require 'rails_helper'
|
||||
|
||||
describe REST::Keys::QueryResultSerializer do
|
||||
let(:serialization) do
|
||||
JSON.parse(
|
||||
ActiveModelSerializers::SerializableResource.new(
|
||||
record, serializer: described_class
|
||||
).to_json
|
||||
)
|
||||
end
|
||||
let(:serialization) { serialized_record_json(record, described_class) }
|
||||
let(:record) { Keys::QueryService::Result.new(Account.new(id: 123), []) }
|
||||
|
||||
describe 'account' do
|
||||
|
|
|
@ -3,13 +3,7 @@
|
|||
require 'rails_helper'
|
||||
|
||||
describe REST::SuggestionSerializer do
|
||||
let(:serialization) do
|
||||
JSON.parse(
|
||||
ActiveModelSerializers::SerializableResource.new(
|
||||
record, serializer: described_class
|
||||
).to_json
|
||||
)
|
||||
end
|
||||
let(:serialization) { serialized_record_json(record, described_class) }
|
||||
let(:record) do
|
||||
AccountSuggestions::Suggestion.new(
|
||||
account: account,
|
||||
|
|
|
@ -36,8 +36,11 @@ RSpec.describe ActivityPub::FetchRepliesService, type: :service do
|
|||
context 'when the payload is a Collection with inlined replies' do
|
||||
context 'when passing the collection itself' do
|
||||
it 'spawns workers for up to 5 replies on the same server' do
|
||||
expect(FetchReplyWorker).to receive(:push_bulk).with(['http://example.com/self-reply-1', 'http://example.com/self-reply-2', 'http://example.com/self-reply-3', 'http://example.com/self-reply-4', 'http://example.com/self-reply-5'])
|
||||
allow(FetchReplyWorker).to receive(:push_bulk)
|
||||
|
||||
subject.call(status, payload)
|
||||
|
||||
expect(FetchReplyWorker).to have_received(:push_bulk).with(['http://example.com/self-reply-1', 'http://example.com/self-reply-2', 'http://example.com/self-reply-3', 'http://example.com/self-reply-4', 'http://example.com/self-reply-5'])
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -47,8 +50,11 @@ RSpec.describe ActivityPub::FetchRepliesService, type: :service do
|
|||
end
|
||||
|
||||
it 'spawns workers for up to 5 replies on the same server' do
|
||||
expect(FetchReplyWorker).to receive(:push_bulk).with(['http://example.com/self-reply-1', 'http://example.com/self-reply-2', 'http://example.com/self-reply-3', 'http://example.com/self-reply-4', 'http://example.com/self-reply-5'])
|
||||
allow(FetchReplyWorker).to receive(:push_bulk)
|
||||
|
||||
subject.call(status, collection_uri)
|
||||
|
||||
expect(FetchReplyWorker).to have_received(:push_bulk).with(['http://example.com/self-reply-1', 'http://example.com/self-reply-2', 'http://example.com/self-reply-3', 'http://example.com/self-reply-4', 'http://example.com/self-reply-5'])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -65,8 +71,11 @@ RSpec.describe ActivityPub::FetchRepliesService, type: :service do
|
|||
|
||||
context 'when passing the collection itself' do
|
||||
it 'spawns workers for up to 5 replies on the same server' do
|
||||
expect(FetchReplyWorker).to receive(:push_bulk).with(['http://example.com/self-reply-1', 'http://example.com/self-reply-2', 'http://example.com/self-reply-3', 'http://example.com/self-reply-4', 'http://example.com/self-reply-5'])
|
||||
allow(FetchReplyWorker).to receive(:push_bulk)
|
||||
|
||||
subject.call(status, payload)
|
||||
|
||||
expect(FetchReplyWorker).to have_received(:push_bulk).with(['http://example.com/self-reply-1', 'http://example.com/self-reply-2', 'http://example.com/self-reply-3', 'http://example.com/self-reply-4', 'http://example.com/self-reply-5'])
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -76,8 +85,11 @@ RSpec.describe ActivityPub::FetchRepliesService, type: :service do
|
|||
end
|
||||
|
||||
it 'spawns workers for up to 5 replies on the same server' do
|
||||
expect(FetchReplyWorker).to receive(:push_bulk).with(['http://example.com/self-reply-1', 'http://example.com/self-reply-2', 'http://example.com/self-reply-3', 'http://example.com/self-reply-4', 'http://example.com/self-reply-5'])
|
||||
allow(FetchReplyWorker).to receive(:push_bulk)
|
||||
|
||||
subject.call(status, collection_uri)
|
||||
|
||||
expect(FetchReplyWorker).to have_received(:push_bulk).with(['http://example.com/self-reply-1', 'http://example.com/self-reply-2', 'http://example.com/self-reply-3', 'http://example.com/self-reply-4', 'http://example.com/self-reply-5'])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -98,8 +110,11 @@ RSpec.describe ActivityPub::FetchRepliesService, type: :service do
|
|||
|
||||
context 'when passing the collection itself' do
|
||||
it 'spawns workers for up to 5 replies on the same server' do
|
||||
expect(FetchReplyWorker).to receive(:push_bulk).with(['http://example.com/self-reply-1', 'http://example.com/self-reply-2', 'http://example.com/self-reply-3', 'http://example.com/self-reply-4', 'http://example.com/self-reply-5'])
|
||||
allow(FetchReplyWorker).to receive(:push_bulk)
|
||||
|
||||
subject.call(status, payload)
|
||||
|
||||
expect(FetchReplyWorker).to have_received(:push_bulk).with(['http://example.com/self-reply-1', 'http://example.com/self-reply-2', 'http://example.com/self-reply-3', 'http://example.com/self-reply-4', 'http://example.com/self-reply-5'])
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -109,8 +124,11 @@ RSpec.describe ActivityPub::FetchRepliesService, type: :service do
|
|||
end
|
||||
|
||||
it 'spawns workers for up to 5 replies on the same server' do
|
||||
expect(FetchReplyWorker).to receive(:push_bulk).with(['http://example.com/self-reply-1', 'http://example.com/self-reply-2', 'http://example.com/self-reply-3', 'http://example.com/self-reply-4', 'http://example.com/self-reply-5'])
|
||||
allow(FetchReplyWorker).to receive(:push_bulk)
|
||||
|
||||
subject.call(status, collection_uri)
|
||||
|
||||
expect(FetchReplyWorker).to have_received(:push_bulk).with(['http://example.com/self-reply-1', 'http://example.com/self-reply-2', 'http://example.com/self-reply-3', 'http://example.com/self-reply-4', 'http://example.com/self-reply-5'])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -41,8 +41,11 @@ RSpec.describe ActivityPub::ProcessCollectionService, type: :service do
|
|||
end
|
||||
|
||||
it 'does not process payload' do
|
||||
expect(ActivityPub::Activity).to_not receive(:factory)
|
||||
allow(ActivityPub::Activity).to receive(:factory)
|
||||
|
||||
subject.call(json, actor)
|
||||
|
||||
expect(ActivityPub::Activity).to_not have_received(:factory)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -59,8 +62,11 @@ RSpec.describe ActivityPub::ProcessCollectionService, type: :service do
|
|||
end
|
||||
|
||||
it 'processes the payload' do
|
||||
expect(ActivityPub::Activity).to receive(:factory)
|
||||
allow(ActivityPub::Activity).to receive(:factory)
|
||||
|
||||
subject.call(json, actor)
|
||||
|
||||
expect(ActivityPub::Activity).to have_received(:factory)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -71,27 +77,33 @@ RSpec.describe ActivityPub::ProcessCollectionService, type: :service do
|
|||
|
||||
it 'does not process payload if no signature exists' do
|
||||
allow_any_instance_of(ActivityPub::LinkedDataSignature).to receive(:verify_actor!).and_return(nil)
|
||||
expect(ActivityPub::Activity).to_not receive(:factory)
|
||||
allow(ActivityPub::Activity).to receive(:factory)
|
||||
|
||||
subject.call(json, forwarder)
|
||||
|
||||
expect(ActivityPub::Activity).to_not have_received(:factory)
|
||||
end
|
||||
|
||||
it 'processes payload with actor if valid signature exists' do
|
||||
payload['signature'] = { 'type' => 'RsaSignature2017' }
|
||||
|
||||
allow_any_instance_of(ActivityPub::LinkedDataSignature).to receive(:verify_actor!).and_return(actor)
|
||||
expect(ActivityPub::Activity).to receive(:factory).with(instance_of(Hash), actor, instance_of(Hash))
|
||||
allow(ActivityPub::Activity).to receive(:factory).with(instance_of(Hash), actor, instance_of(Hash))
|
||||
|
||||
subject.call(json, forwarder)
|
||||
|
||||
expect(ActivityPub::Activity).to have_received(:factory).with(instance_of(Hash), actor, instance_of(Hash))
|
||||
end
|
||||
|
||||
it 'does not process payload if invalid signature exists' do
|
||||
payload['signature'] = { 'type' => 'RsaSignature2017' }
|
||||
|
||||
allow_any_instance_of(ActivityPub::LinkedDataSignature).to receive(:verify_actor!).and_return(nil)
|
||||
expect(ActivityPub::Activity).to_not receive(:factory)
|
||||
allow(ActivityPub::Activity).to receive(:factory)
|
||||
|
||||
subject.call(json, forwarder)
|
||||
|
||||
expect(ActivityPub::Activity).to_not have_received(:factory)
|
||||
end
|
||||
|
||||
context 'when receiving a fabricated status' do
|
||||
|
@ -225,7 +237,11 @@ RSpec.describe ActivityPub::ProcessCollectionService, type: :service do
|
|||
end
|
||||
|
||||
it 'does not process forged payload' do
|
||||
expect(ActivityPub::Activity).to_not receive(:factory).with(
|
||||
allow(ActivityPub::Activity).to receive(:factory)
|
||||
|
||||
subject.call(json, forwarder)
|
||||
|
||||
expect(ActivityPub::Activity).to_not have_received(:factory).with(
|
||||
hash_including(
|
||||
'object' => hash_including(
|
||||
'id' => 'https://example.com/users/bob/fake-status'
|
||||
|
@ -235,7 +251,7 @@ RSpec.describe ActivityPub::ProcessCollectionService, type: :service do
|
|||
anything
|
||||
)
|
||||
|
||||
expect(ActivityPub::Activity).to_not receive(:factory).with(
|
||||
expect(ActivityPub::Activity).to_not have_received(:factory).with(
|
||||
hash_including(
|
||||
'object' => hash_including(
|
||||
'content' => '<p>puck was here</p>'
|
||||
|
@ -245,8 +261,6 @@ RSpec.describe ActivityPub::ProcessCollectionService, type: :service do
|
|||
anything
|
||||
)
|
||||
|
||||
subject.call(json, forwarder)
|
||||
|
||||
expect(Status.where(uri: 'https://example.com/users/bob/fake-status').exists?).to be false
|
||||
end
|
||||
end
|
||||
|
|
|
@ -54,7 +54,7 @@ RSpec.describe BulkImportService do
|
|||
|
||||
Import::RowWorker.drain
|
||||
|
||||
expect(FollowRequest.includes(:target_account).where(account: account).map(&:target_account).map(&:acct)).to contain_exactly('user@foo.bar', 'unknown@unknown.bar')
|
||||
expect(FollowRequest.includes(:target_account).where(account: account).map { |follow_request| follow_request.target_account.acct }).to contain_exactly('user@foo.bar', 'unknown@unknown.bar')
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -102,7 +102,7 @@ RSpec.describe BulkImportService do
|
|||
|
||||
Import::RowWorker.drain
|
||||
|
||||
expect(FollowRequest.includes(:target_account).where(account: account).map(&:target_account).map(&:acct)).to contain_exactly('user@foo.bar', 'unknown@unknown.bar')
|
||||
expect(FollowRequest.includes(:target_account).where(account: account).map { |follow_request| follow_request.target_account.acct }).to contain_exactly('user@foo.bar', 'unknown@unknown.bar')
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -367,7 +367,7 @@ RSpec.describe BulkImportService do
|
|||
|
||||
Import::RowWorker.drain
|
||||
|
||||
expect(account.bookmarks.map(&:status).map(&:uri)).to contain_exactly(already_bookmarked.uri, status.uri, bookmarked.uri, 'https://domain.unknown/foo')
|
||||
expect(account.bookmarks.map { |bookmark| bookmark.status.uri }).to contain_exactly(already_bookmarked.uri, status.uri, bookmarked.uri, 'https://domain.unknown/foo')
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -410,7 +410,7 @@ RSpec.describe BulkImportService do
|
|||
|
||||
Import::RowWorker.drain
|
||||
|
||||
expect(account.bookmarks.map(&:status).map(&:uri)).to contain_exactly(status.uri, bookmarked.uri, 'https://domain.unknown/foo')
|
||||
expect(account.bookmarks.map { |bookmark| bookmark.status.uri }).to contain_exactly(status.uri, bookmarked.uri, 'https://domain.unknown/foo')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -208,7 +208,7 @@ RSpec.describe ImportService, type: :service do
|
|||
let!(:remote_status) { Fabricate(:status, uri: 'https://example.com/statuses/1312') }
|
||||
let!(:direct_status) { Fabricate(:status, uri: 'https://example.com/statuses/direct', visibility: :direct) }
|
||||
|
||||
around(:each) do |example|
|
||||
around do |example|
|
||||
local_before = Rails.configuration.x.local_domain
|
||||
web_before = Rails.configuration.x.web_domain
|
||||
Rails.configuration.x.local_domain = 'local.com'
|
||||
|
@ -232,9 +232,9 @@ RSpec.describe ImportService, type: :service do
|
|||
it 'adds the toots the user has access to to bookmarks' do
|
||||
local_status = Fabricate(:status, account: local_account, uri: 'https://local.com/users/foo/statuses/42', id: 42, local: true)
|
||||
subject.call(import)
|
||||
expect(account.bookmarks.map(&:status).map(&:id)).to include(local_status.id)
|
||||
expect(account.bookmarks.map(&:status).map(&:id)).to include(remote_status.id)
|
||||
expect(account.bookmarks.map(&:status).map(&:id)).to_not include(direct_status.id)
|
||||
expect(account.bookmarks.map { |bookmark| bookmark.status.id }).to include(local_status.id)
|
||||
expect(account.bookmarks.map { |bookmark| bookmark.status.id }).to include(remote_status.id)
|
||||
expect(account.bookmarks.map { |bookmark| bookmark.status.id }).to_not include(direct_status.id)
|
||||
expect(account.bookmarks.count).to eq 3
|
||||
end
|
||||
end
|
||||
|
|
|
@ -58,128 +58,22 @@ def json_str_to_hash(str)
|
|||
JSON.parse(str, symbolize_names: true)
|
||||
end
|
||||
|
||||
def serialized_record_json(record, serializer, adapter: nil)
|
||||
options = { serializer: serializer }
|
||||
options[:adapter] = adapter if adapter.present?
|
||||
JSON.parse(
|
||||
ActiveModelSerializers::SerializableResource.new(
|
||||
record,
|
||||
options
|
||||
).to_json
|
||||
)
|
||||
end
|
||||
|
||||
def expect_push_bulk_to_match(klass, matcher)
|
||||
expect(Sidekiq::Client).to receive(:push_bulk).with(hash_including({
|
||||
allow(Sidekiq::Client).to receive(:push_bulk)
|
||||
yield
|
||||
expect(Sidekiq::Client).to have_received(:push_bulk).with(hash_including({
|
||||
'class' => klass,
|
||||
'args' => matcher,
|
||||
}))
|
||||
end
|
||||
|
||||
class StreamingServerManager
|
||||
@running_thread = nil
|
||||
|
||||
def initialize
|
||||
at_exit { stop }
|
||||
end
|
||||
|
||||
def start(port: 4020)
|
||||
return if @running_thread
|
||||
|
||||
queue = Queue.new
|
||||
|
||||
@queue = queue
|
||||
|
||||
@running_thread = Thread.new do
|
||||
Open3.popen2e(
|
||||
{
|
||||
'REDIS_NAMESPACE' => ENV.fetch('REDIS_NAMESPACE'),
|
||||
'DB_NAME' => "#{ENV.fetch('DB_NAME', 'mastodon')}_test#{ENV.fetch('TEST_ENV_NUMBER', '')}",
|
||||
'RAILS_ENV' => ENV.fetch('RAILS_ENV', 'test'),
|
||||
'NODE_ENV' => ENV.fetch('STREAMING_NODE_ENV', 'development'),
|
||||
'PORT' => port.to_s,
|
||||
},
|
||||
'node index.js', # must not call yarn here, otherwise it will fail because yarn does not send signals to its child process
|
||||
chdir: Rails.root.join('streaming')
|
||||
) do |_stdin, stdout_err, process_thread|
|
||||
status = :starting
|
||||
|
||||
# Spawn a thread to listen on streaming server output
|
||||
output_thread = Thread.new do
|
||||
stdout_err.each_line do |line|
|
||||
Rails.logger.info "Streaming server: #{line}"
|
||||
|
||||
if status == :starting && line.match('Streaming API now listening on')
|
||||
status = :started
|
||||
@queue.enq 'started'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# And another thread to listen on commands from the main thread
|
||||
loop do
|
||||
msg = queue.pop
|
||||
|
||||
case msg
|
||||
when 'stop'
|
||||
# we need to properly stop the reading thread
|
||||
output_thread.kill
|
||||
|
||||
# Then stop the node process
|
||||
Process.kill('KILL', process_thread.pid)
|
||||
|
||||
# And we stop ourselves
|
||||
@running_thread.kill
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# wait for 10 seconds for the streaming server to start
|
||||
Timeout.timeout(10) do
|
||||
loop do
|
||||
break if @queue.pop == 'started'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def stop
|
||||
return unless @running_thread
|
||||
|
||||
@queue.enq 'stop'
|
||||
|
||||
# Wait for the thread to end
|
||||
@running_thread.join
|
||||
end
|
||||
end
|
||||
|
||||
class SearchDataManager
|
||||
def prepare_test_data
|
||||
4.times do |i|
|
||||
username = "search_test_account_#{i}"
|
||||
account = Fabricate.create(:account, username: username, indexable: i.even?, discoverable: i.even?, note: "Lover of #{i}.")
|
||||
2.times do |j|
|
||||
Fabricate.create(:status, account: account, text: "#{username}'s #{j} post", visibility: j.even? ? :public : :private)
|
||||
end
|
||||
end
|
||||
|
||||
3.times do |i|
|
||||
Fabricate.create(:tag, name: "search_test_tag_#{i}")
|
||||
end
|
||||
end
|
||||
|
||||
def indexes
|
||||
[
|
||||
AccountsIndex,
|
||||
PublicStatusesIndex,
|
||||
StatusesIndex,
|
||||
TagsIndex,
|
||||
]
|
||||
end
|
||||
|
||||
def populate_indexes
|
||||
indexes.each do |index_class|
|
||||
index_class.purge!
|
||||
index_class.import!
|
||||
end
|
||||
end
|
||||
|
||||
def remove_indexes
|
||||
indexes.each(&:delete!)
|
||||
end
|
||||
|
||||
def cleanup_test_data
|
||||
Status.destroy_all
|
||||
Account.destroy_all
|
||||
Tag.destroy_all
|
||||
end
|
||||
end
|
||||
|
|
43
spec/support/search_data_manager.rb
Normal file
43
spec/support/search_data_manager.rb
Normal file
|
@ -0,0 +1,43 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class SearchDataManager
|
||||
def prepare_test_data
|
||||
4.times do |i|
|
||||
username = "search_test_account_#{i}"
|
||||
account = Fabricate.create(:account, username: username, indexable: i.even?, discoverable: i.even?, note: "Lover of #{i}.")
|
||||
2.times do |j|
|
||||
Fabricate.create(:status, account: account, text: "#{username}'s #{j} post", visibility: j.even? ? :public : :private)
|
||||
end
|
||||
end
|
||||
|
||||
3.times do |i|
|
||||
Fabricate.create(:tag, name: "search_test_tag_#{i}")
|
||||
end
|
||||
end
|
||||
|
||||
def indexes
|
||||
[
|
||||
AccountsIndex,
|
||||
PublicStatusesIndex,
|
||||
StatusesIndex,
|
||||
TagsIndex,
|
||||
]
|
||||
end
|
||||
|
||||
def populate_indexes
|
||||
indexes.each do |index_class|
|
||||
index_class.purge!
|
||||
index_class.import!
|
||||
end
|
||||
end
|
||||
|
||||
def remove_indexes
|
||||
indexes.each(&:delete!)
|
||||
end
|
||||
|
||||
def cleanup_test_data
|
||||
Status.destroy_all
|
||||
Account.destroy_all
|
||||
Tag.destroy_all
|
||||
end
|
||||
end
|
78
spec/support/streaming_server_manager.rb
Normal file
78
spec/support/streaming_server_manager.rb
Normal file
|
@ -0,0 +1,78 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class StreamingServerManager
|
||||
@running_thread = nil
|
||||
|
||||
def initialize
|
||||
at_exit { stop }
|
||||
end
|
||||
|
||||
def start(port: 4020)
|
||||
return if @running_thread
|
||||
|
||||
queue = Queue.new
|
||||
|
||||
@queue = queue
|
||||
|
||||
@running_thread = Thread.new do
|
||||
Open3.popen2e(
|
||||
{
|
||||
'REDIS_NAMESPACE' => ENV.fetch('REDIS_NAMESPACE'),
|
||||
'DB_NAME' => "#{ENV.fetch('DB_NAME', 'mastodon')}_test#{ENV.fetch('TEST_ENV_NUMBER', '')}",
|
||||
'RAILS_ENV' => ENV.fetch('RAILS_ENV', 'test'),
|
||||
'NODE_ENV' => ENV.fetch('STREAMING_NODE_ENV', 'development'),
|
||||
'PORT' => port.to_s,
|
||||
},
|
||||
'node index.js', # must not call yarn here, otherwise it will fail because yarn does not send signals to its child process
|
||||
chdir: Rails.root.join('streaming')
|
||||
) do |_stdin, stdout_err, process_thread|
|
||||
status = :starting
|
||||
|
||||
# Spawn a thread to listen on streaming server output
|
||||
output_thread = Thread.new do
|
||||
stdout_err.each_line do |line|
|
||||
Rails.logger.info "Streaming server: #{line}"
|
||||
|
||||
if status == :starting && line.match('Streaming API now listening on')
|
||||
status = :started
|
||||
@queue.enq 'started'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# And another thread to listen on commands from the main thread
|
||||
loop do
|
||||
msg = queue.pop
|
||||
|
||||
case msg
|
||||
when 'stop'
|
||||
# we need to properly stop the reading thread
|
||||
output_thread.kill
|
||||
|
||||
# Then stop the node process
|
||||
Process.kill('KILL', process_thread.pid)
|
||||
|
||||
# And we stop ourselves
|
||||
@running_thread.kill
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# wait for 10 seconds for the streaming server to start
|
||||
Timeout.timeout(10) do
|
||||
loop do
|
||||
break if @queue.pop == 'started'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def stop
|
||||
return unless @running_thread
|
||||
|
||||
@queue.enq 'stop'
|
||||
|
||||
# Wait for the thread to end
|
||||
@running_thread.join
|
||||
end
|
||||
end
|
|
@ -6,14 +6,20 @@ describe StatusLengthValidator do
|
|||
describe '#validate' do
|
||||
it 'does not add errors onto remote statuses' do
|
||||
status = instance_double(Status, local?: false)
|
||||
allow(status).to receive(:errors)
|
||||
|
||||
subject.validate(status)
|
||||
expect(status).to_not receive(:errors)
|
||||
|
||||
expect(status).to_not have_received(:errors)
|
||||
end
|
||||
|
||||
it 'does not add errors onto local reblogs' do
|
||||
status = instance_double(Status, local?: false, reblog?: true)
|
||||
allow(status).to receive(:errors)
|
||||
|
||||
subject.validate(status)
|
||||
expect(status).to_not receive(:errors)
|
||||
|
||||
expect(status).to_not have_received(:errors)
|
||||
end
|
||||
|
||||
it 'adds an error when content warning is over 500 characters' do
|
||||
|
|
|
@ -16,8 +16,9 @@ describe ActivityPub::DistributePollUpdateWorker do
|
|||
end
|
||||
|
||||
it 'delivers to followers' do
|
||||
expect_push_bulk_to_match(ActivityPub::DeliveryWorker, [[kind_of(String), account.id, 'http://example.com']])
|
||||
subject.perform(status.id)
|
||||
expect_push_bulk_to_match(ActivityPub::DeliveryWorker, [[kind_of(String), account.id, 'http://example.com']]) do
|
||||
subject.perform(status.id)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -19,8 +19,9 @@ describe ActivityPub::DistributionWorker do
|
|||
end
|
||||
|
||||
it 'delivers to followers' do
|
||||
expect_push_bulk_to_match(ActivityPub::DeliveryWorker, [[kind_of(String), status.account.id, 'http://example.com', anything]])
|
||||
subject.perform(status.id)
|
||||
expect_push_bulk_to_match(ActivityPub::DeliveryWorker, [[kind_of(String), status.account.id, 'http://example.com', anything]]) do
|
||||
subject.perform(status.id)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -30,8 +31,9 @@ describe ActivityPub::DistributionWorker do
|
|||
end
|
||||
|
||||
it 'delivers to followers' do
|
||||
expect_push_bulk_to_match(ActivityPub::DeliveryWorker, [[kind_of(String), status.account.id, 'http://example.com', anything]])
|
||||
subject.perform(status.id)
|
||||
expect_push_bulk_to_match(ActivityPub::DeliveryWorker, [[kind_of(String), status.account.id, 'http://example.com', anything]]) do
|
||||
subject.perform(status.id)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -44,8 +46,9 @@ describe ActivityPub::DistributionWorker do
|
|||
end
|
||||
|
||||
it 'delivers to mentioned accounts' do
|
||||
expect_push_bulk_to_match(ActivityPub::DeliveryWorker, [[kind_of(String), status.account.id, 'https://foo.bar/inbox', anything]])
|
||||
subject.perform(status.id)
|
||||
expect_push_bulk_to_match(ActivityPub::DeliveryWorker, [[kind_of(String), status.account.id, 'https://foo.bar/inbox', anything]]) do
|
||||
subject.perform(status.id)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -19,8 +19,9 @@ describe ActivityPub::MoveDistributionWorker do
|
|||
expect_push_bulk_to_match(ActivityPub::DeliveryWorker, [
|
||||
[kind_of(String), migration.account.id, 'http://example.com'],
|
||||
[kind_of(String), migration.account.id, 'http://example2.com'],
|
||||
])
|
||||
subject.perform(migration.id)
|
||||
]) do
|
||||
subject.perform(migration.id)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -25,9 +25,9 @@ describe ActivityPub::StatusUpdateDistributionWorker do
|
|||
end
|
||||
|
||||
it 'delivers to followers' do
|
||||
expect_push_bulk_to_match(ActivityPub::DeliveryWorker, [[kind_of(String), status.account.id, 'http://example.com', anything]])
|
||||
|
||||
subject.perform(status.id)
|
||||
expect_push_bulk_to_match(ActivityPub::DeliveryWorker, [[kind_of(String), status.account.id, 'http://example.com', anything]]) do
|
||||
subject.perform(status.id)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -37,9 +37,9 @@ describe ActivityPub::StatusUpdateDistributionWorker do
|
|||
end
|
||||
|
||||
it 'delivers to followers' do
|
||||
expect_push_bulk_to_match(ActivityPub::DeliveryWorker, [[kind_of(String), status.account.id, 'http://example.com', anything]])
|
||||
|
||||
subject.perform(status.id)
|
||||
expect_push_bulk_to_match(ActivityPub::DeliveryWorker, [[kind_of(String), status.account.id, 'http://example.com', anything]]) do
|
||||
subject.perform(status.id)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -14,8 +14,9 @@ describe ActivityPub::UpdateDistributionWorker do
|
|||
end
|
||||
|
||||
it 'delivers to followers' do
|
||||
expect_push_bulk_to_match(ActivityPub::DeliveryWorker, [[kind_of(String), account.id, 'http://example.com', anything]])
|
||||
subject.perform(account.id)
|
||||
expect_push_bulk_to_match(ActivityPub::DeliveryWorker, [[kind_of(String), account.id, 'http://example.com', anything]]) do
|
||||
subject.perform(account.id)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue