1
0
mirror of https://github.com/funamitech/mastodon synced 2024-11-23 22:57:05 +09:00

Fix Rails/ActiveRecordCallbacksOrder cop (#24689)

This commit is contained in:
Matt Jankowski 2023-05-02 12:23:35 -04:00 committed by GitHub
parent 38b2974a83
commit b5c4b47746
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 28 additions and 41 deletions

View File

@ -1114,19 +1114,6 @@ RSpec/VerifiedDoubles:
- 'spec/workers/feed_insert_worker_spec.rb'
- 'spec/workers/regeneration_worker_spec.rb'
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: Include.
# Include: app/models/**/*.rb
Rails/ActiveRecordCallbacksOrder:
Exclude:
- 'app/models/account.rb'
- 'app/models/account_conversation.rb'
- 'app/models/announcement_reaction.rb'
- 'app/models/block.rb'
- 'app/models/media_attachment.rb'
- 'app/models/session_activation.rb'
- 'app/models/status.rb'
# This cop supports unsafe autocorrection (--autocorrect-all).
Rails/ApplicationController:
Exclude:

View File

@ -439,9 +439,9 @@ class Account < ApplicationRecord
@emojis ||= CustomEmoji.from_text(emojifiable_text, domain)
end
before_create :generate_keys
before_validation :prepare_contents, if: :local?
before_validation :prepare_username, on: :create
before_create :generate_keys
before_destroy :clean_feed_manager
def ensure_keys!

View File

@ -17,14 +17,13 @@
class AccountConversation < ApplicationRecord
include Redisable
before_validation :set_last_status
after_commit :push_to_streaming_api
belongs_to :account
belongs_to :conversation
belongs_to :last_status, class_name: 'Status'
before_validation :set_last_status
def participant_account_ids=(arr)
self[:participant_account_ids] = arr.sort
end

View File

@ -14,6 +14,7 @@
#
class AnnouncementReaction < ApplicationRecord
before_validation :set_custom_emoji
after_commit :queue_publish
belongs_to :account
@ -23,8 +24,6 @@ class AnnouncementReaction < ApplicationRecord
validates :name, presence: true
validates_with ReactionValidator
before_validation :set_custom_emoji
private
def set_custom_emoji

View File

@ -25,8 +25,8 @@ class Block < ApplicationRecord
false # Force uri_for to use uri attribute
end
after_commit :remove_blocking_cache
before_validation :set_uri, only: :create
after_commit :remove_blocking_cache
private

View File

@ -271,12 +271,12 @@ class MediaAttachment < ApplicationRecord
delay_processing? && attachment_name == :file
end
after_commit :enqueue_processing, on: :create
after_commit :reset_parent_cache, on: :update
before_create :set_unknown_type
before_create :set_processing
after_commit :enqueue_processing, on: :create
after_commit :reset_parent_cache, on: :update
after_post_process :set_meta
class << self

View File

@ -36,8 +36,8 @@ class SessionActivation < ApplicationRecord
detection.platform.id
end
before_create :assign_access_token
before_save :assign_user_agent
before_create :assign_access_token
class << self
def active?(id)

View File

@ -30,8 +30,6 @@
#
class Status < ApplicationRecord
before_destroy :unlink_from_conversations!
include Discard::Model
include Paginable
include Cacheable
@ -114,6 +112,26 @@ class Status < ApplicationRecord
after_create_commit :trigger_create_webhooks
after_update_commit :trigger_update_webhooks
after_create_commit :increment_counter_caches
after_destroy_commit :decrement_counter_caches
after_create_commit :store_uri, if: :local?
after_create_commit :update_statistics, if: :local?
before_validation :prepare_contents, if: :local?
before_validation :set_reblog
before_validation :set_visibility
before_validation :set_conversation
before_validation :set_local
around_create Mastodon::Snowflake::Callbacks
after_create :set_poll_id
# The `prepend: true` option below ensures this runs before
# the `dependent: destroy` callbacks remove relevant records
before_destroy :unlink_from_conversations!, prepend: true
cache_associated :application,
:media_attachments,
:conversation,
@ -311,22 +329,6 @@ class Status < ApplicationRecord
attributes['trendable'].nil? && account.requires_review_notification?
end
after_create_commit :increment_counter_caches
after_destroy_commit :decrement_counter_caches
after_create_commit :store_uri, if: :local?
after_create_commit :update_statistics, if: :local?
before_validation :prepare_contents, if: :local?
before_validation :set_reblog
before_validation :set_visibility
before_validation :set_conversation
before_validation :set_local
around_create Mastodon::Snowflake::Callbacks
after_create :set_poll_id
class << self
def selectable_visibilities
visibilities.keys - %w(direct limited)