Merge pull request #462 from kmycode/upstream-20240115

Upstream 20240115
This commit is contained in:
KMY(雪あすか) 2024-01-15 19:58:03 +09:00 committed by GitHub
commit 90bd2a0f00
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
341 changed files with 1113 additions and 558 deletions

View file

@ -12,6 +12,8 @@ RSpec.describe Admin::InstancesController do
before do
_account_less_popular = Fabricate(:account, domain: 'less.popular')
_account_popular_other = Fabricate(:account, domain: 'popular')
Instance.refresh
sign_in current_user, scope: :user
end

View file

@ -10,19 +10,38 @@ RSpec.describe Disputes::AppealsController do
let!(:admin) { Fabricate(:user, role: UserRole.find_by(name: 'Admin')) }
describe '#create' do
let(:current_user) { Fabricate(:user) }
let(:strike) { Fabricate(:account_warning, target_account: current_user.account) }
context 'with valid params' do
let(:current_user) { Fabricate(:user) }
let(:strike) { Fabricate(:account_warning, target_account: current_user.account) }
before do
post :create, params: { strike_id: strike.id, appeal: { text: 'Foo' } }
before do
post :create, params: { strike_id: strike.id, appeal: { text: 'Foo' } }
end
it 'notifies staff about new appeal', :sidekiq_inline do
expect(ActionMailer::Base.deliveries.first.to).to eq([admin.email])
end
it 'redirects back to the strike page' do
expect(response).to redirect_to(disputes_strike_path(strike.id))
end
end
it 'notifies staff about new appeal', :sidekiq_inline do
expect(ActionMailer::Base.deliveries.first.to).to eq([admin.email])
end
context 'with invalid params' do
let(:current_user) { Fabricate(:user) }
let(:strike) { Fabricate(:account_warning, target_account: current_user.account) }
it 'redirects back to the strike page' do
expect(response).to redirect_to(disputes_strike_path(strike.id))
before do
post :create, params: { strike_id: strike.id, appeal: { text: '' } }
end
it 'does not send email', :sidekiq_inline do
expect(ActionMailer::Base.deliveries.size).to eq(0)
end
it 'renders the strike show page' do
expect(response).to render_template('disputes/strikes/show')
end
end
end
end

View file

@ -0,0 +1,6 @@
# frozen_string_literal: true
Fabricator(:follow_recommendation_mute) do
account { Fabricate.build(:account) }
target_account { Fabricate.build(:account) }
end

View file

@ -139,6 +139,14 @@ RSpec.describe ActivityPub::TagManager do
expect(subject.cc(status)).to include(subject.uri_for(foo))
expect(subject.cc(status)).to_not include(subject.uri_for(alice))
end
it 'returns poster of reblogged post, if reblog' do
bob = Fabricate(:account, username: 'bob', domain: 'example.com', inbox_url: 'http://example.com/bob')
alice = Fabricate(:account, username: 'alice')
status = Fabricate(:status, visibility: :public, account: bob)
reblog = Fabricate(:status, visibility: :public, account: alice, reblog: status)
expect(subject.cc(reblog)).to include(subject.uri_for(bob))
end
end
describe '#cc_for_misskey' do

View file

@ -1222,27 +1222,4 @@ RSpec.describe Account do
expect(subject.reload.followers_count).to eq 15
end
end
describe '.followable_by' do
context 'with follows and follow requests' do
let!(:account) { Fabricate(:account) }
let!(:eligible_account) { Fabricate(:account) }
let!(:following_account) { Fabricate(:account) }
let!(:follow_requested_account) { Fabricate(:account) }
before do
Fabricate :follow, account: account, target_account: following_account
Fabricate :follow_request, account: account, target_account: follow_requested_account
end
it 'returns accounts not already following or requested to follow' do
results = described_class.followable_by(account)
expect(results)
.to include(eligible_account)
.and not_include(following_account)
.and not_include(follow_requested_account)
end
end
end
end

View file

@ -0,0 +1,57 @@
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe AccountSuggestions::Source do
describe '#base_account_scope' do
subject { FakeSource.new }
before do
stub_const 'FakeSource', fake_source_class
end
context 'with follows and follow requests' do
let!(:account_domain_blocked_account) { Fabricate(:account, domain: 'blocked.host') }
let!(:account) { Fabricate(:account) }
let!(:blocked_account) { Fabricate(:account) }
let!(:eligible_account) { Fabricate(:account) }
let!(:follow_recommendation_muted_account) { Fabricate(:account) }
let!(:follow_requested_account) { Fabricate(:account) }
let!(:following_account) { Fabricate(:account) }
let!(:moved_account) { Fabricate(:account, moved_to_account: Fabricate(:account)) }
before do
Fabricate :account_domain_block, account: account, domain: account_domain_blocked_account.domain
Fabricate :block, account: account, target_account: blocked_account
Fabricate :follow_recommendation_mute, account: account, target_account: follow_recommendation_muted_account
Fabricate :follow_request, account: account, target_account: follow_requested_account
Fabricate :follow, account: account, target_account: following_account
end
it 'returns eligible accounts' do
results = subject.get(account)
expect(results)
.to include(eligible_account)
.and not_include(account_domain_blocked_account)
.and not_include(account)
.and not_include(blocked_account)
.and not_include(follow_recommendation_muted_account)
.and not_include(follow_requested_account)
.and not_include(following_account)
.and not_include(moved_account)
end
end
end
private
def fake_source_class
Class.new described_class do
def get(account, limit: 10)
base_account_scope(account)
.limit(limit)
end
end
end
end

View file

@ -2,20 +2,18 @@
require 'rails_helper'
RSpec.describe Api::V1::MarkersController do
render_views
RSpec.describe 'API Markers' do
let(:user) { Fabricate(:user) }
let(:scopes) { 'read:statuses write:statuses' }
let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: scopes) }
let(:headers) { { 'Authorization' => "Bearer #{token.token}" } }
let!(:user) { Fabricate(:user) }
let!(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: 'read:statuses write:statuses') }
before { allow(controller).to receive(:doorkeeper_token) { token } }
describe 'GET #index' do
describe 'GET /api/v1/markers' do
before do
Fabricate(:marker, timeline: 'home', last_read_id: 123, user: user)
Fabricate(:marker, timeline: 'notifications', last_read_id: 456, user: user)
get :index, params: { timeline: %w(home notifications) }
get '/api/v1/markers', headers: headers, params: { timeline: %w(home notifications) }
end
it 'returns markers', :aggregate_failures do
@ -29,10 +27,10 @@ RSpec.describe Api::V1::MarkersController do
end
end
describe 'POST #create' do
describe 'POST /api/v1/markers' do
context 'when no marker exists' do
before do
post :create, params: { home: { last_read_id: '69420' } }
post '/api/v1/markers', headers: headers, params: { home: { last_read_id: '69420' } }
end
it 'creates a marker', :aggregate_failures do
@ -44,8 +42,8 @@ RSpec.describe Api::V1::MarkersController do
context 'when a marker exists' do
before do
post :create, params: { home: { last_read_id: '69420' } }
post :create, params: { home: { last_read_id: '70120' } }
post '/api/v1/markers', headers: headers, params: { home: { last_read_id: '69420' } }
post '/api/v1/markers', headers: headers, params: { home: { last_read_id: '70120' } }
end
it 'updates a marker', :aggregate_failures do

View file

@ -0,0 +1,60 @@
# frozen_string_literal: true
require 'rails_helper'
describe 'Custom CSS' do
include RoutingHelper
describe 'GET /custom.css' do
context 'without any CSS or User Roles' do
it 'returns empty stylesheet' do
get '/custom.css'
expect(response.content_type).to include('text/css')
expect(response.body.presence).to be_nil
end
end
context 'with CSS settings' do
before do
Setting.custom_css = expected_css
end
it 'returns stylesheet from settings' do
get '/custom.css'
expect(response.content_type).to include('text/css')
expect(response.body.strip).to eq(expected_css)
end
def expected_css
<<~CSS.strip
body { background-color: red; }
CSS
end
end
context 'with highlighted colored UserRole records' do
before do
_highlighted_colored = Fabricate :user_role, highlighted: true, color: '#336699', id: '123_123_123'
_highlighted_no_color = Fabricate :user_role, highlighted: true, color: ''
_no_highlight_with_color = Fabricate :user_role, highlighted: false, color: ''
end
it 'returns stylesheet from settings' do
get '/custom.css'
expect(response.content_type).to include('text/css')
expect(response.body.strip).to eq(expected_css)
end
def expected_css
<<~CSS.strip
.user-role-123123123 {
--user-role-accent: #336699;
}
CSS
end
end
end
end

View file

@ -86,9 +86,5 @@ RSpec.describe ReblogService, type: :service do
it 'distributes to followers' do
expect(ActivityPub::DistributionWorker).to have_received(:perform_async)
end
it 'sends an announce activity to the author', :sidekiq_inline do
expect(a_request(:post, bob.inbox_url)).to have_been_made.once
end
end
end

View file

@ -169,4 +169,22 @@ RSpec.describe RemoveStatusService, :sidekiq_inline, type: :service do
)).to have_been_made.once
end
end
context 'when removed status is a reblog of a non-follower' do
let!(:original_status) { Fabricate(:status, account: bill, text: 'Hello ThisIsASecret', visibility: :public) }
let!(:status) { ReblogService.new.call(alice, original_status) }
it 'sends Undo activity to followers' do
subject.call(status)
expect(a_request(:post, bill.shared_inbox_url).with(
body: hash_including({
'type' => 'Undo',
'object' => hash_including({
'type' => 'Announce',
'object' => ActivityPub::TagManager.instance.uri_for(original_status),
}),
})
)).to have_been_made.once
end
end
end

View file

@ -0,0 +1,18 @@
# frozen_string_literal: true
RSpec.configure do |config|
config.after(:each, type: :system) do
errors = page.driver.browser.logs.get(:browser)
if errors.present?
aggregate_failures 'javascript errrors' do
errors.each do |error|
expect(error.level).to_not eq('SEVERE'), error.message
next unless error.level == 'WARNING'
$stderr.warn 'WARN: javascript warning'
$stderr.warn error.message
end
end
end
end
end