diff options
author | Eugen Rochko <eugen@zeonfederated.com> | 2016-02-26 15:28:08 +0100 |
---|---|---|
committer | Eugen Rochko <eugen@zeonfederated.com> | 2016-02-26 15:28:08 +0100 |
commit | f16b31f0773c2fd1122ff0ad98cb392e762f0d0b (patch) | |
tree | 24880b7ee107288e7acb540011281569e8502e96 /spec/models | |
parent | 44c5958203dd8d0f96f880a8014a3233719077a6 (diff) |
Adding a bunch of tests
Diffstat (limited to 'spec/models')
-rw-r--r-- | spec/models/account_spec.rb | 95 | ||||
-rw-r--r-- | spec/models/favourite_spec.rb | 39 | ||||
-rw-r--r-- | spec/models/follow_spec.rb | 29 | ||||
-rw-r--r-- | spec/models/status_spec.rb | 98 | ||||
-rw-r--r-- | spec/models/stream_entry_spec.rb | 36 |
5 files changed, 258 insertions, 39 deletions
diff --git a/spec/models/account_spec.rb b/spec/models/account_spec.rb index fbcc972cf..a5f24a990 100644 --- a/spec/models/account_spec.rb +++ b/spec/models/account_spec.rb @@ -1,47 +1,110 @@ require 'rails_helper' RSpec.describe Account, type: :model do - describe '#follow!' do - pending - end + subject { Fabricate(:account, username: 'alice') } - describe '#unfollow!' do - pending - end + 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) - describe '#following?' do - pending + 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 end describe '#local?' do - pending + 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 end describe '#acct' do - pending + 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 end describe '#subscribed?' do - pending + 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 end describe '#keypair' do - pending + it 'returns an RSA key pair' do + expect(subject.keypair).to be_instance_of OpenSSL::PKey::RSA + end end describe '#subscription' do - pending + it 'returns an OStatus subscription' do + expect(subject.subscription('')).to be_instance_of OStatus2::Subscription + end end describe '#object_type' do - pending + it 'is always a person' do + expect(subject.object_type).to be :person + end end describe '#title' do - pending + it 'is the same as the username' do + expect(subject.title).to eql subject.username + end end describe '#content' do - pending + it 'is the same as the note' do + expect(subject.content).to eql subject.note + end end end diff --git a/spec/models/favourite_spec.rb b/spec/models/favourite_spec.rb index ad803ec4b..c778b13d4 100644 --- a/spec/models/favourite_spec.rb +++ b/spec/models/favourite_spec.rb @@ -1,31 +1,56 @@ require 'rails_helper' RSpec.describe Favourite, type: :model do + let(:alice) { Fabricate(:account, username: 'alice') } + let(:bob) { Fabricate(:account, username: 'bob') } + let(:status) { Fabricate(:status, account: bob) } + + subject { Favourite.new(account: alice, status: status) } + describe '#verb' do - pending + it 'is always favorite' do + expect(subject.verb).to be :favorite + end end describe '#title' do - pending + it 'describes the favourite' do + expect(subject.title).to eql 'alice favourited a status by bob' + end end describe '#content' do - pending + it 'equals the title' do + expect(subject.content).to eq subject.title + end end describe '#object_type' do - pending + it 'is a note when the target is a note' do + expect(subject.object_type).to be :note + end + + it 'is a comment when the target is a comment' do + status.in_reply_to_id = 2 + expect(subject.object_type).to be :comment + end end describe '#target' do - pending + it 'is the status that was favourited' do + expect(subject.target).to eq status + end end describe '#mentions' do - pending + it 'is always empty' do + expect(subject.mentions).to be_empty + end end describe '#thread' do - pending + it 'equals the target' do + expect(subject.thread).to eq subject.target + end end end diff --git a/spec/models/follow_spec.rb b/spec/models/follow_spec.rb index edb084701..28bd41dfd 100644 --- a/spec/models/follow_spec.rb +++ b/spec/models/follow_spec.rb @@ -1,27 +1,44 @@ require 'rails_helper' RSpec.describe Follow, type: :model do + let(:alice) { Fabricate(:account, username: 'alice') } + let(:bob) { Fabricate(:account, username: 'bob') } + + subject { Follow.new(account: alice, target_account: bob) } + describe '#verb' do - pending + it 'is follow' do + expect(subject.verb).to be :follow + end end describe '#title' do - pending + it 'describes the follow' do + expect(subject.title).to eql 'alice started following bob' + end end describe '#content' do - pending + it 'is the same as the title' do + expect(subject.content).to eql subject.title + end end describe '#object_type' do - pending + it 'is a person' do + expect(subject.object_type).to be :person + end end describe '#target' do - pending + it 'is the person being followed' do + expect(subject.target).to eq bob + end end describe '#mentions' do - pending + it 'is empty' do + expect(subject.mentions).to be_empty + end end end diff --git a/spec/models/status_spec.rb b/spec/models/status_spec.rb index 070e7b87f..db7b67117 100644 --- a/spec/models/status_spec.rb +++ b/spec/models/status_spec.rb @@ -1,35 +1,117 @@ require 'rails_helper' RSpec.describe Status, type: :model do + let(:alice) { Fabricate(:account, username: 'alice') } + let(:bob) { Fabricate(:account, username: 'bob') } + let(:other) { Fabricate(:status, account: bob, text: 'Skulls for the skull god! The enemy\'s gates are sideways!')} + + subject { Fabricate(:status, account: alice) } + describe '#local?' do - pending + it 'returns true when no remote URI is set' do + expect(subject.local?).to be true + end + + it 'returns false if a remote URI is set' do + subject.uri = 'a' + expect(subject.local?).to be false + end end describe '#reblog?' do - pending + it 'returns true when the status reblogs another status' do + subject.reblog = other + expect(subject.reblog?).to be true + end + + it 'returns false if the status is self-contained' do + expect(subject.reblog?).to be false + end end describe '#reply?' do - pending + it 'returns true if the status references another' do + subject.thread = other + expect(subject.reply?).to be true + end + + it 'returns false if the status is self-contained' do + expect(subject.reply?).to be false + end end describe '#mentions' do - pending + before do + bob # make sure the account exists + end + + it 'is empty if the status is self-contained and does not mention anyone' do + expect(subject.mentions).to be_empty + end + + it 'returns mentioned accounts' do + subject.text = 'Hello @bob!' + expect(subject.mentions).to include bob + end + + it 'returns account of the replied-to status' do + subject.thread = other + expect(subject.mentions).to include bob + end + + it 'returns the account of the shared status' do + subject.reblog = other + expect(subject.mentions).to include bob + end end describe '#verb' do - pending + it 'is always post' do + expect(subject.verb).to be :post + end end describe '#object_type' do - pending + it 'is note when the status is self-contained' do + expect(subject.object_type).to be :note + end + + it 'is comment when the status replies to another' do + subject.thread = other + expect(subject.object_type).to be :comment + end end describe '#title' do - pending + it 'is a shorter version of the content' do + expect(subject.title).to be_a String + end + end + + describe '#content' do + it 'returns the text of the status if it is not a reblog' do + expect(subject.content).to eql subject.text + end + + it 'returns the text of the reblogged status' do + subject.reblog = other + expect(subject.content).to eql other.text + end end describe '#target' do - pending + it 'returns nil if the status is self-contained' do + expect(subject.target).to be_nil + end + + it 'returns nil if the status is a reply' do + subject.thread = other + expect(subject.target).to be_nil + end + + it 'returns the reblogged status' do + subject.reblog = other + expect(subject.target).to eq other + end end end diff --git a/spec/models/stream_entry_spec.rb b/spec/models/stream_entry_spec.rb index 6386cac0f..9ecf6412a 100644 --- a/spec/models/stream_entry_spec.rb +++ b/spec/models/stream_entry_spec.rb @@ -1,11 +1,43 @@ require 'rails_helper' RSpec.describe StreamEntry, type: :model do + let(:alice) { Fabricate(:account, username: 'alice') } + let(:bob) { Fabricate(:account, username: 'bob') } + let(:follow) { Fabricate(:follow, account: alice, target_account: bob) } + let(:status) { Fabricate(:status, account: alice) } + let(:reblog) { Fabricate(:status, account: bob, reblog: status) } + let(:reply) { Fabricate(:status, account: bob, thread: status) } + let(:favourite) { Fabricate(:favourite, account: alice, status: status) } + describe '#targeted?' do - pending + it 'returns true for a follow' do + expect(follow.stream_entry.targeted?).to be true + end + + it 'returns true for a favourite' do + expect(favourite.stream_entry.targeted?).to be true + end + + it 'returns true for a reblog' do + expect(reblog.stream_entry.targeted?).to be true + end + + it 'returns false otherwise' do + expect(status.stream_entry.targeted?).to be false + end end describe '#threaded?' do - pending + it 'returns true for a favourite' do + expect(favourite.stream_entry.threaded?).to be true + end + + it 'returns true for a reply' do + expect(reply.stream_entry.threaded?).to be true + end + + it 'returns false otherwise' do + expect(status.stream_entry.threaded?).to be false + end end end |