2023-02-22 00:55:31 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-02-20 21:53:20 +00:00
|
|
|
require 'rails_helper'
|
|
|
|
|
2023-05-04 03:49:53 +00:00
|
|
|
RSpec.describe Status do
|
2023-02-20 04:24:14 +00:00
|
|
|
subject { Fabricate(:status, account: alice) }
|
|
|
|
|
2016-02-26 14:28:08 +00:00
|
|
|
let(:alice) { Fabricate(:account, username: 'alice') }
|
|
|
|
let(:bob) { Fabricate(:account, username: 'bob') }
|
2017-07-28 22:06:29 +00:00
|
|
|
let(:other) { Fabricate(:status, account: bob, text: 'Skulls for the skull god! The enemy\'s gates are sideways!') }
|
2016-02-26 14:28:08 +00:00
|
|
|
|
2016-02-24 23:17:01 +00:00
|
|
|
describe '#local?' do
|
2016-02-26 14:28:08 +00: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 17:01:28 +00:00
|
|
|
alice.update(domain: 'example.com')
|
|
|
|
subject.save
|
2016-02-26 14:28:08 +00:00
|
|
|
expect(subject.local?).to be false
|
|
|
|
end
|
2017-09-06 17:01:28 +00: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 23:17:01 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
describe '#reblog?' do
|
2016-02-26 14:28:08 +00: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 23:17:01 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
describe '#reply?' do
|
2016-02-26 14:28:08 +00: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 23:17:01 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
describe '#verb' do
|
2023-05-04 03:49:08 +00:00
|
|
|
context 'when destroyed?' do
|
2017-11-16 06:46:29 +00:00
|
|
|
it 'returns :delete' do
|
|
|
|
subject.destroy!
|
|
|
|
expect(subject.verb).to be :delete
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-05-04 03:49:08 +00:00
|
|
|
context 'when not destroyed?' do
|
|
|
|
context 'when reblog?' do
|
2017-11-16 06:46:29 +00:00
|
|
|
it 'returns :share' do
|
|
|
|
subject.reblog = other
|
|
|
|
expect(subject.verb).to be :share
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-05-04 03:49:08 +00:00
|
|
|
context 'when not reblog?' do
|
2017-11-16 06:46:29 +00:00
|
|
|
it 'returns :post' do
|
|
|
|
subject.reblog = nil
|
|
|
|
expect(subject.verb).to be :post
|
|
|
|
end
|
|
|
|
end
|
2016-02-26 14:28:08 +00:00
|
|
|
end
|
2016-02-24 23:17:01 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
describe '#object_type' do
|
2016-02-26 14:28:08 +00: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 23:17:01 +00:00
|
|
|
end
|
|
|
|
|
2017-11-16 02:07:27 +00:00
|
|
|
describe '#hidden?' do
|
2023-05-04 03:49:08 +00:00
|
|
|
context 'when private_visibility?' do
|
2017-11-16 02:07:27 +00:00
|
|
|
it 'returns true' do
|
|
|
|
subject.visibility = :private
|
|
|
|
expect(subject.hidden?).to be true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-05-04 03:49:08 +00:00
|
|
|
context 'when direct_visibility?' do
|
2017-11-16 02:07:27 +00:00
|
|
|
it 'returns true' do
|
|
|
|
subject.visibility = :direct
|
|
|
|
expect(subject.hidden?).to be true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-05-04 03:49:08 +00:00
|
|
|
context 'when public_visibility?' do
|
2017-11-16 02:07:27 +00:00
|
|
|
it 'returns false' do
|
|
|
|
subject.visibility = :public
|
|
|
|
expect(subject.hidden?).to be false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-05-04 03:49:08 +00:00
|
|
|
context 'when unlisted_visibility?' do
|
2017-11-16 02:07:27 +00:00
|
|
|
it 'returns false' do
|
|
|
|
subject.visibility = :unlisted
|
|
|
|
expect(subject.hidden?).to be false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-02-26 14:28:08 +00: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 23:17:01 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
describe '#target' do
|
2016-02-26 14:28:08 +00:00
|
|
|
it 'returns nil if the status is self-contained' do
|
2018-10-08 02:50:11 +00:00
|
|
|
expect(subject.target).to be_nil
|
2016-02-26 14:28:08 +00: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 23:17:01 +00:00
|
|
|
end
|
2016-03-19 11:13:47 +00:00
|
|
|
|
|
|
|
describe '#reblogs_count' do
|
2017-04-07 19:30:36 +00: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-30 00:50:23 +00: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
|
2018-08-18 01:03:23 +00:00
|
|
|
|
|
|
|
it 'does not fail when original is deleted before reblog' do
|
|
|
|
reblog = Fabricate(:status, account: bob, reblog: subject)
|
|
|
|
expect(subject.reblogs_count).to eq 1
|
|
|
|
expect { subject.destroy }.to_not raise_error
|
2023-06-06 11:58:33 +00:00
|
|
|
expect(described_class.find_by(id: reblog.id)).to be_nil
|
2018-08-18 01:03:23 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#replies_count' do
|
|
|
|
it 'is the number of replies' do
|
2023-10-19 14:55:06 +00:00
|
|
|
Fabricate(:status, account: bob, thread: subject)
|
2018-08-18 01:03:23 +00:00
|
|
|
expect(subject.replies_count).to eq 1
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'is decremented when reply is removed' do
|
|
|
|
reply = Fabricate(:status, account: bob, thread: subject)
|
|
|
|
expect(subject.replies_count).to eq 1
|
|
|
|
reply.destroy
|
|
|
|
expect(subject.replies_count).to eq 0
|
|
|
|
end
|
2016-03-19 11:13:47 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
describe '#favourites_count' do
|
2017-04-07 19:30:36 +00: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-30 00:50:23 +00: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 11:13:47 +00:00
|
|
|
end
|
2017-04-07 18:18:30 +00: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 20:37:24 +00:00
|
|
|
|
2017-12-14 08:27:42 +00:00
|
|
|
describe 'on create' do
|
2023-06-10 14:48:01 +00:00
|
|
|
subject { described_class.new }
|
2023-04-09 09:25:30 +00:00
|
|
|
|
2017-12-14 08:27:42 +00:00
|
|
|
let(:local_account) { Fabricate(:account, username: 'local', domain: nil) }
|
|
|
|
let(:remote_account) { Fabricate(:account, username: 'remote', domain: 'example.com') }
|
|
|
|
|
|
|
|
describe 'on a status that ends with the local-only emoji' do
|
|
|
|
before do
|
2023-04-09 09:25:30 +00:00
|
|
|
subject.text = "A toot #{subject.local_only_emoji}"
|
2017-12-14 08:27:42 +00:00
|
|
|
end
|
|
|
|
|
2023-05-08 17:26:00 +00:00
|
|
|
context 'when the status originates from this instance' do
|
2017-12-14 08:27:42 +00:00
|
|
|
before do
|
|
|
|
subject.account = local_account
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'is marked local-only' do
|
|
|
|
subject.save!
|
|
|
|
|
|
|
|
expect(subject).to be_local_only
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-05-08 17:26:00 +00:00
|
|
|
context 'when the status is remote' do
|
2017-12-14 08:27:42 +00:00
|
|
|
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
|
|
|
|
|
2024-05-06 09:52:34 +00:00
|
|
|
describe '#reported?' do
|
|
|
|
context 'when the status is not reported' do
|
|
|
|
it 'returns false' do
|
|
|
|
expect(subject.reported?).to be false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when the status is part of an open report' do
|
|
|
|
before do
|
|
|
|
Fabricate(:report, target_account: subject.account, status_ids: [subject.id])
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns true' do
|
|
|
|
expect(subject.reported?).to be true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when the status is part of a closed report with an account warning mentioning the account' do
|
|
|
|
before do
|
|
|
|
report = Fabricate(:report, target_account: subject.account, status_ids: [subject.id])
|
|
|
|
report.resolve!(Fabricate(:account))
|
|
|
|
Fabricate(:account_warning, target_account: subject.account, status_ids: [subject.id], report: report)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns true' do
|
|
|
|
expect(subject.reported?).to be true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when the status is part of a closed report with an account warning not mentioning the account' do
|
|
|
|
before do
|
|
|
|
report = Fabricate(:report, target_account: subject.account, status_ids: [subject.id])
|
|
|
|
report.resolve!(Fabricate(:account))
|
|
|
|
Fabricate(:account_warning, target_account: subject.account, report: report)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns false' do
|
|
|
|
expect(subject.reported?).to be false
|
|
|
|
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-15 01:04:13 +00:00
|
|
|
describe '.mutes_map' do
|
2023-06-06 11:58:33 +00:00
|
|
|
subject { described_class.mutes_map([status.conversation.id], account) }
|
2023-02-20 04:24:14 +00:00
|
|
|
|
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-15 01:04:13 +00:00
|
|
|
let(:status) { Fabricate(:status) }
|
|
|
|
let(:account) { Fabricate(: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
|
2023-06-06 11:58:33 +00:00
|
|
|
subject { described_class.favourites_map([status], account) }
|
2023-02-20 04:24:14 +00:00
|
|
|
|
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-15 01:04:13 +00:00
|
|
|
let(:status) { Fabricate(:status) }
|
|
|
|
let(:account) { Fabricate(: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
|
2023-06-06 11:58:33 +00:00
|
|
|
subject { described_class.reblogs_map([status], account) }
|
2023-02-20 04:24:14 +00:00
|
|
|
|
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-15 01:04:13 +00:00
|
|
|
let(:status) { Fabricate(:status) }
|
|
|
|
let(:account) { Fabricate(: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
|
|
|
|
|
2017-10-16 04:02:39 +00:00
|
|
|
describe '.as_direct_timeline' do
|
2023-06-10 14:48:01 +00:00
|
|
|
subject(:results) { described_class.as_direct_timeline(account) }
|
2023-04-09 09:25:30 +00:00
|
|
|
|
2017-10-16 04:02:39 +00:00
|
|
|
let(:account) { Fabricate(:account) }
|
|
|
|
let(:followed) { Fabricate(:account) }
|
|
|
|
let(:not_followed) { Fabricate(:account) }
|
|
|
|
|
2023-04-09 09:25:30 +00:00
|
|
|
let!(:self_public_status) { Fabricate(:status, account: account, visibility: :public) }
|
|
|
|
let!(:self_direct_status) { Fabricate(:status, account: account, visibility: :direct) }
|
|
|
|
let!(:followed_public_status) { Fabricate(:status, account: followed, visibility: :public) }
|
|
|
|
let!(:followed_direct_status) { Fabricate(:status, account: followed, visibility: :direct) }
|
|
|
|
let!(:not_followed_direct_status) { Fabricate(:status, account: not_followed, visibility: :direct) }
|
2017-10-16 04:02:39 +00:00
|
|
|
|
2023-04-09 09:25:30 +00:00
|
|
|
before do
|
|
|
|
account.follow!(followed)
|
2017-10-16 04:02:39 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not include public statuses from self' do
|
2023-04-09 09:25:30 +00:00
|
|
|
expect(results).to_not include(self_public_status)
|
2017-10-16 04:02:39 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'includes direct statuses from self' do
|
2023-04-09 09:25:30 +00:00
|
|
|
expect(results).to include(self_direct_status)
|
2017-10-16 04:02:39 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not include public statuses from followed' do
|
2023-04-09 09:25:30 +00:00
|
|
|
expect(results).to_not include(followed_public_status)
|
2017-10-16 04:02:39 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not include direct statuses not mentioning recipient from followed' do
|
2023-04-09 09:25:30 +00:00
|
|
|
expect(results).to_not include(followed_direct_status)
|
2017-10-16 04:02:39 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not include direct statuses not mentioning recipient from non-followed' do
|
2023-04-09 09:25:30 +00:00
|
|
|
expect(results).to_not include(not_followed_direct_status)
|
2017-10-16 04:02:39 +00:00
|
|
|
end
|
|
|
|
|
2018-05-28 09:04:06 +00:00
|
|
|
it 'includes direct statuses mentioning recipient from followed' do
|
2023-04-09 09:25:30 +00:00
|
|
|
Fabricate(:mention, account: account, status: followed_direct_status)
|
2023-06-10 14:48:01 +00:00
|
|
|
results2 = described_class.as_direct_timeline(account)
|
2023-04-09 09:25:30 +00:00
|
|
|
expect(results2).to include(followed_direct_status)
|
2018-05-28 09:04:06 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'includes direct statuses mentioning recipient from non-followed' do
|
2023-04-09 09:25:30 +00:00
|
|
|
Fabricate(:mention, account: account, status: not_followed_direct_status)
|
2023-06-10 14:48:01 +00:00
|
|
|
results2 = described_class.as_direct_timeline(account)
|
2023-04-09 09:25:30 +00:00
|
|
|
expect(results2).to include(not_followed_direct_status)
|
2018-05-28 09:04:06 +00:00
|
|
|
end
|
2017-10-16 04:02:39 +00:00
|
|
|
end
|
|
|
|
|
2022-01-23 17:10:10 +00:00
|
|
|
describe '.tagged_with' do
|
2023-06-14 14:44:37 +00:00
|
|
|
let(:tag_cats) { Fabricate(:tag, name: 'cats') }
|
|
|
|
let(:tag_dogs) { Fabricate(:tag, name: 'dogs') }
|
|
|
|
let(:tag_zebras) { Fabricate(:tag, name: 'zebras') }
|
|
|
|
let!(:status_with_tag_cats) { Fabricate(:status, tags: [tag_cats]) }
|
|
|
|
let!(:status_with_tag_dogs) { Fabricate(:status, tags: [tag_dogs]) }
|
|
|
|
let!(:status_tagged_with_zebras) { Fabricate(:status, tags: [tag_zebras]) }
|
|
|
|
let!(:status_without_tags) { Fabricate(:status, tags: []) }
|
|
|
|
let!(:status_with_all_tags) { Fabricate(:status, tags: [tag_cats, tag_dogs, tag_zebras]) }
|
2022-01-23 17:10:10 +00:00
|
|
|
|
|
|
|
context 'when given one tag' do
|
|
|
|
it 'returns the expected statuses' do
|
2023-12-22 08:32:27 +00:00
|
|
|
expect(described_class.tagged_with([tag_cats.id]))
|
|
|
|
.to include(status_with_tag_cats, status_with_all_tags)
|
|
|
|
.and not_include(status_without_tags)
|
|
|
|
expect(described_class.tagged_with([tag_dogs.id]))
|
|
|
|
.to include(status_with_tag_dogs, status_with_all_tags)
|
|
|
|
.and not_include(status_without_tags)
|
|
|
|
expect(described_class.tagged_with([tag_zebras.id]))
|
|
|
|
.to include(status_tagged_with_zebras, status_with_all_tags)
|
|
|
|
.and not_include(status_without_tags)
|
2022-01-23 17:10:10 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when given multiple tags' do
|
|
|
|
it 'returns the expected statuses' do
|
2023-12-22 08:32:27 +00:00
|
|
|
expect(described_class.tagged_with([tag_cats.id, tag_dogs.id]))
|
|
|
|
.to include(status_with_tag_cats, status_with_tag_dogs, status_with_all_tags)
|
|
|
|
.and not_include(status_without_tags)
|
|
|
|
expect(described_class.tagged_with([tag_cats.id, tag_zebras.id]))
|
|
|
|
.to include(status_with_tag_cats, status_tagged_with_zebras, status_with_all_tags)
|
|
|
|
.and not_include(status_without_tags)
|
|
|
|
expect(described_class.tagged_with([tag_dogs.id, tag_zebras.id]))
|
|
|
|
.to include(status_with_tag_dogs, status_tagged_with_zebras, status_with_all_tags)
|
|
|
|
.and not_include(status_without_tags)
|
2022-01-23 17:10:10 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '.tagged_with_all' do
|
2023-06-14 14:44:37 +00:00
|
|
|
let(:tag_cats) { Fabricate(:tag, name: 'cats') }
|
|
|
|
let(:tag_dogs) { Fabricate(:tag, name: 'dogs') }
|
|
|
|
let(:tag_zebras) { Fabricate(:tag, name: 'zebras') }
|
|
|
|
let!(:status_with_tag_cats) { Fabricate(:status, tags: [tag_cats]) }
|
|
|
|
let!(:status_with_tag_dogs) { Fabricate(:status, tags: [tag_dogs]) }
|
|
|
|
let!(:status_tagged_with_zebras) { Fabricate(:status, tags: [tag_zebras]) }
|
|
|
|
let!(:status_without_tags) { Fabricate(:status, tags: []) }
|
|
|
|
let!(:status_with_all_tags) { Fabricate(:status, tags: [tag_cats, tag_dogs]) }
|
2022-01-23 17:10:10 +00:00
|
|
|
|
|
|
|
context 'when given one tag' do
|
|
|
|
it 'returns the expected statuses' do
|
2023-12-22 08:32:27 +00:00
|
|
|
expect(described_class.tagged_with_all([tag_cats.id]))
|
|
|
|
.to include(status_with_tag_cats, status_with_all_tags)
|
|
|
|
.and not_include(status_without_tags)
|
|
|
|
expect(described_class.tagged_with_all([tag_dogs.id]))
|
|
|
|
.to include(status_with_tag_dogs, status_with_all_tags)
|
|
|
|
.and not_include(status_without_tags)
|
|
|
|
expect(described_class.tagged_with_all([tag_zebras.id]))
|
|
|
|
.to include(status_tagged_with_zebras)
|
|
|
|
.and not_include(status_without_tags)
|
2022-01-23 17:10:10 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when given multiple tags' do
|
|
|
|
it 'returns the expected statuses' do
|
2023-12-22 08:32:27 +00:00
|
|
|
expect(described_class.tagged_with_all([tag_cats.id, tag_dogs.id]))
|
|
|
|
.to include(status_with_all_tags)
|
|
|
|
expect(described_class.tagged_with_all([tag_cats.id, tag_zebras.id]))
|
|
|
|
.to eq []
|
|
|
|
expect(described_class.tagged_with_all([tag_dogs.id, tag_zebras.id]))
|
|
|
|
.to eq []
|
2022-01-23 17:10:10 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '.tagged_with_none' do
|
2023-06-14 14:44:37 +00:00
|
|
|
let(:tag_cats) { Fabricate(:tag, name: 'cats') }
|
|
|
|
let(:tag_dogs) { Fabricate(:tag, name: 'dogs') }
|
|
|
|
let(:tag_zebras) { Fabricate(:tag, name: 'zebras') }
|
|
|
|
let!(:status_with_tag_cats) { Fabricate(:status, tags: [tag_cats]) }
|
|
|
|
let!(:status_with_tag_dogs) { Fabricate(:status, tags: [tag_dogs]) }
|
|
|
|
let!(:status_tagged_with_zebras) { Fabricate(:status, tags: [tag_zebras]) }
|
|
|
|
let!(:status_without_tags) { Fabricate(:status, tags: []) }
|
|
|
|
let!(:status_with_all_tags) { Fabricate(:status, tags: [tag_cats, tag_dogs, tag_zebras]) }
|
2022-01-23 17:10:10 +00:00
|
|
|
|
|
|
|
context 'when given one tag' do
|
|
|
|
it 'returns the expected statuses' do
|
2023-12-22 08:32:27 +00:00
|
|
|
expect(described_class.tagged_with_none([tag_cats.id]))
|
|
|
|
.to include(status_with_tag_dogs, status_tagged_with_zebras, status_without_tags)
|
|
|
|
.and not_include(status_with_all_tags)
|
|
|
|
expect(described_class.tagged_with_none([tag_dogs.id]))
|
|
|
|
.to include(status_with_tag_cats, status_tagged_with_zebras, status_without_tags)
|
|
|
|
.and not_include(status_with_all_tags)
|
|
|
|
expect(described_class.tagged_with_none([tag_zebras.id]))
|
|
|
|
.to include(status_with_tag_cats, status_with_tag_dogs, status_without_tags)
|
|
|
|
.and not_include(status_with_all_tags)
|
2022-01-23 17:10:10 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when given multiple tags' do
|
|
|
|
it 'returns the expected statuses' do
|
2023-12-22 08:32:27 +00:00
|
|
|
expect(described_class.tagged_with_none([tag_cats.id, tag_dogs.id]))
|
|
|
|
.to include(status_tagged_with_zebras, status_without_tags)
|
|
|
|
.and not_include(status_with_all_tags)
|
|
|
|
expect(described_class.tagged_with_none([tag_cats.id, tag_zebras.id]))
|
|
|
|
.to include(status_with_tag_dogs, status_without_tags)
|
|
|
|
.and not_include(status_with_all_tags)
|
|
|
|
expect(described_class.tagged_with_none([tag_dogs.id, tag_zebras.id]))
|
|
|
|
.to include(status_with_tag_cats, status_without_tags)
|
|
|
|
.and not_include(status_with_all_tags)
|
2022-01-23 17:10:10 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-09-06 17:01:28 +00:00
|
|
|
describe 'before_validation' do
|
2017-05-12 17:09:21 +00: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
|
2023-06-06 11:58:33 +00:00
|
|
|
expect(described_class.create(account: alice, text: 'First').conversation_id).to_not be_nil
|
2017-05-12 17:09:21 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'keeps conversation of parent node' do
|
|
|
|
parent = Fabricate(:status, text: 'First')
|
2023-06-06 11:58:33 +00:00
|
|
|
expect(described_class.create(account: alice, thread: parent, text: 'Response').conversation_id).to eq parent.conversation_id
|
2017-05-12 17:09:21 +00:00
|
|
|
end
|
2017-09-06 17:01:28 +00:00
|
|
|
|
|
|
|
it 'sets `local` to true for status by local account' do
|
2023-06-06 11:58:33 +00:00
|
|
|
expect(described_class.create(account: alice, text: 'foo').local).to be true
|
2017-09-06 17:01:28 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'sets `local` to false for status by remote account' do
|
|
|
|
alice.update(domain: 'example.com')
|
2023-06-06 11:58:33 +00:00
|
|
|
expect(described_class.create(account: alice, text: 'foo').local).to be false
|
2017-09-06 17:01:28 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-09-17 13:21:57 +00: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 17:01:28 +00:00
|
|
|
describe 'after_create' do
|
|
|
|
it 'saves ActivityPub uri as uri for local status' do
|
2023-06-06 11:58:33 +00:00
|
|
|
status = described_class.create(account: alice, text: 'foo')
|
2017-09-06 17:01:28 +00:00
|
|
|
status.reload
|
|
|
|
expect(status.uri).to start_with('https://')
|
|
|
|
end
|
2017-05-12 17:09:21 +00:00
|
|
|
end
|
2016-02-20 21:53:20 +00:00
|
|
|
end
|