Merge remote-tracking branch 'parent/main' into upstream-20241026
This commit is contained in:
commit
0c99b8fbb0
79 changed files with 2403 additions and 2056 deletions
7
spec/fabricators/account_conversation_fabricator.rb
Normal file
7
spec/fabricators/account_conversation_fabricator.rb
Normal file
|
@ -0,0 +1,7 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
Fabricator(:account_conversation) do
|
||||
account
|
||||
conversation
|
||||
status_ids { [Fabricate(:status).id] }
|
||||
end
|
|
@ -231,28 +231,6 @@ RSpec.describe ApplicationHelper do
|
|||
end
|
||||
end
|
||||
|
||||
describe 'visibility_icon' do
|
||||
it 'returns a globe icon for a public visible status' do
|
||||
result = helper.visibility_icon Status.new(visibility: 'public')
|
||||
expect(result).to match(/globe/)
|
||||
end
|
||||
|
||||
it 'returns an unlock icon for a unlisted visible status' do
|
||||
result = helper.visibility_icon Status.new(visibility: 'unlisted')
|
||||
expect(result).to match(/lock_open/)
|
||||
end
|
||||
|
||||
it 'returns a lock icon for a private visible status' do
|
||||
result = helper.visibility_icon Status.new(visibility: 'private')
|
||||
expect(result).to match(/lock/)
|
||||
end
|
||||
|
||||
it 'returns an at icon for a direct visible status' do
|
||||
result = helper.visibility_icon Status.new(visibility: 'direct')
|
||||
expect(result).to match(/alternate_email/)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'title' do
|
||||
it 'returns site title on production environment' do
|
||||
Setting.site_title = 'site title'
|
||||
|
|
61
spec/helpers/database_helper_spec.rb
Normal file
61
spec/helpers/database_helper_spec.rb
Normal file
|
@ -0,0 +1,61 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe DatabaseHelper do
|
||||
context 'when a replica is enabled' do
|
||||
around do |example|
|
||||
ClimateControl.modify REPLICA_DB_NAME: 'prod-relay-quantum-tunnel-mirror' do
|
||||
example.run
|
||||
end
|
||||
end
|
||||
|
||||
before { allow(ApplicationRecord).to receive(:connected_to) }
|
||||
|
||||
describe '#with_read_replica' do
|
||||
it 'uses the replica for connections' do
|
||||
helper.with_read_replica { _x = 1 }
|
||||
|
||||
expect(ApplicationRecord)
|
||||
.to have_received(:connected_to).with(role: :reading, prevent_writes: true)
|
||||
end
|
||||
end
|
||||
|
||||
describe '#with_primary' do
|
||||
it 'uses the primary for connections' do
|
||||
helper.with_primary { _x = 1 }
|
||||
|
||||
expect(ApplicationRecord)
|
||||
.to have_received(:connected_to).with(role: :writing)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'when a replica is not enabled' do
|
||||
around do |example|
|
||||
ClimateControl.modify REPLICA_DB_NAME: nil do
|
||||
example.run
|
||||
end
|
||||
end
|
||||
|
||||
before { allow(ApplicationRecord).to receive(:connected_to) }
|
||||
|
||||
describe '#with_read_replica' do
|
||||
it 'does not use the replica for connections' do
|
||||
helper.with_read_replica { _x = 1 }
|
||||
|
||||
expect(ApplicationRecord)
|
||||
.to_not have_received(:connected_to).with(role: :reading, prevent_writes: true)
|
||||
end
|
||||
end
|
||||
|
||||
describe '#with_primary' do
|
||||
it 'does not use the primary for connections' do
|
||||
helper.with_primary { _x = 1 }
|
||||
|
||||
expect(ApplicationRecord)
|
||||
.to_not have_received(:connected_to).with(role: :writing)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -47,6 +47,26 @@ RSpec.describe StatusesHelper do
|
|||
end
|
||||
end
|
||||
|
||||
context 'with a status that is public_unlisted' do
|
||||
let(:status) { Status.new(visibility: 'public_unlisted') }
|
||||
|
||||
it 'returns the correct fa icon' do
|
||||
result = helper.visibility_icon(status)
|
||||
|
||||
expect(result).to match('cloud')
|
||||
end
|
||||
end
|
||||
|
||||
context 'with a status that is login' do
|
||||
let(:status) { Status.new(visibility: 'login') }
|
||||
|
||||
it 'returns the correct fa icon' do
|
||||
result = helper.visibility_icon(status)
|
||||
|
||||
expect(result).to match('key')
|
||||
end
|
||||
end
|
||||
|
||||
context 'with a status that is unlisted' do
|
||||
let(:status) { Status.new(visibility: 'unlisted') }
|
||||
|
||||
|
@ -76,6 +96,16 @@ RSpec.describe StatusesHelper do
|
|||
expect(result).to match('alternate_email')
|
||||
end
|
||||
end
|
||||
|
||||
context 'with a status that is limited' do
|
||||
let(:status) { Status.new(visibility: 'limited') }
|
||||
|
||||
it 'returns the correct fa icon' do
|
||||
result = helper.visibility_icon(status)
|
||||
|
||||
expect(result).to match('shield')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#stream_link_target' do
|
||||
|
|
|
@ -3,6 +3,8 @@
|
|||
require 'rails_helper'
|
||||
|
||||
RSpec.describe FeedManager do
|
||||
subject { described_class.instance }
|
||||
|
||||
before do |example|
|
||||
unless example.metadata[:skip_stub]
|
||||
stub_const 'FeedManager::MAX_ITEMS', 10
|
||||
|
@ -33,26 +35,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(described_class.instance.filter?(:home, status, bob)).to be false
|
||||
expect(subject.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(described_class.instance.filter?(:home, reblog, bob)).to be false
|
||||
expect(subject.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(described_class.instance.filter?(:home, status, bob)).to be true
|
||||
expect(subject.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(described_class.instance.filter?(:home, status, bob)).to be true
|
||||
expect(subject.filter?(:home, status, bob)).to be true
|
||||
end
|
||||
|
||||
it 'returns true for reblog by followee of blocked account' do
|
||||
|
@ -60,7 +62,7 @@ RSpec.describe FeedManager do
|
|||
reblog = Fabricate(:status, reblog: status, account: alice)
|
||||
bob.follow!(alice)
|
||||
bob.block!(jeff)
|
||||
expect(described_class.instance.filter?(:home, reblog, bob)).to be true
|
||||
expect(subject.filter?(:home, reblog, bob)).to be true
|
||||
end
|
||||
|
||||
it 'returns true for reblog by followee of muted account' do
|
||||
|
@ -68,7 +70,7 @@ RSpec.describe FeedManager do
|
|||
reblog = Fabricate(:status, reblog: status, account: alice)
|
||||
bob.follow!(alice)
|
||||
bob.mute!(jeff)
|
||||
expect(described_class.instance.filter?(:home, reblog, bob)).to be true
|
||||
expect(subject.filter?(:home, reblog, bob)).to be true
|
||||
end
|
||||
|
||||
it 'returns true for reblog by followee of someone who is blocking recipient' do
|
||||
|
@ -76,14 +78,14 @@ RSpec.describe FeedManager do
|
|||
reblog = Fabricate(:status, reblog: status, account: alice)
|
||||
bob.follow!(alice)
|
||||
jeff.block!(bob)
|
||||
expect(described_class.instance.filter?(:home, reblog, bob)).to be true
|
||||
expect(subject.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(described_class.instance.filter?(:home, reblog, bob)).to be true
|
||||
expect(subject.filter?(:home, reblog, bob)).to be true
|
||||
end
|
||||
|
||||
it 'returns false for reply by followee to another followee' do
|
||||
|
@ -91,49 +93,49 @@ RSpec.describe FeedManager do
|
|||
reply = Fabricate(:status, text: 'Nay', thread: status, account: alice)
|
||||
bob.follow!(alice)
|
||||
bob.follow!(jeff)
|
||||
expect(described_class.instance.filter?(:home, reply, bob)).to be false
|
||||
expect(subject.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(described_class.instance.filter?(:home, reply, bob)).to be false
|
||||
expect(subject.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(described_class.instance.filter?(:home, reply, bob)).to be false
|
||||
expect(subject.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(described_class.instance.filter?(:home, reply, bob)).to be true
|
||||
expect(subject.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(described_class.instance.filter?(:home, second_reply, bob)).to be true
|
||||
expect(subject.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(described_class.instance.filter?(:home, status, bob)).to be false
|
||||
expect(subject.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(described_class.instance.filter?(:home, status, bob)).to be true
|
||||
expect(subject.filter?(:home, status, bob)).to be true
|
||||
end
|
||||
|
||||
it 'returns true for reblog of a personally blocked domain' do
|
||||
|
@ -141,19 +143,19 @@ RSpec.describe FeedManager do
|
|||
alice.follow!(jeff)
|
||||
status = Fabricate(:status, text: 'Hello world', account: bob)
|
||||
reblog = Fabricate(:status, reblog: status, account: jeff)
|
||||
expect(described_class.instance.filter?(:home, reblog, alice)).to be true
|
||||
expect(subject.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(described_class.instance.filter?(:home, status, alice)).to be true
|
||||
expect(subject.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(described_class.instance.filter?(:home, status, alice)).to be false
|
||||
expect(subject.filter?(:home, status, alice)).to be false
|
||||
end
|
||||
|
||||
it 'returns true for post from followee on exclusive list' do
|
||||
|
@ -162,7 +164,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(described_class.instance.filter?(:home, status, alice)).to be true
|
||||
expect(subject.filter?(:home, status, alice)).to be true
|
||||
end
|
||||
|
||||
it 'returns true for reblog from followee on exclusive list' do
|
||||
|
@ -172,7 +174,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(described_class.instance.filter?(:home, reblog, alice)).to be true
|
||||
expect(subject.filter?(:home, reblog, alice)).to be true
|
||||
end
|
||||
|
||||
it 'returns false for post from followee on non-exclusive list' do
|
||||
|
@ -180,7 +182,7 @@ RSpec.describe FeedManager do
|
|||
alice.follow!(bob)
|
||||
list.accounts << bob
|
||||
status = Fabricate(:status, text: 'I post a lot', account: bob)
|
||||
expect(described_class.instance.filter?(:home, status, alice)).to be false
|
||||
expect(subject.filter?(:home, status, alice)).to be false
|
||||
end
|
||||
|
||||
it 'returns false for reblog from followee on non-exclusive list' do
|
||||
|
@ -189,7 +191,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(described_class.instance.filter?(:home, reblog, alice)).to be false
|
||||
expect(subject.filter?(:home, reblog, alice)).to be false
|
||||
end
|
||||
|
||||
it 'returns true for post from followee on exclusive antenna' do
|
||||
|
@ -233,27 +235,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(described_class.instance.filter?(:mentions, status, bob)).to be true
|
||||
expect(subject.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(described_class.instance.filter?(:mentions, reply, bob)).to be true
|
||||
expect(subject.filter?(:mentions, reply, bob)).to be true
|
||||
end
|
||||
|
||||
it 'returns false for status by limited account who recipient is not following' do
|
||||
status = Fabricate(:status, text: 'Hello world', account: alice)
|
||||
alice.silence!
|
||||
expect(described_class.instance.filter?(:mentions, status, bob)).to be false
|
||||
expect(subject.filter?(:mentions, status, bob)).to be false
|
||||
end
|
||||
|
||||
it 'returns false for status by followed limited account' do
|
||||
status = Fabricate(:status, text: 'Hello world', account: alice)
|
||||
alice.silence!
|
||||
bob.follow!(alice)
|
||||
expect(described_class.instance.filter?(:mentions, status, bob)).to be false
|
||||
expect(subject.filter?(:mentions, status, bob)).to be false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -265,7 +267,7 @@ RSpec.describe FeedManager do
|
|||
members = Array.new(described_class::MAX_ITEMS) { |count| [count, count] }
|
||||
redis.zadd("feed:home:#{account.id}", members)
|
||||
|
||||
described_class.instance.push_to_home(account, status)
|
||||
subject.push_to_home(account, status)
|
||||
|
||||
expect(redis.zcard("feed:home:#{account.id}")).to eq described_class::MAX_ITEMS
|
||||
end
|
||||
|
@ -276,7 +278,7 @@ RSpec.describe FeedManager do
|
|||
reblogged = Fabricate(:status)
|
||||
reblog = Fabricate(:status, reblog: reblogged)
|
||||
|
||||
expect(described_class.instance.push_to_home(account, reblog)).to be true
|
||||
expect(subject.push_to_home(account, reblog)).to be true
|
||||
end
|
||||
|
||||
it 'does not save a new reblog of a recent status' do
|
||||
|
@ -284,9 +286,9 @@ RSpec.describe FeedManager do
|
|||
reblogged = Fabricate(:status)
|
||||
reblog = Fabricate(:status, reblog: reblogged)
|
||||
|
||||
described_class.instance.push_to_home(account, reblogged)
|
||||
subject.push_to_home(account, reblogged)
|
||||
|
||||
expect(described_class.instance.push_to_home(account, reblog)).to be false
|
||||
expect(subject.push_to_home(account, reblog)).to be false
|
||||
end
|
||||
|
||||
it 'saves a new reblog of an old status' do
|
||||
|
@ -294,14 +296,14 @@ RSpec.describe FeedManager do
|
|||
reblogged = Fabricate(:status)
|
||||
reblog = Fabricate(:status, reblog: reblogged)
|
||||
|
||||
described_class.instance.push_to_home(account, reblogged)
|
||||
subject.push_to_home(account, reblogged)
|
||||
|
||||
# Fill the feed with intervening statuses
|
||||
described_class::REBLOG_FALLOFF.times do
|
||||
described_class.instance.push_to_home(account, Fabricate(:status))
|
||||
subject.push_to_home(account, Fabricate(:status))
|
||||
end
|
||||
|
||||
expect(described_class.instance.push_to_home(account, reblog)).to be true
|
||||
expect(subject.push_to_home(account, reblog)).to be true
|
||||
end
|
||||
|
||||
it 'does not save a new reblog of a recently-reblogged status' do
|
||||
|
@ -310,10 +312,10 @@ RSpec.describe FeedManager do
|
|||
reblogs = Array.new(2) { Fabricate(:status, reblog: reblogged) }
|
||||
|
||||
# The first reblog will be accepted
|
||||
described_class.instance.push_to_home(account, reblogs.first)
|
||||
subject.push_to_home(account, reblogs.first)
|
||||
|
||||
# The second reblog should be ignored
|
||||
expect(described_class.instance.push_to_home(account, reblogs.last)).to be false
|
||||
expect(subject.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
|
||||
|
@ -322,15 +324,15 @@ RSpec.describe FeedManager do
|
|||
old_reblog = Fabricate(:status, reblog: reblogged)
|
||||
|
||||
# The first reblog should be accepted
|
||||
expect(described_class.instance.push_to_home(account, old_reblog)).to be true
|
||||
expect(subject.push_to_home(account, old_reblog)).to be true
|
||||
|
||||
# The first reblog should be successfully removed
|
||||
expect(described_class.instance.unpush_from_home(account, old_reblog)).to be true
|
||||
expect(subject.unpush_from_home(account, old_reblog)).to be true
|
||||
|
||||
reblog = Fabricate(:status, reblog: reblogged)
|
||||
|
||||
# The second reblog should be accepted
|
||||
expect(described_class.instance.push_to_home(account, reblog)).to be true
|
||||
expect(subject.push_to_home(account, reblog)).to be true
|
||||
end
|
||||
|
||||
it 'does not save a new reblog of a multiply-reblogged-then-unreblogged status' do
|
||||
|
@ -339,14 +341,14 @@ RSpec.describe FeedManager do
|
|||
reblogs = Array.new(3) { Fabricate(:status, reblog: reblogged) }
|
||||
|
||||
# Accept the reblogs
|
||||
described_class.instance.push_to_home(account, reblogs[0])
|
||||
described_class.instance.push_to_home(account, reblogs[1])
|
||||
subject.push_to_home(account, reblogs[0])
|
||||
subject.push_to_home(account, reblogs[1])
|
||||
|
||||
# Unreblog the first one
|
||||
described_class.instance.unpush_from_home(account, reblogs[0])
|
||||
subject.unpush_from_home(account, reblogs[0])
|
||||
|
||||
# The last reblog should still be ignored
|
||||
expect(described_class.instance.push_to_home(account, reblogs.last)).to be false
|
||||
expect(subject.push_to_home(account, reblogs.last)).to be false
|
||||
end
|
||||
|
||||
it 'saves a new reblog of a long-ago-reblogged status' do
|
||||
|
@ -355,15 +357,15 @@ RSpec.describe FeedManager do
|
|||
reblogs = Array.new(2) { Fabricate(:status, reblog: reblogged) }
|
||||
|
||||
# The first reblog will be accepted
|
||||
described_class.instance.push_to_home(account, reblogs.first)
|
||||
subject.push_to_home(account, reblogs.first)
|
||||
|
||||
# Fill the feed with intervening statuses
|
||||
described_class::REBLOG_FALLOFF.times do
|
||||
described_class.instance.push_to_home(account, Fabricate(:status))
|
||||
subject.push_to_home(account, Fabricate(:status))
|
||||
end
|
||||
|
||||
# The second reblog should also be accepted
|
||||
expect(described_class.instance.push_to_home(account, reblogs.last)).to be true
|
||||
expect(subject.push_to_home(account, reblogs.last)).to be true
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -371,9 +373,9 @@ RSpec.describe FeedManager do
|
|||
account = Fabricate(:account)
|
||||
reblog = Fabricate(:status)
|
||||
status = Fabricate(:status, reblog: reblog)
|
||||
described_class.instance.push_to_home(account, status)
|
||||
subject.push_to_home(account, status)
|
||||
|
||||
expect(described_class.instance.push_to_home(account, reblog)).to be false
|
||||
expect(subject.push_to_home(account, reblog)).to be false
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -396,9 +398,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)
|
||||
described_class.instance.push_to_list(list, status)
|
||||
subject.push_to_list(list, status)
|
||||
|
||||
expect(described_class.instance.push_to_list(list, reblog)).to be false
|
||||
expect(subject.push_to_list(list, reblog)).to be false
|
||||
end
|
||||
|
||||
context 'when replies policy is set to no replies' do
|
||||
|
@ -408,19 +410,19 @@ RSpec.describe FeedManager do
|
|||
|
||||
it 'pushes statuses that are not replies' do
|
||||
status = Fabricate(:status, text: 'Hello world', account: bob)
|
||||
expect(described_class.instance.push_to_list(list, status)).to be true
|
||||
expect(subject.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(described_class.instance.push_to_list(list, reply)).to be true
|
||||
expect(subject.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(described_class.instance.push_to_list(list, reply)).to be false
|
||||
expect(subject.push_to_list(list, reply)).to be false
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -431,25 +433,25 @@ RSpec.describe FeedManager do
|
|||
|
||||
it 'pushes statuses that are not replies' do
|
||||
status = Fabricate(:status, text: 'Hello world', account: bob)
|
||||
expect(described_class.instance.push_to_list(list, status)).to be true
|
||||
expect(subject.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(described_class.instance.push_to_list(list, reply)).to be true
|
||||
expect(subject.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(described_class.instance.push_to_list(list, reply)).to be true
|
||||
expect(subject.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(described_class.instance.push_to_list(list, reply)).to be false
|
||||
expect(subject.push_to_list(list, reply)).to be false
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -460,25 +462,25 @@ RSpec.describe FeedManager do
|
|||
|
||||
it 'pushes statuses that are not replies' do
|
||||
status = Fabricate(:status, text: 'Hello world', account: bob)
|
||||
expect(described_class.instance.push_to_list(list, status)).to be true
|
||||
expect(subject.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(described_class.instance.push_to_list(list, reply)).to be true
|
||||
expect(subject.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(described_class.instance.push_to_list(list, reply)).to be true
|
||||
expect(subject.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(described_class.instance.push_to_list(list, reply)).to be true
|
||||
expect(subject.push_to_list(list, reply)).to be true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -488,9 +490,9 @@ RSpec.describe FeedManager do
|
|||
account = Fabricate(:account, id: 0)
|
||||
reblog = Fabricate(:status)
|
||||
status = Fabricate(:status, reblog: reblog)
|
||||
described_class.instance.push_to_home(account, status)
|
||||
subject.push_to_home(account, status)
|
||||
|
||||
described_class.instance.merge_into_home(account, reblog.account)
|
||||
subject.merge_into_home(account, reblog.account)
|
||||
|
||||
expect(redis.zscore('feed:home:0', reblog.id)).to be_nil
|
||||
end
|
||||
|
@ -503,14 +505,14 @@ RSpec.describe FeedManager do
|
|||
reblogged = Fabricate(:status)
|
||||
status = Fabricate(:status, reblog: reblogged)
|
||||
|
||||
described_class.instance.push_to_home(receiver, reblogged)
|
||||
described_class::REBLOG_FALLOFF.times { described_class.instance.push_to_home(receiver, Fabricate(:status)) }
|
||||
described_class.instance.push_to_home(receiver, status)
|
||||
subject.push_to_home(receiver, reblogged)
|
||||
described_class::REBLOG_FALLOFF.times { subject.push_to_home(receiver, Fabricate(:status)) }
|
||||
subject.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)
|
||||
|
||||
described_class.instance.unpush_from_home(receiver, status)
|
||||
subject.unpush_from_home(receiver, status)
|
||||
|
||||
# Restore original status
|
||||
expect(redis.zrange("feed:home:#{receiver.id}", 0, -1)).to_not include(status.id.to_s)
|
||||
|
@ -521,12 +523,12 @@ RSpec.describe FeedManager do
|
|||
reblogged = Fabricate(:status)
|
||||
status = Fabricate(:status, reblog: reblogged)
|
||||
|
||||
described_class.instance.push_to_home(receiver, status)
|
||||
subject.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]
|
||||
|
||||
described_class.instance.unpush_from_home(receiver, status)
|
||||
subject.unpush_from_home(receiver, status)
|
||||
|
||||
expect(redis.zrange("feed:home:#{receiver.id}", 0, -1)).to be_empty
|
||||
end
|
||||
|
@ -536,14 +538,14 @@ RSpec.describe FeedManager do
|
|||
reblogs = Array.new(3) { Fabricate(:status, reblog: reblogged) }
|
||||
|
||||
reblogs.each do |reblog|
|
||||
described_class.instance.push_to_home(receiver, reblog)
|
||||
subject.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|
|
||||
described_class.instance.unpush_from_home(receiver, reblog)
|
||||
subject.unpush_from_home(receiver, reblog)
|
||||
end
|
||||
|
||||
expect(redis.zrange("feed:home:#{receiver.id}", 0, -1)).to eq [reblogs.last.id.to_s]
|
||||
|
@ -552,10 +554,10 @@ RSpec.describe FeedManager do
|
|||
it 'sends push updates' do
|
||||
status = Fabricate(:status)
|
||||
|
||||
described_class.instance.push_to_home(receiver, status)
|
||||
subject.push_to_home(receiver, status)
|
||||
|
||||
allow(redis).to receive_messages(publish: nil)
|
||||
described_class.instance.unpush_from_home(receiver, status)
|
||||
subject.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)
|
||||
|
@ -569,9 +571,9 @@ RSpec.describe FeedManager do
|
|||
it 'leaves a tagged status' do
|
||||
status = Fabricate(:status)
|
||||
status.tags << tag
|
||||
described_class.instance.push_to_home(receiver, status)
|
||||
subject.push_to_home(receiver, status)
|
||||
|
||||
described_class.instance.unmerge_tag_from_home(tag, receiver)
|
||||
subject.unmerge_tag_from_home(tag, receiver)
|
||||
|
||||
expect(redis.zrange("feed:home:#{receiver.id}", 0, -1)).to_not include(status.id.to_s)
|
||||
end
|
||||
|
@ -582,9 +584,9 @@ RSpec.describe FeedManager do
|
|||
|
||||
status = Fabricate(:status, account: followee)
|
||||
status.tags << tag
|
||||
described_class.instance.push_to_home(receiver, status)
|
||||
subject.push_to_home(receiver, status)
|
||||
|
||||
described_class.instance.unmerge_tag_from_home(tag, receiver)
|
||||
subject.unmerge_tag_from_home(tag, receiver)
|
||||
|
||||
expect(redis.zrange("feed:home:#{receiver.id}", 0, -1)).to include(status.id.to_s)
|
||||
end
|
||||
|
@ -592,9 +594,9 @@ RSpec.describe FeedManager do
|
|||
it 'remains a tagged status written by receiver' do
|
||||
status = Fabricate(:status, account: receiver)
|
||||
status.tags << tag
|
||||
described_class.instance.push_to_home(receiver, status)
|
||||
subject.push_to_home(receiver, status)
|
||||
|
||||
described_class.instance.unmerge_tag_from_home(tag, receiver)
|
||||
subject.unmerge_tag_from_home(tag, receiver)
|
||||
|
||||
expect(redis.zrange("feed:home:#{receiver.id}", 0, -1)).to include(status.id.to_s)
|
||||
end
|
||||
|
@ -625,7 +627,7 @@ RSpec.describe FeedManager do
|
|||
end
|
||||
|
||||
it 'correctly cleans the home timeline' do
|
||||
described_class.instance.clear_from_home(account, target_account)
|
||||
subject.clear_from_home(account, target_account)
|
||||
|
||||
expect(redis.zrange("feed:home:#{account.id}", 0, -1)).to eq [status_from_followed_account_first.id.to_s, status_from_followed_account_next.id.to_s]
|
||||
end
|
||||
|
|
|
@ -8,4 +8,26 @@ RSpec.describe AccountAlias do
|
|||
it { is_expected.to normalize(:acct).from(' @username@domain ').to('username@domain') }
|
||||
end
|
||||
end
|
||||
|
||||
describe 'Validations' do
|
||||
subject { described_class.new(account:) }
|
||||
|
||||
let(:account) { Fabricate :account }
|
||||
|
||||
it { is_expected.to_not allow_values(nil, '').for(:uri).against(:acct).with_message(not_found_message) }
|
||||
|
||||
it { is_expected.to_not allow_values(account_uri).for(:uri).against(:acct).with_message(self_move_message) }
|
||||
|
||||
def account_uri
|
||||
ActivityPub::TagManager.instance.uri_for(subject.account)
|
||||
end
|
||||
|
||||
def not_found_message
|
||||
I18n.t('migrations.errors.not_found')
|
||||
end
|
||||
|
||||
def self_move_message
|
||||
I18n.t('migrations.errors.move_to_self')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -9,8 +9,8 @@ RSpec.describe AccountMigration do
|
|||
end
|
||||
end
|
||||
|
||||
describe 'validations' do
|
||||
subject { described_class.new(account: source_account, acct: target_acct) }
|
||||
describe 'Validations' do
|
||||
subject { Fabricate.build :account_migration, account: source_account }
|
||||
|
||||
let(:source_account) { Fabricate(:account) }
|
||||
let(:target_acct) { target_account.acct }
|
||||
|
@ -26,9 +26,7 @@ RSpec.describe AccountMigration do
|
|||
allow(service_double).to receive(:call).with(target_acct, anything).and_return(target_account)
|
||||
end
|
||||
|
||||
it 'passes validations' do
|
||||
expect(subject).to be_valid
|
||||
end
|
||||
it { is_expected.to allow_value(target_account.acct).for(:acct) }
|
||||
end
|
||||
|
||||
context 'with unresolvable account' do
|
||||
|
@ -40,17 +38,13 @@ RSpec.describe AccountMigration do
|
|||
allow(service_double).to receive(:call).with(target_acct, anything).and_return(nil)
|
||||
end
|
||||
|
||||
it 'has errors on acct field' do
|
||||
expect(subject).to model_have_error_on_field(:acct)
|
||||
end
|
||||
it { is_expected.to_not allow_value(target_acct).for(:acct) }
|
||||
end
|
||||
|
||||
context 'with a space in the domain part' do
|
||||
let(:target_acct) { 'target@remote. org' }
|
||||
|
||||
it 'has errors on acct field' do
|
||||
expect(subject).to model_have_error_on_field(:acct)
|
||||
end
|
||||
it { is_expected.to_not allow_value(target_acct).for(:acct) }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -3,29 +3,24 @@
|
|||
require 'rails_helper'
|
||||
|
||||
RSpec.describe AccountModerationNote do
|
||||
describe 'chronological scope' do
|
||||
it 'returns account moderation notes oldest to newest' do
|
||||
account = Fabricate(:account)
|
||||
note1 = Fabricate(:account_moderation_note, target_account: account)
|
||||
note2 = Fabricate(:account_moderation_note, target_account: account)
|
||||
describe 'Scopes' do
|
||||
describe '.chronological' do
|
||||
it 'returns account moderation notes oldest to newest' do
|
||||
account = Fabricate(:account)
|
||||
note1 = Fabricate(:account_moderation_note, target_account: account)
|
||||
note2 = Fabricate(:account_moderation_note, target_account: account)
|
||||
|
||||
expect(account.targeted_moderation_notes.chronological).to eq [note1, note2]
|
||||
expect(account.targeted_moderation_notes.chronological).to eq [note1, note2]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'validations' do
|
||||
it 'is invalid if the content is empty' do
|
||||
report = Fabricate.build(:account_moderation_note, content: '')
|
||||
expect(report.valid?).to be false
|
||||
end
|
||||
describe 'Validations' do
|
||||
subject { Fabricate.build :account_moderation_note }
|
||||
|
||||
it 'is invalid if content is longer than character limit' do
|
||||
report = Fabricate.build(:account_moderation_note, content: comment_over_limit)
|
||||
expect(report.valid?).to be false
|
||||
end
|
||||
|
||||
def comment_over_limit
|
||||
Faker::Lorem.paragraph_by_chars(number: described_class::CONTENT_SIZE_LIMIT * 2)
|
||||
describe 'content' do
|
||||
it { is_expected.to_not allow_value('').for(:content) }
|
||||
it { is_expected.to validate_length_of(:content).is_at_most(described_class::CONTENT_SIZE_LIMIT) }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -10,64 +10,6 @@ RSpec.describe Account do
|
|||
|
||||
let(:bob) { Fabricate(:account, username: 'bob') }
|
||||
|
||||
describe '#suspended_locally?' do
|
||||
context 'when the account is not suspended' do
|
||||
it 'returns false' do
|
||||
expect(subject.suspended_locally?).to be false
|
||||
end
|
||||
end
|
||||
|
||||
context 'when the account is suspended locally' do
|
||||
before do
|
||||
subject.update!(suspended_at: 1.day.ago, suspension_origin: :local)
|
||||
end
|
||||
|
||||
it 'returns true' do
|
||||
expect(subject.suspended_locally?).to be true
|
||||
end
|
||||
end
|
||||
|
||||
context 'when the account is suspended remotely' do
|
||||
before do
|
||||
subject.update!(suspended_at: 1.day.ago, suspension_origin: :remote)
|
||||
end
|
||||
|
||||
it 'returns false' do
|
||||
expect(subject.suspended_locally?).to be false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#suspend!' do
|
||||
it 'marks the account as suspended and creates a deletion request' do
|
||||
expect { subject.suspend! }
|
||||
.to change(subject, :suspended?).from(false).to(true)
|
||||
.and change(subject, :suspended_locally?).from(false).to(true)
|
||||
.and(change { AccountDeletionRequest.exists?(account: subject) }.from(false).to(true))
|
||||
end
|
||||
|
||||
context 'when the account is of a local user' do
|
||||
subject { local_user_account }
|
||||
|
||||
let!(:local_user_account) { Fabricate(:user, email: 'foo+bar@domain.org').account }
|
||||
|
||||
it 'creates a canonical domain block' do
|
||||
subject.suspend!
|
||||
expect(CanonicalEmailBlock.block?(subject.user_email)).to be true
|
||||
end
|
||||
|
||||
context 'when a canonical domain block already exists for that email' do
|
||||
before do
|
||||
Fabricate(:canonical_email_block, email: subject.user_email)
|
||||
end
|
||||
|
||||
it 'does not raise an error' do
|
||||
expect { subject.suspend! }.to_not raise_error
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#follow!' do
|
||||
it 'creates a follow' do
|
||||
follow = subject.follow!(bob)
|
||||
|
@ -208,16 +150,16 @@ RSpec.describe Account do
|
|||
end
|
||||
end
|
||||
|
||||
context 'when last_webfingered_at is more than 24 hours before' do
|
||||
let(:last_webfingered_at) { 25.hours.ago }
|
||||
context 'when last_webfingered_at is before the threshold' do
|
||||
let(:last_webfingered_at) { (described_class::STALE_THRESHOLD + 1.hour).ago }
|
||||
|
||||
it 'returns true' do
|
||||
expect(account.possibly_stale?).to be true
|
||||
end
|
||||
end
|
||||
|
||||
context 'when last_webfingered_at is less than 24 hours before' do
|
||||
let(:last_webfingered_at) { 23.hours.ago }
|
||||
context 'when last_webfingered_at is after the threshold' do
|
||||
let(:last_webfingered_at) { (described_class::STALE_THRESHOLD - 1.hour).ago }
|
||||
|
||||
it 'returns false' do
|
||||
expect(account.possibly_stale?).to be false
|
||||
|
@ -975,26 +917,42 @@ RSpec.describe Account do
|
|||
end
|
||||
end
|
||||
|
||||
describe '#prepare_contents' do
|
||||
subject { Fabricate.build :account, domain: domain, note: ' padded note ', display_name: ' padded name ' }
|
||||
describe 'Callbacks' do
|
||||
describe 'Stripping content when required' do
|
||||
context 'with a remote account' do
|
||||
subject { Fabricate.build :account, domain: 'host.example', note: ' note ', display_name: ' display name ' }
|
||||
|
||||
context 'with local account' do
|
||||
let(:domain) { nil }
|
||||
|
||||
it 'strips values' do
|
||||
expect { subject.valid? }
|
||||
.to change(subject, :note).to('padded note')
|
||||
.and(change(subject, :display_name).to('padded name'))
|
||||
it 'preserves content' do
|
||||
expect { subject.valid? }
|
||||
.to not_change(subject, :note)
|
||||
.and not_change(subject, :display_name)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'with remote account' do
|
||||
let(:domain) { 'host.example' }
|
||||
context 'with a local account' do
|
||||
subject { Fabricate.build :account, domain: nil, note:, display_name: }
|
||||
|
||||
it 'preserves values' do
|
||||
expect { subject.valid? }
|
||||
.to not_change(subject, :note)
|
||||
.and(not_change(subject, :display_name))
|
||||
context 'with populated fields' do
|
||||
let(:note) { ' note ' }
|
||||
let(:display_name) { ' display name ' }
|
||||
|
||||
it 'strips content' do
|
||||
expect { subject.valid? }
|
||||
.to change(subject, :note).to('note')
|
||||
.and change(subject, :display_name).to('display name')
|
||||
end
|
||||
end
|
||||
|
||||
context 'with empty fields' do
|
||||
let(:note) { nil }
|
||||
let(:display_name) { nil }
|
||||
|
||||
it 'preserves content' do
|
||||
expect { subject.valid? }
|
||||
.to not_change(subject, :note)
|
||||
.and not_change(subject, :display_name)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -1049,22 +1007,19 @@ RSpec.describe Account do
|
|||
end
|
||||
end
|
||||
|
||||
describe 'validations' do
|
||||
describe 'Validations' do
|
||||
it { is_expected.to validate_presence_of(:username) }
|
||||
|
||||
context 'when is local' do
|
||||
it 'is invalid if the username is not unique in case-insensitive comparison among local accounts' do
|
||||
_account = Fabricate(:account, username: 'the_doctor')
|
||||
non_unique_account = Fabricate.build(:account, username: 'the_Doctor')
|
||||
non_unique_account.valid?
|
||||
expect(non_unique_account).to model_have_error_on_field(:username)
|
||||
context 'when account is local' do
|
||||
subject { Fabricate.build :account, domain: nil }
|
||||
|
||||
context 'with an existing differently-cased username account' do
|
||||
before { Fabricate :account, username: 'the_doctor' }
|
||||
|
||||
it { is_expected.to_not allow_value('the_Doctor').for(:username) }
|
||||
end
|
||||
|
||||
it 'is invalid if the username is reserved' do
|
||||
account = Fabricate.build(:account, username: 'support')
|
||||
account.valid?
|
||||
expect(account).to model_have_error_on_field(:username)
|
||||
end
|
||||
it { is_expected.to_not allow_value('support').for(:username) }
|
||||
|
||||
it 'is valid when username is reserved but record has already been created' do
|
||||
account = Fabricate.build(:account, username: 'support')
|
||||
|
@ -1072,9 +1027,10 @@ RSpec.describe Account do
|
|||
expect(account.valid?).to be true
|
||||
end
|
||||
|
||||
it 'is valid if we are creating an instance actor account with a period' do
|
||||
account = Fabricate.build(:account, id: described_class::INSTANCE_ACTOR_ID, actor_type: 'Application', locked: true, username: 'example.com')
|
||||
expect(account.valid?).to be true
|
||||
context 'with the instance actor' do
|
||||
subject { Fabricate.build :account, id: described_class::INSTANCE_ACTOR_ID, actor_type: 'Application', locked: true }
|
||||
|
||||
it { is_expected.to allow_value('example.com').for(:username) }
|
||||
end
|
||||
|
||||
it 'is valid if we are creating a possibly-conflicting instance actor account' do
|
||||
|
@ -1083,81 +1039,31 @@ RSpec.describe Account do
|
|||
expect(instance_account.valid?).to be true
|
||||
end
|
||||
|
||||
it 'is invalid if the username doesn\'t only contains letters, numbers and underscores' do
|
||||
account = Fabricate.build(:account, username: 'the-doctor')
|
||||
account.valid?
|
||||
expect(account).to model_have_error_on_field(:username)
|
||||
end
|
||||
it { is_expected.to_not allow_values('the-doctor', 'the.doctor').for(:username) }
|
||||
|
||||
it 'is invalid if the username contains a period' do
|
||||
account = Fabricate.build(:account, username: 'the.doctor')
|
||||
account.valid?
|
||||
expect(account).to model_have_error_on_field(:username)
|
||||
end
|
||||
it { is_expected.to validate_length_of(:username).is_at_most(described_class::USERNAME_LENGTH_LIMIT) }
|
||||
it { is_expected.to validate_length_of(:display_name).is_at_most(described_class::DISPLAY_NAME_LENGTH_LIMIT) }
|
||||
|
||||
it 'is invalid if the username is longer than the character limit' do
|
||||
account = Fabricate.build(:account, username: username_over_limit)
|
||||
account.valid?
|
||||
expect(account).to model_have_error_on_field(:username)
|
||||
end
|
||||
|
||||
it 'is invalid if the display name is longer than the character limit' do
|
||||
account = Fabricate.build(:account, display_name: display_name_over_limit)
|
||||
account.valid?
|
||||
expect(account).to model_have_error_on_field(:display_name)
|
||||
end
|
||||
|
||||
it 'is invalid if the note is longer than the character limit' do
|
||||
account = Fabricate.build(:account, note: account_note_over_limit)
|
||||
account.valid?
|
||||
expect(account).to model_have_error_on_field(:note)
|
||||
end
|
||||
it { is_expected.to_not allow_values(account_note_over_limit).for(:note) }
|
||||
end
|
||||
|
||||
context 'when is remote' do
|
||||
it 'is invalid if the username is same among accounts in the same normalized domain' do
|
||||
Fabricate(:account, domain: 'にゃん', username: 'username')
|
||||
account = Fabricate.build(:account, domain: 'xn--r9j5b5b', username: 'username')
|
||||
account.valid?
|
||||
expect(account).to model_have_error_on_field(:username)
|
||||
context 'when account is remote' do
|
||||
subject { Fabricate.build :account, domain: 'host.example' }
|
||||
|
||||
context 'when a normalized domain account exists' do
|
||||
subject { Fabricate.build :account, domain: 'xn--r9j5b5b' }
|
||||
|
||||
before { Fabricate(:account, domain: 'にゃん', username: 'username') }
|
||||
|
||||
it { is_expected.to_not allow_values('username', 'Username').for(:username) }
|
||||
end
|
||||
|
||||
it 'is invalid if the username is not unique in case-insensitive comparison among accounts in the same normalized domain' do
|
||||
Fabricate(:account, domain: 'にゃん', username: 'username')
|
||||
account = Fabricate.build(:account, domain: 'xn--r9j5b5b', username: 'Username')
|
||||
account.valid?
|
||||
expect(account).to model_have_error_on_field(:username)
|
||||
end
|
||||
it { is_expected.to allow_values('the-doctor', username_over_limit).for(:username) }
|
||||
it { is_expected.to_not allow_values('the doctor').for(:username) }
|
||||
|
||||
it 'is valid even if the username contains hyphens' do
|
||||
account = Fabricate.build(:account, domain: 'domain', username: 'the-doctor')
|
||||
account.valid?
|
||||
expect(account).to_not model_have_error_on_field(:username)
|
||||
end
|
||||
it { is_expected.to allow_values(display_name_over_limit).for(:display_name) }
|
||||
|
||||
it 'is invalid if the username doesn\'t only contains letters, numbers, underscores and hyphens' do
|
||||
account = Fabricate.build(:account, domain: 'domain', username: 'the doctor')
|
||||
account.valid?
|
||||
expect(account).to model_have_error_on_field(:username)
|
||||
end
|
||||
|
||||
it 'is valid even if the username is longer than the character limit' do
|
||||
account = Fabricate.build(:account, domain: 'domain', username: username_over_limit)
|
||||
account.valid?
|
||||
expect(account).to_not model_have_error_on_field(:username)
|
||||
end
|
||||
|
||||
it 'is valid even if the display name is longer than the character limit' do
|
||||
account = Fabricate.build(:account, domain: 'domain', display_name: display_name_over_limit)
|
||||
account.valid?
|
||||
expect(account).to_not model_have_error_on_field(:display_name)
|
||||
end
|
||||
|
||||
it 'is valid even if the note is longer than the character limit' do
|
||||
account = Fabricate.build(:account, domain: 'domain', note: account_note_over_limit)
|
||||
account.valid?
|
||||
expect(account).to_not model_have_error_on_field(:note)
|
||||
end
|
||||
it { is_expected.to allow_values(account_note_over_limit).for(:note) }
|
||||
end
|
||||
|
||||
def username_over_limit
|
||||
|
@ -1308,14 +1214,6 @@ RSpec.describe Account do
|
|||
end
|
||||
end
|
||||
|
||||
describe 'suspended' do
|
||||
it 'returns an array of accounts who are suspended' do
|
||||
suspended_account = Fabricate(:account, suspended: true)
|
||||
_account = Fabricate(:account, suspended: false)
|
||||
expect(described_class.suspended).to contain_exactly(suspended_account)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'searchable' do
|
||||
let!(:suspended_local) { Fabricate(:account, suspended: true, username: 'suspended_local') }
|
||||
let!(:suspended_remote) { Fabricate(:account, suspended: true, domain: 'example.org', username: 'suspended_remote') }
|
||||
|
|
|
@ -5,13 +5,12 @@ require 'rails_helper'
|
|||
RSpec.describe AccountStatusesCleanupPolicy do
|
||||
let(:account) { Fabricate(:account, username: 'alice', domain: nil) }
|
||||
|
||||
describe 'validation' do
|
||||
it 'disallow remote accounts' do
|
||||
account.update(domain: 'example.com')
|
||||
account_statuses_cleanup_policy = Fabricate.build(:account_statuses_cleanup_policy, account: account)
|
||||
account_statuses_cleanup_policy.valid?
|
||||
expect(account_statuses_cleanup_policy).to model_have_error_on_field(:account)
|
||||
end
|
||||
describe 'Validations' do
|
||||
subject { Fabricate.build :account_statuses_cleanup_policy }
|
||||
|
||||
let(:remote_account) { Fabricate(:account, domain: 'example.com') }
|
||||
|
||||
it { is_expected.to_not allow_value(remote_account).for(:account) }
|
||||
end
|
||||
|
||||
describe 'save hooks' do
|
||||
|
@ -339,14 +338,7 @@ RSpec.describe AccountStatusesCleanupPolicy do
|
|||
end
|
||||
|
||||
context 'when policy is set to keep DMs and reject everything else' do
|
||||
before do
|
||||
account_statuses_cleanup_policy.keep_direct = true
|
||||
account_statuses_cleanup_policy.keep_pinned = false
|
||||
account_statuses_cleanup_policy.keep_polls = false
|
||||
account_statuses_cleanup_policy.keep_media = false
|
||||
account_statuses_cleanup_policy.keep_self_fav = false
|
||||
account_statuses_cleanup_policy.keep_self_bookmark = false
|
||||
end
|
||||
before { establish_policy(keep_direct: true) }
|
||||
|
||||
it 'returns every old status except does not return the old direct message for deletion' do
|
||||
expect(subject.pluck(:id))
|
||||
|
@ -356,14 +348,7 @@ RSpec.describe AccountStatusesCleanupPolicy do
|
|||
end
|
||||
|
||||
context 'when policy is set to keep self-bookmarked toots and reject everything else' do
|
||||
before do
|
||||
account_statuses_cleanup_policy.keep_direct = false
|
||||
account_statuses_cleanup_policy.keep_pinned = false
|
||||
account_statuses_cleanup_policy.keep_polls = false
|
||||
account_statuses_cleanup_policy.keep_media = false
|
||||
account_statuses_cleanup_policy.keep_self_fav = false
|
||||
account_statuses_cleanup_policy.keep_self_bookmark = true
|
||||
end
|
||||
before { establish_policy(keep_self_bookmark: true) }
|
||||
|
||||
it 'returns every old status but does not return the old self-bookmarked message for deletion' do
|
||||
expect(subject.pluck(:id))
|
||||
|
@ -373,14 +358,7 @@ RSpec.describe AccountStatusesCleanupPolicy do
|
|||
end
|
||||
|
||||
context 'when policy is set to keep self-faved toots and reject everything else' do
|
||||
before do
|
||||
account_statuses_cleanup_policy.keep_direct = false
|
||||
account_statuses_cleanup_policy.keep_pinned = false
|
||||
account_statuses_cleanup_policy.keep_polls = false
|
||||
account_statuses_cleanup_policy.keep_media = false
|
||||
account_statuses_cleanup_policy.keep_self_fav = true
|
||||
account_statuses_cleanup_policy.keep_self_bookmark = false
|
||||
end
|
||||
before { establish_policy(keep_self_fav: true) }
|
||||
|
||||
it 'returns every old status but does not return the old self-faved message for deletion' do
|
||||
expect(subject.pluck(:id))
|
||||
|
@ -390,14 +368,7 @@ RSpec.describe AccountStatusesCleanupPolicy do
|
|||
end
|
||||
|
||||
context 'when policy is set to keep toots with media and reject everything else' do
|
||||
before do
|
||||
account_statuses_cleanup_policy.keep_direct = false
|
||||
account_statuses_cleanup_policy.keep_pinned = false
|
||||
account_statuses_cleanup_policy.keep_polls = false
|
||||
account_statuses_cleanup_policy.keep_media = true
|
||||
account_statuses_cleanup_policy.keep_self_fav = false
|
||||
account_statuses_cleanup_policy.keep_self_bookmark = false
|
||||
end
|
||||
before { establish_policy(keep_media: true) }
|
||||
|
||||
it 'returns every old status but does not return the old message with media for deletion' do
|
||||
expect(subject.pluck(:id))
|
||||
|
@ -407,14 +378,7 @@ RSpec.describe AccountStatusesCleanupPolicy do
|
|||
end
|
||||
|
||||
context 'when policy is set to keep toots with polls and reject everything else' do
|
||||
before do
|
||||
account_statuses_cleanup_policy.keep_direct = false
|
||||
account_statuses_cleanup_policy.keep_pinned = false
|
||||
account_statuses_cleanup_policy.keep_polls = true
|
||||
account_statuses_cleanup_policy.keep_media = false
|
||||
account_statuses_cleanup_policy.keep_self_fav = false
|
||||
account_statuses_cleanup_policy.keep_self_bookmark = false
|
||||
end
|
||||
before { establish_policy(keep_polls: true) }
|
||||
|
||||
it 'returns every old status but does not return the old poll message for deletion' do
|
||||
expect(subject.pluck(:id))
|
||||
|
@ -424,14 +388,7 @@ RSpec.describe AccountStatusesCleanupPolicy do
|
|||
end
|
||||
|
||||
context 'when policy is set to keep pinned toots and reject everything else' do
|
||||
before do
|
||||
account_statuses_cleanup_policy.keep_direct = false
|
||||
account_statuses_cleanup_policy.keep_pinned = true
|
||||
account_statuses_cleanup_policy.keep_polls = false
|
||||
account_statuses_cleanup_policy.keep_media = false
|
||||
account_statuses_cleanup_policy.keep_self_fav = false
|
||||
account_statuses_cleanup_policy.keep_self_bookmark = false
|
||||
end
|
||||
before { establish_policy(keep_pinned: true) }
|
||||
|
||||
it 'returns every old status but does not return the old pinned message for deletion' do
|
||||
expect(subject.pluck(:id))
|
||||
|
@ -441,14 +398,7 @@ RSpec.describe AccountStatusesCleanupPolicy do
|
|||
end
|
||||
|
||||
context 'when policy is to not keep any special messages' do
|
||||
before do
|
||||
account_statuses_cleanup_policy.keep_direct = false
|
||||
account_statuses_cleanup_policy.keep_pinned = false
|
||||
account_statuses_cleanup_policy.keep_polls = false
|
||||
account_statuses_cleanup_policy.keep_media = false
|
||||
account_statuses_cleanup_policy.keep_self_fav = false
|
||||
account_statuses_cleanup_policy.keep_self_bookmark = false
|
||||
end
|
||||
before { establish_policy }
|
||||
|
||||
it 'returns every old status but does not return the recent or unrelated statuses' do
|
||||
expect(subject.pluck(:id))
|
||||
|
@ -459,14 +409,7 @@ RSpec.describe AccountStatusesCleanupPolicy do
|
|||
end
|
||||
|
||||
context 'when policy is set to keep every category of toots' do
|
||||
before do
|
||||
account_statuses_cleanup_policy.keep_direct = true
|
||||
account_statuses_cleanup_policy.keep_pinned = true
|
||||
account_statuses_cleanup_policy.keep_polls = true
|
||||
account_statuses_cleanup_policy.keep_media = true
|
||||
account_statuses_cleanup_policy.keep_self_fav = true
|
||||
account_statuses_cleanup_policy.keep_self_bookmark = true
|
||||
end
|
||||
before { establish_policy(keep_direct: true, keep_pinned: true, keep_polls: true, keep_media: true, keep_self_fav: true, keep_self_bookmark: true) }
|
||||
|
||||
it 'returns normal statuses and does not return unrelated old status' do
|
||||
expect(subject.pluck(:id))
|
||||
|
@ -502,5 +445,24 @@ RSpec.describe AccountStatusesCleanupPolicy do
|
|||
.and include(very_old_status.id, faved_primary.id, reblogged_primary.id, reblogged_secondary.id)
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def establish_policy(options = {})
|
||||
default_policy_options.merge(options).each do |attribute, value|
|
||||
account_statuses_cleanup_policy.send :"#{attribute}=", value
|
||||
end
|
||||
end
|
||||
|
||||
def default_policy_options
|
||||
{
|
||||
keep_direct: false,
|
||||
keep_media: false,
|
||||
keep_pinned: false,
|
||||
keep_polls: false,
|
||||
keep_self_bookmark: false,
|
||||
keep_self_fav: false,
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -67,18 +67,30 @@ RSpec.describe Announcement do
|
|||
it { is_expected.to validate_presence_of(:text) }
|
||||
|
||||
describe 'ends_at' do
|
||||
it 'validates presence when starts_at is present' do
|
||||
record = Fabricate.build(:announcement, starts_at: 1.day.ago)
|
||||
context 'when starts_at is present' do
|
||||
subject { Fabricate.build :announcement, starts_at: 1.day.ago }
|
||||
|
||||
expect(record).to_not be_valid
|
||||
expect(record.errors[:ends_at]).to be_present
|
||||
it { is_expected.to validate_presence_of(:ends_at) }
|
||||
end
|
||||
|
||||
it 'does not validate presence when starts_at is missing' do
|
||||
record = Fabricate.build(:announcement, starts_at: nil)
|
||||
context 'when starts_at is missing' do
|
||||
subject { Fabricate.build :announcement, starts_at: nil }
|
||||
|
||||
expect(record).to be_valid
|
||||
expect(record.errors[:ends_at]).to_not be_present
|
||||
it { is_expected.to_not validate_presence_of(:ends_at) }
|
||||
end
|
||||
end
|
||||
|
||||
describe 'starts_at' do
|
||||
context 'when ends_at is present' do
|
||||
subject { Fabricate.build :announcement, ends_at: 1.day.ago }
|
||||
|
||||
it { is_expected.to validate_presence_of(:starts_at) }
|
||||
end
|
||||
|
||||
context 'when ends_at is missing' do
|
||||
subject { Fabricate.build :announcement, ends_at: nil }
|
||||
|
||||
it { is_expected.to_not validate_presence_of(:starts_at) }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -4,20 +4,85 @@ require 'rails_helper'
|
|||
|
||||
RSpec.describe Appeal do
|
||||
describe 'Validations' do
|
||||
it 'validates text length is under limit' do
|
||||
appeal = Fabricate.build(
|
||||
:appeal,
|
||||
strike: Fabricate(:account_warning),
|
||||
text: 'a' * described_class::TEXT_LENGTH_LIMIT * 2
|
||||
)
|
||||
subject { Fabricate.build :appeal, strike: Fabricate(:account_warning) }
|
||||
|
||||
expect(appeal).to_not be_valid
|
||||
expect(appeal).to model_have_error_on_field(:text)
|
||||
it { is_expected.to validate_length_of(:text).is_at_most(described_class::TEXT_LENGTH_LIMIT) }
|
||||
|
||||
context 'with a strike created too long ago' do
|
||||
let(:strike) { Fabricate.build :account_warning, created_at: 100.days.ago }
|
||||
|
||||
it { is_expected.to_not allow_values(strike).for(:strike).against(:base).on(:create) }
|
||||
end
|
||||
end
|
||||
|
||||
describe 'scopes' do
|
||||
describe 'approved' do
|
||||
describe 'Query methods' do
|
||||
describe '#pending?' do
|
||||
subject { Fabricate.build :appeal, approved_at:, rejected_at: }
|
||||
|
||||
context 'with not approved and not rejected' do
|
||||
let(:approved_at) { nil }
|
||||
let(:rejected_at) { nil }
|
||||
|
||||
it { expect(subject).to be_pending }
|
||||
end
|
||||
|
||||
context 'with approved and rejected' do
|
||||
let(:approved_at) { 1.day.ago }
|
||||
let(:rejected_at) { 1.day.ago }
|
||||
|
||||
it { expect(subject).to_not be_pending }
|
||||
end
|
||||
|
||||
context 'with approved and not rejected' do
|
||||
let(:approved_at) { 1.day.ago }
|
||||
let(:rejected_at) { nil }
|
||||
|
||||
it { expect(subject).to_not be_pending }
|
||||
end
|
||||
|
||||
context 'with not approved and rejected' do
|
||||
let(:approved_at) { nil }
|
||||
let(:rejected_at) { 1.day.ago }
|
||||
|
||||
it { expect(subject).to_not be_pending }
|
||||
end
|
||||
end
|
||||
|
||||
describe '#approved?' do
|
||||
subject { Fabricate.build :appeal, approved_at: }
|
||||
|
||||
context 'with not approved' do
|
||||
let(:approved_at) { nil }
|
||||
|
||||
it { expect(subject).to_not be_approved }
|
||||
end
|
||||
|
||||
context 'with approved' do
|
||||
let(:approved_at) { 1.day.ago }
|
||||
|
||||
it { expect(subject).to be_approved }
|
||||
end
|
||||
end
|
||||
|
||||
describe '#rejected?' do
|
||||
subject { Fabricate.build :appeal, rejected_at: }
|
||||
|
||||
context 'with not rejected' do
|
||||
let(:rejected_at) { nil }
|
||||
|
||||
it { expect(subject).to_not be_rejected }
|
||||
end
|
||||
|
||||
context 'with rejected' do
|
||||
let(:rejected_at) { 1.day.ago }
|
||||
|
||||
it { expect(subject).to be_rejected }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'Scopes' do
|
||||
describe '.approved' do
|
||||
let(:approved_appeal) { Fabricate(:appeal, approved_at: 10.days.ago) }
|
||||
let(:not_approved_appeal) { Fabricate(:appeal, approved_at: nil) }
|
||||
|
||||
|
@ -27,7 +92,7 @@ RSpec.describe Appeal do
|
|||
end
|
||||
end
|
||||
|
||||
describe 'rejected' do
|
||||
describe '.rejected' do
|
||||
let(:rejected_appeal) { Fabricate(:appeal, rejected_at: 10.days.ago) }
|
||||
let(:not_rejected_appeal) { Fabricate(:appeal, rejected_at: nil) }
|
||||
|
||||
|
@ -37,7 +102,7 @@ RSpec.describe Appeal do
|
|||
end
|
||||
end
|
||||
|
||||
describe 'pending' do
|
||||
describe '.pending' do
|
||||
let(:approved_appeal) { Fabricate(:appeal, approved_at: 10.days.ago) }
|
||||
let(:rejected_appeal) { Fabricate(:appeal, rejected_at: 10.days.ago) }
|
||||
let(:pending_appeal) { Fabricate(:appeal, rejected_at: nil, approved_at: nil) }
|
||||
|
|
65
spec/models/concerns/account/suspensions_spec.rb
Normal file
65
spec/models/concerns/account/suspensions_spec.rb
Normal file
|
@ -0,0 +1,65 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe Account::Suspensions do
|
||||
subject { Fabricate(:account) }
|
||||
|
||||
describe '.suspended' do
|
||||
let!(:suspended_account) { Fabricate :account, suspended: true }
|
||||
|
||||
before { Fabricate :account, suspended: false }
|
||||
|
||||
it 'returns accounts that are suspended' do
|
||||
expect(Account.suspended)
|
||||
.to contain_exactly(suspended_account)
|
||||
end
|
||||
end
|
||||
|
||||
describe '#suspended_locally?' do
|
||||
context 'when the account is not suspended' do
|
||||
it { is_expected.to_not be_suspended_locally }
|
||||
end
|
||||
|
||||
context 'when the account is suspended locally' do
|
||||
before { subject.update!(suspended_at: 1.day.ago, suspension_origin: :local) }
|
||||
|
||||
it { is_expected.to be_suspended_locally }
|
||||
end
|
||||
|
||||
context 'when the account is suspended remotely' do
|
||||
before { subject.update!(suspended_at: 1.day.ago, suspension_origin: :remote) }
|
||||
|
||||
it { is_expected.to_not be_suspended_locally }
|
||||
end
|
||||
end
|
||||
|
||||
describe '#suspend!' do
|
||||
it 'marks the account as suspended and creates a deletion request' do
|
||||
expect { subject.suspend! }
|
||||
.to change(subject, :suspended?).from(false).to(true)
|
||||
.and change(subject, :suspended_locally?).from(false).to(true)
|
||||
.and(change { AccountDeletionRequest.exists?(account: subject) }.from(false).to(true))
|
||||
end
|
||||
|
||||
context 'when the account is of a local user' do
|
||||
subject { local_user_account }
|
||||
|
||||
let!(:local_user_account) { Fabricate(:user, email: 'foo+bar@domain.org').account }
|
||||
|
||||
it 'creates a canonical domain block' do
|
||||
expect { subject.suspend! }
|
||||
.to change { CanonicalEmailBlock.block?(subject.user_email) }.from(false).to(true)
|
||||
end
|
||||
|
||||
context 'when a canonical domain block already exists for that email' do
|
||||
before { Fabricate(:canonical_email_block, email: subject.user_email) }
|
||||
|
||||
it 'does not raise an error' do
|
||||
expect { subject.suspend! }
|
||||
.to_not raise_error
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -6,11 +6,10 @@ RSpec.describe DomainAllow do
|
|||
describe 'Validations' do
|
||||
it { is_expected.to validate_presence_of(:domain) }
|
||||
|
||||
it 'is invalid if the same normalized domain already exists' do
|
||||
_domain_allow = Fabricate(:domain_allow, domain: 'にゃん')
|
||||
domain_allow_with_normalized_value = Fabricate.build(:domain_allow, domain: 'xn--r9j5b5b')
|
||||
domain_allow_with_normalized_value.valid?
|
||||
expect(domain_allow_with_normalized_value).to model_have_error_on_field(:domain)
|
||||
context 'when a normalized domain exists' do
|
||||
before { Fabricate(:domain_allow, domain: 'にゃん') }
|
||||
|
||||
it { is_expected.to_not allow_value('xn--r9j5b5b').for(:domain) }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -3,27 +3,26 @@
|
|||
require 'rails_helper'
|
||||
|
||||
RSpec.describe Follow do
|
||||
let(:alice) { Fabricate(:account, username: 'alice') }
|
||||
let(:bob) { Fabricate(:account, username: 'bob') }
|
||||
|
||||
describe 'validations' do
|
||||
subject { described_class.new(account: alice, target_account: bob, rate_limit: true) }
|
||||
|
||||
describe 'Associations' do
|
||||
it { is_expected.to belong_to(:account).required }
|
||||
it { is_expected.to belong_to(:target_account).required }
|
||||
end
|
||||
|
||||
it 'is invalid if account already follows too many people' do
|
||||
alice.update(following_count: FollowLimitValidator::LIMIT)
|
||||
describe 'Validations' do
|
||||
subject { Fabricate.build :follow, rate_limit: true }
|
||||
|
||||
expect(subject).to_not be_valid
|
||||
expect(subject).to model_have_error_on_field(:base)
|
||||
let(:account) { Fabricate(:account) }
|
||||
|
||||
context 'when account follows too many people' do
|
||||
before { account.update(following_count: FollowLimitValidator::LIMIT) }
|
||||
|
||||
it { is_expected.to_not allow_value(account).for(:account).against(:base) }
|
||||
end
|
||||
|
||||
it 'is valid if account is only on the brink of following too many people' do
|
||||
alice.update(following_count: FollowLimitValidator::LIMIT - 1)
|
||||
context 'when account is on brink of following too many people' do
|
||||
before { account.update(following_count: FollowLimitValidator::LIMIT - 1) }
|
||||
|
||||
expect(subject).to be_valid
|
||||
expect(subject).to_not model_have_error_on_field(:base)
|
||||
it { is_expected.to allow_value(account).for(:account).against(:base) }
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -54,4 +53,58 @@ RSpec.describe Follow do
|
|||
expect(account.requested?(target_account)).to be true
|
||||
end
|
||||
end
|
||||
|
||||
describe '#local?' do
|
||||
it { is_expected.to_not be_local }
|
||||
end
|
||||
|
||||
describe 'Callbacks' do
|
||||
describe 'Setting a URI' do
|
||||
context 'when URI exists' do
|
||||
subject { Fabricate.build :follow, uri: 'https://uri/value' }
|
||||
|
||||
it 'does not change' do
|
||||
expect { subject.save }
|
||||
.to not_change(subject, :uri)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when URI is blank' do
|
||||
subject { Fabricate.build :follow, uri: nil }
|
||||
|
||||
it 'populates the value' do
|
||||
expect { subject.save }
|
||||
.to change(subject, :uri).to(be_present)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'Maintaining counters' do
|
||||
subject { Fabricate.build :follow, account:, target_account: }
|
||||
|
||||
let(:account) { Fabricate :account }
|
||||
let(:target_account) { Fabricate :account }
|
||||
|
||||
before do
|
||||
account.account_stat.update following_count: 123
|
||||
target_account.account_stat.update followers_count: 123
|
||||
end
|
||||
|
||||
describe 'saving the follow' do
|
||||
it 'increments counters' do
|
||||
expect { subject.save }
|
||||
.to change(account, :following_count).by(1)
|
||||
.and(change(target_account, :followers_count).by(1))
|
||||
end
|
||||
end
|
||||
|
||||
describe 'destroying the follow' do
|
||||
it 'decrements counters' do
|
||||
expect { subject.destroy }
|
||||
.to change(account, :following_count).by(-1)
|
||||
.and(change(target_account, :followers_count).by(-1))
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -3,33 +3,17 @@
|
|||
require 'rails_helper'
|
||||
|
||||
RSpec.describe Form::AdminSettings do
|
||||
describe 'validations' do
|
||||
describe 'Validations' do
|
||||
describe 'site_contact_username' do
|
||||
context 'with no accounts' do
|
||||
it 'is not valid' do
|
||||
setting = described_class.new(site_contact_username: 'Test')
|
||||
setting.valid?
|
||||
|
||||
expect(setting).to model_have_error_on_field(:site_contact_username)
|
||||
end
|
||||
it { is_expected.to_not allow_value('Test').for(:site_contact_username) }
|
||||
end
|
||||
|
||||
context 'with an account' do
|
||||
before { Fabricate(:account, username: 'Glorp') }
|
||||
|
||||
it 'is not valid when account doesnt match' do
|
||||
setting = described_class.new(site_contact_username: 'Test')
|
||||
setting.valid?
|
||||
|
||||
expect(setting).to model_have_error_on_field(:site_contact_username)
|
||||
end
|
||||
|
||||
it 'is valid when account matches' do
|
||||
setting = described_class.new(site_contact_username: 'Glorp')
|
||||
setting.valid?
|
||||
|
||||
expect(setting).to_not model_have_error_on_field(:site_contact_username)
|
||||
end
|
||||
it { is_expected.to_not allow_value('Test').for(:site_contact_username) }
|
||||
it { is_expected.to allow_value('Glorp').for(:site_contact_username) }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -3,18 +3,13 @@
|
|||
require 'rails_helper'
|
||||
|
||||
RSpec.describe IpBlock do
|
||||
describe 'validations' do
|
||||
describe 'Validations' do
|
||||
subject { Fabricate.build :ip_block }
|
||||
|
||||
it { is_expected.to validate_presence_of(:ip) }
|
||||
it { is_expected.to validate_presence_of(:severity) }
|
||||
|
||||
it 'validates ip uniqueness', :aggregate_failures do
|
||||
described_class.create!(ip: '127.0.0.1', severity: :no_access)
|
||||
|
||||
ip_block = described_class.new(ip: '127.0.0.1', severity: :no_access)
|
||||
|
||||
expect(ip_block).to_not be_valid
|
||||
expect(ip_block).to model_have_error_on_field(:ip)
|
||||
end
|
||||
it { is_expected.to validate_uniqueness_of(:ip) }
|
||||
end
|
||||
|
||||
describe '#to_log_human_identifier' do
|
||||
|
|
|
@ -9,26 +9,10 @@ RSpec.describe PreviewCard do
|
|||
end
|
||||
end
|
||||
|
||||
describe 'validations' do
|
||||
describe 'urls' do
|
||||
it 'allows http schemes' do
|
||||
record = described_class.new(url: 'http://example.host/path')
|
||||
|
||||
expect(record).to be_valid
|
||||
end
|
||||
|
||||
it 'allows https schemes' do
|
||||
record = described_class.new(url: 'https://example.host/path')
|
||||
|
||||
expect(record).to be_valid
|
||||
end
|
||||
|
||||
it 'does not allow javascript: schemes' do
|
||||
record = described_class.new(url: 'javascript:alert()')
|
||||
|
||||
expect(record).to_not be_valid
|
||||
expect(record).to model_have_error_on_field(:url)
|
||||
end
|
||||
describe 'Validations' do
|
||||
describe 'url' do
|
||||
it { is_expected.to allow_values('http://example.host/path', 'https://example.host/path').for(:url) }
|
||||
it { is_expected.to_not allow_value('javascript:alert()').for(:url) }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -3,29 +3,24 @@
|
|||
require 'rails_helper'
|
||||
|
||||
RSpec.describe ReportNote do
|
||||
describe 'chronological scope' do
|
||||
it 'returns report notes oldest to newest' do
|
||||
report = Fabricate(:report)
|
||||
note1 = Fabricate(:report_note, report: report)
|
||||
note2 = Fabricate(:report_note, report: report)
|
||||
describe 'Scopes' do
|
||||
describe '.chronological' do
|
||||
it 'returns report notes oldest to newest' do
|
||||
report = Fabricate(:report)
|
||||
note1 = Fabricate(:report_note, report: report)
|
||||
note2 = Fabricate(:report_note, report: report)
|
||||
|
||||
expect(report.notes.chronological).to eq [note1, note2]
|
||||
expect(report.notes.chronological).to eq [note1, note2]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'validations' do
|
||||
it 'is invalid if the content is empty' do
|
||||
report = Fabricate.build(:report_note, content: '')
|
||||
expect(report.valid?).to be false
|
||||
end
|
||||
describe 'Validations' do
|
||||
subject { Fabricate.build :report_note }
|
||||
|
||||
it 'is invalid if content is longer than character limit' do
|
||||
report = Fabricate.build(:report_note, content: comment_over_limit)
|
||||
expect(report.valid?).to be false
|
||||
end
|
||||
|
||||
def comment_over_limit
|
||||
Faker::Lorem.paragraph_by_chars(number: described_class::CONTENT_SIZE_LIMIT * 2)
|
||||
describe 'content' do
|
||||
it { is_expected.to_not allow_value('').for(:content) }
|
||||
it { is_expected.to validate_length_of(:content).is_at_most(described_class::CONTENT_SIZE_LIMIT) }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -3,53 +3,17 @@
|
|||
require 'rails_helper'
|
||||
|
||||
RSpec.describe WebauthnCredential do
|
||||
describe 'validations' do
|
||||
describe 'Validations' do
|
||||
subject { Fabricate.build :webauthn_credential }
|
||||
|
||||
it { is_expected.to validate_presence_of(:external_id) }
|
||||
it { is_expected.to validate_presence_of(:public_key) }
|
||||
it { is_expected.to validate_presence_of(:nickname) }
|
||||
it { is_expected.to validate_presence_of(:sign_count) }
|
||||
|
||||
it 'is invalid if already exist a webauthn credential with the same external id' do
|
||||
Fabricate(:webauthn_credential, external_id: '_Typ0ygudDnk9YUVWLQayw')
|
||||
new_webauthn_credential = Fabricate.build(:webauthn_credential, external_id: '_Typ0ygudDnk9YUVWLQayw')
|
||||
it { is_expected.to validate_uniqueness_of(:external_id) }
|
||||
it { is_expected.to validate_uniqueness_of(:nickname).scoped_to(:user_id) }
|
||||
|
||||
new_webauthn_credential.valid?
|
||||
|
||||
expect(new_webauthn_credential).to model_have_error_on_field(:external_id)
|
||||
end
|
||||
|
||||
it 'is invalid if user already registered a webauthn credential with the same nickname' do
|
||||
user = Fabricate(:user)
|
||||
Fabricate(:webauthn_credential, user_id: user.id, nickname: 'USB Key')
|
||||
new_webauthn_credential = Fabricate.build(:webauthn_credential, user_id: user.id, nickname: 'USB Key')
|
||||
|
||||
new_webauthn_credential.valid?
|
||||
|
||||
expect(new_webauthn_credential).to model_have_error_on_field(:nickname)
|
||||
end
|
||||
|
||||
it 'is invalid if sign_count is not a number' do
|
||||
webauthn_credential = Fabricate.build(:webauthn_credential, sign_count: 'invalid sign_count')
|
||||
|
||||
webauthn_credential.valid?
|
||||
|
||||
expect(webauthn_credential).to model_have_error_on_field(:sign_count)
|
||||
end
|
||||
|
||||
it 'is invalid if sign_count is negative number' do
|
||||
webauthn_credential = Fabricate.build(:webauthn_credential, sign_count: -1)
|
||||
|
||||
webauthn_credential.valid?
|
||||
|
||||
expect(webauthn_credential).to model_have_error_on_field(:sign_count)
|
||||
end
|
||||
|
||||
it 'is invalid if sign_count is greater than the limit' do
|
||||
webauthn_credential = Fabricate.build(:webauthn_credential, sign_count: (described_class::SIGN_COUNT_LIMIT * 2))
|
||||
|
||||
webauthn_credential.valid?
|
||||
|
||||
expect(webauthn_credential).to model_have_error_on_field(:sign_count)
|
||||
end
|
||||
it { is_expected.to validate_numericality_of(:sign_count).only_integer.is_greater_than_or_equal_to(0).is_less_than_or_equal_to(described_class::SIGN_COUNT_LIMIT - 1) }
|
||||
end
|
||||
end
|
||||
|
|
25
spec/requests/activitypub/likes_spec.rb
Normal file
25
spec/requests/activitypub/likes_spec.rb
Normal file
|
@ -0,0 +1,25 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe 'ActivityPub Likes' do
|
||||
let(:account) { Fabricate(:account) }
|
||||
let(:status) { Fabricate :status, account: account }
|
||||
|
||||
before { Fabricate :favourite, status: status }
|
||||
|
||||
describe 'GET /accounts/:account_username/statuses/:status_id/likes' do
|
||||
it 'returns http success and activity json types and correct items count' do
|
||||
get account_status_likes_path(account, status)
|
||||
|
||||
expect(response)
|
||||
.to have_http_status(200)
|
||||
expect(response.media_type)
|
||||
.to eq 'application/activity+json'
|
||||
|
||||
expect(response.parsed_body)
|
||||
.to include(type: 'Collection')
|
||||
.and include(totalItems: 1)
|
||||
end
|
||||
end
|
||||
end
|
25
spec/requests/activitypub/shares_spec.rb
Normal file
25
spec/requests/activitypub/shares_spec.rb
Normal file
|
@ -0,0 +1,25 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe 'ActivityPub Shares' do
|
||||
let(:account) { Fabricate(:account) }
|
||||
let(:status) { Fabricate :status, account: account }
|
||||
|
||||
before { Fabricate :status, reblog: status }
|
||||
|
||||
describe 'GET /accounts/:account_username/statuses/:status_id/shares' do
|
||||
it 'returns http success and activity json types and correct items count' do
|
||||
get account_status_shares_path(account, status)
|
||||
|
||||
expect(response)
|
||||
.to have_http_status(200)
|
||||
expect(response.media_type)
|
||||
.to eq 'application/activity+json'
|
||||
|
||||
expect(response.parsed_body)
|
||||
.to include(type: 'Collection')
|
||||
.and include(totalItems: 1)
|
||||
end
|
||||
end
|
||||
end
|
36
spec/requests/api/v1/domain_blocks/previews_spec.rb
Normal file
36
spec/requests/api/v1/domain_blocks/previews_spec.rb
Normal file
|
@ -0,0 +1,36 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe 'Domain Blocks Previews API' do
|
||||
let(:user) { Fabricate(:user) }
|
||||
let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: scopes) }
|
||||
let(:scopes) { 'write:blocks' }
|
||||
let(:headers) { { 'Authorization' => "Bearer #{token.token}" } }
|
||||
let(:account) { Fabricate(:account, user: user) }
|
||||
|
||||
describe 'GET /api/v1/domain_blocks/preview' do
|
||||
subject { get '/api/v1/domain_blocks/preview', params: { domain: domain }, headers: headers }
|
||||
|
||||
let(:domain) { 'host.example' }
|
||||
|
||||
before do
|
||||
Fabricate :follow, account: account, target_account: Fabricate(:account, domain: domain)
|
||||
Fabricate :follow, target_account: account, account: Fabricate(:account, domain: domain)
|
||||
end
|
||||
|
||||
it_behaves_like 'forbidden for wrong scope', 'write:statuses'
|
||||
|
||||
it 'returns http success and follower counts' do
|
||||
subject
|
||||
|
||||
expect(response)
|
||||
.to have_http_status(200)
|
||||
expect(response.content_type)
|
||||
.to start_with('application/json')
|
||||
expect(response.parsed_body)
|
||||
.to include(followers_count: 1)
|
||||
.and include(following_count: 1)
|
||||
end
|
||||
end
|
||||
end
|
55
spec/requests/api/web/push_subscriptions_spec.rb
Normal file
55
spec/requests/api/web/push_subscriptions_spec.rb
Normal file
|
@ -0,0 +1,55 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe 'API Web Push Subscriptions' do
|
||||
describe 'DELETE /api/web/push_subscriptions/:id' do
|
||||
subject { delete api_web_push_subscription_path(token) }
|
||||
|
||||
context 'when the subscription exists' do
|
||||
let!(:web_push_subscription) do
|
||||
Fabricate(:web_push_subscription)
|
||||
end
|
||||
let(:token) do
|
||||
web_push_subscription.generate_token_for(:unsubscribe)
|
||||
end
|
||||
|
||||
it 'deletes the subscription' do
|
||||
expect { subject }
|
||||
.to change(Web::PushSubscription, :count).by(-1)
|
||||
|
||||
expect(response).to have_http_status(200)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when the subscription does not exist' do
|
||||
let(:web_push_subscription) do
|
||||
Fabricate(:web_push_subscription)
|
||||
end
|
||||
let(:token) do
|
||||
web_push_subscription.generate_token_for(:unsubscribe)
|
||||
end
|
||||
|
||||
before do
|
||||
token # memoize before destroying the record
|
||||
web_push_subscription.destroy!
|
||||
end
|
||||
|
||||
it 'does nothing' do
|
||||
subject
|
||||
|
||||
expect(response).to have_http_status(200)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when the token is invalid' do
|
||||
let(:token) { 'invalid--invalid' }
|
||||
|
||||
it 'does nothing' do
|
||||
subject
|
||||
|
||||
expect(response).to have_http_status(200)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,7 +1,7 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
module ProfileStories
|
||||
attr_reader :bob, :alice, :alice_bio
|
||||
attr_reader :bob
|
||||
|
||||
def fill_in_auth_details(email, password)
|
||||
fill_in 'user_email', with: email
|
||||
|
@ -32,18 +32,6 @@ module ProfileStories
|
|||
bob.update!(role: UserRole.find_by!(name: 'Admin'))
|
||||
end
|
||||
|
||||
def with_alice_as_local_user
|
||||
@alice_bio = '@alice and @bob are fictional characters commonly used as' \
|
||||
'placeholder names in #cryptology, as well as #science and' \
|
||||
'engineering 📖 literature. Not affiliated with @pepe.'
|
||||
|
||||
@alice = Fabricate(
|
||||
:user,
|
||||
email: 'alice@example.com', password: password, confirmed_at: confirmed_at,
|
||||
account: Fabricate(:account, username: 'alice', note: @alice_bio)
|
||||
)
|
||||
end
|
||||
|
||||
def confirmed_at
|
||||
@confirmed_at ||= Time.zone.now
|
||||
end
|
||||
|
|
|
@ -11,10 +11,10 @@ RSpec.describe 'Profile' do
|
|||
|
||||
before do
|
||||
as_a_logged_in_user
|
||||
with_alice_as_local_user
|
||||
Fabricate(:user, account: Fabricate(:account, username: 'alice'))
|
||||
end
|
||||
|
||||
it 'I can view Annes public account' do
|
||||
it 'I can view public account page for Alice' do
|
||||
visit account_path('alice')
|
||||
|
||||
expect(subject).to have_title("alice (@alice@#{local_domain})")
|
||||
|
|
|
@ -7,9 +7,7 @@ RSpec.describe AccountRefreshWorker do
|
|||
let(:service) { instance_double(ResolveAccountService, call: true) }
|
||||
|
||||
describe '#perform' do
|
||||
before do
|
||||
allow(ResolveAccountService).to receive(:new).and_return(service)
|
||||
end
|
||||
before { stub_service }
|
||||
|
||||
context 'when account does not exist' do
|
||||
it 'returns immediately without processing' do
|
||||
|
@ -48,5 +46,11 @@ RSpec.describe AccountRefreshWorker do
|
|||
(Account::BACKGROUND_REFRESH_INTERVAL + 3.days).ago
|
||||
end
|
||||
end
|
||||
|
||||
def stub_service
|
||||
allow(ResolveAccountService)
|
||||
.to receive(:new)
|
||||
.and_return(service)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -0,0 +1,33 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe ActivityPub::FollowersSynchronizationWorker do
|
||||
let(:worker) { described_class.new }
|
||||
let(:service) { instance_double(ActivityPub::SynchronizeFollowersService, call: true) }
|
||||
|
||||
describe '#perform' do
|
||||
before { stub_service }
|
||||
|
||||
let(:account) { Fabricate(:account, domain: 'host.example') }
|
||||
let(:url) { 'https://sync.url' }
|
||||
|
||||
it 'sends the status to the service' do
|
||||
worker.perform(account.id, url)
|
||||
|
||||
expect(service).to have_received(:call).with(account, url)
|
||||
end
|
||||
|
||||
it 'returns nil for non-existent record' do
|
||||
result = worker.perform(123_123_123, url)
|
||||
|
||||
expect(result).to be(true)
|
||||
end
|
||||
end
|
||||
|
||||
def stub_service
|
||||
allow(ActivityPub::SynchronizeFollowersService)
|
||||
.to receive(:new)
|
||||
.and_return(service)
|
||||
end
|
||||
end
|
|
@ -6,8 +6,30 @@ RSpec.describe PushConversationWorker do
|
|||
let(:worker) { described_class.new }
|
||||
|
||||
describe 'perform' do
|
||||
it 'runs without error for missing record' do
|
||||
expect { worker.perform(nil) }.to_not raise_error
|
||||
context 'with missing values' do
|
||||
it 'runs without error' do
|
||||
expect { worker.perform(nil) }
|
||||
.to_not raise_error
|
||||
end
|
||||
end
|
||||
|
||||
context 'with valid records' do
|
||||
let(:account_conversation) { Fabricate :account_conversation }
|
||||
|
||||
before { allow(redis).to receive(:publish) }
|
||||
|
||||
it 'pushes message to timeline' do
|
||||
expect { worker.perform(account_conversation.id) }
|
||||
.to_not raise_error
|
||||
|
||||
expect(redis)
|
||||
.to have_received(:publish)
|
||||
.with(redis_key, anything)
|
||||
end
|
||||
|
||||
def redis_key
|
||||
"timeline:direct:#{account_conversation.account_id}"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -6,11 +6,31 @@ RSpec.describe PushUpdateWorker do
|
|||
let(:worker) { described_class.new }
|
||||
|
||||
describe 'perform' do
|
||||
it 'runs without error for missing record' do
|
||||
account_id = nil
|
||||
status_id = nil
|
||||
context 'with missing values' do
|
||||
it 'runs without error' do
|
||||
expect { worker.perform(nil, nil) }
|
||||
.to_not raise_error
|
||||
end
|
||||
end
|
||||
|
||||
expect { worker.perform(account_id, status_id) }.to_not raise_error
|
||||
context 'with valid records' do
|
||||
let(:account) { Fabricate :account }
|
||||
let(:status) { Fabricate :status }
|
||||
|
||||
before { allow(redis).to receive(:publish) }
|
||||
|
||||
it 'pushes message to timeline' do
|
||||
expect { worker.perform(account.id, status.id) }
|
||||
.to_not raise_error
|
||||
|
||||
expect(redis)
|
||||
.to have_received(:publish)
|
||||
.with(redis_key, anything)
|
||||
end
|
||||
|
||||
def redis_key
|
||||
"timeline:#{account.id}"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
38
spec/workers/remote_account_refresh_worker_spec.rb
Normal file
38
spec/workers/remote_account_refresh_worker_spec.rb
Normal file
|
@ -0,0 +1,38 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe RemoteAccountRefreshWorker do
|
||||
let(:worker) { described_class.new }
|
||||
let(:service) { instance_double(ActivityPub::FetchRemoteAccountService, call: true) }
|
||||
|
||||
describe '#perform' do
|
||||
before { stub_service }
|
||||
|
||||
let(:account) { Fabricate(:account, domain: 'host.example') }
|
||||
|
||||
it 'sends the status to the service' do
|
||||
worker.perform(account.id)
|
||||
|
||||
expect(service).to have_received(:call).with(account.uri)
|
||||
end
|
||||
|
||||
it 'returns nil for non-existent record' do
|
||||
result = worker.perform(123_123_123)
|
||||
|
||||
expect(result).to be_nil
|
||||
end
|
||||
|
||||
it 'returns nil for a local record' do
|
||||
account = Fabricate :account, domain: nil
|
||||
result = worker.perform(account)
|
||||
expect(result).to be_nil
|
||||
end
|
||||
|
||||
def stub_service
|
||||
allow(ActivityPub::FetchRemoteAccountService)
|
||||
.to receive(:new)
|
||||
.and_return(service)
|
||||
end
|
||||
end
|
||||
end
|
|
@ -4,12 +4,35 @@ require 'rails_helper'
|
|||
|
||||
RSpec.describe RemoveFeaturedTagWorker do
|
||||
let(:worker) { described_class.new }
|
||||
let(:service) { instance_double(RemoveFeaturedTagService, call: true) }
|
||||
|
||||
describe 'perform' do
|
||||
it 'runs without error for missing record' do
|
||||
account_id = nil
|
||||
featured_tag_id = nil
|
||||
expect { worker.perform(account_id, featured_tag_id) }.to_not raise_error
|
||||
context 'with missing values' do
|
||||
it 'runs without error' do
|
||||
expect { worker.perform(nil, nil) }
|
||||
.to_not raise_error
|
||||
end
|
||||
end
|
||||
|
||||
context 'with real records' do
|
||||
before { stub_service }
|
||||
|
||||
let(:account) { Fabricate :account }
|
||||
let(:featured_tag) { Fabricate :featured_tag }
|
||||
|
||||
it 'calls the service for processing' do
|
||||
worker.perform(account.id, featured_tag.id)
|
||||
|
||||
expect(service)
|
||||
.to have_received(:call)
|
||||
.with(be_an(Account), be_an(FeaturedTag))
|
||||
end
|
||||
|
||||
def stub_service
|
||||
allow(RemoveFeaturedTagService)
|
||||
.to receive(:new)
|
||||
.and_return(service)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -4,10 +4,34 @@ require 'rails_helper'
|
|||
|
||||
RSpec.describe ResolveAccountWorker do
|
||||
let(:worker) { described_class.new }
|
||||
let(:service) { instance_double(ResolveAccountService, call: true) }
|
||||
|
||||
describe 'perform' do
|
||||
it 'runs without error for missing record' do
|
||||
expect { worker.perform(nil) }.to_not raise_error
|
||||
context 'with missing values' do
|
||||
it 'runs without error' do
|
||||
expect { worker.perform(nil) }
|
||||
.to_not raise_error
|
||||
end
|
||||
end
|
||||
|
||||
context 'with a URI' do
|
||||
before { stub_service }
|
||||
|
||||
let(:uri) { 'https://host/path/value' }
|
||||
|
||||
it 'initiates account resolution' do
|
||||
worker.perform(uri)
|
||||
|
||||
expect(service)
|
||||
.to have_received(:call)
|
||||
.with(uri)
|
||||
end
|
||||
|
||||
def stub_service
|
||||
allow(ResolveAccountService)
|
||||
.to receive(:new)
|
||||
.and_return(service)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -61,6 +61,7 @@ RSpec.describe Web::PushNotificationWorker do
|
|||
'Ttl' => '172800',
|
||||
'Urgency' => 'normal',
|
||||
'Authorization' => 'WebPush jwt.encoded.payload',
|
||||
'Unsubscribe-URL' => %r{/api/web/push_subscriptions/},
|
||||
},
|
||||
body: "+\xB8\xDBT}\u0013\xB6\xDD.\xF9\xB0\xA7\xC8Ҁ\xFD\x99#\xF7\xAC\x83\xA4\xDB,\u001F\xB5\xB9w\x85>\xF7\xADr"
|
||||
)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue