This repository has been archived on 2019-05-14. You can view files and clone it, but cannot push or open issues or pull requests.
mastodon/spec/models/account_spec.rb

115 lines
2.7 KiB
Ruby
Raw Normal View History

2016-02-20 21:53:20 +00:00
require 'rails_helper'
RSpec.describe Account, type: :model do
2016-02-26 14:28:08 +00:00
subject { Fabricate(:account, username: 'alice') }
2016-02-24 23:17:01 +00:00
2016-02-26 14:28:08 +00: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-24 23:17:01 +00:00
2016-02-26 14:28:08 +00: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-24 23:17:01 +00:00
end
describe '#local?' do
2016-02-26 14:28:08 +00: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-24 23:17:01 +00:00
end
describe '#acct' do
2016-02-26 14:28:08 +00: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-24 23:17:01 +00:00
end
describe '#subscribed?' do
2016-02-26 14:28:08 +00:00
it 'returns false when no secrets and tokens have been set' do
expect(subject.subscribed?).to be false
end
it 'returns true when the secret and token have been set' do
subject.secret = 'a'
subject.verify_token = 'b'
expect(subject.subscribed?).to be true
end
2016-02-24 23:17:01 +00:00
end
describe '#keypair' do
2016-02-26 14:28:08 +00:00
it 'returns an RSA key pair' do
expect(subject.keypair).to be_instance_of OpenSSL::PKey::RSA
end
2016-02-24 23:17:01 +00:00
end
describe '#subscription' do
2016-02-26 14:28:08 +00:00
it 'returns an OStatus subscription' do
expect(subject.subscription('')).to be_instance_of OStatus2::Subscription
end
2016-02-24 23:17:01 +00:00
end
describe '#object_type' do
2016-02-26 14:28:08 +00:00
it 'is always a person' do
expect(subject.object_type).to be :person
end
2016-02-24 23:17:01 +00:00
end
describe '#title' do
2016-02-26 14:28:08 +00:00
it 'is the same as the username' do
expect(subject.title).to eql subject.username
end
2016-02-24 23:17:01 +00:00
end
describe '#content' do
2016-02-26 14:28:08 +00:00
it 'is the same as the note' do
expect(subject.content).to eql subject.note
end
2016-02-24 23:17:01 +00:00
end
describe '#ping!' do
pending
end
2016-02-20 21:53:20 +00:00
end