mirror of
https://github.com/mastodon/mastodon.git
synced 2024-08-20 21:08:15 -07:00
Fix Rails/ActiveRecordCallbacksOrder cop (#24689)
This commit is contained in:
parent
38b2974a83
commit
b5c4b47746
8 changed files with 28 additions and 41 deletions
|
@ -1114,19 +1114,6 @@ RSpec/VerifiedDoubles:
|
||||||
- 'spec/workers/feed_insert_worker_spec.rb'
|
- 'spec/workers/feed_insert_worker_spec.rb'
|
||||||
- 'spec/workers/regeneration_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).
|
# This cop supports unsafe autocorrection (--autocorrect-all).
|
||||||
Rails/ApplicationController:
|
Rails/ApplicationController:
|
||||||
Exclude:
|
Exclude:
|
||||||
|
|
|
@ -439,9 +439,9 @@ class Account < ApplicationRecord
|
||||||
@emojis ||= CustomEmoji.from_text(emojifiable_text, domain)
|
@emojis ||= CustomEmoji.from_text(emojifiable_text, domain)
|
||||||
end
|
end
|
||||||
|
|
||||||
before_create :generate_keys
|
|
||||||
before_validation :prepare_contents, if: :local?
|
before_validation :prepare_contents, if: :local?
|
||||||
before_validation :prepare_username, on: :create
|
before_validation :prepare_username, on: :create
|
||||||
|
before_create :generate_keys
|
||||||
before_destroy :clean_feed_manager
|
before_destroy :clean_feed_manager
|
||||||
|
|
||||||
def ensure_keys!
|
def ensure_keys!
|
||||||
|
|
|
@ -17,14 +17,13 @@
|
||||||
class AccountConversation < ApplicationRecord
|
class AccountConversation < ApplicationRecord
|
||||||
include Redisable
|
include Redisable
|
||||||
|
|
||||||
|
before_validation :set_last_status
|
||||||
after_commit :push_to_streaming_api
|
after_commit :push_to_streaming_api
|
||||||
|
|
||||||
belongs_to :account
|
belongs_to :account
|
||||||
belongs_to :conversation
|
belongs_to :conversation
|
||||||
belongs_to :last_status, class_name: 'Status'
|
belongs_to :last_status, class_name: 'Status'
|
||||||
|
|
||||||
before_validation :set_last_status
|
|
||||||
|
|
||||||
def participant_account_ids=(arr)
|
def participant_account_ids=(arr)
|
||||||
self[:participant_account_ids] = arr.sort
|
self[:participant_account_ids] = arr.sort
|
||||||
end
|
end
|
||||||
|
|
|
@ -14,6 +14,7 @@
|
||||||
#
|
#
|
||||||
|
|
||||||
class AnnouncementReaction < ApplicationRecord
|
class AnnouncementReaction < ApplicationRecord
|
||||||
|
before_validation :set_custom_emoji
|
||||||
after_commit :queue_publish
|
after_commit :queue_publish
|
||||||
|
|
||||||
belongs_to :account
|
belongs_to :account
|
||||||
|
@ -23,8 +24,6 @@ class AnnouncementReaction < ApplicationRecord
|
||||||
validates :name, presence: true
|
validates :name, presence: true
|
||||||
validates_with ReactionValidator
|
validates_with ReactionValidator
|
||||||
|
|
||||||
before_validation :set_custom_emoji
|
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def set_custom_emoji
|
def set_custom_emoji
|
||||||
|
|
|
@ -25,8 +25,8 @@ class Block < ApplicationRecord
|
||||||
false # Force uri_for to use uri attribute
|
false # Force uri_for to use uri attribute
|
||||||
end
|
end
|
||||||
|
|
||||||
after_commit :remove_blocking_cache
|
|
||||||
before_validation :set_uri, only: :create
|
before_validation :set_uri, only: :create
|
||||||
|
after_commit :remove_blocking_cache
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
|
|
|
@ -271,12 +271,12 @@ class MediaAttachment < ApplicationRecord
|
||||||
delay_processing? && attachment_name == :file
|
delay_processing? && attachment_name == :file
|
||||||
end
|
end
|
||||||
|
|
||||||
after_commit :enqueue_processing, on: :create
|
|
||||||
after_commit :reset_parent_cache, on: :update
|
|
||||||
|
|
||||||
before_create :set_unknown_type
|
before_create :set_unknown_type
|
||||||
before_create :set_processing
|
before_create :set_processing
|
||||||
|
|
||||||
|
after_commit :enqueue_processing, on: :create
|
||||||
|
after_commit :reset_parent_cache, on: :update
|
||||||
|
|
||||||
after_post_process :set_meta
|
after_post_process :set_meta
|
||||||
|
|
||||||
class << self
|
class << self
|
||||||
|
|
|
@ -36,8 +36,8 @@ class SessionActivation < ApplicationRecord
|
||||||
detection.platform.id
|
detection.platform.id
|
||||||
end
|
end
|
||||||
|
|
||||||
before_create :assign_access_token
|
|
||||||
before_save :assign_user_agent
|
before_save :assign_user_agent
|
||||||
|
before_create :assign_access_token
|
||||||
|
|
||||||
class << self
|
class << self
|
||||||
def active?(id)
|
def active?(id)
|
||||||
|
|
|
@ -30,8 +30,6 @@
|
||||||
#
|
#
|
||||||
|
|
||||||
class Status < ApplicationRecord
|
class Status < ApplicationRecord
|
||||||
before_destroy :unlink_from_conversations!
|
|
||||||
|
|
||||||
include Discard::Model
|
include Discard::Model
|
||||||
include Paginable
|
include Paginable
|
||||||
include Cacheable
|
include Cacheable
|
||||||
|
@ -114,6 +112,26 @@ class Status < ApplicationRecord
|
||||||
after_create_commit :trigger_create_webhooks
|
after_create_commit :trigger_create_webhooks
|
||||||
after_update_commit :trigger_update_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,
|
cache_associated :application,
|
||||||
:media_attachments,
|
:media_attachments,
|
||||||
:conversation,
|
:conversation,
|
||||||
|
@ -311,22 +329,6 @@ class Status < ApplicationRecord
|
||||||
attributes['trendable'].nil? && account.requires_review_notification?
|
attributes['trendable'].nil? && account.requires_review_notification?
|
||||||
end
|
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
|
class << self
|
||||||
def selectable_visibilities
|
def selectable_visibilities
|
||||||
visibilities.keys - %w(direct limited)
|
visibilities.keys - %w(direct limited)
|
||||||
|
|
Loading…
Reference in a new issue