1
0
Fork 0
forked from gitea/nas

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

This commit is contained in:
KMY 2024-12-16 10:14:31 +09:00
commit 3784ad273c
555 changed files with 7564 additions and 3363 deletions

View file

@ -0,0 +1,33 @@
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe AccountPin do
describe 'Associations' do
it { is_expected.to belong_to(:account).required }
it { is_expected.to belong_to(:target_account).required }
end
describe 'Validations' do
describe 'the follow relationship' do
subject { Fabricate.build :account_pin, account: account }
let(:account) { Fabricate :account }
let(:target_account) { Fabricate :account }
context 'when account is following target account' do
before { account.follow!(target_account) }
it { is_expected.to allow_value(target_account).for(:target_account).against(:base) }
end
context 'when account is not following target account' do
it { is_expected.to_not allow_value(target_account).for(:target_account).against(:base).with_message(not_following_message) }
def not_following_message
I18n.t('accounts.pin_errors.following')
end
end
end
end
end

View file

@ -7,19 +7,8 @@ RSpec.describe CustomFilter do
it { is_expected.to validate_presence_of(:title) }
it { is_expected.to validate_presence_of(:context) }
it 'requires non-empty of context' do
record = described_class.new(context: [])
record.valid?
expect(record).to model_have_error_on_field(:context)
end
it 'requires valid context value' do
record = described_class.new(context: ['invalid'])
record.valid?
expect(record).to model_have_error_on_field(:context)
end
it { is_expected.to_not allow_values([], %w(invalid)).for(:context) }
it { is_expected.to allow_values(%w(home)).for(:context) }
end
describe 'Normalizations' do

View file

@ -61,10 +61,7 @@ RSpec.describe Form::Import do
let(:import_type) { 'following' }
let(:import_file) { 'boop.ogg' }
it 'has errors' do
# NOTE: not testing more specific error because we don't know the string to match
expect(subject).to model_have_error_on_field(:data)
end
it { is_expected.to_not allow_value(data).for(:data) }
end
context 'when importing more follows than allowed' do

View file

@ -90,7 +90,7 @@ RSpec.describe MediaAttachment, :attachment_processing do
media.destroy
end
it 'saves media attachment with correct file and size metadata' do
it 'saves metadata and generates styles' do
expect(media)
.to be_persisted
.and be_processing_complete
@ -98,18 +98,28 @@ RSpec.describe MediaAttachment, :attachment_processing do
file: be_present,
type: eq('image'),
file_content_type: eq(content_type),
file_file_name: end_with(extension)
file_file_name: end_with(extension),
blurhash: have_attributes(size: eq(36))
)
# Rack::Mime (used by PublicFileServerMiddleware) recognizes file extension
expect(Rack::Mime.mime_type(extension, nil)).to eq content_type
# Strip original file name
expect(media.file_file_name)
.to_not start_with '600x400'
# Generate styles
expect(FastImage.size(media.file.path(:original)))
.to eq [600, 400]
expect(FastImage.size(media.file.path(:small)))
.to eq [588, 392]
# Use extension recognized by Rack::Mime (used by PublicFileServerMiddleware)
expect(media.file.path(:original))
.to end_with(extension)
expect(media.file.path(:small))
.to end_with(extension)
# Set meta for original and thumbnail
expect(media.file.meta.deep_symbolize_keys)
expect(media_metadata)
.to include(
original: include(
width: eq(600),
@ -122,6 +132,60 @@ RSpec.describe MediaAttachment, :attachment_processing do
aspect: eq(1.5)
)
)
# Rack::Mime (used by PublicFileServerMiddleware) recognizes file extension
expect(Rack::Mime.mime_type(extension, nil)).to eq content_type
end
end
shared_examples 'animated 600x400 image' do
after do
media.destroy
end
it 'saves metadata and generates styles' do
expect(media)
.to be_persisted
.and be_processing_complete
.and have_attributes(
file: be_present,
type: eq('gifv'),
file_content_type: eq('video/mp4'),
file_file_name: end_with('.mp4'),
blurhash: have_attributes(size: eq(36))
)
# Strip original file name
expect(media.file_file_name)
.to_not start_with '600x400'
# Transcode to MP4
expect(media.file.path(:original))
.to end_with('.mp4')
# Generate static thumbnail
expect(FastImage.size(media.file.path(:small)))
.to eq [600, 400]
expect(FastImage.animated?(media.file.path(:small)))
.to be false
expect(media.file.path(:small))
.to end_with('.png')
# Set meta for styles
expect(media_metadata)
.to include(
original: include(
width: eq(600),
height: eq(400),
duration: eq(3),
frame_rate: '1/1'
),
small: include(
width: eq(600),
height: eq(400),
aspect: eq(1.5)
)
)
end
end
@ -137,10 +201,10 @@ RSpec.describe MediaAttachment, :attachment_processing do
it_behaves_like 'static 600x400 image', 'image/png', '.png'
end
describe 'monochrome jpg' do
let(:media) { Fabricate(:media_attachment, file: attachment_fixture('monochrome.png')) }
describe 'gif' do
let(:media) { Fabricate(:media_attachment, file: attachment_fixture('600x400.gif')) }
it_behaves_like 'static 600x400 image', 'image/png', '.png'
it_behaves_like 'static 600x400 image', 'image/gif', '.gif'
end
describe 'webp' do
@ -161,6 +225,12 @@ RSpec.describe MediaAttachment, :attachment_processing do
it_behaves_like 'static 600x400 image', 'image/jpeg', '.jpeg'
end
describe 'monochrome jpg' do
let(:media) { Fabricate(:media_attachment, file: attachment_fixture('monochrome.png')) }
it_behaves_like 'static 600x400 image', 'image/png', '.png'
end
describe 'base64-encoded image' do
let(:base64_attachment) { "data:image/jpeg;base64,#{Base64.encode64(attachment_fixture('600x400.jpeg').read)}" }
let(:media) { Fabricate(:media_attachment, file: base64_attachment) }
@ -169,51 +239,15 @@ RSpec.describe MediaAttachment, :attachment_processing do
end
describe 'animated gif' do
let(:media) { Fabricate(:media_attachment, file: attachment_fixture('avatar.gif')) }
let(:media) { Fabricate(:media_attachment, file: attachment_fixture('600x400-animated.gif')) }
it 'sets correct file metadata' do
expect(media)
.to have_attributes(
type: eq('gifv'),
file_content_type: eq('video/mp4')
)
expect(media_metadata)
.to include(
original: include(
width: eq(128),
height: eq(128)
)
)
end
it_behaves_like 'animated 600x400 image'
end
describe 'static gif' do
fixtures = [
{ filename: 'attachment.gif', width: 600, height: 400, aspect: 1.5 },
{ filename: 'mini-static.gif', width: 32, height: 32, aspect: 1.0 },
]
describe 'animated png' do
let(:media) { Fabricate(:media_attachment, file: attachment_fixture('600x400-animated.png')) }
fixtures.each do |fixture|
context fixture[:filename] do
let(:media) { Fabricate(:media_attachment, file: attachment_fixture(fixture[:filename])) }
it 'sets correct file metadata' do
expect(media)
.to have_attributes(
type: eq('image'),
file_content_type: eq('image/gif')
)
expect(media_metadata)
.to include(
original: include(
width: eq(fixture[:width]),
height: eq(fixture[:height]),
aspect: eq(fixture[:aspect])
)
)
end
end
end
it_behaves_like 'animated 600x400 image'
end
describe 'ogg with cover art' do

View file

@ -3,8 +3,14 @@
require 'rails_helper'
RSpec.describe Mention do
describe 'validations' do
describe 'Associations' do
it { is_expected.to belong_to(:account).required }
it { is_expected.to belong_to(:status).required }
end
describe 'Validations' do
subject { Fabricate.build :mention }
it { is_expected.to validate_uniqueness_of(:account_id).scoped_to(:status_id) }
end
end

View file

@ -105,25 +105,32 @@ RSpec.describe Report do
describe 'history' do
subject(:action_logs) { report.history }
let(:report) { Fabricate(:report, target_account_id: target_account.id, status_ids: [status.id], created_at: 3.days.ago, updated_at: 1.day.ago) }
let(:report) { Fabricate(:report, target_account_id: target_account.id, status_ids: [status.id]) }
let(:target_account) { Fabricate(:account) }
let(:status) { Fabricate(:status) }
let(:account_warning) { Fabricate(:account_warning, report_id: report.id) }
before do
Fabricate(:action_log, target_type: 'Report', account_id: target_account.id, target_id: report.id, created_at: 2.days.ago)
Fabricate(:action_log, target_type: 'Account', account_id: target_account.id, target_id: report.target_account_id, created_at: 2.days.ago)
Fabricate(:action_log, target_type: 'Status', account_id: target_account.id, target_id: status.id, created_at: 2.days.ago)
Fabricate(:action_log, target_type: 'AccountWarning', account_id: target_account.id, target_id: account_warning.id, created_at: 2.days.ago)
end
let!(:matched_type_account_warning) { Fabricate(:action_log, target_type: 'AccountWarning', target_id: account_warning.id) }
let!(:matched_type_account) { Fabricate(:action_log, target_type: 'Account', target_id: report.target_account_id) }
let!(:matched_type_report) { Fabricate(:action_log, target_type: 'Report', target_id: report.id) }
let!(:matched_type_status) { Fabricate(:action_log, target_type: 'Status', target_id: status.id) }
let!(:unmatched_type_account_warning) { Fabricate(:action_log, target_type: 'AccountWarning') }
let!(:unmatched_type_account) { Fabricate(:action_log, target_type: 'Account') }
let!(:unmatched_type_report) { Fabricate(:action_log, target_type: 'Report') }
let!(:unmatched_type_status) { Fabricate(:action_log, target_type: 'Status') }
it 'returns expected logs' do
expect(action_logs)
.to have_attributes(count: 4)
.and include(have_attributes(target_type: 'Account'))
.and include(have_attributes(target_type: 'AccountWarning'))
.and include(have_attributes(target_type: 'Report'))
.and include(have_attributes(target_type: 'Status'))
.and include(matched_type_account_warning)
.and include(matched_type_account)
.and include(matched_type_report)
.and include(matched_type_status)
.and not_include(unmatched_type_account_warning)
.and not_include(unmatched_type_account)
.and not_include(unmatched_type_report)
.and not_include(unmatched_type_status)
end
end
@ -149,13 +156,13 @@ RSpec.describe Report do
end
end
describe 'validations' do
describe 'Validations' do
let(:remote_account) { Fabricate(:account, domain: 'example.com', protocol: :activitypub, inbox_url: 'http://example.com/inbox') }
it 'is invalid if comment is longer than character limit and reporter is local' do
report = Fabricate.build(:report, comment: comment_over_limit)
expect(report.valid?).to be false
expect(report).to model_have_error_on_field(:comment)
report = Fabricate.build(:report)
expect(report).to_not allow_value(comment_over_limit).for(:comment)
end
it 'is valid if comment is longer than character limit and reporter is not local' do
@ -164,16 +171,16 @@ RSpec.describe Report do
end
it 'is invalid if it references invalid rules' do
report = Fabricate.build(:report, category: :violation, rule_ids: [-1])
expect(report.valid?).to be false
expect(report).to model_have_error_on_field(:rule_ids)
report = Fabricate.build(:report, category: :violation)
expect(report).to_not allow_value([-1]).for(:rule_ids)
end
it 'is invalid if it references rules but category is not "violation"' do
rule = Fabricate(:rule)
report = Fabricate.build(:report, category: :spam, rule_ids: rule.id)
expect(report.valid?).to be false
expect(report).to model_have_error_on_field(:rule_ids)
report = Fabricate.build(:report, category: :spam)
expect(report).to_not allow_value(rule.id).for(:rule_ids)
end
def comment_over_limit

View file

@ -5,7 +5,39 @@ require 'rails_helper'
RSpec.describe Tag do
include_examples 'Reviewable'
describe 'validations' do
describe 'Validations' do
describe 'name' do
context 'with a new record' do
subject { Fabricate.build :tag, name: 'original' }
it { is_expected.to allow_value('changed').for(:name) }
end
context 'with an existing record' do
subject { Fabricate :tag, name: 'original' }
it { is_expected.to_not allow_value('changed').for(:name).with_message(previous_name_error_message) }
end
end
describe 'display_name' do
context 'with a new record' do
subject { Fabricate.build :tag, name: 'original', display_name: 'OriginalDisplayName' }
it { is_expected.to allow_value('ChangedDisplayName').for(:display_name) }
end
context 'with an existing record' do
subject { Fabricate :tag, name: 'original', display_name: 'OriginalDisplayName' }
it { is_expected.to_not allow_value('ChangedDisplayName').for(:display_name).with_message(previous_name_error_message) }
end
end
def previous_name_error_message
I18n.t('tags.does_not_match_previous_name')
end
it 'invalid with #' do
expect(described_class.new(name: '#hello_world')).to_not be_valid
end

View file

@ -0,0 +1,27 @@
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe TermsOfService do
describe '#scope_for_notification' do
subject { terms_of_service.scope_for_notification }
let(:published_at) { Time.now.utc }
let(:terms_of_service) { Fabricate(:terms_of_service, published_at: published_at) }
let(:user_before) { Fabricate(:user, created_at: published_at - 2.days) }
let(:user_before_unconfirmed) { Fabricate(:user, created_at: published_at - 2.days, confirmed_at: nil) }
let(:user_before_suspended) { Fabricate(:user, created_at: published_at - 2.days) }
let(:user_after) { Fabricate(:user, created_at: published_at + 1.hour) }
before do
user_before_suspended.account.suspend!
user_before_unconfirmed
user_before
user_after
end
it 'includes only users created before the terms of service were published' do
expect(subject.pluck(:id)).to match_array(user_before.id)
end
end
end