diff --git a/spec/controllers/activitypub/outboxes_controller_spec.rb b/spec/controllers/activitypub/outboxes_controller_spec.rb index 53c4f0c09c..ead231f29f 100644 --- a/spec/controllers/activitypub/outboxes_controller_spec.rb +++ b/spec/controllers/activitypub/outboxes_controller_spec.rb @@ -79,7 +79,7 @@ RSpec.describe ActivityPub::OutboxesController do it 'returns orderedItems with public or unlisted statuses' do expect(body[:orderedItems]).to be_an Array expect(body[:orderedItems].size).to eq 2 - expect(body[:orderedItems].all? { |item| item[:to].include?(ActivityPub::TagManager::COLLECTIONS[:public]) || item[:cc].include?(ActivityPub::TagManager::COLLECTIONS[:public]) }).to be true + expect(body[:orderedItems].all? { |item| targets_public_collection?(item) }).to be true end it_behaves_like 'cacheable response' @@ -132,7 +132,7 @@ RSpec.describe ActivityPub::OutboxesController do json = body_as_json expect(json[:orderedItems]).to be_an Array expect(json[:orderedItems].size).to eq 2 - expect(json[:orderedItems].all? { |item| item[:to].include?(ActivityPub::TagManager::COLLECTIONS[:public]) || item[:cc].include?(ActivityPub::TagManager::COLLECTIONS[:public]) }).to be true + expect(json[:orderedItems].all? { |item| targets_public_collection?(item) }).to be true end it 'returns private Cache-Control header' do @@ -158,7 +158,7 @@ RSpec.describe ActivityPub::OutboxesController do json = body_as_json expect(json[:orderedItems]).to be_an Array expect(json[:orderedItems].size).to eq 3 - expect(json[:orderedItems].all? { |item| item[:to].include?(ActivityPub::TagManager::COLLECTIONS[:public]) || item[:cc].include?(ActivityPub::TagManager::COLLECTIONS[:public]) || item[:to].include?(account_followers_url(account, ActionMailer::Base.default_url_options)) }).to be true + expect(json[:orderedItems].all? { |item| targets_public_collection?(item) || targets_followers_collection?(item, account) }).to be true end it 'returns private Cache-Control header' do @@ -217,4 +217,20 @@ RSpec.describe ActivityPub::OutboxesController do end end end + + private + + def ap_public_collection + ActivityPub::TagManager::COLLECTIONS[:public] + end + + def targets_public_collection?(item) + item[:to].include?(ap_public_collection) || item[:cc].include?(ap_public_collection) + end + + def targets_followers_collection?(item, account) + item[:to].include?( + account_followers_url(account, ActionMailer::Base.default_url_options) + ) + end end diff --git a/spec/controllers/activitypub/replies_controller_spec.rb b/spec/controllers/activitypub/replies_controller_spec.rb index 5fc9698a32..6b5a69d42a 100644 --- a/spec/controllers/activitypub/replies_controller_spec.rb +++ b/spec/controllers/activitypub/replies_controller_spec.rb @@ -84,7 +84,7 @@ RSpec.describe ActivityPub::RepliesController do expect(page_json).to be_a Hash expect(page_json[:items]).to be_an Array expect(page_json[:items].size).to eq 1 - expect(page_json[:items].all? { |item| item[:to].include?(ActivityPub::TagManager::COLLECTIONS[:public]) || item[:cc].include?(ActivityPub::TagManager::COLLECTIONS[:public]) }).to be true + expect(page_json[:items].all? { |item| targets_public_collection?(item) }).to be true end context 'when there are few self-replies' do @@ -117,8 +117,7 @@ RSpec.describe ActivityPub::RepliesController do it 'only inlines items that are local and public or unlisted replies' do inlined_replies = page_json[:items].select { |x| x.is_a?(Hash) } - public_collection = ActivityPub::TagManager::COLLECTIONS[:public] - expect(inlined_replies.all? { |item| item[:to].include?(public_collection) || item[:cc].include?(public_collection) }).to be true + expect(inlined_replies.all? { |item| targets_public_collection?(item) }).to be true expect(inlined_replies.all? { |item| ActivityPub::TagManager.instance.local_uri?(item[:id]) }).to be true end @@ -194,4 +193,14 @@ RSpec.describe ActivityPub::RepliesController do end end end + + private + + def ap_public_collection + ActivityPub::TagManager::COLLECTIONS[:public] + end + + def targets_public_collection?(item) + item[:to].include?(ap_public_collection) || item[:cc].include?(ap_public_collection) + end end