mirror of
https://github.com/mastodon/mastodon.git
synced 2024-09-19 11:55:15 +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? }
|
validates_with UniqueUsernameValidator, if: -> { will_save_change_to_username? }
|
||||||
|
|
||||||
# Remote user validations, also applies to internal actors
|
# 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
|
# Remote user validations
|
||||||
validates :uri, presence: true, unless: :local?, on: :create
|
validates :uri, presence: true, unless: :local?, on: :create
|
||||||
|
@ -181,6 +181,10 @@ class Account < ApplicationRecord
|
||||||
domain.nil?
|
domain.nil?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def remote?
|
||||||
|
domain.present?
|
||||||
|
end
|
||||||
|
|
||||||
def moved?
|
def moved?
|
||||||
moved_to_account_id.present?
|
moved_to_account_id.present?
|
||||||
end
|
end
|
||||||
|
|
|
@ -64,11 +64,7 @@ class Poll < ApplicationRecord
|
||||||
votes.where(account: account).pluck(:choice)
|
votes.where(account: account).pluck(:choice)
|
||||||
end
|
end
|
||||||
|
|
||||||
delegate :local?, to: :account
|
delegate :local?, :remote?, to: :account
|
||||||
|
|
||||||
def remote?
|
|
||||||
!local?
|
|
||||||
end
|
|
||||||
|
|
||||||
def emojis
|
def emojis
|
||||||
@emojis ||= CustomEmoji.from_text(options.join(' '), account.domain)
|
@emojis ||= CustomEmoji.from_text(options.join(' '), account.domain)
|
||||||
|
|
|
@ -77,14 +77,26 @@ RSpec.describe Account do
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '#local?' do
|
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)
|
account = Fabricate(:account, domain: nil)
|
||||||
expect(account.local?).to be true
|
expect(account).to be_local
|
||||||
end
|
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')
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue