forked from mastodon/mastodon
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Ruby 3.0 support (mastodon#16046)
* Fix issues with POSIX::Spawn, Terrapin and Ruby 3.0 Also improve the Terrapin monkey-patch for the stderr/stdout issue. * Fix keyword argument handling throughout the codebase * Monkey-patch Paperclip to fix keyword arguments handling in validators * Change validation_extensions to please CodeClimate * Bump microformats from 4.2.1 to 4.3.1 * Allow Ruby 3.0 * Add Ruby 3.0 test target to CircleCI * Add test for admin dashboard warnings * Fix admin dashboard warnings on Ruby 3.0
- Loading branch information
1 parent
0a3fa03
commit 566fc90
Showing
19 changed files
with
177 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,6 @@ | ||
# Be sure to restart your server when you modify this file. | ||
|
||
Rails.application.config.session_store :cookie_store, { | ||
Rails.application.config.session_store :cookie_store, | ||
key: '_mastodon_session', | ||
secure: (Rails.env.production? || ENV['LOCAL_HTTPS'] == 'true'), | ||
same_site: :lax, | ||
} | ||
same_site: :lax |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
# frozen_string_literal: true | ||
|
||
# Monkey-patch various Paperclip validators for Ruby 3.0 compatibility | ||
|
||
module Paperclip | ||
module Validators | ||
module AttachmentSizeValidatorExtensions | ||
def validate_each(record, attr_name, _value) | ||
base_attr_name = attr_name | ||
attr_name = "#{attr_name}_file_size".to_sym | ||
value = record.send(:read_attribute_for_validation, attr_name) | ||
|
||
if value.present? | ||
options.slice(*Paperclip::Validators::AttachmentSizeValidator::AVAILABLE_CHECKS).each do |option, option_value| | ||
option_value = option_value.call(record) if option_value.is_a?(Proc) | ||
option_value = extract_option_value(option, option_value) | ||
|
||
next if value.send(Paperclip::Validators::AttachmentSizeValidator::CHECKS[option], option_value) | ||
|
||
error_message_key = options[:in] ? :in_between : option | ||
[attr_name, base_attr_name].each do |error_attr_name| | ||
record.errors.add(error_attr_name, error_message_key, **filtered_options(value).merge( | ||
min: min_value_in_human_size(record), | ||
max: max_value_in_human_size(record), | ||
count: human_size(option_value) | ||
)) | ||
end | ||
end | ||
end | ||
end | ||
end | ||
|
||
module AttachmentContentTypeValidatorExtensions | ||
def mark_invalid(record, attribute, types) | ||
record.errors.add attribute, :invalid, **options.merge({ types: types.join(', ') }) | ||
end | ||
end | ||
|
||
module AttachmentPresenceValidatorExtensions | ||
def validate_each(record, attribute, _value) | ||
if record.send("#{attribute}_file_name").blank? | ||
record.errors.add(attribute, :blank, **options) | ||
end | ||
end | ||
end | ||
|
||
module AttachmentFileNameValidatorExtensions | ||
def mark_invalid(record, attribute, patterns) | ||
record.errors.add attribute, :invalid, options.merge({ names: patterns.join(', ') }) | ||
end | ||
end | ||
end | ||
end | ||
|
||
Paperclip::Validators::AttachmentSizeValidator.prepend(Paperclip::Validators::AttachmentSizeValidatorExtensions) | ||
Paperclip::Validators::AttachmentContentTypeValidator.prepend(Paperclip::Validators::AttachmentContentTypeValidatorExtensions) | ||
Paperclip::Validators::AttachmentPresenceValidator.prepend(Paperclip::Validators::AttachmentPresenceValidatorExtensions) | ||
Paperclip::Validators::AttachmentFileNameValidator.prepend(Paperclip::Validators::AttachmentFileNameValidatorExtensions) |
Oops, something went wrong.