mirror of
https://github.com/mastodon/mastodon.git
synced 2024-09-18 19:40:41 +00:00
Add Account#remote?
query method
This commit is contained in:
parent
2caa3f365d
commit
92fbff9be0
|
@ -100,7 +100,7 @@ class Account < ApplicationRecord
|
|||
validates_with UniqueUsernameValidator, if: -> { will_save_change_to_username? }
|
||||
|
||||
# Remote user validations, also applies to internal actors
|
||||
validates :username, format: { with: USERNAME_ONLY_RE }, if: -> { (!local? || actor_type == 'Application') && will_save_change_to_username? }
|
||||
validates :username, format: { with: USERNAME_ONLY_RE }, if: -> { (remote? || actor_type == 'Application') && will_save_change_to_username? }
|
||||
|
||||
# Remote user validations
|
||||
validates :uri, presence: true, unless: :local?, on: :create
|
||||
|
@ -181,6 +181,10 @@ class Account < ApplicationRecord
|
|||
domain.nil?
|
||||
end
|
||||
|
||||
def remote?
|
||||
domain.present?
|
||||
end
|
||||
|
||||
def moved?
|
||||
moved_to_account_id.present?
|
||||
end
|
||||
|
|
|
@ -64,11 +64,7 @@ class Poll < ApplicationRecord
|
|||
votes.where(account: account).pluck(:choice)
|
||||
end
|
||||
|
||||
delegate :local?, to: :account
|
||||
|
||||
def remote?
|
||||
!local?
|
||||
end
|
||||
delegate :local?, :remote?, to: :account
|
||||
|
||||
def emojis
|
||||
@emojis ||= CustomEmoji.from_text(options.join(' '), account.domain)
|
||||
|
|
|
@ -77,14 +77,26 @@ RSpec.describe Account do
|
|||
end
|
||||
|
||||
describe '#local?' do
|
||||
it 'returns true when the account is local' do
|
||||
it 'returns true when domain is null' do
|
||||
account = Fabricate(:account, domain: nil)
|
||||
expect(account.local?).to be true
|
||||
expect(account).to be_local
|
||||
end
|
||||
|
||||
it 'returns false when the account is on a different domain' do
|
||||
it 'returns false when domain is present' do
|
||||
account = Fabricate(:account, domain: 'foreign.tld')
|
||||
expect(account.local?).to be false
|
||||
expect(account).to_not be_local
|
||||
end
|
||||
end
|
||||
|
||||
describe '#remote?' do
|
||||
it 'returns false when the domain is null' do
|
||||
account = Fabricate(:account, domain: nil)
|
||||
expect(account).to_not be_remote
|
||||
end
|
||||
|
||||
it 'returns true when domain is present' do
|
||||
account = Fabricate(:account, domain: 'foreign.tld')
|
||||
expect(account).to be_remote
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue