Skip to content

Commit

Permalink
Move account silence-related methods to concern (mastodon#28866)
Browse files Browse the repository at this point in the history
  • Loading branch information
mjankowski authored Nov 11, 2024
1 parent 157fba4 commit d033920
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 22 deletions.
15 changes: 1 addition & 14 deletions app/models/account.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ class Account < ApplicationRecord
include Account::Interactions
include Account::Merging
include Account::Search
include Account::Silences
include Account::StatusesSearch
include Account::Suspensions
include Account::AttributionDomains
Expand Down Expand Up @@ -129,9 +130,7 @@ class Account < ApplicationRecord
scope :remote, -> { where.not(domain: nil) }
scope :local, -> { where(domain: nil) }
scope :partitioned, -> { order(Arel.sql('row_number() over (partition by domain)')) }
scope :silenced, -> { where.not(silenced_at: nil) }
scope :sensitized, -> { where.not(sensitized_at: nil) }
scope :without_silenced, -> { where(silenced_at: nil) }
scope :without_instance_actor, -> { where.not(id: INSTANCE_ACTOR_ID) }
scope :recent, -> { reorder(id: :desc) }
scope :bots, -> { where(actor_type: AUTOMATED_ACTOR_TYPES) }
Expand Down Expand Up @@ -244,18 +243,6 @@ def refresh!
ResolveAccountService.new.call(acct) unless local?
end

def silenced?
silenced_at.present?
end

def silence!(date = Time.now.utc)
update!(silenced_at: date)
end

def unsilence!
update!(silenced_at: nil)
end

def sensitized?
sensitized_at.present?
end
Expand Down
22 changes: 22 additions & 0 deletions app/models/concerns/account/silences.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# frozen_string_literal: true

module Account::Silences
extend ActiveSupport::Concern

included do
scope :silenced, -> { where.not(silenced_at: nil) }
scope :without_silenced, -> { where(silenced_at: nil) }
end

def silenced?
silenced_at.present?
end

def silence!(date = Time.now.utc)
update!(silenced_at: date)
end

def unsilence!
update!(silenced_at: nil)
end
end
8 changes: 0 additions & 8 deletions spec/models/account_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -983,14 +983,6 @@ def account_note_over_limit
end
end

describe 'silenced' do
it 'returns an array of accounts who are silenced' do
silenced_account = Fabricate(:account, silenced: true)
_account = Fabricate(:account, silenced: false)
expect(described_class.silenced).to contain_exactly(silenced_account)
end
end

describe 'searchable' do
let!(:suspended_local) { Fabricate(:account, suspended: true, username: 'suspended_local') }
let!(:suspended_remote) { Fabricate(:account, suspended: true, domain: 'example.org', username: 'suspended_remote') }
Expand Down
18 changes: 18 additions & 0 deletions spec/models/concerns/account/silences_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# frozen_string_literal: true

require 'rails_helper'

RSpec.describe Account::Silences do
describe 'Scopes' do
describe '.silenced' do
let(:silenced_account) { Fabricate :account, silenced: true }

before { Fabricate :account, silenced: false }

it 'returns an array of accounts who are silenced' do
expect(Account.silenced)
.to contain_exactly(silenced_account)
end
end
end
end

0 comments on commit d033920

Please sign in to comment.