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

This commit is contained in:
KMY 2024-09-06 08:42:24 +09:00
commit f18eabfe75
689 changed files with 4369 additions and 2434 deletions

View file

@ -1,6 +1,6 @@
# frozen_string_literal: true
shared_examples 'forbidden for wrong scope' do |wrong_scope|
RSpec.shared_examples 'forbidden for wrong scope' do |wrong_scope|
let(:scopes) { wrong_scope }
it 'returns http forbidden' do
@ -11,7 +11,7 @@ shared_examples 'forbidden for wrong scope' do |wrong_scope|
end
end
shared_examples 'forbidden for wrong role' do |wrong_role|
RSpec.shared_examples 'forbidden for wrong role' do |wrong_role|
let(:role) { UserRole.find_by(name: wrong_role) }
it 'returns http forbidden' do

View file

@ -1,14 +0,0 @@
# frozen_string_literal: true
shared_examples 'cacheable response' do |expects_vary: false|
it 'sets correct cache and vary headers and does not set cookies or session', :aggregate_failures do
expect(response.cookies).to be_empty
expect(response.headers['Set-Cookies']).to be_nil
expect(session).to be_empty
expect(response.headers['Vary']).to include(expects_vary) if expects_vary
expect(response.headers['Cache-Control']).to include('public')
end
end

View file

@ -1,6 +1,6 @@
# frozen_string_literal: true
shared_examples 'CLI Command' do
RSpec.shared_examples 'CLI Command' do
it 'configures Thor to exit on failure' do
expect(described_class.exit_on_failure?).to be true
end

View file

@ -1,6 +1,6 @@
# frozen_string_literal: true
shared_examples 'a check available to devops users' do
RSpec.shared_examples 'a check available to devops users' do
describe 'skip?' do
context 'when user can view devops' do
before { allow(user).to receive(:can?).with(:view_devops).and_return(true) }

View file

@ -1,6 +1,6 @@
# frozen_string_literal: true
shared_examples 'localized subject' do |*args, **kwrest|
RSpec.shared_examples 'localized subject' do |*args, **kwrest|
it 'renders subject localized for the locale of the receiver' do
locale = :de
receiver.update!(locale: locale)

View file

@ -1,6 +1,6 @@
# frozen_string_literal: true
shared_examples 'AccountAvatar' do |fabricator|
RSpec.shared_examples 'AccountAvatar' do |fabricator|
describe 'static avatars', :attachment_processing do
describe 'when GIF' do
it 'creates a png static style' do

View file

@ -1,6 +1,6 @@
# frozen_string_literal: true
shared_examples 'AccountHeader' do |fabricator|
RSpec.shared_examples 'AccountHeader' do |fabricator|
describe 'base64-encoded files', :attachment_processing do
let(:base64_attachment) { "data:image/jpeg;base64,#{Base64.encode64(attachment_fixture('attachment.jpg').read)}" }
let(:account) { Fabricate(fabricator, header: base64_attachment) }

View file

@ -0,0 +1,54 @@
# frozen_string_literal: true
RSpec.shared_examples 'Reviewable' do
subject { described_class.new(reviewed_at: reviewed_at, requested_review_at: requested_review_at) }
let(:reviewed_at) { nil }
let(:requested_review_at) { nil }
describe '#requires_review?' do
it { is_expected.to be_requires_review }
context 'when reviewed_at is not null' do
let(:reviewed_at) { 5.days.ago }
it { is_expected.to_not be_requires_review }
end
end
describe '#reviewed?' do
it { is_expected.to_not be_reviewed }
context 'when reviewed_at is not null' do
let(:reviewed_at) { 5.days.ago }
it { is_expected.to be_reviewed }
end
end
describe '#requested_review?' do
it { is_expected.to_not be_requested_review }
context 'when requested_reviewed_at is not null' do
let(:requested_review_at) { 5.days.ago }
it { is_expected.to be_requested_review }
end
end
describe '#requires_review_notification?' do
it { is_expected.to be_requires_review_notification }
context 'when reviewed_at is not null' do
let(:reviewed_at) { 5.days.ago }
it { is_expected.to_not be_requires_review_notification }
end
context 'when requested_reviewed_at is not null' do
let(:requested_review_at) { 5.days.ago }
it { is_expected.to_not be_requires_review_notification }
end
end
end

View file

@ -3,7 +3,7 @@
RSpec::Matchers.define :include_pagination_headers do |links|
match do |response|
links.map do |key, value|
response.headers['Link'].find_link(['rel', key.to_s]).href == value
expect(response).to have_http_link_header(value).for(rel: key.to_s)
end.all?
end

View file

@ -0,0 +1,48 @@
# frozen_string_literal: true
RSpec::Matchers.define :have_cacheable_headers do
match do |response|
@response = response
@errors = [].tap do |errors|
errors << check_cookies
errors << check_cookie_headers
errors << check_session
errors << check_cache_control
errors << check_vary if @expected_vary.present?
end
@errors.compact.empty?
end
chain :with_vary do |string|
@expected_vary = string
end
failure_message do
<<~ERROR
Expected that the response would be cacheable but it was not:
- #{@errors.compact.join("\n - ")}
ERROR
end
def check_vary
"Response `Vary` header does not contain `#{@expected_vary}`" unless @response.headers['Vary'].include?(@expected_vary)
end
def check_cookies
'Reponse cookies are present' unless @response.cookies.empty?
end
def check_cookie_headers
'Response `Set-Cookies` headers are present' if @response.headers['Set-Cookies'].present?
end
def check_session
'The session is not empty' unless session.empty?
end
def check_cache_control
'The `Cache-Control` header does not contain `public`' unless @response.headers['Cache-Control'].include?('public')
end
end

View file

@ -0,0 +1,33 @@
# frozen_string_literal: true
RSpec::Matchers.define :have_http_link_header do |href|
match do |response|
@response = response
header_link&.href == href
end
match_when_negated do |response|
response.headers['Link'].blank?
end
chain :for do |attributes|
@attributes = attributes
end
failure_message do |response|
"Expected `#{response.headers['Link']}` to include `href` value of `#{href}` for `#{@attributes}` but it did not."
end
failure_message_when_negated do
"Expected response not to have a `Link` header but `#{response.headers['Link']}` is present."
end
def header_link
LinkHeader
.parse(@response.headers['Link'])
.find_link(*@attributes.stringify_keys)
end
end
RSpec::Matchers.define_negated_matcher :not_have_http_link_header, :have_http_link_header # Allow chaining

View file

@ -9,7 +9,9 @@ end
RSpec::Matchers.define :match_json_values do |values|
match do |string|
expect(json_str_to_hash(string))
parsed_json = JSON.parse(string, symbolize_names: true)
expect(parsed_json)
.to include(values)
end

View file

@ -0,0 +1,14 @@
# frozen_string_literal: true
RSpec::Matchers.define :have_private_cache_control do
match do |page|
page.response_headers['Cache-Control'] == 'private, no-store'
end
failure_message do |page|
<<~ERROR
Expected page to have `Cache-Control` header with `private, no-store` but it has:
#{page.response_headers['Cache-Control']}
ERROR
end
end

View file

@ -0,0 +1,8 @@
# frozen_string_literal: true
Shoulda::Matchers.configure do |config|
config.integrate do |with|
with.test_framework :rspec
with.library :rails
end
end

View file

@ -17,7 +17,7 @@ class StreamingServerManager
@running_thread = Thread.new do
Open3.popen2e(
{
'REDIS_NAMESPACE' => ENV.fetch('REDIS_NAMESPACE'),
'REDIS_NAMESPACE' => REDIS_CONFIGURATION.base[: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'),

View file

@ -0,0 +1,19 @@
# frozen_string_literal: true
module SystemHelpers
def admin_user
Fabricate(:user, role: UserRole.find_by(name: 'Admin'))
end
def submit_button
I18n.t('generic.save_changes')
end
def success_message
I18n.t('generic.changes_saved_msg')
end
def form_label(key)
I18n.t key, scope: 'simple_form.labels'
end
end