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.
Move account silence-related methods to concern (mastodon#28866)
- Loading branch information
1 parent
157fba4
commit d033920
Showing
4 changed files
with
41 additions
and
22 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
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 |
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 |
---|---|---|
@@ -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 |