Merge commit 'b85c387c5c0527b0ad31c27031a09d361826c5fc' into glitch-soc/merge-upstream
Conflicts: - `config/initializers/content_security_policy.rb`: Kept our version, it was not affected by upstream's bug.
This commit is contained in:
@ -31,7 +31,7 @@ RSpec.describe ActivityPub::Activity::Undo do
|
||||
}
|
||||
end
|
||||
|
||||
context do
|
||||
context 'when not atomUri' do
|
||||
before do
|
||||
Fabricate(:status, reblog: status, account: sender, uri: 'bar')
|
||||
end
|
||||
|
17
spec/lib/admin/metrics/measure/active_users_measure_spec.rb
Normal file
17
spec/lib/admin/metrics/measure/active_users_measure_spec.rb
Normal file
@ -0,0 +1,17 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
describe Admin::Metrics::Measure::ActiveUsersMeasure do
|
||||
subject(:measure) { described_class.new(start_at, end_at, params) }
|
||||
|
||||
let(:start_at) { 2.days.ago }
|
||||
let(:end_at) { Time.now.utc }
|
||||
let(:params) { ActionController::Parameters.new }
|
||||
|
||||
describe '#data' do
|
||||
it 'runs data query without error' do
|
||||
expect { measure.data }.to_not raise_error
|
||||
end
|
||||
end
|
||||
end
|
@ -37,4 +37,10 @@ describe Admin::Metrics::Measure::InstanceAccountsMeasure do
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#data' do
|
||||
it 'runs data query without error' do
|
||||
expect { measure.data }.to_not raise_error
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -39,4 +39,10 @@ describe Admin::Metrics::Measure::InstanceFollowersMeasure do
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#data' do
|
||||
it 'runs data query without error' do
|
||||
expect { measure.data }.to_not raise_error
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -39,4 +39,10 @@ describe Admin::Metrics::Measure::InstanceFollowsMeasure do
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#data' do
|
||||
it 'runs data query without error' do
|
||||
expect { measure.data }.to_not raise_error
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -40,4 +40,10 @@ describe Admin::Metrics::Measure::InstanceMediaAttachmentsMeasure do
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#data' do
|
||||
it 'runs data query without error' do
|
||||
expect { measure.data }.to_not raise_error
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -36,4 +36,10 @@ describe Admin::Metrics::Measure::InstanceReportsMeasure do
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#data' do
|
||||
it 'runs data query without error' do
|
||||
expect { measure.data }.to_not raise_error
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -36,4 +36,10 @@ describe Admin::Metrics::Measure::InstanceStatusesMeasure do
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#data' do
|
||||
it 'runs data query without error' do
|
||||
expect { measure.data }.to_not raise_error
|
||||
end
|
||||
end
|
||||
end
|
||||
|
17
spec/lib/admin/metrics/measure/interactions_measure_spec.rb
Normal file
17
spec/lib/admin/metrics/measure/interactions_measure_spec.rb
Normal file
@ -0,0 +1,17 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
describe Admin::Metrics::Measure::InteractionsMeasure do
|
||||
subject(:measure) { described_class.new(start_at, end_at, params) }
|
||||
|
||||
let(:start_at) { 2.days.ago }
|
||||
let(:end_at) { Time.now.utc }
|
||||
let(:params) { ActionController::Parameters.new }
|
||||
|
||||
describe '#data' do
|
||||
it 'runs data query without error' do
|
||||
expect { measure.data }.to_not raise_error
|
||||
end
|
||||
end
|
||||
end
|
17
spec/lib/admin/metrics/measure/new_users_measure_spec.rb
Normal file
17
spec/lib/admin/metrics/measure/new_users_measure_spec.rb
Normal file
@ -0,0 +1,17 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
describe Admin::Metrics::Measure::NewUsersMeasure do
|
||||
subject(:measure) { described_class.new(start_at, end_at, params) }
|
||||
|
||||
let(:start_at) { 2.days.ago }
|
||||
let(:end_at) { Time.now.utc }
|
||||
let(:params) { ActionController::Parameters.new }
|
||||
|
||||
describe '#data' do
|
||||
it 'runs data query without error' do
|
||||
expect { measure.data }.to_not raise_error
|
||||
end
|
||||
end
|
||||
end
|
@ -0,0 +1,17 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
describe Admin::Metrics::Measure::OpenedReportsMeasure do
|
||||
subject(:measure) { described_class.new(start_at, end_at, params) }
|
||||
|
||||
let(:start_at) { 2.days.ago }
|
||||
let(:end_at) { Time.now.utc }
|
||||
let(:params) { ActionController::Parameters.new }
|
||||
|
||||
describe '#data' do
|
||||
it 'runs data query without error' do
|
||||
expect { measure.data }.to_not raise_error
|
||||
end
|
||||
end
|
||||
end
|
@ -0,0 +1,17 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
describe Admin::Metrics::Measure::ResolvedReportsMeasure do
|
||||
subject(:measure) { described_class.new(start_at, end_at, params) }
|
||||
|
||||
let(:start_at) { 2.days.ago }
|
||||
let(:end_at) { Time.now.utc }
|
||||
let(:params) { ActionController::Parameters.new }
|
||||
|
||||
describe '#data' do
|
||||
it 'runs data query without error' do
|
||||
expect { measure.data }.to_not raise_error
|
||||
end
|
||||
end
|
||||
end
|
19
spec/lib/admin/metrics/measure/tag_accounts_measure_spec.rb
Normal file
19
spec/lib/admin/metrics/measure/tag_accounts_measure_spec.rb
Normal file
@ -0,0 +1,19 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
describe Admin::Metrics::Measure::TagAccountsMeasure do
|
||||
subject(:measure) { described_class.new(start_at, end_at, params) }
|
||||
|
||||
let!(:tag) { Fabricate(:tag) }
|
||||
|
||||
let(:start_at) { 2.days.ago }
|
||||
let(:end_at) { Time.now.utc }
|
||||
let(:params) { ActionController::Parameters.new(id: tag.id) }
|
||||
|
||||
describe '#data' do
|
||||
it 'runs data query without error' do
|
||||
expect { measure.data }.to_not raise_error
|
||||
end
|
||||
end
|
||||
end
|
19
spec/lib/admin/metrics/measure/tag_servers_measure_spec.rb
Normal file
19
spec/lib/admin/metrics/measure/tag_servers_measure_spec.rb
Normal file
@ -0,0 +1,19 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
describe Admin::Metrics::Measure::TagServersMeasure do
|
||||
subject(:measure) { described_class.new(start_at, end_at, params) }
|
||||
|
||||
let!(:tag) { Fabricate(:tag) }
|
||||
|
||||
let(:start_at) { 2.days.ago }
|
||||
let(:end_at) { Time.now.utc }
|
||||
let(:params) { ActionController::Parameters.new(id: tag.id) }
|
||||
|
||||
describe '#data' do
|
||||
it 'runs data query without error' do
|
||||
expect { measure.data }.to_not raise_error
|
||||
end
|
||||
end
|
||||
end
|
19
spec/lib/admin/metrics/measure/tag_uses_measure_spec.rb
Normal file
19
spec/lib/admin/metrics/measure/tag_uses_measure_spec.rb
Normal file
@ -0,0 +1,19 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
describe Admin::Metrics::Measure::TagUsesMeasure do
|
||||
subject(:measure) { described_class.new(start_at, end_at, params) }
|
||||
|
||||
let!(:tag) { Fabricate(:tag) }
|
||||
|
||||
let(:start_at) { 2.days.ago }
|
||||
let(:end_at) { Time.now.utc }
|
||||
let(:params) { ActionController::Parameters.new(id: tag.id) }
|
||||
|
||||
describe '#data' do
|
||||
it 'runs data query without error' do
|
||||
expect { measure.data }.to_not raise_error
|
||||
end
|
||||
end
|
||||
end
|
@ -7,7 +7,7 @@ RSpec.describe EntityCache do
|
||||
let(:remote_account) { Fabricate(:account, domain: 'remote.test', username: 'bob', url: 'https://remote.test/') }
|
||||
|
||||
describe '#emoji' do
|
||||
subject { EntityCache.instance.emoji(shortcodes, domain) }
|
||||
subject { described_class.instance.emoji(shortcodes, domain) }
|
||||
|
||||
context 'when called with an empty list of shortcodes' do
|
||||
let(:shortcodes) { [] }
|
||||
|
@ -6,19 +6,19 @@ describe Extractor do
|
||||
describe 'extract_mentions_or_lists_with_indices' do
|
||||
it 'returns an empty array if the given string does not have at signs' do
|
||||
text = 'a string without at signs'
|
||||
extracted = Extractor.extract_mentions_or_lists_with_indices(text)
|
||||
extracted = described_class.extract_mentions_or_lists_with_indices(text)
|
||||
expect(extracted).to eq []
|
||||
end
|
||||
|
||||
it 'does not extract mentions which ends with particular characters' do
|
||||
text = '@screen_name@'
|
||||
extracted = Extractor.extract_mentions_or_lists_with_indices(text)
|
||||
extracted = described_class.extract_mentions_or_lists_with_indices(text)
|
||||
expect(extracted).to eq []
|
||||
end
|
||||
|
||||
it 'returns mentions as an array' do
|
||||
text = '@screen_name'
|
||||
extracted = Extractor.extract_mentions_or_lists_with_indices(text)
|
||||
extracted = described_class.extract_mentions_or_lists_with_indices(text)
|
||||
expect(extracted).to eq [
|
||||
{ screen_name: 'screen_name', indices: [0, 12] },
|
||||
]
|
||||
@ -26,7 +26,7 @@ describe Extractor do
|
||||
|
||||
it 'yields mentions if a block is given' do
|
||||
text = '@screen_name'
|
||||
Extractor.extract_mentions_or_lists_with_indices(text) do |screen_name, start_position, end_position|
|
||||
described_class.extract_mentions_or_lists_with_indices(text) do |screen_name, start_position, end_position|
|
||||
expect(screen_name).to eq 'screen_name'
|
||||
expect(start_position).to eq 0
|
||||
expect(end_position).to eq 12
|
||||
@ -37,31 +37,31 @@ describe Extractor do
|
||||
describe 'extract_hashtags_with_indices' do
|
||||
it 'returns an empty array if it does not have #' do
|
||||
text = 'a string without hash sign'
|
||||
extracted = Extractor.extract_hashtags_with_indices(text)
|
||||
extracted = described_class.extract_hashtags_with_indices(text)
|
||||
expect(extracted).to eq []
|
||||
end
|
||||
|
||||
it 'does not exclude normal hash text before ://' do
|
||||
text = '#hashtag://'
|
||||
extracted = Extractor.extract_hashtags_with_indices(text)
|
||||
extracted = described_class.extract_hashtags_with_indices(text)
|
||||
expect(extracted).to eq [{ hashtag: 'hashtag', indices: [0, 8] }]
|
||||
end
|
||||
|
||||
it 'excludes http://' do
|
||||
text = '#hashtaghttp://'
|
||||
extracted = Extractor.extract_hashtags_with_indices(text)
|
||||
extracted = described_class.extract_hashtags_with_indices(text)
|
||||
expect(extracted).to eq [{ hashtag: 'hashtag', indices: [0, 8] }]
|
||||
end
|
||||
|
||||
it 'excludes https://' do
|
||||
text = '#hashtaghttps://'
|
||||
extracted = Extractor.extract_hashtags_with_indices(text)
|
||||
extracted = described_class.extract_hashtags_with_indices(text)
|
||||
expect(extracted).to eq [{ hashtag: 'hashtag', indices: [0, 8] }]
|
||||
end
|
||||
|
||||
it 'yields hashtags if a block is given' do
|
||||
text = '#hashtag'
|
||||
Extractor.extract_hashtags_with_indices(text) do |hashtag, start_position, end_position|
|
||||
described_class.extract_hashtags_with_indices(text) do |hashtag, start_position, end_position|
|
||||
expect(hashtag).to eq 'hashtag'
|
||||
expect(start_position).to eq 0
|
||||
expect(end_position).to eq 8
|
||||
@ -72,7 +72,7 @@ describe Extractor do
|
||||
describe 'extract_cashtags_with_indices' do
|
||||
it 'returns []' do
|
||||
text = '$cashtag'
|
||||
extracted = Extractor.extract_cashtags_with_indices(text)
|
||||
extracted = described_class.extract_cashtags_with_indices(text)
|
||||
expect(extracted).to eq []
|
||||
end
|
||||
end
|
||||
|
@ -15,7 +15,7 @@ RSpec.describe FeedManager do
|
||||
end
|
||||
|
||||
describe '#key' do
|
||||
subject { FeedManager.instance.key(:home, 1) }
|
||||
subject { described_class.instance.key(:home, 1) }
|
||||
|
||||
it 'returns a string' do
|
||||
expect(subject).to be_a String
|
||||
@ -32,26 +32,26 @@ RSpec.describe FeedManager do
|
||||
it 'returns false for followee\'s status' do
|
||||
status = Fabricate(:status, text: 'Hello world', account: alice)
|
||||
bob.follow!(alice)
|
||||
expect(FeedManager.instance.filter?(:home, status, bob)).to be false
|
||||
expect(described_class.instance.filter?(:home, status, bob)).to be false
|
||||
end
|
||||
|
||||
it 'returns false for reblog by followee' do
|
||||
status = Fabricate(:status, text: 'Hello world', account: jeff)
|
||||
reblog = Fabricate(:status, reblog: status, account: alice)
|
||||
bob.follow!(alice)
|
||||
expect(FeedManager.instance.filter?(:home, reblog, bob)).to be false
|
||||
expect(described_class.instance.filter?(:home, reblog, bob)).to be false
|
||||
end
|
||||
|
||||
it 'returns true for post from account who blocked me' do
|
||||
status = Fabricate(:status, text: 'Hello, World', account: alice)
|
||||
alice.block!(bob)
|
||||
expect(FeedManager.instance.filter?(:home, status, bob)).to be true
|
||||
expect(described_class.instance.filter?(:home, status, bob)).to be true
|
||||
end
|
||||
|
||||
it 'returns true for post from blocked account' do
|
||||
status = Fabricate(:status, text: 'Hello, World', account: alice)
|
||||
bob.block!(alice)
|
||||
expect(FeedManager.instance.filter?(:home, status, bob)).to be true
|
||||
expect(described_class.instance.filter?(:home, status, bob)).to be true
|
||||
end
|
||||
|
||||
it 'returns true for reblog by followee of blocked account' do
|
||||
@ -59,7 +59,7 @@ RSpec.describe FeedManager do
|
||||
reblog = Fabricate(:status, reblog: status, account: alice)
|
||||
bob.follow!(alice)
|
||||
bob.block!(jeff)
|
||||
expect(FeedManager.instance.filter?(:home, reblog, bob)).to be true
|
||||
expect(described_class.instance.filter?(:home, reblog, bob)).to be true
|
||||
end
|
||||
|
||||
it 'returns true for reblog by followee of muted account' do
|
||||
@ -67,7 +67,7 @@ RSpec.describe FeedManager do
|
||||
reblog = Fabricate(:status, reblog: status, account: alice)
|
||||
bob.follow!(alice)
|
||||
bob.mute!(jeff)
|
||||
expect(FeedManager.instance.filter?(:home, reblog, bob)).to be true
|
||||
expect(described_class.instance.filter?(:home, reblog, bob)).to be true
|
||||
end
|
||||
|
||||
it 'returns true for reblog by followee of someone who is blocking recipient' do
|
||||
@ -75,14 +75,14 @@ RSpec.describe FeedManager do
|
||||
reblog = Fabricate(:status, reblog: status, account: alice)
|
||||
bob.follow!(alice)
|
||||
jeff.block!(bob)
|
||||
expect(FeedManager.instance.filter?(:home, reblog, bob)).to be true
|
||||
expect(described_class.instance.filter?(:home, reblog, bob)).to be true
|
||||
end
|
||||
|
||||
it 'returns true for reblog from account with reblogs disabled' do
|
||||
status = Fabricate(:status, text: 'Hello world', account: jeff)
|
||||
reblog = Fabricate(:status, reblog: status, account: alice)
|
||||
bob.follow!(alice, reblogs: false)
|
||||
expect(FeedManager.instance.filter?(:home, reblog, bob)).to be true
|
||||
expect(described_class.instance.filter?(:home, reblog, bob)).to be true
|
||||
end
|
||||
|
||||
it 'returns false for reply by followee to another followee' do
|
||||
@ -90,56 +90,56 @@ RSpec.describe FeedManager do
|
||||
reply = Fabricate(:status, text: 'Nay', thread: status, account: alice)
|
||||
bob.follow!(alice)
|
||||
bob.follow!(jeff)
|
||||
expect(FeedManager.instance.filter?(:home, reply, bob)).to be false
|
||||
expect(described_class.instance.filter?(:home, reply, bob)).to be false
|
||||
end
|
||||
|
||||
it 'returns false for reply by followee to recipient' do
|
||||
status = Fabricate(:status, text: 'Hello world', account: bob)
|
||||
reply = Fabricate(:status, text: 'Nay', thread: status, account: alice)
|
||||
bob.follow!(alice)
|
||||
expect(FeedManager.instance.filter?(:home, reply, bob)).to be false
|
||||
expect(described_class.instance.filter?(:home, reply, bob)).to be false
|
||||
end
|
||||
|
||||
it 'returns false for reply by followee to self' do
|
||||
status = Fabricate(:status, text: 'Hello world', account: alice)
|
||||
reply = Fabricate(:status, text: 'Nay', thread: status, account: alice)
|
||||
bob.follow!(alice)
|
||||
expect(FeedManager.instance.filter?(:home, reply, bob)).to be false
|
||||
expect(described_class.instance.filter?(:home, reply, bob)).to be false
|
||||
end
|
||||
|
||||
it 'returns true for reply by followee to non-followed account' do
|
||||
status = Fabricate(:status, text: 'Hello world', account: jeff)
|
||||
reply = Fabricate(:status, text: 'Nay', thread: status, account: alice)
|
||||
bob.follow!(alice)
|
||||
expect(FeedManager.instance.filter?(:home, reply, bob)).to be true
|
||||
expect(described_class.instance.filter?(:home, reply, bob)).to be true
|
||||
end
|
||||
|
||||
it 'returns true for the second reply by followee to a non-federated status' do
|
||||
reply = Fabricate(:status, text: 'Reply 1', reply: true, account: alice)
|
||||
second_reply = Fabricate(:status, text: 'Reply 2', thread: reply, account: alice)
|
||||
bob.follow!(alice)
|
||||
expect(FeedManager.instance.filter?(:home, second_reply, bob)).to be true
|
||||
expect(described_class.instance.filter?(:home, second_reply, bob)).to be true
|
||||
end
|
||||
|
||||
it 'returns false for status by followee mentioning another account' do
|
||||
bob.follow!(alice)
|
||||
jeff.follow!(alice)
|
||||
status = PostStatusService.new.call(alice, text: 'Hey @jeff')
|
||||
expect(FeedManager.instance.filter?(:home, status, bob)).to be false
|
||||
expect(described_class.instance.filter?(:home, status, bob)).to be false
|
||||
end
|
||||
|
||||
it 'returns true for status by followee mentioning blocked account' do
|
||||
bob.block!(jeff)
|
||||
bob.follow!(alice)
|
||||
status = PostStatusService.new.call(alice, text: 'Hey @jeff')
|
||||
expect(FeedManager.instance.filter?(:home, status, bob)).to be true
|
||||
expect(described_class.instance.filter?(:home, status, bob)).to be true
|
||||
end
|
||||
|
||||
it 'returns true for status by followee mentioning muted account' do
|
||||
bob.mute!(jeff)
|
||||
bob.follow!(alice)
|
||||
status = PostStatusService.new.call(alice, text: 'Hey @jeff')
|
||||
expect(FeedManager.instance.filter?(:home, status, bob)).to be true
|
||||
expect(described_class.instance.filter?(:home, status, bob)).to be true
|
||||
end
|
||||
|
||||
it 'returns true for reblog of a personally blocked domain' do
|
||||
@ -147,19 +147,19 @@ RSpec.describe FeedManager do
|
||||
alice.follow!(jeff)
|
||||
status = Fabricate(:status, text: 'Hello world', account: bob)
|
||||
reblog = Fabricate(:status, reblog: status, account: jeff)
|
||||
expect(FeedManager.instance.filter?(:home, reblog, alice)).to be true
|
||||
expect(described_class.instance.filter?(:home, reblog, alice)).to be true
|
||||
end
|
||||
|
||||
it 'returns true for German post when follow is set to English only' do
|
||||
alice.follow!(bob, languages: %w(en))
|
||||
status = Fabricate(:status, text: 'Hallo Welt', account: bob, language: 'de')
|
||||
expect(FeedManager.instance.filter?(:home, status, alice)).to be true
|
||||
expect(described_class.instance.filter?(:home, status, alice)).to be true
|
||||
end
|
||||
|
||||
it 'returns false for German post when follow is set to German' do
|
||||
alice.follow!(bob, languages: %w(de))
|
||||
status = Fabricate(:status, text: 'Hallo Welt', account: bob, language: 'de')
|
||||
expect(FeedManager.instance.filter?(:home, status, alice)).to be false
|
||||
expect(described_class.instance.filter?(:home, status, alice)).to be false
|
||||
end
|
||||
|
||||
it 'returns true for post from followee on exclusive list' do
|
||||
@ -168,7 +168,7 @@ RSpec.describe FeedManager do
|
||||
list.accounts << bob
|
||||
allow(List).to receive(:where).and_return(list)
|
||||
status = Fabricate(:status, text: 'I post a lot', account: bob)
|
||||
expect(FeedManager.instance.filter?(:home, status, alice)).to be true
|
||||
expect(described_class.instance.filter?(:home, status, alice)).to be true
|
||||
end
|
||||
|
||||
it 'returns true for reblog from followee on exclusive list' do
|
||||
@ -178,7 +178,7 @@ RSpec.describe FeedManager do
|
||||
allow(List).to receive(:where).and_return(list)
|
||||
status = Fabricate(:status, text: 'I post a lot', account: bob)
|
||||
reblog = Fabricate(:status, reblog: status, account: jeff)
|
||||
expect(FeedManager.instance.filter?(:home, reblog, alice)).to be true
|
||||
expect(described_class.instance.filter?(:home, reblog, alice)).to be true
|
||||
end
|
||||
|
||||
it 'returns false for post from followee on non-exclusive list' do
|
||||
@ -186,7 +186,7 @@ RSpec.describe FeedManager do
|
||||
alice.follow!(bob)
|
||||
list.accounts << bob
|
||||
status = Fabricate(:status, text: 'I post a lot', account: bob)
|
||||
expect(FeedManager.instance.filter?(:home, status, alice)).to be false
|
||||
expect(described_class.instance.filter?(:home, status, alice)).to be false
|
||||
end
|
||||
|
||||
it 'returns false for reblog from followee on non-exclusive list' do
|
||||
@ -195,7 +195,7 @@ RSpec.describe FeedManager do
|
||||
list.accounts << jeff
|
||||
status = Fabricate(:status, text: 'I post a lot', account: bob)
|
||||
reblog = Fabricate(:status, reblog: status, account: jeff)
|
||||
expect(FeedManager.instance.filter?(:home, reblog, alice)).to be false
|
||||
expect(described_class.instance.filter?(:home, reblog, alice)).to be false
|
||||
end
|
||||
end
|
||||
|
||||
@ -203,27 +203,27 @@ RSpec.describe FeedManager do
|
||||
it 'returns true for status that mentions blocked account' do
|
||||
bob.block!(jeff)
|
||||
status = PostStatusService.new.call(alice, text: 'Hey @jeff')
|
||||
expect(FeedManager.instance.filter?(:mentions, status, bob)).to be true
|
||||
expect(described_class.instance.filter?(:mentions, status, bob)).to be true
|
||||
end
|
||||
|
||||
it 'returns true for status that replies to a blocked account' do
|
||||
status = Fabricate(:status, text: 'Hello world', account: jeff)
|
||||
reply = Fabricate(:status, text: 'Nay', thread: status, account: alice)
|
||||
bob.block!(jeff)
|
||||
expect(FeedManager.instance.filter?(:mentions, reply, bob)).to be true
|
||||
expect(described_class.instance.filter?(:mentions, reply, bob)).to be true
|
||||
end
|
||||
|
||||
it 'returns true for status by silenced account who recipient is not following' do
|
||||
status = Fabricate(:status, text: 'Hello world', account: alice)
|
||||
alice.silence!
|
||||
expect(FeedManager.instance.filter?(:mentions, status, bob)).to be true
|
||||
expect(described_class.instance.filter?(:mentions, status, bob)).to be true
|
||||
end
|
||||
|
||||
it 'returns false for status by followed silenced account' do
|
||||
status = Fabricate(:status, text: 'Hello world', account: alice)
|
||||
alice.silence!
|
||||
bob.follow!(alice)
|
||||
expect(FeedManager.instance.filter?(:mentions, status, bob)).to be false
|
||||
expect(described_class.instance.filter?(:mentions, status, bob)).to be false
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -235,7 +235,7 @@ RSpec.describe FeedManager do
|
||||
members = Array.new(FeedManager::MAX_ITEMS) { |count| [count, count] }
|
||||
redis.zadd("feed:home:#{account.id}", members)
|
||||
|
||||
FeedManager.instance.push_to_home(account, status)
|
||||
described_class.instance.push_to_home(account, status)
|
||||
|
||||
expect(redis.zcard("feed:home:#{account.id}")).to eq FeedManager::MAX_ITEMS
|
||||
end
|
||||
@ -246,7 +246,7 @@ RSpec.describe FeedManager do
|
||||
reblogged = Fabricate(:status)
|
||||
reblog = Fabricate(:status, reblog: reblogged)
|
||||
|
||||
expect(FeedManager.instance.push_to_home(account, reblog)).to be true
|
||||
expect(described_class.instance.push_to_home(account, reblog)).to be true
|
||||
end
|
||||
|
||||
it 'does not save a new reblog of a recent status' do
|
||||
@ -254,9 +254,9 @@ RSpec.describe FeedManager do
|
||||
reblogged = Fabricate(:status)
|
||||
reblog = Fabricate(:status, reblog: reblogged)
|
||||
|
||||
FeedManager.instance.push_to_home(account, reblogged)
|
||||
described_class.instance.push_to_home(account, reblogged)
|
||||
|
||||
expect(FeedManager.instance.push_to_home(account, reblog)).to be false
|
||||
expect(described_class.instance.push_to_home(account, reblog)).to be false
|
||||
end
|
||||
|
||||
it 'saves a new reblog of an old status' do
|
||||
@ -264,14 +264,14 @@ RSpec.describe FeedManager do
|
||||
reblogged = Fabricate(:status)
|
||||
reblog = Fabricate(:status, reblog: reblogged)
|
||||
|
||||
FeedManager.instance.push_to_home(account, reblogged)
|
||||
described_class.instance.push_to_home(account, reblogged)
|
||||
|
||||
# Fill the feed with intervening statuses
|
||||
FeedManager::REBLOG_FALLOFF.times do
|
||||
FeedManager.instance.push_to_home(account, Fabricate(:status))
|
||||
described_class.instance.push_to_home(account, Fabricate(:status))
|
||||
end
|
||||
|
||||
expect(FeedManager.instance.push_to_home(account, reblog)).to be true
|
||||
expect(described_class.instance.push_to_home(account, reblog)).to be true
|
||||
end
|
||||
|
||||
it 'does not save a new reblog of a recently-reblogged status' do
|
||||
@ -280,10 +280,10 @@ RSpec.describe FeedManager do
|
||||
reblogs = Array.new(2) { Fabricate(:status, reblog: reblogged) }
|
||||
|
||||
# The first reblog will be accepted
|
||||
FeedManager.instance.push_to_home(account, reblogs.first)
|
||||
described_class.instance.push_to_home(account, reblogs.first)
|
||||
|
||||
# The second reblog should be ignored
|
||||
expect(FeedManager.instance.push_to_home(account, reblogs.last)).to be false
|
||||
expect(described_class.instance.push_to_home(account, reblogs.last)).to be false
|
||||
end
|
||||
|
||||
it 'saves a new reblog of a recently-reblogged status when previous reblog has been deleted' do
|
||||
@ -292,15 +292,15 @@ RSpec.describe FeedManager do
|
||||
old_reblog = Fabricate(:status, reblog: reblogged)
|
||||
|
||||
# The first reblog should be accepted
|
||||
expect(FeedManager.instance.push_to_home(account, old_reblog)).to be true
|
||||
expect(described_class.instance.push_to_home(account, old_reblog)).to be true
|
||||
|
||||
# The first reblog should be successfully removed
|
||||
expect(FeedManager.instance.unpush_from_home(account, old_reblog)).to be true
|
||||
expect(described_class.instance.unpush_from_home(account, old_reblog)).to be true
|
||||
|
||||
reblog = Fabricate(:status, reblog: reblogged)
|
||||
|
||||
# The second reblog should be accepted
|
||||
expect(FeedManager.instance.push_to_home(account, reblog)).to be true
|
||||
expect(described_class.instance.push_to_home(account, reblog)).to be true
|
||||
end
|
||||
|
||||
it 'does not save a new reblog of a multiply-reblogged-then-unreblogged status' do
|
||||
@ -309,14 +309,14 @@ RSpec.describe FeedManager do
|
||||
reblogs = Array.new(3) { Fabricate(:status, reblog: reblogged) }
|
||||
|
||||
# Accept the reblogs
|
||||
FeedManager.instance.push_to_home(account, reblogs[0])
|
||||
FeedManager.instance.push_to_home(account, reblogs[1])
|
||||
described_class.instance.push_to_home(account, reblogs[0])
|
||||
described_class.instance.push_to_home(account, reblogs[1])
|
||||
|
||||
# Unreblog the first one
|
||||
FeedManager.instance.unpush_from_home(account, reblogs[0])
|
||||
described_class.instance.unpush_from_home(account, reblogs[0])
|
||||
|
||||
# The last reblog should still be ignored
|
||||
expect(FeedManager.instance.push_to_home(account, reblogs.last)).to be false
|
||||
expect(described_class.instance.push_to_home(account, reblogs.last)).to be false
|
||||
end
|
||||
|
||||
it 'saves a new reblog of a long-ago-reblogged status' do
|
||||
@ -325,15 +325,15 @@ RSpec.describe FeedManager do
|
||||
reblogs = Array.new(2) { Fabricate(:status, reblog: reblogged) }
|
||||
|
||||
# The first reblog will be accepted
|
||||
FeedManager.instance.push_to_home(account, reblogs.first)
|
||||
described_class.instance.push_to_home(account, reblogs.first)
|
||||
|
||||
# Fill the feed with intervening statuses
|
||||
FeedManager::REBLOG_FALLOFF.times do
|
||||
FeedManager.instance.push_to_home(account, Fabricate(:status))
|
||||
described_class.instance.push_to_home(account, Fabricate(:status))
|
||||
end
|
||||
|
||||
# The second reblog should also be accepted
|
||||
expect(FeedManager.instance.push_to_home(account, reblogs.last)).to be true
|
||||
expect(described_class.instance.push_to_home(account, reblogs.last)).to be true
|
||||
end
|
||||
end
|
||||
|
||||
@ -341,9 +341,9 @@ RSpec.describe FeedManager do
|
||||
account = Fabricate(:account)
|
||||
reblog = Fabricate(:status)
|
||||
status = Fabricate(:status, reblog: reblog)
|
||||
FeedManager.instance.push_to_home(account, status)
|
||||
described_class.instance.push_to_home(account, status)
|
||||
|
||||
expect(FeedManager.instance.push_to_home(account, reblog)).to be false
|
||||
expect(described_class.instance.push_to_home(account, reblog)).to be false
|
||||
end
|
||||
end
|
||||
|
||||
@ -366,9 +366,9 @@ RSpec.describe FeedManager do
|
||||
it "does not push when the given status's reblog is already inserted" do
|
||||
reblog = Fabricate(:status)
|
||||
status = Fabricate(:status, reblog: reblog)
|
||||
FeedManager.instance.push_to_list(list, status)
|
||||
described_class.instance.push_to_list(list, status)
|
||||
|
||||
expect(FeedManager.instance.push_to_list(list, reblog)).to be false
|
||||
expect(described_class.instance.push_to_list(list, reblog)).to be false
|
||||
end
|
||||
|
||||
context 'when replies policy is set to no replies' do
|
||||
@ -378,19 +378,19 @@ RSpec.describe FeedManager do
|
||||
|
||||
it 'pushes statuses that are not replies' do
|
||||
status = Fabricate(:status, text: 'Hello world', account: bob)
|
||||
expect(FeedManager.instance.push_to_list(list, status)).to be true
|
||||
expect(described_class.instance.push_to_list(list, status)).to be true
|
||||
end
|
||||
|
||||
it 'pushes statuses that are replies to list owner' do
|
||||
status = Fabricate(:status, text: 'Hello world', account: owner)
|
||||
reply = Fabricate(:status, text: 'Nay', thread: status, account: bob)
|
||||
expect(FeedManager.instance.push_to_list(list, reply)).to be true
|
||||
expect(described_class.instance.push_to_list(list, reply)).to be true
|
||||
end
|
||||
|
||||
it 'does not push replies to another member of the list' do
|
||||
status = Fabricate(:status, text: 'Hello world', account: alice)
|
||||
reply = Fabricate(:status, text: 'Nay', thread: status, account: bob)
|
||||
expect(FeedManager.instance.push_to_list(list, reply)).to be false
|
||||
expect(described_class.instance.push_to_list(list, reply)).to be false
|
||||
end
|
||||
end
|
||||
|
||||
@ -401,25 +401,25 @@ RSpec.describe FeedManager do
|
||||
|
||||
it 'pushes statuses that are not replies' do
|
||||
status = Fabricate(:status, text: 'Hello world', account: bob)
|
||||
expect(FeedManager.instance.push_to_list(list, status)).to be true
|
||||
expect(described_class.instance.push_to_list(list, status)).to be true
|
||||
end
|
||||
|
||||
it 'pushes statuses that are replies to list owner' do
|
||||
status = Fabricate(:status, text: 'Hello world', account: owner)
|
||||
reply = Fabricate(:status, text: 'Nay', thread: status, account: bob)
|
||||
expect(FeedManager.instance.push_to_list(list, reply)).to be true
|
||||
expect(described_class.instance.push_to_list(list, reply)).to be true
|
||||
end
|
||||
|
||||
it 'pushes replies to another member of the list' do
|
||||
status = Fabricate(:status, text: 'Hello world', account: alice)
|
||||
reply = Fabricate(:status, text: 'Nay', thread: status, account: bob)
|
||||
expect(FeedManager.instance.push_to_list(list, reply)).to be true
|
||||
expect(described_class.instance.push_to_list(list, reply)).to be true
|
||||
end
|
||||
|
||||
it 'does not push replies to someone not a member of the list' do
|
||||
status = Fabricate(:status, text: 'Hello world', account: eve)
|
||||
reply = Fabricate(:status, text: 'Nay', thread: status, account: bob)
|
||||
expect(FeedManager.instance.push_to_list(list, reply)).to be false
|
||||
expect(described_class.instance.push_to_list(list, reply)).to be false
|
||||
end
|
||||
end
|
||||
|
||||
@ -430,25 +430,25 @@ RSpec.describe FeedManager do
|
||||
|
||||
it 'pushes statuses that are not replies' do
|
||||
status = Fabricate(:status, text: 'Hello world', account: bob)
|
||||
expect(FeedManager.instance.push_to_list(list, status)).to be true
|
||||
expect(described_class.instance.push_to_list(list, status)).to be true
|
||||
end
|
||||
|
||||
it 'pushes statuses that are replies to list owner' do
|
||||
status = Fabricate(:status, text: 'Hello world', account: owner)
|
||||
reply = Fabricate(:status, text: 'Nay', thread: status, account: bob)
|
||||
expect(FeedManager.instance.push_to_list(list, reply)).to be true
|
||||
expect(described_class.instance.push_to_list(list, reply)).to be true
|
||||
end
|
||||
|
||||
it 'pushes replies to another member of the list' do
|
||||
status = Fabricate(:status, text: 'Hello world', account: alice)
|
||||
reply = Fabricate(:status, text: 'Nay', thread: status, account: bob)
|
||||
expect(FeedManager.instance.push_to_list(list, reply)).to be true
|
||||
expect(described_class.instance.push_to_list(list, reply)).to be true
|
||||
end
|
||||
|
||||
it 'pushes replies to someone not a member of the list' do
|
||||
status = Fabricate(:status, text: 'Hello world', account: eve)
|
||||
reply = Fabricate(:status, text: 'Nay', thread: status, account: bob)
|
||||
expect(FeedManager.instance.push_to_list(list, reply)).to be true
|
||||
expect(described_class.instance.push_to_list(list, reply)).to be true
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -458,9 +458,9 @@ RSpec.describe FeedManager do
|
||||
account = Fabricate(:account, id: 0)
|
||||
reblog = Fabricate(:status)
|
||||
status = Fabricate(:status, reblog: reblog)
|
||||
FeedManager.instance.push_to_home(account, status)
|
||||
described_class.instance.push_to_home(account, status)
|
||||
|
||||
FeedManager.instance.merge_into_home(account, reblog.account)
|
||||
described_class.instance.merge_into_home(account, reblog.account)
|
||||
|
||||
expect(redis.zscore('feed:home:0', reblog.id)).to be_nil
|
||||
end
|
||||
@ -473,14 +473,14 @@ RSpec.describe FeedManager do
|
||||
reblogged = Fabricate(:status)
|
||||
status = Fabricate(:status, reblog: reblogged)
|
||||
|
||||
FeedManager.instance.push_to_home(receiver, reblogged)
|
||||
FeedManager::REBLOG_FALLOFF.times { FeedManager.instance.push_to_home(receiver, Fabricate(:status)) }
|
||||
FeedManager.instance.push_to_home(receiver, status)
|
||||
described_class.instance.push_to_home(receiver, reblogged)
|
||||
FeedManager::REBLOG_FALLOFF.times { described_class.instance.push_to_home(receiver, Fabricate(:status)) }
|
||||
described_class.instance.push_to_home(receiver, status)
|
||||
|
||||
# The reblogging status should show up under normal conditions.
|
||||
expect(redis.zrange("feed:home:#{receiver.id}", 0, -1)).to include(status.id.to_s)
|
||||
|
||||
FeedManager.instance.unpush_from_home(receiver, status)
|
||||
described_class.instance.unpush_from_home(receiver, status)
|
||||
|
||||
# Restore original status
|
||||
expect(redis.zrange("feed:home:#{receiver.id}", 0, -1)).to_not include(status.id.to_s)
|
||||
@ -491,12 +491,12 @@ RSpec.describe FeedManager do
|
||||
reblogged = Fabricate(:status)
|
||||
status = Fabricate(:status, reblog: reblogged)
|
||||
|
||||
FeedManager.instance.push_to_home(receiver, status)
|
||||
described_class.instance.push_to_home(receiver, status)
|
||||
|
||||
# The reblogging status should show up under normal conditions.
|
||||
expect(redis.zrange("feed:home:#{receiver.id}", 0, -1)).to eq [status.id.to_s]
|
||||
|
||||
FeedManager.instance.unpush_from_home(receiver, status)
|
||||
described_class.instance.unpush_from_home(receiver, status)
|
||||
|
||||
expect(redis.zrange("feed:home:#{receiver.id}", 0, -1)).to be_empty
|
||||
end
|
||||
@ -506,14 +506,14 @@ RSpec.describe FeedManager do
|
||||
reblogs = Array.new(3) { Fabricate(:status, reblog: reblogged) }
|
||||
|
||||
reblogs.each do |reblog|
|
||||
FeedManager.instance.push_to_home(receiver, reblog)
|
||||
described_class.instance.push_to_home(receiver, reblog)
|
||||
end
|
||||
|
||||
# The reblogging status should show up under normal conditions.
|
||||
expect(redis.zrange("feed:home:#{receiver.id}", 0, -1)).to eq [reblogs.first.id.to_s]
|
||||
|
||||
reblogs[0...-1].each do |reblog|
|
||||
FeedManager.instance.unpush_from_home(receiver, reblog)
|
||||
described_class.instance.unpush_from_home(receiver, reblog)
|
||||
end
|
||||
|
||||
expect(redis.zrange("feed:home:#{receiver.id}", 0, -1)).to eq [reblogs.last.id.to_s]
|
||||
@ -522,10 +522,10 @@ RSpec.describe FeedManager do
|
||||
it 'sends push updates' do
|
||||
status = Fabricate(:status)
|
||||
|
||||
FeedManager.instance.push_to_home(receiver, status)
|
||||
described_class.instance.push_to_home(receiver, status)
|
||||
|
||||
allow(redis).to receive_messages(publish: nil)
|
||||
FeedManager.instance.unpush_from_home(receiver, status)
|
||||
described_class.instance.unpush_from_home(receiver, status)
|
||||
|
||||
deletion = Oj.dump(event: :delete, payload: status.id.to_s)
|
||||
expect(redis).to have_received(:publish).with("timeline:#{receiver.id}", deletion)
|
||||
@ -551,7 +551,7 @@ RSpec.describe FeedManager do
|
||||
end
|
||||
|
||||
it 'correctly cleans the home timeline' do
|
||||
FeedManager.instance.clear_from_home(account, target_account)
|
||||
described_class.instance.clear_from_home(account, target_account)
|
||||
|
||||
expect(redis.zrange("feed:home:#{account.id}", 0, -1)).to eq [status_1.id.to_s, status_7.id.to_s]
|
||||
end
|
||||
|
@ -1248,4 +1248,117 @@ describe Mastodon::CLI::Accounts do
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#reset_relationships' do
|
||||
let(:target_account) { Fabricate(:account) }
|
||||
let(:arguments) { [target_account.username] }
|
||||
|
||||
context 'when no option is given' do
|
||||
it 'exits with an error message indicating that at least one option is required' do
|
||||
expect { cli.invoke(:reset_relationships, arguments) }.to output(
|
||||
a_string_including('Please specify either --follows or --followers, or both')
|
||||
).to_stdout
|
||||
.and raise_error(SystemExit)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when the given username is not found' do
|
||||
let(:arguments) { ['non_existent_username'] }
|
||||
|
||||
it 'exits with an error message indicating that there is no such account' do
|
||||
expect { cli.invoke(:reset_relationships, arguments, follows: true) }.to output(
|
||||
a_string_including('No such account')
|
||||
).to_stdout
|
||||
.and raise_error(SystemExit)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when the given username is found' do
|
||||
let(:total_relationships) { 10 }
|
||||
let!(:accounts) { Fabricate.times(total_relationships, :account) }
|
||||
|
||||
context 'with --follows option' do
|
||||
let(:options) { { follows: true } }
|
||||
|
||||
before do
|
||||
accounts.each { |account| target_account.follow!(account) }
|
||||
end
|
||||
|
||||
it 'resets all "following" relationships from the target account' do
|
||||
cli.invoke(:reset_relationships, arguments, options)
|
||||
|
||||
expect(target_account.reload.following).to be_empty
|
||||
end
|
||||
|
||||
it 'calls BootstrapTimelineWorker once to rebuild the timeline' do
|
||||
allow(BootstrapTimelineWorker).to receive(:perform_async)
|
||||
|
||||
cli.invoke(:reset_relationships, arguments, options)
|
||||
|
||||
expect(BootstrapTimelineWorker).to have_received(:perform_async).with(target_account.id).once
|
||||
end
|
||||
|
||||
it 'displays a successful message' do
|
||||
expect { cli.invoke(:reset_relationships, arguments, options) }.to output(
|
||||
a_string_including("Processed #{total_relationships} relationships")
|
||||
).to_stdout
|
||||
end
|
||||
end
|
||||
|
||||
context 'with --followers option' do
|
||||
let(:options) { { followers: true } }
|
||||
|
||||
before do
|
||||
accounts.each { |account| account.follow!(target_account) }
|
||||
end
|
||||
|
||||
it 'resets all "followers" relationships from the target account' do
|
||||
cli.invoke(:reset_relationships, arguments, options)
|
||||
|
||||
expect(target_account.reload.followers).to be_empty
|
||||
end
|
||||
|
||||
it 'displays a successful message' do
|
||||
expect { cli.invoke(:reset_relationships, arguments, options) }.to output(
|
||||
a_string_including("Processed #{total_relationships} relationships")
|
||||
).to_stdout
|
||||
end
|
||||
end
|
||||
|
||||
context 'with --follows and --followers options' do
|
||||
let(:options) { { followers: true, follows: true } }
|
||||
|
||||
before do
|
||||
accounts.first(6).each { |account| account.follow!(target_account) }
|
||||
accounts.last(4).each { |account| target_account.follow!(account) }
|
||||
end
|
||||
|
||||
it 'resets all "followers" relationships from the target account' do
|
||||
cli.invoke(:reset_relationships, arguments, options)
|
||||
|
||||
expect(target_account.reload.followers).to be_empty
|
||||
end
|
||||
|
||||
it 'resets all "following" relationships from the target account' do
|
||||
cli.invoke(:reset_relationships, arguments, options)
|
||||
|
||||
expect(target_account.reload.following).to be_empty
|
||||
end
|
||||
|
||||
it 'calls BootstrapTimelineWorker once to rebuild the timeline' do
|
||||
allow(BootstrapTimelineWorker).to receive(:perform_async)
|
||||
|
||||
cli.invoke(:reset_relationships, arguments, options)
|
||||
|
||||
expect(BootstrapTimelineWorker).to have_received(:perform_async).with(target_account.id).once
|
||||
end
|
||||
|
||||
it 'displays a successful message' do
|
||||
expect { cli.invoke(:reset_relationships, arguments, options) }.to output(
|
||||
a_string_including("Processed #{total_relationships} relationships")
|
||||
).to_stdout
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -5,40 +5,40 @@ require 'rails_helper'
|
||||
describe OStatus::TagManager do
|
||||
describe '#unique_tag' do
|
||||
it 'returns a unique tag' do
|
||||
expect(OStatus::TagManager.instance.unique_tag(Time.utc(2000), 12, 'Status')).to eq 'tag:cb6e6126.ngrok.io,2000-01-01:objectId=12:objectType=Status'
|
||||
expect(described_class.instance.unique_tag(Time.utc(2000), 12, 'Status')).to eq 'tag:cb6e6126.ngrok.io,2000-01-01:objectId=12:objectType=Status'
|
||||
end
|
||||
end
|
||||
|
||||
describe '#unique_tag_to_local_id' do
|
||||
it 'returns the ID part' do
|
||||
expect(OStatus::TagManager.instance.unique_tag_to_local_id('tag:cb6e6126.ngrok.io,2000-01-01:objectId=12:objectType=Status', 'Status')).to eql '12'
|
||||
expect(described_class.instance.unique_tag_to_local_id('tag:cb6e6126.ngrok.io,2000-01-01:objectId=12:objectType=Status', 'Status')).to eql '12'
|
||||
end
|
||||
|
||||
it 'returns nil if it is not local id' do
|
||||
expect(OStatus::TagManager.instance.unique_tag_to_local_id('tag:remote,2000-01-01:objectId=12:objectType=Status', 'Status')).to be_nil
|
||||
expect(described_class.instance.unique_tag_to_local_id('tag:remote,2000-01-01:objectId=12:objectType=Status', 'Status')).to be_nil
|
||||
end
|
||||
|
||||
it 'returns nil if it is not expected type' do
|
||||
expect(OStatus::TagManager.instance.unique_tag_to_local_id('tag:cb6e6126.ngrok.io,2000-01-01:objectId=12:objectType=Block', 'Status')).to be_nil
|
||||
expect(described_class.instance.unique_tag_to_local_id('tag:cb6e6126.ngrok.io,2000-01-01:objectId=12:objectType=Block', 'Status')).to be_nil
|
||||
end
|
||||
|
||||
it 'returns nil if it does not have object ID' do
|
||||
expect(OStatus::TagManager.instance.unique_tag_to_local_id('tag:cb6e6126.ngrok.io,2000-01-01:objectType=Status', 'Status')).to be_nil
|
||||
expect(described_class.instance.unique_tag_to_local_id('tag:cb6e6126.ngrok.io,2000-01-01:objectType=Status', 'Status')).to be_nil
|
||||
end
|
||||
end
|
||||
|
||||
describe '#local_id?' do
|
||||
it 'returns true for a local ID' do
|
||||
expect(OStatus::TagManager.instance.local_id?('tag:cb6e6126.ngrok.io;objectId=12:objectType=Status')).to be true
|
||||
expect(described_class.instance.local_id?('tag:cb6e6126.ngrok.io;objectId=12:objectType=Status')).to be true
|
||||
end
|
||||
|
||||
it 'returns false for a foreign ID' do
|
||||
expect(OStatus::TagManager.instance.local_id?('tag:foreign.tld;objectId=12:objectType=Status')).to be false
|
||||
expect(described_class.instance.local_id?('tag:foreign.tld;objectId=12:objectType=Status')).to be false
|
||||
end
|
||||
end
|
||||
|
||||
describe '#uri_for' do
|
||||
subject { OStatus::TagManager.instance.uri_for(target) }
|
||||
subject { described_class.instance.uri_for(target) }
|
||||
|
||||
context 'with comment object' do
|
||||
let(:target) { Fabricate(:status, created_at: '2000-01-01T00:00:00Z', reply: true) }
|
||||
|
@ -4,7 +4,7 @@ require 'rails_helper'
|
||||
require 'securerandom'
|
||||
|
||||
describe Request do
|
||||
subject { Request.new(:get, 'http://example.com') }
|
||||
subject { described_class.new(:get, 'http://example.com') }
|
||||
|
||||
describe '#headers' do
|
||||
it 'returns user agent' do
|
||||
|
@ -71,10 +71,8 @@ describe StatusReachFinder do
|
||||
bob.statuses.create!(thread: status, text: 'Hoge')
|
||||
end
|
||||
|
||||
context do
|
||||
it 'includes the inbox of the replier' do
|
||||
expect(subject.inboxes).to include 'https://foo.bar/inbox'
|
||||
end
|
||||
it 'includes the inbox of the replier' do
|
||||
expect(subject.inboxes).to include 'https://foo.bar/inbox'
|
||||
end
|
||||
|
||||
context 'when status is not public' do
|
||||
@ -90,10 +88,8 @@ describe StatusReachFinder do
|
||||
let(:bob) { Fabricate(:account, username: 'bob', domain: 'foo.bar', protocol: :activitypub, inbox_url: 'https://foo.bar/inbox') }
|
||||
let(:parent_status) { Fabricate(:status, account: bob) }
|
||||
|
||||
context do
|
||||
it 'includes the inbox of the replied-to account' do
|
||||
expect(subject.inboxes).to include 'https://foo.bar/inbox'
|
||||
end
|
||||
it 'includes the inbox of the replied-to account' do
|
||||
expect(subject.inboxes).to include 'https://foo.bar/inbox'
|
||||
end
|
||||
|
||||
context 'when status is not public and replied-to account is not mentioned' do
|
||||
|
@ -16,15 +16,15 @@ RSpec.describe TagManager do
|
||||
end
|
||||
|
||||
it 'returns true for nil' do
|
||||
expect(TagManager.instance.local_domain?(nil)).to be true
|
||||
expect(described_class.instance.local_domain?(nil)).to be true
|
||||
end
|
||||
|
||||
it 'returns true if the slash-stripped string equals to local domain' do
|
||||
expect(TagManager.instance.local_domain?('DoMaIn.Example.com/')).to be true
|
||||
expect(described_class.instance.local_domain?('DoMaIn.Example.com/')).to be true
|
||||
end
|
||||
|
||||
it 'returns false for irrelevant string' do
|
||||
expect(TagManager.instance.local_domain?('DoMaIn.Example.com!')).to be false
|
||||
expect(described_class.instance.local_domain?('DoMaIn.Example.com!')).to be false
|
||||
end
|
||||
end
|
||||
|
||||
@ -41,25 +41,25 @@ RSpec.describe TagManager do
|
||||
end
|
||||
|
||||
it 'returns true for nil' do
|
||||
expect(TagManager.instance.web_domain?(nil)).to be true
|
||||
expect(described_class.instance.web_domain?(nil)).to be true
|
||||
end
|
||||
|
||||
it 'returns true if the slash-stripped string equals to web domain' do
|
||||
expect(TagManager.instance.web_domain?('DoMaIn.Example.com/')).to be true
|
||||
expect(described_class.instance.web_domain?('DoMaIn.Example.com/')).to be true
|
||||
end
|
||||
|
||||
it 'returns false for string with irrelevant characters' do
|
||||
expect(TagManager.instance.web_domain?('DoMaIn.Example.com!')).to be false
|
||||
expect(described_class.instance.web_domain?('DoMaIn.Example.com!')).to be false
|
||||
end
|
||||
end
|
||||
|
||||
describe '#normalize_domain' do
|
||||
it 'returns nil if the given parameter is nil' do
|
||||
expect(TagManager.instance.normalize_domain(nil)).to be_nil
|
||||
expect(described_class.instance.normalize_domain(nil)).to be_nil
|
||||
end
|
||||
|
||||
it 'returns normalized domain' do
|
||||
expect(TagManager.instance.normalize_domain('DoMaIn.Example.com/')).to eq 'domain.example.com'
|
||||
expect(described_class.instance.normalize_domain('DoMaIn.Example.com/')).to eq 'domain.example.com'
|
||||
end
|
||||
end
|
||||
|
||||
@ -72,17 +72,17 @@ RSpec.describe TagManager do
|
||||
|
||||
it 'returns true if the normalized string with port is local URL' do
|
||||
Rails.configuration.x.web_domain = 'domain.example.com:42'
|
||||
expect(TagManager.instance.local_url?('https://DoMaIn.Example.com:42/')).to be true
|
||||
expect(described_class.instance.local_url?('https://DoMaIn.Example.com:42/')).to be true
|
||||
end
|
||||
|
||||
it 'returns true if the normalized string without port is local URL' do
|
||||
Rails.configuration.x.web_domain = 'domain.example.com'
|
||||
expect(TagManager.instance.local_url?('https://DoMaIn.Example.com/')).to be true
|
||||
expect(described_class.instance.local_url?('https://DoMaIn.Example.com/')).to be true
|
||||
end
|
||||
|
||||
it 'returns false for string with irrelevant characters' do
|
||||
Rails.configuration.x.web_domain = 'domain.example.com'
|
||||
expect(TagManager.instance.local_url?('https://domain.example.net/')).to be false
|
||||
expect(described_class.instance.local_url?('https://domain.example.net/')).to be false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -17,7 +17,7 @@ describe WebfingerResource do
|
||||
resource = 'https://example.com/users/alice/other'
|
||||
|
||||
expect do
|
||||
WebfingerResource.new(resource).username
|
||||
described_class.new(resource).username
|
||||
end.to raise_error(ActiveRecord::RecordNotFound)
|
||||
end
|
||||
|
||||
@ -32,7 +32,7 @@ describe WebfingerResource do
|
||||
expect(Rails.application.routes).to receive(:recognize_path).with(resource).and_return(recognized).at_least(:once)
|
||||
|
||||
expect do
|
||||
WebfingerResource.new(resource).username
|
||||
described_class.new(resource).username
|
||||
end.to raise_error(ActiveRecord::RecordNotFound)
|
||||
end
|
||||
|
||||
@ -40,28 +40,28 @@ describe WebfingerResource do
|
||||
resource = 'website for http://example.com/users/alice/other'
|
||||
|
||||
expect do
|
||||
WebfingerResource.new(resource).username
|
||||
described_class.new(resource).username
|
||||
end.to raise_error(WebfingerResource::InvalidRequest)
|
||||
end
|
||||
|
||||
it 'finds the username in a valid https route' do
|
||||
resource = 'https://example.com/users/alice'
|
||||
|
||||
result = WebfingerResource.new(resource).username
|
||||
result = described_class.new(resource).username
|
||||
expect(result).to eq 'alice'
|
||||
end
|
||||
|
||||
it 'finds the username in a mixed case http route' do
|
||||
resource = 'HTTp://exAMPLe.com/users/alice'
|
||||
|
||||
result = WebfingerResource.new(resource).username
|
||||
result = described_class.new(resource).username
|
||||
expect(result).to eq 'alice'
|
||||
end
|
||||
|
||||
it 'finds the username in a valid http route' do
|
||||
resource = 'http://example.com/users/alice'
|
||||
|
||||
result = WebfingerResource.new(resource).username
|
||||
result = described_class.new(resource).username
|
||||
expect(result).to eq 'alice'
|
||||
end
|
||||
end
|
||||
@ -71,7 +71,7 @@ describe WebfingerResource do
|
||||
resource = 'user@remote-host.com'
|
||||
|
||||
expect do
|
||||
WebfingerResource.new(resource).username
|
||||
described_class.new(resource).username
|
||||
end.to raise_error(ActiveRecord::RecordNotFound)
|
||||
end
|
||||
|
||||
@ -79,7 +79,7 @@ describe WebfingerResource do
|
||||
Rails.configuration.x.local_domain = 'example.com'
|
||||
resource = 'alice@example.com'
|
||||
|
||||
result = WebfingerResource.new(resource).username
|
||||
result = described_class.new(resource).username
|
||||
expect(result).to eq 'alice'
|
||||
end
|
||||
|
||||
@ -87,7 +87,7 @@ describe WebfingerResource do
|
||||
Rails.configuration.x.web_domain = 'example.com'
|
||||
resource = 'alice@example.com'
|
||||
|
||||
result = WebfingerResource.new(resource).username
|
||||
result = described_class.new(resource).username
|
||||
expect(result).to eq 'alice'
|
||||
end
|
||||
end
|
||||
@ -97,7 +97,7 @@ describe WebfingerResource do
|
||||
resource = 'acct:user@remote-host.com'
|
||||
|
||||
expect do
|
||||
WebfingerResource.new(resource).username
|
||||
described_class.new(resource).username
|
||||
end.to raise_error(ActiveRecord::RecordNotFound)
|
||||
end
|
||||
|
||||
@ -105,7 +105,7 @@ describe WebfingerResource do
|
||||
resource = 'acct:user@remote-host@remote-hostess.remote.local@remote'
|
||||
|
||||
expect do
|
||||
WebfingerResource.new(resource).username
|
||||
described_class.new(resource).username
|
||||
end.to raise_error(ActiveRecord::RecordNotFound)
|
||||
end
|
||||
|
||||
@ -113,7 +113,7 @@ describe WebfingerResource do
|
||||
Rails.configuration.x.local_domain = 'example.com'
|
||||
resource = 'acct:alice@example.com'
|
||||
|
||||
result = WebfingerResource.new(resource).username
|
||||
result = described_class.new(resource).username
|
||||
expect(result).to eq 'alice'
|
||||
end
|
||||
|
||||
@ -121,7 +121,7 @@ describe WebfingerResource do
|
||||
Rails.configuration.x.web_domain = 'example.com'
|
||||
resource = 'acct:alice@example.com'
|
||||
|
||||
result = WebfingerResource.new(resource).username
|
||||
result = described_class.new(resource).username
|
||||
expect(result).to eq 'alice'
|
||||
end
|
||||
end
|
||||
@ -131,7 +131,7 @@ describe WebfingerResource do
|
||||
resource = 'df/:dfkj'
|
||||
|
||||
expect do
|
||||
WebfingerResource.new(resource).username
|
||||
described_class.new(resource).username
|
||||
end.to raise_error(WebfingerResource::InvalidRequest)
|
||||
end
|
||||
end
|
||||
|
30
spec/lib/webhooks/payload_renderer_spec.rb
Normal file
30
spec/lib/webhooks/payload_renderer_spec.rb
Normal file
@ -0,0 +1,30 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
describe Webhooks::PayloadRenderer do
|
||||
subject(:renderer) { described_class.new(json) }
|
||||
|
||||
let(:event) { Webhooks::EventPresenter.new(type, object) }
|
||||
let(:payload) { ActiveModelSerializers::SerializableResource.new(event, serializer: REST::Admin::WebhookEventSerializer, scope: nil, scope_name: :current_user).as_json }
|
||||
let(:json) { Oj.dump(payload) }
|
||||
|
||||
describe '#render' do
|
||||
context 'when event is account.approved' do
|
||||
let(:type) { 'account.approved' }
|
||||
let(:object) { Fabricate(:account, display_name: 'Foo"') }
|
||||
|
||||
it 'renders event-related variables into template' do
|
||||
expect(renderer.render('foo={{event}}')).to eq 'foo=account.approved'
|
||||
end
|
||||
|
||||
it 'renders event-specific variables into template' do
|
||||
expect(renderer.render('foo={{object.username}}')).to eq "foo=#{object.username}"
|
||||
end
|
||||
|
||||
it 'escapes values for use in JSON' do
|
||||
expect(renderer.render('foo={{object.account.display_name}}')).to eq 'foo=Foo\\"'
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Reference in New Issue
Block a user