2016-02-20 22:53:20 +01:00
|
|
|
require 'rails_helper'
|
|
|
|
|
|
|
|
RSpec.describe Account, type: :model do
|
2016-02-26 15:28:08 +01:00
|
|
|
subject { Fabricate(:account, username: 'alice') }
|
2016-02-25 00:17:01 +01:00
|
|
|
|
2016-02-26 15:28:08 +01:00
|
|
|
context do
|
|
|
|
let(:bob) { Fabricate(:account, username: 'bob') }
|
|
|
|
|
|
|
|
describe '#follow!' do
|
|
|
|
it 'creates a follow' do
|
|
|
|
follow = subject.follow!(bob)
|
|
|
|
|
|
|
|
expect(follow).to be_instance_of Follow
|
|
|
|
expect(follow.account).to eq subject
|
|
|
|
expect(follow.target_account).to eq bob
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#unfollow!' do
|
|
|
|
before do
|
|
|
|
subject.follow!(bob)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'destroys a follow' do
|
|
|
|
unfollow = subject.unfollow!(bob)
|
2016-02-25 00:17:01 +01:00
|
|
|
|
2016-02-26 15:28:08 +01:00
|
|
|
expect(unfollow).to be_instance_of Follow
|
|
|
|
expect(unfollow.account).to eq subject
|
|
|
|
expect(unfollow.target_account).to eq bob
|
|
|
|
expect(unfollow.destroyed?).to be true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#following?' do
|
|
|
|
it 'returns true when the target is followed' do
|
|
|
|
subject.follow!(bob)
|
|
|
|
expect(subject.following?(bob)).to be true
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns false if the target is not followed' do
|
|
|
|
expect(subject.following?(bob)).to be false
|
|
|
|
end
|
|
|
|
end
|
2016-02-25 00:17:01 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
describe '#local?' do
|
2016-02-26 15:28:08 +01:00
|
|
|
it 'returns true when the account is local' do
|
|
|
|
expect(subject.local?).to be true
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns false when the account is on a different domain' do
|
|
|
|
subject.domain = 'foreign.tld'
|
|
|
|
expect(subject.local?).to be false
|
|
|
|
end
|
2016-02-25 00:17:01 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
describe '#acct' do
|
2016-02-26 15:28:08 +01:00
|
|
|
it 'returns username for local users' do
|
|
|
|
expect(subject.acct).to eql 'alice'
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns username@domain for foreign users' do
|
|
|
|
subject.domain = 'foreign.tld'
|
|
|
|
expect(subject.acct).to eql 'alice@foreign.tld'
|
|
|
|
end
|
2016-02-25 00:17:01 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
describe '#subscribed?' do
|
2016-09-20 02:43:20 +02:00
|
|
|
it 'returns false when no subscription expiration information is present' do
|
2016-02-26 15:28:08 +01:00
|
|
|
expect(subject.subscribed?).to be false
|
|
|
|
end
|
|
|
|
|
2016-09-20 02:43:20 +02:00
|
|
|
it 'returns true when subscription expiration has been set' do
|
|
|
|
subject.subscription_expires_at = 30.days.from_now
|
2016-02-26 15:28:08 +01:00
|
|
|
expect(subject.subscribed?).to be true
|
|
|
|
end
|
2016-02-25 00:17:01 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
describe '#keypair' do
|
2016-02-26 15:28:08 +01:00
|
|
|
it 'returns an RSA key pair' do
|
|
|
|
expect(subject.keypair).to be_instance_of OpenSSL::PKey::RSA
|
|
|
|
end
|
2016-02-25 00:17:01 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
describe '#subscription' do
|
2016-02-26 15:28:08 +01:00
|
|
|
it 'returns an OStatus subscription' do
|
|
|
|
expect(subject.subscription('')).to be_instance_of OStatus2::Subscription
|
|
|
|
end
|
2016-02-25 00:17:01 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
describe '#object_type' do
|
2016-02-26 15:28:08 +01:00
|
|
|
it 'is always a person' do
|
|
|
|
expect(subject.object_type).to be :person
|
|
|
|
end
|
2016-02-25 00:17:01 +01:00
|
|
|
end
|
|
|
|
|
2016-02-28 14:33:13 +01:00
|
|
|
describe '#ping!' do
|
|
|
|
pending
|
|
|
|
end
|
2016-03-19 12:13:47 +01:00
|
|
|
|
|
|
|
describe '#favourited?' do
|
|
|
|
pending
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#reblogged?' do
|
|
|
|
pending
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '.find_local' do
|
2016-11-13 11:27:13 +01:00
|
|
|
before do
|
|
|
|
Fabricate(:account, username: 'Alice')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns Alice for alice' do
|
|
|
|
expect(Account.find_local('alice')).to_not be_nil
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns Alice for Alice' do
|
|
|
|
expect(Account.find_local('Alice')).to_not be_nil
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not return anything for a_ice' do
|
|
|
|
expect(Account.find_local('a_ice')).to be_nil
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not return anything for al%' do
|
|
|
|
expect(Account.find_local('al%')).to be_nil
|
|
|
|
end
|
2016-03-19 12:13:47 +01:00
|
|
|
end
|
2016-03-27 23:51:18 +02:00
|
|
|
|
2016-09-09 20:04:34 +02:00
|
|
|
describe '.find_remote' do
|
2016-11-13 11:27:13 +01:00
|
|
|
before do
|
|
|
|
Fabricate(:account, username: 'Alice', domain: 'mastodon.social')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns Alice for alice@mastodon.social' do
|
|
|
|
expect(Account.find_remote('alice', 'mastodon.social')).to_not be_nil
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns Alice for ALICE@MASTODON.SOCIAL' do
|
|
|
|
expect(Account.find_remote('ALICE', 'MASTODON.SOCIAL')).to_not be_nil
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not return anything for a_ice@mastodon.social' do
|
|
|
|
expect(Account.find_remote('a_ice', 'mastodon.social')).to be_nil
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not return anything for alice@m_stodon.social' do
|
|
|
|
expect(Account.find_remote('alice', 'm_stodon.social')).to be_nil
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not return anything for alice@m%' do
|
|
|
|
expect(Account.find_remote('alice', 'm%')).to be_nil
|
|
|
|
end
|
2016-09-09 20:04:34 +02:00
|
|
|
end
|
|
|
|
|
2017-01-09 14:00:55 +01:00
|
|
|
describe '.following_map' do
|
|
|
|
it 'returns an hash' do
|
|
|
|
expect(Account.following_map([], 1)).to be_a Hash
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '.followed_by_map' do
|
|
|
|
it 'returns an hash' do
|
|
|
|
expect(Account.followed_by_map([], 1)).to be_a Hash
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '.blocking_map' do
|
|
|
|
it 'returns an hash' do
|
|
|
|
expect(Account.blocking_map([], 1)).to be_a Hash
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '.requested_map' do
|
|
|
|
it 'returns an hash' do
|
|
|
|
expect(Account.requested_map([], 1)).to be_a Hash
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-03-27 23:51:18 +02:00
|
|
|
describe 'MENTION_RE' do
|
|
|
|
subject { Account::MENTION_RE }
|
|
|
|
|
|
|
|
it 'matches usernames in the middle of a sentence' do
|
|
|
|
expect(subject.match('Hello to @alice from me')[1]).to eq 'alice'
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'matches usernames in the beginning of status' do
|
|
|
|
expect(subject.match('@alice Hey how are you?')[1]).to eq 'alice'
|
|
|
|
end
|
|
|
|
|
2017-03-05 18:08:19 +01:00
|
|
|
it 'matches full usernames' do
|
|
|
|
expect(subject.match('@alice@example.com')[1]).to eq 'alice@example.com'
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'matches full usernames with a dot at the end' do
|
|
|
|
expect(subject.match('Hello @alice@example.com.')[1]).to eq 'alice@example.com'
|
|
|
|
end
|
|
|
|
|
2016-03-27 23:51:18 +02:00
|
|
|
it 'matches dot-prepended usernames' do
|
|
|
|
expect(subject.match('.@alice I want everybody to see this')[1]).to eq 'alice'
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not match e-mails' do
|
|
|
|
expect(subject.match('Drop me an e-mail at alice@example.com')).to be_nil
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not match URLs' do
|
|
|
|
expect(subject.match('Check this out https://medium.com/@alice/some-article#.abcdef123')).to be_nil
|
|
|
|
end
|
|
|
|
end
|
2016-02-20 22:53:20 +01:00
|
|
|
end
|