Merge remote-tracking branch 'parent/main' into kb_migration
This commit is contained in:
commit
979292d950
56 changed files with 774 additions and 277 deletions
|
@ -52,24 +52,36 @@ describe Admin::StatusesController do
|
|||
end
|
||||
|
||||
describe 'POST #batch' do
|
||||
before do
|
||||
post :batch, params: { :account_id => account.id, action => '', :admin_status_batch_action => { status_ids: status_ids } }
|
||||
end
|
||||
subject { post :batch, params: { :account_id => account.id, action => '', :admin_status_batch_action => { status_ids: status_ids } } }
|
||||
|
||||
let(:status_ids) { [media_attached_status.id] }
|
||||
|
||||
context 'when action is report' do
|
||||
shared_examples 'when action is report' do
|
||||
let(:action) { 'report' }
|
||||
|
||||
it 'creates a report' do
|
||||
subject
|
||||
|
||||
report = Report.last
|
||||
expect(report.target_account_id).to eq account.id
|
||||
expect(report.status_ids).to eq status_ids
|
||||
end
|
||||
|
||||
it 'redirects to report page' do
|
||||
subject
|
||||
|
||||
expect(response).to redirect_to(admin_report_path(Report.last.id))
|
||||
end
|
||||
end
|
||||
|
||||
it_behaves_like 'when action is report'
|
||||
|
||||
context 'when the moderator is blocked by the author' do
|
||||
before do
|
||||
account.block!(user.account)
|
||||
end
|
||||
|
||||
it_behaves_like 'when action is report'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -15,12 +15,13 @@ describe Api::V1::DirectoriesController do
|
|||
describe 'GET #show' do
|
||||
context 'with no params' do
|
||||
before do
|
||||
_local_unconfirmed_account = Fabricate(
|
||||
local_unconfirmed_account = Fabricate(
|
||||
:account,
|
||||
domain: nil,
|
||||
user: Fabricate(:user, confirmed_at: nil, approved: true),
|
||||
username: 'local_unconfirmed'
|
||||
)
|
||||
local_unconfirmed_account.create_account_stat!
|
||||
|
||||
local_unapproved_account = Fabricate(
|
||||
:account,
|
||||
|
@ -28,15 +29,17 @@ describe Api::V1::DirectoriesController do
|
|||
user: Fabricate(:user, confirmed_at: 10.days.ago),
|
||||
username: 'local_unapproved'
|
||||
)
|
||||
local_unapproved_account.create_account_stat!
|
||||
local_unapproved_account.user.update(approved: false)
|
||||
|
||||
_local_undiscoverable_account = Fabricate(
|
||||
local_undiscoverable_account = Fabricate(
|
||||
:account,
|
||||
domain: nil,
|
||||
user: Fabricate(:user, confirmed_at: 10.days.ago, approved: true),
|
||||
discoverable: false,
|
||||
username: 'local_undiscoverable'
|
||||
)
|
||||
local_undiscoverable_account.create_account_stat!
|
||||
|
||||
excluded_from_timeline_account = Fabricate(
|
||||
:account,
|
||||
|
@ -44,18 +47,20 @@ describe Api::V1::DirectoriesController do
|
|||
discoverable: true,
|
||||
username: 'remote_excluded_from_timeline'
|
||||
)
|
||||
excluded_from_timeline_account.create_account_stat!
|
||||
Fabricate(:block, account: user.account, target_account: excluded_from_timeline_account)
|
||||
|
||||
_domain_blocked_account = Fabricate(
|
||||
domain_blocked_account = Fabricate(
|
||||
:account,
|
||||
domain: 'test.example',
|
||||
discoverable: true,
|
||||
username: 'remote_domain_blocked'
|
||||
)
|
||||
domain_blocked_account.create_account_stat!
|
||||
Fabricate(:account_domain_block, account: user.account, domain: 'test.example')
|
||||
end
|
||||
|
||||
it 'returns only the local discoverable account' do
|
||||
it 'returns the local discoverable account and the remote discoverable account' do
|
||||
local_discoverable_account = Fabricate(
|
||||
:account,
|
||||
domain: nil,
|
||||
|
@ -63,6 +68,7 @@ describe Api::V1::DirectoriesController do
|
|||
discoverable: true,
|
||||
username: 'local_discoverable'
|
||||
)
|
||||
local_discoverable_account.create_account_stat!
|
||||
|
||||
eligible_remote_account = Fabricate(
|
||||
:account,
|
||||
|
@ -70,13 +76,13 @@ describe Api::V1::DirectoriesController do
|
|||
discoverable: true,
|
||||
username: 'eligible_remote'
|
||||
)
|
||||
eligible_remote_account.create_account_stat!
|
||||
|
||||
get :show
|
||||
|
||||
expect(response).to have_http_status(200)
|
||||
expect(body_as_json.size).to eq(2)
|
||||
expect(body_as_json.first[:id]).to include(eligible_remote_account.id.to_s)
|
||||
expect(body_as_json.second[:id]).to include(local_discoverable_account.id.to_s)
|
||||
expect(body_as_json.pluck(:id)).to contain_exactly(eligible_remote_account.id.to_s, local_discoverable_account.id.to_s)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -85,6 +91,8 @@ describe Api::V1::DirectoriesController do
|
|||
user = Fabricate(:user, confirmed_at: 10.days.ago, approved: true)
|
||||
local_account = Fabricate(:account, domain: nil, user: user)
|
||||
remote_account = Fabricate(:account, domain: 'host.example')
|
||||
local_account.create_account_stat!
|
||||
remote_account.create_account_stat!
|
||||
|
||||
get :show, params: { local: '1' }
|
||||
|
||||
|
@ -97,24 +105,23 @@ describe Api::V1::DirectoriesController do
|
|||
|
||||
context 'when ordered by active' do
|
||||
it 'returns accounts in order of most recent status activity' do
|
||||
status_old = Fabricate(:status)
|
||||
travel_to 10.seconds.from_now
|
||||
status_new = Fabricate(:status)
|
||||
old_stat = Fabricate(:account_stat, last_status_at: 1.day.ago)
|
||||
new_stat = Fabricate(:account_stat, last_status_at: 1.minute.ago)
|
||||
|
||||
get :show, params: { order: 'active' }
|
||||
|
||||
expect(response).to have_http_status(200)
|
||||
expect(body_as_json.size).to eq(2)
|
||||
expect(body_as_json.first[:id]).to include(status_new.account.id.to_s)
|
||||
expect(body_as_json.second[:id]).to include(status_old.account.id.to_s)
|
||||
expect(body_as_json.first[:id]).to include(new_stat.account_id.to_s)
|
||||
expect(body_as_json.second[:id]).to include(old_stat.account_id.to_s)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when ordered by new' do
|
||||
it 'returns accounts in order of creation' do
|
||||
account_old = Fabricate(:account)
|
||||
account_old = Fabricate(:account_stat).account
|
||||
travel_to 10.seconds.from_now
|
||||
account_new = Fabricate(:account)
|
||||
account_new = Fabricate(:account_stat).account
|
||||
|
||||
get :show, params: { order: 'new' }
|
||||
|
||||
|
|
|
@ -57,4 +57,24 @@ describe SearchQueryTransformer do
|
|||
expect(subject.send(:filter_clauses)).to be_empty
|
||||
end
|
||||
end
|
||||
|
||||
context 'with \'"hello world"\'' do
|
||||
let(:query) { '"hello world"' }
|
||||
|
||||
it 'transforms clauses' do
|
||||
expect(subject.send(:must_clauses).map(&:phrase)).to contain_exactly('hello world')
|
||||
expect(subject.send(:must_not_clauses)).to be_empty
|
||||
expect(subject.send(:filter_clauses)).to be_empty
|
||||
end
|
||||
end
|
||||
|
||||
context 'with \'before:"2022-01-01 23:00"\'' do
|
||||
let(:query) { 'before:"2022-01-01 23:00"' }
|
||||
|
||||
it 'transforms clauses' do
|
||||
expect(subject.send(:must_clauses)).to be_empty
|
||||
expect(subject.send(:must_not_clauses)).to be_empty
|
||||
expect(subject.send(:filter_clauses).map(&:term)).to contain_exactly(lt: '2022-01-01 23:00', time_zone: 'UTC')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -228,6 +228,20 @@ RSpec.describe AccountStatusesFilter do
|
|||
end
|
||||
end
|
||||
|
||||
context 'when blocking a reblogged domain' do
|
||||
let(:other_account) { Fabricate(:account, domain: 'example.com') }
|
||||
let(:reblogging_status) { Fabricate(:status, account: other_account) }
|
||||
let(:reblog) { Fabricate(:status, account: account, visibility: 'public', reblog: reblogging_status) }
|
||||
|
||||
before do
|
||||
current_account.block_domain!(other_account.domain)
|
||||
end
|
||||
|
||||
it 'does not return reblog of blocked domain' do
|
||||
expect(subject.results.pluck(:id)).to_not include(reblog.id)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when muting a reblogged account' do
|
||||
let(:reblog) { status_with_reblog!('public') }
|
||||
|
||||
|
|
|
@ -7,7 +7,8 @@ describe Admin::StatusPolicy do
|
|||
let(:policy) { described_class }
|
||||
let(:admin) { Fabricate(:user, role: UserRole.find_by(name: 'Admin')).account }
|
||||
let(:john) { Fabricate(:account) }
|
||||
let(:status) { Fabricate(:status) }
|
||||
let(:status) { Fabricate(:status, visibility: status_visibility) }
|
||||
let(:status_visibility) { :public }
|
||||
|
||||
permissions :index?, :update?, :review?, :destroy? do
|
||||
context 'with an admin' do
|
||||
|
@ -26,7 +27,7 @@ describe Admin::StatusPolicy do
|
|||
permissions :show? do
|
||||
context 'with an admin' do
|
||||
context 'with a public visible status' do
|
||||
before { allow(status).to receive(:public_visibility?).and_return(true) }
|
||||
let(:status_visibility) { :public }
|
||||
|
||||
it 'permits' do
|
||||
expect(policy).to permit(admin, status)
|
||||
|
@ -34,11 +35,21 @@ describe Admin::StatusPolicy do
|
|||
end
|
||||
|
||||
context 'with a not public visible status' do
|
||||
before { allow(status).to receive(:public_visibility?).and_return(false) }
|
||||
let(:status_visibility) { :direct }
|
||||
|
||||
it 'denies' do
|
||||
expect(policy).to_not permit(admin, status)
|
||||
end
|
||||
|
||||
context 'when the status mentions the admin' do
|
||||
before do
|
||||
status.mentions.create!(account: admin)
|
||||
end
|
||||
|
||||
it 'permits' do
|
||||
expect(policy).to permit(admin, status)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -4,11 +4,17 @@ ENV['RAILS_ENV'] ||= 'test'
|
|||
|
||||
# This needs to be defined before Rails is initialized
|
||||
RUN_SYSTEM_SPECS = ENV.fetch('RUN_SYSTEM_SPECS', false)
|
||||
RUN_SEARCH_SPECS = ENV.fetch('RUN_SEARCH_SPECS', false)
|
||||
|
||||
if RUN_SYSTEM_SPECS
|
||||
STREAMING_PORT = ENV.fetch('TEST_STREAMING_PORT', '4020')
|
||||
ENV['STREAMING_API_BASE_URL'] = "http://localhost:#{STREAMING_PORT}"
|
||||
end
|
||||
|
||||
if RUN_SEARCH_SPECS
|
||||
# Include any configuration or setups specific to search tests here
|
||||
end
|
||||
|
||||
require File.expand_path('../config/environment', __dir__)
|
||||
|
||||
abort('The Rails environment is running in production mode!') if Rails.env.production?
|
||||
|
@ -30,6 +36,7 @@ Sidekiq.logger = nil
|
|||
# System tests config
|
||||
DatabaseCleaner.strategy = [:deletion]
|
||||
streaming_server_manager = StreamingServerManager.new
|
||||
search_data_manager = SearchDataManager.new
|
||||
|
||||
Devise::Test::ControllerHelpers.module_eval do
|
||||
alias_method :original_sign_in, :sign_in
|
||||
|
@ -69,7 +76,14 @@ end
|
|||
|
||||
RSpec.configure do |config|
|
||||
# This is set before running spec:system, see lib/tasks/tests.rake
|
||||
config.filter_run_excluding type: :system unless RUN_SYSTEM_SPECS
|
||||
config.filter_run_excluding type: lambda { |type|
|
||||
case type
|
||||
when :system
|
||||
!RUN_SYSTEM_SPECS
|
||||
when :search
|
||||
!RUN_SEARCH_SPECS
|
||||
end
|
||||
}
|
||||
config.fixture_path = Rails.root.join('spec', 'fixtures')
|
||||
config.use_transactional_fixtures = true
|
||||
config.order = 'random'
|
||||
|
@ -113,10 +127,17 @@ RSpec.configure do |config|
|
|||
Webpacker.compile
|
||||
streaming_server_manager.start(port: STREAMING_PORT)
|
||||
end
|
||||
|
||||
if RUN_SEARCH_SPECS
|
||||
Chewy.strategy(:urgent)
|
||||
search_data_manager.prepare_test_data
|
||||
end
|
||||
end
|
||||
|
||||
config.after :suite do
|
||||
streaming_server_manager.stop
|
||||
|
||||
search_data_manager.cleanup_test_data if RUN_SEARCH_SPECS
|
||||
end
|
||||
|
||||
config.around :each, type: :system do |example|
|
||||
|
@ -137,6 +158,12 @@ RSpec.configure do |config|
|
|||
self.use_transactional_tests = true
|
||||
end
|
||||
|
||||
config.around :each, type: :search do |example|
|
||||
search_data_manager.populate_indexes
|
||||
example.run
|
||||
search_data_manager.remove_indexes
|
||||
end
|
||||
|
||||
config.before(:each) do |example|
|
||||
unless example.metadata[:paperclip_processing]
|
||||
allow_any_instance_of(Paperclip::Attachment).to receive(:post_process).and_return(true) # rubocop:disable RSpec/AnyInstance
|
||||
|
|
51
spec/search/models/concerns/account_search_spec.rb
Normal file
51
spec/search/models/concerns/account_search_spec.rb
Normal file
|
@ -0,0 +1,51 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
describe AccountSearch do
|
||||
describe 'a non-discoverable account becoming discoverable' do
|
||||
let(:account) { Account.find_by(username: 'search_test_account_1') }
|
||||
|
||||
context 'when picking a non-discoverable account' do
|
||||
it 'its bio is not in the AccountsIndex' do
|
||||
results = AccountsIndex.filter(term: { username: account.username })
|
||||
expect(results.count).to eq(1)
|
||||
expect(results.first.text).to be_nil
|
||||
end
|
||||
end
|
||||
|
||||
context 'when the non-discoverable account becomes discoverable' do
|
||||
it 'its bio is added to the AccountsIndex' do
|
||||
account.discoverable = true
|
||||
account.save!
|
||||
|
||||
results = AccountsIndex.filter(term: { username: account.username })
|
||||
expect(results.count).to eq(1)
|
||||
expect(results.first.text).to eq(account.note)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'a discoverable account becoming non-discoverable' do
|
||||
let(:account) { Account.find_by(username: 'search_test_account_0') }
|
||||
|
||||
context 'when picking an discoverable account' do
|
||||
it 'has its bio in the AccountsIndex' do
|
||||
results = AccountsIndex.filter(term: { username: account.username })
|
||||
expect(results.count).to eq(1)
|
||||
expect(results.first.text).to eq(account.note)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when the discoverable account becomes non-discoverable' do
|
||||
it 'its bio is removed from the AccountsIndex' do
|
||||
account.discoverable = false
|
||||
account.save!
|
||||
|
||||
results = AccountsIndex.filter(term: { username: account.username })
|
||||
expect(results.count).to eq(1)
|
||||
expect(results.first.text).to be_nil
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
53
spec/search/models/concerns/account_statuses_search_spec.rb
Normal file
53
spec/search/models/concerns/account_statuses_search_spec.rb
Normal file
|
@ -0,0 +1,53 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
describe AccountStatusesSearch do
|
||||
describe 'a non-indexable account becoming indexable' do
|
||||
let(:account) { Account.find_by(username: 'search_test_account_1') }
|
||||
|
||||
context 'when picking a non-indexable account' do
|
||||
it 'has no statuses in the PublicStatusesIndex' do
|
||||
expect(PublicStatusesIndex.filter(term: { account_id: account.id }).count).to eq(0)
|
||||
end
|
||||
|
||||
it 'has statuses in the StatusesIndex' do
|
||||
expect(StatusesIndex.filter(term: { account_id: account.id }).count).to eq(account.statuses.count)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when the non-indexable account becomes indexable' do
|
||||
it 'adds the public statuses to the PublicStatusesIndex' do
|
||||
account.indexable = true
|
||||
account.save!
|
||||
|
||||
expect(PublicStatusesIndex.filter(term: { account_id: account.id }).count).to eq(account.statuses.where(visibility: :public).count)
|
||||
expect(StatusesIndex.filter(term: { account_id: account.id }).count).to eq(account.statuses.count)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'an indexable account becoming non-indexable' do
|
||||
let(:account) { Account.find_by(username: 'search_test_account_0') }
|
||||
|
||||
context 'when picking an indexable account' do
|
||||
it 'has statuses in the PublicStatusesIndex' do
|
||||
expect(PublicStatusesIndex.filter(term: { account_id: account.id }).count).to eq(account.statuses.where(visibility: :public).count)
|
||||
end
|
||||
|
||||
it 'has statuses in the StatusesIndex' do
|
||||
expect(StatusesIndex.filter(term: { account_id: account.id }).count).to eq(account.statuses.count)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when the indexable account becomes non-indexable' do
|
||||
it 'removes the statuses from the PublicStatusesIndex' do
|
||||
account.indexable = false
|
||||
account.save!
|
||||
|
||||
expect(PublicStatusesIndex.filter(term: { account_id: account.id }).count).to eq(0)
|
||||
expect(StatusesIndex.filter(term: { account_id: account.id }).count).to eq(account.statuses.count)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -135,3 +135,45 @@ class StreamingServerManager
|
|||
@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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue