2016-02-20 13:53:20 -08:00
|
|
|
require 'rails_helper'
|
|
|
|
|
|
|
|
RSpec.describe Status, type: :model do
|
2016-02-26 06:28:08 -08:00
|
|
|
let(:alice) { Fabricate(:account, username: 'alice') }
|
|
|
|
let(:bob) { Fabricate(:account, username: 'bob') }
|
2017-07-28 15:06:29 -07:00
|
|
|
let(:other) { Fabricate(:status, account: bob, text: 'Skulls for the skull god! The enemy\'s gates are sideways!') }
|
2016-02-26 06:28:08 -08:00
|
|
|
|
|
|
|
subject { Fabricate(:status, account: alice) }
|
|
|
|
|
2016-02-24 15:17:01 -08:00
|
|
|
describe '#local?' do
|
2016-02-26 06:28:08 -08:00
|
|
|
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
|
2017-09-06 10:01:28 -07:00
|
|
|
alice.update(domain: 'example.com')
|
|
|
|
subject.save
|
2016-02-26 06:28:08 -08:00
|
|
|
expect(subject.local?).to be false
|
|
|
|
end
|
2017-09-06 10:01:28 -07:00
|
|
|
|
|
|
|
it 'returns true if a URI is set and `local` is true' do
|
|
|
|
subject.update(uri: 'example.com', local: true)
|
|
|
|
expect(subject.local?).to be true
|
|
|
|
end
|
2016-02-24 15:17:01 -08:00
|
|
|
end
|
|
|
|
|
|
|
|
describe '#reblog?' do
|
2016-02-26 06:28:08 -08:00
|
|
|
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
|
2016-02-24 15:17:01 -08:00
|
|
|
end
|
|
|
|
|
|
|
|
describe '#reply?' do
|
2016-02-26 06:28:08 -08:00
|
|
|
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
|
2016-02-24 15:17:01 -08:00
|
|
|
end
|
|
|
|
|
|
|
|
describe '#verb' do
|
2017-11-15 22:46:29 -08:00
|
|
|
context 'if destroyed?' do
|
|
|
|
it 'returns :delete' do
|
|
|
|
subject.destroy!
|
|
|
|
expect(subject.verb).to be :delete
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'unless destroyed?' do
|
|
|
|
context 'if reblog?' do
|
|
|
|
it 'returns :share' do
|
|
|
|
subject.reblog = other
|
|
|
|
expect(subject.verb).to be :share
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'unless reblog?' do
|
|
|
|
it 'returns :post' do
|
|
|
|
subject.reblog = nil
|
|
|
|
expect(subject.verb).to be :post
|
|
|
|
end
|
|
|
|
end
|
2016-02-26 06:28:08 -08:00
|
|
|
end
|
2016-02-24 15:17:01 -08:00
|
|
|
end
|
|
|
|
|
|
|
|
describe '#object_type' do
|
2016-02-26 06:28:08 -08:00
|
|
|
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
|
2016-02-24 15:17:01 -08:00
|
|
|
end
|
|
|
|
|
|
|
|
describe '#title' do
|
2017-11-18 19:15:17 -08:00
|
|
|
# rubocop:disable Style/InterpolationCheck
|
|
|
|
|
|
|
|
let(:account) { subject.account }
|
|
|
|
|
|
|
|
context 'if destroyed?' do
|
|
|
|
it 'returns "#{account.acct} deleted status"' do
|
|
|
|
subject.destroy!
|
|
|
|
expect(subject.title).to eq "#{account.acct} deleted status"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'unless destroyed?' do
|
|
|
|
context 'if reblog?' do
|
|
|
|
it 'returns "#{account.acct} shared a status by #{reblog.account.acct}"' do
|
|
|
|
reblog = subject.reblog = other
|
|
|
|
expect(subject.title).to eq "#{account.acct} shared a status by #{reblog.account.acct}"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'unless reblog?' do
|
|
|
|
it 'returns "New status by #{account.acct}"' do
|
|
|
|
subject.reblog = nil
|
|
|
|
expect(subject.title).to eq "New status by #{account.acct}"
|
|
|
|
end
|
|
|
|
end
|
2016-02-26 06:28:08 -08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-11-15 18:07:27 -08:00
|
|
|
describe '#hidden?' do
|
|
|
|
context 'if private_visibility?' do
|
|
|
|
it 'returns true' do
|
|
|
|
subject.visibility = :private
|
|
|
|
expect(subject.hidden?).to be true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'if direct_visibility?' do
|
|
|
|
it 'returns true' do
|
|
|
|
subject.visibility = :direct
|
|
|
|
expect(subject.hidden?).to be true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'if public_visibility?' do
|
|
|
|
it 'returns false' do
|
|
|
|
subject.visibility = :public
|
|
|
|
expect(subject.hidden?).to be false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'if unlisted_visibility?' do
|
|
|
|
it 'returns false' do
|
|
|
|
subject.visibility = :unlisted
|
|
|
|
expect(subject.hidden?).to be false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-02-26 06:28:08 -08:00
|
|
|
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
|
2016-02-24 15:17:01 -08:00
|
|
|
end
|
|
|
|
|
|
|
|
describe '#target' do
|
2016-02-26 06:28:08 -08:00
|
|
|
it 'returns nil if the status is self-contained' do
|
2018-05-28 02:04:06 -07:00
|
|
|
expect(subject.target).to be_nil
|
2016-02-26 06:28:08 -08:00
|
|
|
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
|
2016-02-24 15:17:01 -08:00
|
|
|
end
|
2016-03-19 04:13:47 -07:00
|
|
|
|
|
|
|
describe '#reblogs_count' do
|
2017-04-07 12:30:36 -07:00
|
|
|
it 'is the number of reblogs' do
|
|
|
|
Fabricate(:status, account: bob, reblog: subject)
|
|
|
|
Fabricate(:status, account: alice, reblog: subject)
|
|
|
|
|
|
|
|
expect(subject.reblogs_count).to eq 2
|
|
|
|
end
|
2018-05-29 17:50:23 -07:00
|
|
|
|
|
|
|
it 'is decremented when reblog is removed' do
|
|
|
|
reblog = Fabricate(:status, account: bob, reblog: subject)
|
|
|
|
expect(subject.reblogs_count).to eq 1
|
|
|
|
reblog.destroy
|
|
|
|
expect(subject.reblogs_count).to eq 0
|
|
|
|
end
|
2016-03-19 04:13:47 -07:00
|
|
|
end
|
|
|
|
|
|
|
|
describe '#favourites_count' do
|
2017-04-07 12:30:36 -07:00
|
|
|
it 'is the number of favorites' do
|
|
|
|
Fabricate(:favourite, account: bob, status: subject)
|
|
|
|
Fabricate(:favourite, account: alice, status: subject)
|
|
|
|
|
|
|
|
expect(subject.favourites_count).to eq 2
|
|
|
|
end
|
2018-05-29 17:50:23 -07:00
|
|
|
|
|
|
|
it 'is decremented when favourite is removed' do
|
|
|
|
favourite = Fabricate(:favourite, account: bob, status: subject)
|
|
|
|
expect(subject.favourites_count).to eq 1
|
|
|
|
favourite.destroy
|
|
|
|
expect(subject.favourites_count).to eq 0
|
|
|
|
end
|
2016-03-19 04:13:47 -07:00
|
|
|
end
|
2017-04-07 11:18:30 -07:00
|
|
|
|
|
|
|
describe '#proper' do
|
|
|
|
it 'is itself for original statuses' do
|
|
|
|
expect(subject.proper).to eq subject
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'is the source status for reblogs' do
|
|
|
|
subject.reblog = other
|
|
|
|
expect(subject.proper).to eq other
|
|
|
|
end
|
|
|
|
end
|
2017-04-24 13:37:24 -07:00
|
|
|
|
2017-12-14 00:27:42 -08:00
|
|
|
describe 'on create' do
|
|
|
|
let(:local_account) { Fabricate(:account, username: 'local', domain: nil) }
|
|
|
|
let(:remote_account) { Fabricate(:account, username: 'remote', domain: 'example.com') }
|
|
|
|
|
|
|
|
subject { Status.new }
|
|
|
|
|
|
|
|
describe 'on a status that ends with the local-only emoji' do
|
|
|
|
before do
|
|
|
|
subject.text = 'A toot ' + subject.local_only_emoji
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'if the status originates from this instance' do
|
|
|
|
before do
|
|
|
|
subject.account = local_account
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'is marked local-only' do
|
|
|
|
subject.save!
|
|
|
|
|
|
|
|
expect(subject).to be_local_only
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'if the status is remote' do
|
|
|
|
before do
|
|
|
|
subject.account = remote_account
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'is not marked local-only' do
|
|
|
|
subject.save!
|
|
|
|
|
|
|
|
expect(subject).to_not be_local_only
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
Feature conversations muting (#3017)
* Add <ostatus:conversation /> tag to Atom input/output
Only uses ref attribute (not href) because href would be
the alternate link that's always included also.
Creates new conversation for every non-reply status. Carries
over conversation for every reply. Keeps remote URIs verbatim,
generates local URIs on the fly like the rest of them.
* Conversation muting - prevents notifications that reference a conversation
(including replies, favourites, reblogs) from being created. API endpoints
/api/v1/statuses/:id/mute and /api/v1/statuses/:id/unmute
Currently no way to tell when a status/conversation is muted, so the web UI
only has a "disable notifications" button, doesn't work as a toggle
* Display "Dismiss notifications" on all statuses in notifications column, not just own
* Add "muted" as a boolean attribute on statuses JSON
For now always false on contained reblogs, since it's only relevant for
statuses returned from the notifications endpoint, which are not nested
Remove "Disable notifications" from detailed status view, since it's
only relevant in the notifications column
* Up max class length
* Remove pending test for conversation mute
* Add tests, clean up
* Rename to "mute conversation" and "unmute conversation"
* Raise validation error when trying to mute/unmute status without conversation
2017-05-14 18:04:13 -07:00
|
|
|
describe '.mutes_map' do
|
|
|
|
let(:status) { Fabricate(:status) }
|
|
|
|
let(:account) { Fabricate(:account) }
|
|
|
|
|
|
|
|
subject { Status.mutes_map([status.conversation.id], account) }
|
|
|
|
|
|
|
|
it 'returns a hash' do
|
|
|
|
expect(subject).to be_a Hash
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'contains true value' do
|
|
|
|
account.mute_conversation!(status.conversation)
|
|
|
|
expect(subject[status.conversation.id]).to be true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '.favourites_map' do
|
|
|
|
let(:status) { Fabricate(:status) }
|
|
|
|
let(:account) { Fabricate(:account) }
|
|
|
|
|
|
|
|
subject { Status.favourites_map([status], account) }
|
|
|
|
|
|
|
|
it 'returns a hash' do
|
|
|
|
expect(subject).to be_a Hash
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'contains true value' do
|
|
|
|
Fabricate(:favourite, status: status, account: account)
|
|
|
|
expect(subject[status.id]).to be true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '.reblogs_map' do
|
|
|
|
let(:status) { Fabricate(:status) }
|
|
|
|
let(:account) { Fabricate(:account) }
|
|
|
|
|
|
|
|
subject { Status.reblogs_map([status], account) }
|
|
|
|
|
|
|
|
it 'returns a hash' do
|
|
|
|
expect(subject).to be_a Hash
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'contains true value' do
|
|
|
|
Fabricate(:status, account: account, reblog: status)
|
|
|
|
expect(subject[status.id]).to be true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-06-17 04:54:02 -07:00
|
|
|
describe '.in_chosen_languages' do
|
2017-09-22 10:33:17 -07:00
|
|
|
context 'for accounts with language filters' do
|
2018-06-17 04:54:02 -07:00
|
|
|
let(:user) { Fabricate(:user, chosen_languages: ['en']) }
|
2017-09-22 10:33:17 -07:00
|
|
|
|
2018-06-17 04:54:02 -07:00
|
|
|
it 'does not include statuses in not in chosen languages' do
|
|
|
|
status = Fabricate(:status, language: 'de')
|
|
|
|
expect(Status.in_chosen_languages(user.account)).not_to include status
|
2017-09-22 10:33:17 -07:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'includes status with unknown language' do
|
|
|
|
status = Fabricate(:status, language: nil)
|
2018-06-17 04:54:02 -07:00
|
|
|
expect(Status.in_chosen_languages(user.account)).to include status
|
2017-09-22 10:33:17 -07:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-04-26 11:08:30 -07:00
|
|
|
describe '.as_home_timeline' do
|
2017-06-20 11:41:23 -07:00
|
|
|
let(:account) { Fabricate(:account) }
|
|
|
|
let(:followed) { Fabricate(:account) }
|
|
|
|
let(:not_followed) { Fabricate(:account) }
|
|
|
|
|
2017-04-26 11:08:30 -07:00
|
|
|
before do
|
|
|
|
Fabricate(:follow, account: account, target_account: followed)
|
|
|
|
|
2017-06-20 11:41:23 -07:00
|
|
|
@self_status = Fabricate(:status, account: account, visibility: :public)
|
|
|
|
@self_direct_status = Fabricate(:status, account: account, visibility: :direct)
|
|
|
|
@followed_status = Fabricate(:status, account: followed, visibility: :public)
|
|
|
|
@followed_direct_status = Fabricate(:status, account: followed, visibility: :direct)
|
|
|
|
@not_followed_status = Fabricate(:status, account: not_followed, visibility: :public)
|
2017-04-26 11:08:30 -07:00
|
|
|
|
|
|
|
@results = Status.as_home_timeline(account)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'includes statuses from self' do
|
|
|
|
expect(@results).to include(@self_status)
|
|
|
|
end
|
|
|
|
|
2017-06-21 17:38:50 -07:00
|
|
|
it 'does not include direct statuses from self' do
|
|
|
|
expect(@results).to_not include(@self_direct_status)
|
2017-06-20 11:41:23 -07:00
|
|
|
end
|
|
|
|
|
2017-04-26 11:08:30 -07:00
|
|
|
it 'includes statuses from followed' do
|
|
|
|
expect(@results).to include(@followed_status)
|
|
|
|
end
|
|
|
|
|
2017-06-21 17:38:50 -07:00
|
|
|
it 'does not include direct statuses mentioning recipient from followed' do
|
2017-06-20 11:41:23 -07:00
|
|
|
Fabricate(:mention, account: account, status: @followed_direct_status)
|
2017-06-21 17:38:50 -07:00
|
|
|
expect(@results).to_not include(@followed_direct_status)
|
2017-06-20 11:41:23 -07:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not include direct statuses not mentioning recipient from followed' do
|
|
|
|
expect(@results).not_to include(@followed_direct_status)
|
|
|
|
end
|
|
|
|
|
2017-04-26 11:08:30 -07:00
|
|
|
it 'does not include statuses from non-followed' do
|
|
|
|
expect(@results).not_to include(@not_followed_status)
|
|
|
|
end
|
|
|
|
end
|
2017-04-28 06:10:41 -07:00
|
|
|
|
2017-10-15 21:02:39 -07:00
|
|
|
describe '.as_direct_timeline' do
|
|
|
|
let(:account) { Fabricate(:account) }
|
|
|
|
let(:followed) { Fabricate(:account) }
|
|
|
|
let(:not_followed) { Fabricate(:account) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
Fabricate(:follow, account: account, target_account: followed)
|
|
|
|
|
|
|
|
@self_public_status = Fabricate(:status, account: account, visibility: :public)
|
|
|
|
@self_direct_status = Fabricate(:status, account: account, visibility: :direct)
|
|
|
|
@followed_public_status = Fabricate(:status, account: followed, visibility: :public)
|
|
|
|
@followed_direct_status = Fabricate(:status, account: followed, visibility: :direct)
|
|
|
|
@not_followed_direct_status = Fabricate(:status, account: not_followed, visibility: :direct)
|
|
|
|
|
|
|
|
@results = Status.as_direct_timeline(account)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not include public statuses from self' do
|
|
|
|
expect(@results).to_not include(@self_public_status)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'includes direct statuses from self' do
|
|
|
|
expect(@results).to include(@self_direct_status)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not include public statuses from followed' do
|
|
|
|
expect(@results).to_not include(@followed_public_status)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not include direct statuses not mentioning recipient from followed' do
|
|
|
|
expect(@results).to_not include(@followed_direct_status)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not include direct statuses not mentioning recipient from non-followed' do
|
|
|
|
expect(@results).to_not include(@not_followed_direct_status)
|
|
|
|
end
|
|
|
|
|
2018-05-28 02:04:06 -07:00
|
|
|
it 'includes direct statuses mentioning recipient from followed' do
|
|
|
|
Fabricate(:mention, account: account, status: @followed_direct_status)
|
|
|
|
results2 = Status.as_direct_timeline(account)
|
|
|
|
expect(results2).to include(@followed_direct_status)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'includes direct statuses mentioning recipient from non-followed' do
|
|
|
|
Fabricate(:mention, account: account, status: @not_followed_direct_status)
|
|
|
|
results2 = Status.as_direct_timeline(account)
|
|
|
|
expect(results2).to include(@not_followed_direct_status)
|
|
|
|
end
|
2017-10-15 21:02:39 -07:00
|
|
|
end
|
|
|
|
|
2017-04-28 06:10:41 -07:00
|
|
|
describe '.as_public_timeline' do
|
|
|
|
it 'only includes statuses with public visibility' do
|
|
|
|
public_status = Fabricate(:status, visibility: :public)
|
|
|
|
private_status = Fabricate(:status, visibility: :private)
|
|
|
|
|
|
|
|
results = Status.as_public_timeline
|
|
|
|
expect(results).to include(public_status)
|
|
|
|
expect(results).not_to include(private_status)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not include replies' do
|
|
|
|
status = Fabricate(:status)
|
|
|
|
reply = Fabricate(:status, in_reply_to_id: status.id)
|
|
|
|
|
|
|
|
results = Status.as_public_timeline
|
|
|
|
expect(results).to include(status)
|
|
|
|
expect(results).not_to include(reply)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not include boosts' do
|
|
|
|
status = Fabricate(:status)
|
|
|
|
boost = Fabricate(:status, reblog_of_id: status.id)
|
|
|
|
|
|
|
|
results = Status.as_public_timeline
|
|
|
|
expect(results).to include(status)
|
|
|
|
expect(results).not_to include(boost)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'filters out silenced accounts' do
|
|
|
|
account = Fabricate(:account)
|
|
|
|
silenced_account = Fabricate(:account, silenced: true)
|
|
|
|
status = Fabricate(:status, account: account)
|
|
|
|
silenced_status = Fabricate(:status, account: silenced_account)
|
|
|
|
|
|
|
|
results = Status.as_public_timeline
|
|
|
|
expect(results).to include(status)
|
|
|
|
expect(results).not_to include(silenced_status)
|
|
|
|
end
|
|
|
|
|
2017-05-20 07:56:30 -07:00
|
|
|
context 'without local_only option' do
|
|
|
|
let(:viewer) { nil }
|
|
|
|
|
|
|
|
let!(:local_account) { Fabricate(:account, domain: nil) }
|
|
|
|
let!(:remote_account) { Fabricate(:account, domain: 'test.com') }
|
|
|
|
let!(:local_status) { Fabricate(:status, account: local_account) }
|
|
|
|
let!(:remote_status) { Fabricate(:status, account: remote_account) }
|
|
|
|
|
|
|
|
subject { Status.as_public_timeline(viewer, false) }
|
|
|
|
|
|
|
|
context 'without a viewer' do
|
|
|
|
let(:viewer) { nil }
|
|
|
|
|
|
|
|
it 'includes remote instances statuses' do
|
|
|
|
expect(subject).to include(remote_status)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'includes local statuses' do
|
|
|
|
expect(subject).to include(local_status)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with a viewer' do
|
|
|
|
let(:viewer) { Fabricate(:account, username: 'viewer') }
|
|
|
|
|
|
|
|
it 'includes remote instances statuses' do
|
|
|
|
expect(subject).to include(remote_status)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'includes local statuses' do
|
|
|
|
expect(subject).to include(local_status)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-04-28 06:10:41 -07:00
|
|
|
context 'with a local_only option set' do
|
2017-05-20 07:56:30 -07:00
|
|
|
let!(:local_account) { Fabricate(:account, domain: nil) }
|
|
|
|
let!(:remote_account) { Fabricate(:account, domain: 'test.com') }
|
|
|
|
let!(:local_status) { Fabricate(:status, account: local_account) }
|
|
|
|
let!(:remote_status) { Fabricate(:status, account: remote_account) }
|
|
|
|
|
|
|
|
subject { Status.as_public_timeline(viewer, true) }
|
|
|
|
|
|
|
|
context 'without a viewer' do
|
|
|
|
let(:viewer) { nil }
|
|
|
|
|
|
|
|
it 'does not include remote instances statuses' do
|
|
|
|
expect(subject).to include(local_status)
|
|
|
|
expect(subject).not_to include(remote_status)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with a viewer' do
|
|
|
|
let(:viewer) { Fabricate(:account, username: 'viewer') }
|
|
|
|
|
|
|
|
it 'does not include remote instances statuses' do
|
|
|
|
expect(subject).to include(local_status)
|
|
|
|
expect(subject).not_to include(remote_status)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'is not affected by personal domain blocks' do
|
|
|
|
viewer.block_domain!('test.com')
|
|
|
|
expect(subject).to include(local_status)
|
|
|
|
expect(subject).not_to include(remote_status)
|
|
|
|
end
|
2017-04-28 06:10:41 -07:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'with an account passed in' do
|
|
|
|
before do
|
|
|
|
@account = Fabricate(:account)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'excludes statuses from accounts blocked by the account' do
|
|
|
|
blocked = Fabricate(:account)
|
2017-04-30 05:49:24 -07:00
|
|
|
Fabricate(:block, account: @account, target_account: blocked)
|
2017-04-28 06:10:41 -07:00
|
|
|
blocked_status = Fabricate(:status, account: blocked)
|
|
|
|
|
|
|
|
results = Status.as_public_timeline(@account)
|
|
|
|
expect(results).not_to include(blocked_status)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'excludes statuses from accounts who have blocked the account' do
|
|
|
|
blocked = Fabricate(:account)
|
2017-04-30 05:49:24 -07:00
|
|
|
Fabricate(:block, account: blocked, target_account: @account)
|
2017-04-28 06:10:41 -07:00
|
|
|
blocked_status = Fabricate(:status, account: blocked)
|
|
|
|
|
|
|
|
results = Status.as_public_timeline(@account)
|
|
|
|
expect(results).not_to include(blocked_status)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'excludes statuses from accounts muted by the account' do
|
|
|
|
muted = Fabricate(:account)
|
2017-04-30 05:49:24 -07:00
|
|
|
Fabricate(:mute, account: @account, target_account: muted)
|
2017-04-28 06:10:41 -07:00
|
|
|
muted_status = Fabricate(:status, account: muted)
|
|
|
|
|
|
|
|
results = Status.as_public_timeline(@account)
|
|
|
|
expect(results).not_to include(muted_status)
|
|
|
|
end
|
|
|
|
|
Account domain blocks (#2381)
* Add <ostatus:conversation /> tag to Atom input/output
Only uses ref attribute (not href) because href would be
the alternate link that's always included also.
Creates new conversation for every non-reply status. Carries
over conversation for every reply. Keeps remote URIs verbatim,
generates local URIs on the fly like the rest of them.
* Conversation muting - prevents notifications that reference a conversation
(including replies, favourites, reblogs) from being created. API endpoints
/api/v1/statuses/:id/mute and /api/v1/statuses/:id/unmute
Currently no way to tell when a status/conversation is muted, so the web UI
only has a "disable notifications" button, doesn't work as a toggle
* Display "Dismiss notifications" on all statuses in notifications column, not just own
* Add "muted" as a boolean attribute on statuses JSON
For now always false on contained reblogs, since it's only relevant for
statuses returned from the notifications endpoint, which are not nested
Remove "Disable notifications" from detailed status view, since it's
only relevant in the notifications column
* Up max class length
* Remove pending test for conversation mute
* Add tests, clean up
* Rename to "mute conversation" and "unmute conversation"
* Raise validation error when trying to mute/unmute status without conversation
* Adding account domain blocks that filter notifications and public timelines
* Add tests for domain blocks in notifications, public timelines
Filter reblogs of blocked domains from home
* Add API for listing and creating account domain blocks
* API for creating/deleting domain blocks, tests for Status#ancestors
and Status#descendants, filter domain blocks from them
* Filter domains in streaming API
* Update account_domain_block_spec.rb
2017-05-18 16:14:30 -07:00
|
|
|
it 'excludes statuses from accounts from personally blocked domains' do
|
|
|
|
blocked = Fabricate(:account, domain: 'example.com')
|
|
|
|
@account.block_domain!(blocked.domain)
|
|
|
|
blocked_status = Fabricate(:status, account: blocked)
|
|
|
|
|
|
|
|
results = Status.as_public_timeline(@account)
|
|
|
|
expect(results).not_to include(blocked_status)
|
|
|
|
end
|
|
|
|
|
2017-05-01 08:42:13 -07:00
|
|
|
context 'with language preferences' do
|
|
|
|
it 'excludes statuses in languages not allowed by the account user' do
|
2018-06-17 04:54:02 -07:00
|
|
|
user = Fabricate(:user, chosen_languages: [:en, :es])
|
2017-05-01 08:42:13 -07:00
|
|
|
@account.update(user: user)
|
|
|
|
en_status = Fabricate(:status, language: 'en')
|
|
|
|
es_status = Fabricate(:status, language: 'es')
|
|
|
|
fr_status = Fabricate(:status, language: 'fr')
|
|
|
|
|
|
|
|
results = Status.as_public_timeline(@account)
|
|
|
|
expect(results).to include(en_status)
|
|
|
|
expect(results).to include(es_status)
|
|
|
|
expect(results).not_to include(fr_status)
|
|
|
|
end
|
|
|
|
|
2017-05-07 18:32:52 -07:00
|
|
|
it 'includes all languages when user does not have a setting' do
|
2018-06-17 04:54:02 -07:00
|
|
|
user = Fabricate(:user, chosen_languages: nil)
|
2017-05-07 18:32:52 -07:00
|
|
|
@account.update(user: user)
|
|
|
|
|
|
|
|
en_status = Fabricate(:status, language: 'en')
|
|
|
|
es_status = Fabricate(:status, language: 'es')
|
|
|
|
|
|
|
|
results = Status.as_public_timeline(@account)
|
|
|
|
expect(results).to include(en_status)
|
|
|
|
expect(results).to include(es_status)
|
|
|
|
end
|
|
|
|
|
2017-05-01 08:42:13 -07:00
|
|
|
it 'includes all languages when account does not have a user' do
|
|
|
|
expect(@account.user).to be_nil
|
|
|
|
en_status = Fabricate(:status, language: 'en')
|
|
|
|
es_status = Fabricate(:status, language: 'es')
|
|
|
|
|
|
|
|
results = Status.as_public_timeline(@account)
|
|
|
|
expect(results).to include(en_status)
|
|
|
|
expect(results).to include(es_status)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-04-28 06:10:41 -07:00
|
|
|
context 'where that account is silenced' do
|
|
|
|
it 'includes statuses from other accounts that are silenced' do
|
|
|
|
@account.update(silenced: true)
|
|
|
|
other_silenced_account = Fabricate(:account, silenced: true)
|
|
|
|
other_status = Fabricate(:status, account: other_silenced_account)
|
|
|
|
|
|
|
|
results = Status.as_public_timeline(@account)
|
|
|
|
expect(results).to include(other_status)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2017-12-14 00:57:59 -08:00
|
|
|
|
|
|
|
context 'with local-only statuses' do
|
|
|
|
let(:status) { Fabricate(:status, local_only: true) }
|
|
|
|
|
|
|
|
subject { Status.as_public_timeline(viewer) }
|
|
|
|
|
|
|
|
context 'without a viewer' do
|
|
|
|
let(:viewer) { nil }
|
|
|
|
|
|
|
|
it 'excludes local-only statuses' do
|
|
|
|
expect(subject).to_not include(status)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with a viewer' do
|
|
|
|
let(:viewer) { Fabricate(:account, username: 'viewer') }
|
|
|
|
|
|
|
|
it 'includes local-only statuses' do
|
|
|
|
expect(subject).to include(status)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# TODO: What happens if the viewer is remote?
|
|
|
|
# Can the viewer be remote?
|
|
|
|
# What prevents the viewer from being remote?
|
|
|
|
end
|
2017-04-28 06:10:41 -07:00
|
|
|
end
|
|
|
|
|
|
|
|
describe '.as_tag_timeline' do
|
|
|
|
it 'includes statuses with a tag' do
|
|
|
|
tag = Fabricate(:tag)
|
|
|
|
status = Fabricate(:status, tags: [tag])
|
|
|
|
other = Fabricate(:status)
|
|
|
|
|
|
|
|
results = Status.as_tag_timeline(tag)
|
|
|
|
expect(results).to include(status)
|
|
|
|
expect(results).not_to include(other)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'allows replies to be included' do
|
|
|
|
original = Fabricate(:status)
|
|
|
|
tag = Fabricate(:tag)
|
|
|
|
status = Fabricate(:status, tags: [tag], in_reply_to_id: original.id)
|
|
|
|
|
|
|
|
results = Status.as_tag_timeline(tag)
|
|
|
|
expect(results).to include(status)
|
|
|
|
end
|
2017-12-14 00:27:42 -08:00
|
|
|
|
|
|
|
context 'on a local-only status' do
|
|
|
|
let(:tag) { Fabricate(:tag) }
|
|
|
|
let(:status) { Fabricate(:status, local_only: true, tags: [tag]) }
|
|
|
|
|
2017-12-14 00:57:59 -08:00
|
|
|
context 'without a viewer' do
|
|
|
|
let(:viewer) { nil }
|
2017-12-14 00:27:42 -08:00
|
|
|
|
|
|
|
it 'filters the local-only status out of the result set' do
|
2017-12-14 00:57:59 -08:00
|
|
|
expect(Status.as_tag_timeline(tag, viewer)).not_to include(status)
|
2017-12-14 00:27:42 -08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-12-14 00:57:59 -08:00
|
|
|
context 'with a viewer' do
|
|
|
|
let(:viewer) { Fabricate(:account, username: 'viewer', domain: nil) }
|
2017-12-14 00:27:42 -08:00
|
|
|
|
|
|
|
it 'keeps the local-only status in the result set' do
|
2017-12-14 00:57:59 -08:00
|
|
|
expect(Status.as_tag_timeline(tag, viewer)).to include(status)
|
2017-12-14 00:27:42 -08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2017-04-28 06:10:41 -07:00
|
|
|
end
|
2017-05-12 10:09:21 -07:00
|
|
|
|
2017-05-15 17:54:17 -07:00
|
|
|
describe '.permitted_for' do
|
|
|
|
subject { described_class.permitted_for(target_account, account).pluck(:visibility) }
|
|
|
|
|
|
|
|
let(:target_account) { alice }
|
|
|
|
let(:account) { bob }
|
|
|
|
let!(:public_status) { Fabricate(:status, account: target_account, visibility: 'public') }
|
|
|
|
let!(:unlisted_status) { Fabricate(:status, account: target_account, visibility: 'unlisted') }
|
|
|
|
let!(:private_status) { Fabricate(:status, account: target_account, visibility: 'private') }
|
|
|
|
|
|
|
|
let!(:direct_status) do
|
|
|
|
Fabricate(:status, account: target_account, visibility: 'direct').tap do |status|
|
|
|
|
Fabricate(:mention, status: status, account: account)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
let!(:other_direct_status) do
|
|
|
|
Fabricate(:status, account: target_account, visibility: 'direct').tap do |status|
|
|
|
|
Fabricate(:mention, status: status)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'given nil' do
|
|
|
|
let(:account) { nil }
|
|
|
|
let(:direct_status) { nil }
|
|
|
|
it { is_expected.to eq(%w(unlisted public)) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'given blocked account' do
|
|
|
|
before do
|
|
|
|
target_account.block!(account)
|
|
|
|
end
|
|
|
|
|
|
|
|
it { is_expected.to be_empty }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'given same account' do
|
|
|
|
let(:account) { target_account }
|
|
|
|
it { is_expected.to eq(%w(direct direct private unlisted public)) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'given followed account' do
|
|
|
|
before do
|
|
|
|
account.follow!(target_account)
|
|
|
|
end
|
|
|
|
|
|
|
|
it { is_expected.to eq(%w(direct private unlisted public)) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'given unfollowed account' do
|
|
|
|
it { is_expected.to eq(%w(direct unlisted public)) }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-09-06 10:01:28 -07:00
|
|
|
describe 'before_validation' do
|
2017-05-12 10:09:21 -07:00
|
|
|
it 'sets account being replied to correctly over intermediary nodes' do
|
|
|
|
first_status = Fabricate(:status, account: bob)
|
|
|
|
intermediary = Fabricate(:status, thread: first_status, account: alice)
|
|
|
|
final = Fabricate(:status, thread: intermediary, account: alice)
|
|
|
|
|
|
|
|
expect(final.in_reply_to_account_id).to eq bob.id
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'creates new conversation for stand-alone status' do
|
|
|
|
expect(Status.create(account: alice, text: 'First').conversation_id).to_not be_nil
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'keeps conversation of parent node' do
|
|
|
|
parent = Fabricate(:status, text: 'First')
|
|
|
|
expect(Status.create(account: alice, thread: parent, text: 'Response').conversation_id).to eq parent.conversation_id
|
|
|
|
end
|
2017-09-06 10:01:28 -07:00
|
|
|
|
|
|
|
it 'sets `local` to true for status by local account' do
|
|
|
|
expect(Status.create(account: alice, text: 'foo').local).to be true
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'sets `local` to false for status by remote account' do
|
|
|
|
alice.update(domain: 'example.com')
|
|
|
|
expect(Status.create(account: alice, text: 'foo').local).to be false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-09-17 06:21:57 -07:00
|
|
|
describe 'validation' do
|
|
|
|
it 'disallow empty uri for remote status' do
|
|
|
|
alice.update(domain: 'example.com')
|
|
|
|
status = Fabricate.build(:status, uri: '', account: alice)
|
|
|
|
expect(status).to model_have_error_on_field(:uri)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-09-06 10:01:28 -07:00
|
|
|
describe 'after_create' do
|
|
|
|
it 'saves ActivityPub uri as uri for local status' do
|
|
|
|
status = Status.create(account: alice, text: 'foo')
|
|
|
|
status.reload
|
|
|
|
expect(status.uri).to start_with('https://')
|
|
|
|
end
|
2017-05-12 10:09:21 -07:00
|
|
|
end
|
2016-02-20 13:53:20 -08:00
|
|
|
end
|