Add Account#remote?
query method (#33508)
This commit is contained in:
parent
15669fcf75
commit
f22a2aab40
3 changed files with 30 additions and 10 deletions
|
@ -107,7 +107,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
|
||||
|
@ -186,6 +186,10 @@ class Account < ApplicationRecord
|
|||
domain.nil?
|
||||
end
|
||||
|
||||
def remote?
|
||||
domain.present?
|
||||
end
|
||||
|
||||
def moved?
|
||||
moved_to_account_id.present?
|
||||
end
|
||||
|
|
|
@ -61,11 +61,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)
|
||||
|
|
|
@ -48,14 +48,34 @@ 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
|
||||
context 'when the domain is null' do
|
||||
subject { Fabricate.build :account, domain: nil }
|
||||
|
||||
it { is_expected.to_not be_remote }
|
||||
end
|
||||
|
||||
context 'when the domain is blank' do
|
||||
subject { Fabricate.build :account, domain: '' }
|
||||
|
||||
it { is_expected.to_not be_remote }
|
||||
end
|
||||
|
||||
context 'when the domain is present' do
|
||||
subject { Fabricate.build :account, domain: 'host.example' }
|
||||
|
||||
it { is_expected.to be_remote }
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue