1
0
mirror of https://github.com/mastodon/mastodon synced 2024-12-03 17:28:19 +09:00

Replace Oj with plain JSON across spec/

This commit is contained in:
Matt Jankowski 2024-10-30 15:27:16 -04:00
parent 46c43d263c
commit c66405cdf4
25 changed files with 79 additions and 79 deletions

View File

@ -35,7 +35,7 @@ RSpec.describe ActivityPub::Activity::Announce do
context 'when sender is followed by a local account' do context 'when sender is followed by a local account' do
before do before do
Fabricate(:account).follow!(sender) Fabricate(:account).follow!(sender)
stub_request(:get, 'https://example.com/actor/hello-world').to_return(body: Oj.dump(unknown_object_json), headers: { 'Content-Type': 'application/activity+json' }) stub_request(:get, 'https://example.com/actor/hello-world').to_return(body: JSON.dump(unknown_object_json), headers: { 'Content-Type': 'application/activity+json' })
subject.perform subject.perform
end end
@ -120,7 +120,7 @@ RSpec.describe ActivityPub::Activity::Announce do
let(:object_json) { 'https://example.com/actor/hello-world' } let(:object_json) { 'https://example.com/actor/hello-world' }
before do before do
stub_request(:get, 'https://example.com/actor/hello-world').to_return(body: Oj.dump(unknown_object_json), headers: { 'Content-Type': 'application/activity+json' }) stub_request(:get, 'https://example.com/actor/hello-world').to_return(body: JSON.dump(unknown_object_json), headers: { 'Content-Type': 'application/activity+json' })
end end
context 'when the relay is enabled' do context 'when the relay is enabled' do

View File

@ -983,7 +983,7 @@ RSpec.describe ActivityPub::Activity::Create do
before do before do
stub_request(:get, object_json[:id]) stub_request(:get, object_json[:id])
.with(headers: { Authorization: "Bearer #{token}" }) .with(headers: { Authorization: "Bearer #{token}" })
.to_return(body: Oj.dump(object_json), headers: { 'Content-Type': 'application/activity+json' }) .to_return(body: JSON.dump(object_json), headers: { 'Content-Type': 'application/activity+json' })
subject.perform subject.perform
end end

View File

@ -12,7 +12,7 @@ RSpec.describe ActivityPub::Dereferencer do
let(:uri) { nil } let(:uri) { nil }
before do before do
stub_request(:get, 'https://example.com/foo').to_return(body: Oj.dump(object), headers: { 'Content-Type' => 'application/activity+json' }) stub_request(:get, 'https://example.com/foo').to_return(body: JSON.dump(object), headers: { 'Content-Type' => 'application/activity+json' })
end end
context 'with a URI' do context 'with a URI' do

View File

@ -522,7 +522,7 @@ RSpec.describe FeedManager do
allow(redis).to receive_messages(publish: nil) allow(redis).to receive_messages(publish: nil)
subject.unpush_from_home(receiver, status) subject.unpush_from_home(receiver, status)
deletion = Oj.dump(event: :delete, payload: status.id.to_s) deletion = JSON.dump(event: :delete, payload: status.id.to_s)
expect(redis).to have_received(:publish).with("timeline:#{receiver.id}", deletion) expect(redis).to have_received(:publish).with("timeline:#{receiver.id}", deletion)
end end
end end

View File

@ -87,7 +87,7 @@ RSpec.describe Mastodon::CLI::Domains do
end end
def json_summary def json_summary
Oj.dump('host.example': { activity: {} }) JSON.dump('host.example': { activity: {} })
end end
end end
end end

View File

@ -8,7 +8,7 @@ RSpec.describe Webfinger do
let!(:webfinger) { { subject: 'acct:alice@example.com', links: [{ rel: 'self', href: 'https://example.com/alice', type: 'application/activity+json' }] } } let!(:webfinger) { { subject: 'acct:alice@example.com', links: [{ rel: 'self', href: 'https://example.com/alice', type: 'application/activity+json' }] } }
it 'correctly parses the response' do it 'correctly parses the response' do
stub_request(:get, 'https://example.com/.well-known/webfinger?resource=acct:alice@example.com').to_return(body: Oj.dump(webfinger), headers: { 'Content-Type': 'application/jrd+json' }) stub_request(:get, 'https://example.com/.well-known/webfinger?resource=acct:alice@example.com').to_return(body: JSON.dump(webfinger), headers: { 'Content-Type': 'application/jrd+json' })
response = described_class.new('acct:alice@example.com').perform response = described_class.new('acct:alice@example.com').perform
@ -20,7 +20,7 @@ RSpec.describe Webfinger do
let!(:webfinger) { { subject: 'acct:alice@example.com', links: [{ rel: 'self', href: 'https://example.com/alice', type: 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"' }] } } let!(:webfinger) { { subject: 'acct:alice@example.com', links: [{ rel: 'self', href: 'https://example.com/alice', type: 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"' }] } }
it 'correctly parses the response' do it 'correctly parses the response' do
stub_request(:get, 'https://example.com/.well-known/webfinger?resource=acct:alice@example.com').to_return(body: Oj.dump(webfinger), headers: { 'Content-Type': 'application/jrd+json' }) stub_request(:get, 'https://example.com/.well-known/webfinger?resource=acct:alice@example.com').to_return(body: JSON.dump(webfinger), headers: { 'Content-Type': 'application/jrd+json' })
response = described_class.new('acct:alice@example.com').perform response = described_class.new('acct:alice@example.com').perform
@ -32,7 +32,7 @@ RSpec.describe Webfinger do
let!(:webfinger) { { subject: 'acct:alice@example.com', links: [{ rel: 'self', href: 'https://example.com/alice', type: 'application/json"' }] } } let!(:webfinger) { { subject: 'acct:alice@example.com', links: [{ rel: 'self', href: 'https://example.com/alice', type: 'application/json"' }] } }
it 'raises an error' do it 'raises an error' do
stub_request(:get, 'https://example.com/.well-known/webfinger?resource=acct:alice@example.com').to_return(body: Oj.dump(webfinger), headers: { 'Content-Type': 'application/jrd+json' }) stub_request(:get, 'https://example.com/.well-known/webfinger?resource=acct:alice@example.com').to_return(body: JSON.dump(webfinger), headers: { 'Content-Type': 'application/jrd+json' })
expect { described_class.new('acct:alice@example.com').perform }.to raise_error(Webfinger::Error) expect { described_class.new('acct:alice@example.com').perform }.to raise_error(Webfinger::Error)
end end

View File

@ -7,7 +7,7 @@ RSpec.describe Webhooks::PayloadRenderer do
let(:event) { Webhooks::EventPresenter.new(type, object) } let(:event) { Webhooks::EventPresenter.new(type, object) }
let(:payload) { ActiveModelSerializers::SerializableResource.new(event, serializer: REST::Admin::WebhookEventSerializer, scope: nil, scope_name: :current_user).as_json } let(:payload) { ActiveModelSerializers::SerializableResource.new(event, serializer: REST::Admin::WebhookEventSerializer, scope: nil, scope_name: :current_user).as_json }
let(:json) { Oj.dump(payload) } let(:json) { JSON.dump(payload) }
describe '#render' do describe '#render' do
context 'when event is account.approved' do context 'when event is account.approved' do

View File

@ -506,7 +506,7 @@ RSpec.describe User do
expect { web_push_subscription.reload } expect { web_push_subscription.reload }
.to raise_error(ActiveRecord::RecordNotFound) .to raise_error(ActiveRecord::RecordNotFound)
expect(redis_pipeline_stub) expect(redis_pipeline_stub)
.to have_received(:publish).with("timeline:access_token:#{access_token.id}", Oj.dump(event: :kill)).once .to have_received(:publish).with("timeline:access_token:#{access_token.id}", JSON.dump(event: :kill)).once
end end
def remove_activated_sessions def remove_activated_sessions

View File

@ -210,7 +210,7 @@ RSpec.describe 'Filters' do
expect(keyword.reload.keyword).to eq 'updated' expect(keyword.reload.keyword).to eq 'updated'
expect(redis).to have_received(:publish).with("timeline:#{user.account.id}", Oj.dump(event: :filters_changed)).once expect(redis).to have_received(:publish).with("timeline:#{user.account.id}", JSON.dump(event: :filters_changed)).once
end end
end end

View File

@ -72,11 +72,11 @@ RSpec.describe ActivityPub::FetchFeaturedCollectionService do
shared_examples 'sets pinned posts' do shared_examples 'sets pinned posts' do
before do before do
stub_request(:get, 'https://example.com/account/pinned/known').to_return(status: 200, body: Oj.dump(status_json_pinned_known), headers: { 'Content-Type': 'application/activity+json' }) stub_request(:get, 'https://example.com/account/pinned/known').to_return(status: 200, body: JSON.dump(status_json_pinned_known), headers: { 'Content-Type': 'application/activity+json' })
stub_request(:get, 'https://example.com/account/pinned/unknown-inlined').to_return(status: 200, body: Oj.dump(status_json_pinned_unknown_inlined), headers: { 'Content-Type': 'application/activity+json' }) stub_request(:get, 'https://example.com/account/pinned/unknown-inlined').to_return(status: 200, body: JSON.dump(status_json_pinned_unknown_inlined), headers: { 'Content-Type': 'application/activity+json' })
stub_request(:get, 'https://example.com/account/pinned/unknown-unreachable').to_return(status: 404) stub_request(:get, 'https://example.com/account/pinned/unknown-unreachable').to_return(status: 404)
stub_request(:get, 'https://example.com/account/pinned/unknown-reachable').to_return(status: 200, body: Oj.dump(status_json_pinned_unknown_reachable), headers: { 'Content-Type': 'application/activity+json' }) stub_request(:get, 'https://example.com/account/pinned/unknown-reachable').to_return(status: 200, body: JSON.dump(status_json_pinned_unknown_reachable), headers: { 'Content-Type': 'application/activity+json' })
stub_request(:get, 'https://example.com/account/collections/featured').to_return(status: 200, body: Oj.dump(featured_with_null), headers: { 'Content-Type': 'application/activity+json' }) stub_request(:get, 'https://example.com/account/collections/featured').to_return(status: 200, body: JSON.dump(featured_with_null), headers: { 'Content-Type': 'application/activity+json' })
subject.call(actor, note: true, hashtag: false) subject.call(actor, note: true, hashtag: false)
end end
@ -94,7 +94,7 @@ RSpec.describe ActivityPub::FetchFeaturedCollectionService do
describe '#call' do describe '#call' do
context 'when the endpoint is a Collection' do context 'when the endpoint is a Collection' do
before do before do
stub_request(:get, actor.featured_collection_url).to_return(status: 200, body: Oj.dump(payload), headers: { 'Content-Type': 'application/activity+json' }) stub_request(:get, actor.featured_collection_url).to_return(status: 200, body: JSON.dump(payload), headers: { 'Content-Type': 'application/activity+json' })
end end
it_behaves_like 'sets pinned posts' it_behaves_like 'sets pinned posts'
@ -111,7 +111,7 @@ RSpec.describe ActivityPub::FetchFeaturedCollectionService do
end end
before do before do
stub_request(:get, actor.featured_collection_url).to_return(status: 200, body: Oj.dump(payload), headers: { 'Content-Type': 'application/activity+json' }) stub_request(:get, actor.featured_collection_url).to_return(status: 200, body: JSON.dump(payload), headers: { 'Content-Type': 'application/activity+json' })
end end
it_behaves_like 'sets pinned posts' it_behaves_like 'sets pinned posts'
@ -120,7 +120,7 @@ RSpec.describe ActivityPub::FetchFeaturedCollectionService do
let(:items) { 'https://example.com/account/pinned/unknown-reachable' } let(:items) { 'https://example.com/account/pinned/unknown-reachable' }
before do before do
stub_request(:get, 'https://example.com/account/pinned/unknown-reachable').to_return(status: 200, body: Oj.dump(status_json_pinned_unknown_reachable), headers: { 'Content-Type': 'application/activity+json' }) stub_request(:get, 'https://example.com/account/pinned/unknown-reachable').to_return(status: 200, body: JSON.dump(status_json_pinned_unknown_reachable), headers: { 'Content-Type': 'application/activity+json' })
subject.call(actor, note: true, hashtag: false) subject.call(actor, note: true, hashtag: false)
end end
@ -147,7 +147,7 @@ RSpec.describe ActivityPub::FetchFeaturedCollectionService do
end end
before do before do
stub_request(:get, actor.featured_collection_url).to_return(status: 200, body: Oj.dump(payload), headers: { 'Content-Type': 'application/activity+json' }) stub_request(:get, actor.featured_collection_url).to_return(status: 200, body: JSON.dump(payload), headers: { 'Content-Type': 'application/activity+json' })
end end
it_behaves_like 'sets pinned posts' it_behaves_like 'sets pinned posts'
@ -156,7 +156,7 @@ RSpec.describe ActivityPub::FetchFeaturedCollectionService do
let(:items) { 'https://example.com/account/pinned/unknown-reachable' } let(:items) { 'https://example.com/account/pinned/unknown-reachable' }
before do before do
stub_request(:get, 'https://example.com/account/pinned/unknown-reachable').to_return(status: 200, body: Oj.dump(status_json_pinned_unknown_reachable), headers: { 'Content-Type': 'application/activity+json' }) stub_request(:get, 'https://example.com/account/pinned/unknown-reachable').to_return(status: 200, body: JSON.dump(status_json_pinned_unknown_reachable), headers: { 'Content-Type': 'application/activity+json' })
subject.call(actor, note: true, hashtag: false) subject.call(actor, note: true, hashtag: false)
end end

View File

@ -38,7 +38,7 @@ RSpec.describe ActivityPub::FetchFeaturedTagsCollectionService do
describe '#call' do describe '#call' do
context 'when the endpoint is a Collection' do context 'when the endpoint is a Collection' do
before do before do
stub_request(:get, collection_url).to_return(status: 200, body: Oj.dump(payload), headers: { 'Content-Type': 'application/activity+json' }) stub_request(:get, collection_url).to_return(status: 200, body: JSON.dump(payload), headers: { 'Content-Type': 'application/activity+json' })
end end
it_behaves_like 'sets featured tags' it_behaves_like 'sets featured tags'
@ -46,7 +46,7 @@ RSpec.describe ActivityPub::FetchFeaturedTagsCollectionService do
context 'when the account already has featured tags' do context 'when the account already has featured tags' do
before do before do
stub_request(:get, collection_url).to_return(status: 200, body: Oj.dump(payload), headers: { 'Content-Type': 'application/activity+json' }) stub_request(:get, collection_url).to_return(status: 200, body: JSON.dump(payload), headers: { 'Content-Type': 'application/activity+json' })
actor.featured_tags.create!(name: 'FoO') actor.featured_tags.create!(name: 'FoO')
actor.featured_tags.create!(name: 'baz') actor.featured_tags.create!(name: 'baz')
@ -67,7 +67,7 @@ RSpec.describe ActivityPub::FetchFeaturedTagsCollectionService do
end end
before do before do
stub_request(:get, collection_url).to_return(status: 200, body: Oj.dump(payload), headers: { 'Content-Type': 'application/activity+json' }) stub_request(:get, collection_url).to_return(status: 200, body: JSON.dump(payload), headers: { 'Content-Type': 'application/activity+json' })
end end
it_behaves_like 'sets featured tags' it_behaves_like 'sets featured tags'
@ -88,7 +88,7 @@ RSpec.describe ActivityPub::FetchFeaturedTagsCollectionService do
end end
before do before do
stub_request(:get, collection_url).to_return(status: 200, body: Oj.dump(payload), headers: { 'Content-Type': 'application/activity+json' }) stub_request(:get, collection_url).to_return(status: 200, body: JSON.dump(payload), headers: { 'Content-Type': 'application/activity+json' })
end end
it_behaves_like 'sets featured tags' it_behaves_like 'sets featured tags'

View File

@ -38,8 +38,8 @@ RSpec.describe ActivityPub::FetchRemoteAccountService do
before do before do
actor[:inbox] = nil actor[:inbox] = nil
stub_request(:get, 'https://example.com/alice').to_return(body: Oj.dump(actor), headers: { 'Content-Type': 'application/activity+json' }) stub_request(:get, 'https://example.com/alice').to_return(body: JSON.dump(actor), headers: { 'Content-Type': 'application/activity+json' })
stub_request(:get, 'https://example.com/.well-known/webfinger?resource=acct:alice@example.com').to_return(body: Oj.dump(webfinger), headers: { 'Content-Type': 'application/jrd+json' }) stub_request(:get, 'https://example.com/.well-known/webfinger?resource=acct:alice@example.com').to_return(body: JSON.dump(webfinger), headers: { 'Content-Type': 'application/jrd+json' })
end end
it 'fetches resource and looks up webfinger and returns nil' do it 'fetches resource and looks up webfinger and returns nil' do
@ -54,8 +54,8 @@ RSpec.describe ActivityPub::FetchRemoteAccountService do
let!(:webfinger) { { subject: 'acct:alice@example.com', links: [{ rel: 'self', href: 'https://example.com/alice', type: 'application/activity+json' }] } } let!(:webfinger) { { subject: 'acct:alice@example.com', links: [{ rel: 'self', href: 'https://example.com/alice', type: 'application/activity+json' }] } }
before do before do
stub_request(:get, 'https://example.com/alice').to_return(body: Oj.dump(actor), headers: { 'Content-Type': 'application/activity+json' }) stub_request(:get, 'https://example.com/alice').to_return(body: JSON.dump(actor), headers: { 'Content-Type': 'application/activity+json' })
stub_request(:get, 'https://example.com/.well-known/webfinger?resource=acct:alice@example.com').to_return(body: Oj.dump(webfinger), headers: { 'Content-Type': 'application/jrd+json' }) stub_request(:get, 'https://example.com/.well-known/webfinger?resource=acct:alice@example.com').to_return(body: JSON.dump(webfinger), headers: { 'Content-Type': 'application/jrd+json' })
end end
it 'fetches resource and looks up webfinger and sets attributes' do it 'fetches resource and looks up webfinger and sets attributes' do
@ -75,9 +75,9 @@ RSpec.describe ActivityPub::FetchRemoteAccountService do
let!(:webfinger) { { subject: 'acct:alice@iscool.af', links: [{ rel: 'self', href: 'https://example.com/alice', type: 'application/activity+json' }] } } let!(:webfinger) { { subject: 'acct:alice@iscool.af', links: [{ rel: 'self', href: 'https://example.com/alice', type: 'application/activity+json' }] } }
before do before do
stub_request(:get, 'https://example.com/alice').to_return(body: Oj.dump(actor), headers: { 'Content-Type': 'application/activity+json' }) stub_request(:get, 'https://example.com/alice').to_return(body: JSON.dump(actor), headers: { 'Content-Type': 'application/activity+json' })
stub_request(:get, 'https://example.com/.well-known/webfinger?resource=acct:alice@example.com').to_return(body: Oj.dump(webfinger), headers: { 'Content-Type': 'application/jrd+json' }) stub_request(:get, 'https://example.com/.well-known/webfinger?resource=acct:alice@example.com').to_return(body: JSON.dump(webfinger), headers: { 'Content-Type': 'application/jrd+json' })
stub_request(:get, 'https://iscool.af/.well-known/webfinger?resource=acct:alice@iscool.af').to_return(body: Oj.dump(webfinger), headers: { 'Content-Type': 'application/jrd+json' }) stub_request(:get, 'https://iscool.af/.well-known/webfinger?resource=acct:alice@iscool.af').to_return(body: JSON.dump(webfinger), headers: { 'Content-Type': 'application/jrd+json' })
end end
it 'fetches resource and looks up webfinger and follows redirection and sets attributes' do it 'fetches resource and looks up webfinger and follows redirection and sets attributes' do
@ -98,8 +98,8 @@ RSpec.describe ActivityPub::FetchRemoteAccountService do
let!(:webfinger) { { subject: 'acct:alice@example.com', links: [{ rel: 'self', href: 'https://example.com/bob', type: 'application/activity+json' }] } } let!(:webfinger) { { subject: 'acct:alice@example.com', links: [{ rel: 'self', href: 'https://example.com/bob', type: 'application/activity+json' }] } }
before do before do
stub_request(:get, 'https://example.com/alice').to_return(body: Oj.dump(actor), headers: { 'Content-Type': 'application/activity+json' }) stub_request(:get, 'https://example.com/alice').to_return(body: JSON.dump(actor), headers: { 'Content-Type': 'application/activity+json' })
stub_request(:get, 'https://example.com/.well-known/webfinger?resource=acct:alice@example.com').to_return(body: Oj.dump(webfinger), headers: { 'Content-Type': 'application/jrd+json' }) stub_request(:get, 'https://example.com/.well-known/webfinger?resource=acct:alice@example.com').to_return(body: JSON.dump(webfinger), headers: { 'Content-Type': 'application/jrd+json' })
end end
it 'fetches resource and looks up webfinger and does not create account' do it 'fetches resource and looks up webfinger and does not create account' do
@ -114,9 +114,9 @@ RSpec.describe ActivityPub::FetchRemoteAccountService do
let!(:webfinger) { { subject: 'acct:alice@iscool.af', links: [{ rel: 'self', href: 'https://example.com/bob', type: 'application/activity+json' }] } } let!(:webfinger) { { subject: 'acct:alice@iscool.af', links: [{ rel: 'self', href: 'https://example.com/bob', type: 'application/activity+json' }] } }
before do before do
stub_request(:get, 'https://example.com/alice').to_return(body: Oj.dump(actor), headers: { 'Content-Type': 'application/activity+json' }) stub_request(:get, 'https://example.com/alice').to_return(body: JSON.dump(actor), headers: { 'Content-Type': 'application/activity+json' })
stub_request(:get, 'https://example.com/.well-known/webfinger?resource=acct:alice@example.com').to_return(body: Oj.dump(webfinger), headers: { 'Content-Type': 'application/jrd+json' }) stub_request(:get, 'https://example.com/.well-known/webfinger?resource=acct:alice@example.com').to_return(body: JSON.dump(webfinger), headers: { 'Content-Type': 'application/jrd+json' })
stub_request(:get, 'https://iscool.af/.well-known/webfinger?resource=acct:alice@iscool.af').to_return(body: Oj.dump(webfinger), headers: { 'Content-Type': 'application/jrd+json' }) stub_request(:get, 'https://iscool.af/.well-known/webfinger?resource=acct:alice@iscool.af').to_return(body: JSON.dump(webfinger), headers: { 'Content-Type': 'application/jrd+json' })
end end
it 'fetches resource and looks up webfinger and follows redirect and does not create account' do it 'fetches resource and looks up webfinger and follows redirect and does not create account' do
@ -130,7 +130,7 @@ RSpec.describe ActivityPub::FetchRemoteAccountService do
context 'with wrong id' do context 'with wrong id' do
it 'does not create account' do it 'does not create account' do
expect(subject.call('https://fake.address/@foo', prefetched_body: Oj.dump(actor))).to be_nil expect(subject.call('https://fake.address/@foo', prefetched_body: JSON.dump(actor))).to be_nil
end end
end end
end end

View File

@ -38,8 +38,8 @@ RSpec.describe ActivityPub::FetchRemoteActorService do
before do before do
actor[:inbox] = nil actor[:inbox] = nil
stub_request(:get, 'https://example.com/alice').to_return(body: Oj.dump(actor), headers: { 'Content-Type': 'application/activity+json' }) stub_request(:get, 'https://example.com/alice').to_return(body: JSON.dump(actor), headers: { 'Content-Type': 'application/activity+json' })
stub_request(:get, 'https://example.com/.well-known/webfinger?resource=acct:alice@example.com').to_return(body: Oj.dump(webfinger), headers: { 'Content-Type': 'application/jrd+json' }) stub_request(:get, 'https://example.com/.well-known/webfinger?resource=acct:alice@example.com').to_return(body: JSON.dump(webfinger), headers: { 'Content-Type': 'application/jrd+json' })
end end
it 'fetches resource and looks up webfinger and returns nil' do it 'fetches resource and looks up webfinger and returns nil' do
@ -54,8 +54,8 @@ RSpec.describe ActivityPub::FetchRemoteActorService do
let!(:webfinger) { { subject: 'acct:alice@example.com', links: [{ rel: 'self', href: 'https://example.com/alice', type: 'application/activity+json' }] } } let!(:webfinger) { { subject: 'acct:alice@example.com', links: [{ rel: 'self', href: 'https://example.com/alice', type: 'application/activity+json' }] } }
before do before do
stub_request(:get, 'https://example.com/alice').to_return(body: Oj.dump(actor), headers: { 'Content-Type': 'application/activity+json' }) stub_request(:get, 'https://example.com/alice').to_return(body: JSON.dump(actor), headers: { 'Content-Type': 'application/activity+json' })
stub_request(:get, 'https://example.com/.well-known/webfinger?resource=acct:alice@example.com').to_return(body: Oj.dump(webfinger), headers: { 'Content-Type': 'application/jrd+json' }) stub_request(:get, 'https://example.com/.well-known/webfinger?resource=acct:alice@example.com').to_return(body: JSON.dump(webfinger), headers: { 'Content-Type': 'application/jrd+json' })
end end
it 'fetches resource and looks up webfinger and sets values' do it 'fetches resource and looks up webfinger and sets values' do
@ -75,9 +75,9 @@ RSpec.describe ActivityPub::FetchRemoteActorService do
let!(:webfinger) { { subject: 'acct:alice@iscool.af', links: [{ rel: 'self', href: 'https://example.com/alice', type: 'application/activity+json' }] } } let!(:webfinger) { { subject: 'acct:alice@iscool.af', links: [{ rel: 'self', href: 'https://example.com/alice', type: 'application/activity+json' }] } }
before do before do
stub_request(:get, 'https://example.com/alice').to_return(body: Oj.dump(actor), headers: { 'Content-Type': 'application/activity+json' }) stub_request(:get, 'https://example.com/alice').to_return(body: JSON.dump(actor), headers: { 'Content-Type': 'application/activity+json' })
stub_request(:get, 'https://example.com/.well-known/webfinger?resource=acct:alice@example.com').to_return(body: Oj.dump(webfinger), headers: { 'Content-Type': 'application/jrd+json' }) stub_request(:get, 'https://example.com/.well-known/webfinger?resource=acct:alice@example.com').to_return(body: JSON.dump(webfinger), headers: { 'Content-Type': 'application/jrd+json' })
stub_request(:get, 'https://iscool.af/.well-known/webfinger?resource=acct:alice@iscool.af').to_return(body: Oj.dump(webfinger), headers: { 'Content-Type': 'application/jrd+json' }) stub_request(:get, 'https://iscool.af/.well-known/webfinger?resource=acct:alice@iscool.af').to_return(body: JSON.dump(webfinger), headers: { 'Content-Type': 'application/jrd+json' })
end end
it 'fetches resource and looks up webfinger and follows redirect and sets values' do it 'fetches resource and looks up webfinger and follows redirect and sets values' do
@ -98,8 +98,8 @@ RSpec.describe ActivityPub::FetchRemoteActorService do
let!(:webfinger) { { subject: 'acct:alice@example.com', links: [{ rel: 'self', href: 'https://example.com/bob', type: 'application/activity+json' }] } } let!(:webfinger) { { subject: 'acct:alice@example.com', links: [{ rel: 'self', href: 'https://example.com/bob', type: 'application/activity+json' }] } }
before do before do
stub_request(:get, 'https://example.com/alice').to_return(body: Oj.dump(actor), headers: { 'Content-Type': 'application/activity+json' }) stub_request(:get, 'https://example.com/alice').to_return(body: JSON.dump(actor), headers: { 'Content-Type': 'application/activity+json' })
stub_request(:get, 'https://example.com/.well-known/webfinger?resource=acct:alice@example.com').to_return(body: Oj.dump(webfinger), headers: { 'Content-Type': 'application/jrd+json' }) stub_request(:get, 'https://example.com/.well-known/webfinger?resource=acct:alice@example.com').to_return(body: JSON.dump(webfinger), headers: { 'Content-Type': 'application/jrd+json' })
end end
it 'fetches resource and looks up webfinger and does not create account' do it 'fetches resource and looks up webfinger and does not create account' do
@ -114,9 +114,9 @@ RSpec.describe ActivityPub::FetchRemoteActorService do
let!(:webfinger) { { subject: 'acct:alice@iscool.af', links: [{ rel: 'self', href: 'https://example.com/bob', type: 'application/activity+json' }] } } let!(:webfinger) { { subject: 'acct:alice@iscool.af', links: [{ rel: 'self', href: 'https://example.com/bob', type: 'application/activity+json' }] } }
before do before do
stub_request(:get, 'https://example.com/alice').to_return(body: Oj.dump(actor), headers: { 'Content-Type': 'application/activity+json' }) stub_request(:get, 'https://example.com/alice').to_return(body: JSON.dump(actor), headers: { 'Content-Type': 'application/activity+json' })
stub_request(:get, 'https://example.com/.well-known/webfinger?resource=acct:alice@example.com').to_return(body: Oj.dump(webfinger), headers: { 'Content-Type': 'application/jrd+json' }) stub_request(:get, 'https://example.com/.well-known/webfinger?resource=acct:alice@example.com').to_return(body: JSON.dump(webfinger), headers: { 'Content-Type': 'application/jrd+json' })
stub_request(:get, 'https://iscool.af/.well-known/webfinger?resource=acct:alice@iscool.af').to_return(body: Oj.dump(webfinger), headers: { 'Content-Type': 'application/jrd+json' }) stub_request(:get, 'https://iscool.af/.well-known/webfinger?resource=acct:alice@iscool.af').to_return(body: JSON.dump(webfinger), headers: { 'Content-Type': 'application/jrd+json' })
end end
it 'fetches resource and looks up webfinger and follows redirect and does not create account' do it 'fetches resource and looks up webfinger and follows redirect and does not create account' do
@ -130,7 +130,7 @@ RSpec.describe ActivityPub::FetchRemoteActorService do
context 'with wrong id' do context 'with wrong id' do
it 'does not create account' do it 'does not create account' do
expect(subject.call('https://fake.address/@foo', prefetched_body: Oj.dump(actor))).to be_nil expect(subject.call('https://fake.address/@foo', prefetched_body: JSON.dump(actor))).to be_nil
end end
end end
end end

View File

@ -50,8 +50,8 @@ RSpec.describe ActivityPub::FetchRemoteKeyService do
end end
before do before do
stub_request(:get, 'https://example.com/alice').to_return(body: Oj.dump(actor), headers: { 'Content-Type': 'application/activity+json' }) stub_request(:get, 'https://example.com/alice').to_return(body: JSON.dump(actor), headers: { 'Content-Type': 'application/activity+json' })
stub_request(:get, 'https://example.com/.well-known/webfinger?resource=acct:alice@example.com').to_return(body: Oj.dump(webfinger), headers: { 'Content-Type': 'application/jrd+json' }) stub_request(:get, 'https://example.com/.well-known/webfinger?resource=acct:alice@example.com').to_return(body: JSON.dump(webfinger), headers: { 'Content-Type': 'application/jrd+json' })
end end
describe '#call' do describe '#call' do
@ -59,7 +59,7 @@ RSpec.describe ActivityPub::FetchRemoteKeyService do
context 'when the key is a sub-object from the actor' do context 'when the key is a sub-object from the actor' do
before do before do
stub_request(:get, public_key_id).to_return(body: Oj.dump(actor), headers: { 'Content-Type': 'application/activity+json' }) stub_request(:get, public_key_id).to_return(body: JSON.dump(actor), headers: { 'Content-Type': 'application/activity+json' })
end end
it 'returns the expected account' do it 'returns the expected account' do
@ -71,7 +71,7 @@ RSpec.describe ActivityPub::FetchRemoteKeyService do
let(:public_key_id) { 'https://example.com/alice-public-key.json' } let(:public_key_id) { 'https://example.com/alice-public-key.json' }
before do before do
stub_request(:get, public_key_id).to_return(body: Oj.dump(key_json.merge({ '@context': ['https://www.w3.org/ns/activitystreams', 'https://w3id.org/security/v1'] })), headers: { 'Content-Type': 'application/activity+json' }) stub_request(:get, public_key_id).to_return(body: JSON.dump(key_json.merge({ '@context': ['https://www.w3.org/ns/activitystreams', 'https://w3id.org/security/v1'] })), headers: { 'Content-Type': 'application/activity+json' })
end end
it 'returns the expected account' do it 'returns the expected account' do
@ -84,7 +84,7 @@ RSpec.describe ActivityPub::FetchRemoteKeyService do
let(:actor_public_key) { 'https://example.com/alice-public-key.json' } let(:actor_public_key) { 'https://example.com/alice-public-key.json' }
before do before do
stub_request(:get, public_key_id).to_return(body: Oj.dump(key_json.merge({ '@context': ['https://www.w3.org/ns/activitystreams', 'https://w3id.org/security/v1'] })), headers: { 'Content-Type': 'application/activity+json' }) stub_request(:get, public_key_id).to_return(body: JSON.dump(key_json.merge({ '@context': ['https://www.w3.org/ns/activitystreams', 'https://w3id.org/security/v1'] })), headers: { 'Content-Type': 'application/activity+json' })
end end
it 'returns the nil' do it 'returns the nil' do

View File

@ -23,13 +23,13 @@ RSpec.describe ActivityPub::FetchRemoteStatusService do
before do before do
stub_request(:get, 'https://foo.bar/watch?v=12345').to_return(status: 404, body: '') stub_request(:get, 'https://foo.bar/watch?v=12345').to_return(status: 404, body: '')
stub_request(:get, object[:id]).to_return(body: Oj.dump(object)) stub_request(:get, object[:id]).to_return(body: JSON.dump(object))
end end
describe '#call' do describe '#call' do
before do before do
existing_status existing_status
subject.call(object[:id], prefetched_body: Oj.dump(object)) subject.call(object[:id], prefetched_body: JSON.dump(object))
end end
context 'with Note object' do context 'with Note object' do
@ -309,7 +309,7 @@ RSpec.describe ActivityPub::FetchRemoteStatusService do
end end
it 'creates statuses but not more than limit allows' do it 'creates statuses but not more than limit allows' do
expect { subject.call(object[:id], prefetched_body: Oj.dump(object)) } expect { subject.call(object[:id], prefetched_body: JSON.dump(object)) }
.to change { sender.statuses.count }.by_at_least(2) .to change { sender.statuses.count }.by_at_least(2)
.and change { sender.statuses.count }.by_at_most(3) .and change { sender.statuses.count }.by_at_most(3)
end end
@ -359,7 +359,7 @@ RSpec.describe ActivityPub::FetchRemoteStatusService do
end end
it 'creates statuses but not more than limit allows' do it 'creates statuses but not more than limit allows' do
expect { subject.call(object[:id], prefetched_body: Oj.dump(object)) } expect { subject.call(object[:id], prefetched_body: JSON.dump(object)) }
.to change { sender.statuses.count }.by_at_least(2) .to change { sender.statuses.count }.by_at_least(2)
.and change { sender.statuses.count }.by_at_most(3) .and change { sender.statuses.count }.by_at_most(3)
end end

View File

@ -58,7 +58,7 @@ RSpec.describe ActivityPub::FetchRepliesService do
context 'when passing the URL to the collection' do context 'when passing the URL to the collection' do
before do before do
stub_request(:get, collection_uri).to_return(status: 200, body: Oj.dump(payload), headers: { 'Content-Type': 'application/activity+json' }) stub_request(:get, collection_uri).to_return(status: 200, body: JSON.dump(payload), headers: { 'Content-Type': 'application/activity+json' })
end end
it 'spawns workers for up to 5 replies on the same server' do it 'spawns workers for up to 5 replies on the same server' do
@ -93,7 +93,7 @@ RSpec.describe ActivityPub::FetchRepliesService do
context 'when passing the URL to the collection' do context 'when passing the URL to the collection' do
before do before do
stub_request(:get, collection_uri).to_return(status: 200, body: Oj.dump(payload), headers: { 'Content-Type': 'application/activity+json' }) stub_request(:get, collection_uri).to_return(status: 200, body: JSON.dump(payload), headers: { 'Content-Type': 'application/activity+json' })
end end
it 'spawns workers for up to 5 replies on the same server' do it 'spawns workers for up to 5 replies on the same server' do
@ -132,7 +132,7 @@ RSpec.describe ActivityPub::FetchRepliesService do
context 'when passing the URL to the collection' do context 'when passing the URL to the collection' do
before do before do
stub_request(:get, collection_uri).to_return(status: 200, body: Oj.dump(payload), headers: { 'Content-Type': 'application/activity+json' }) stub_request(:get, collection_uri).to_return(status: 200, body: JSON.dump(payload), headers: { 'Content-Type': 'application/activity+json' })
end end
it 'spawns workers for up to 5 replies on the same server' do it 'spawns workers for up to 5 replies on the same server' do

View File

@ -21,7 +21,7 @@ RSpec.describe ActivityPub::ProcessCollectionService do
} }
end end
let(:json) { Oj.dump(payload) } let(:json) { JSON.dump(payload) }
describe '#call' do describe '#call' do
context 'when actor is suspended' do context 'when actor is suspended' do

View File

@ -20,7 +20,7 @@ RSpec.describe ActivityPub::ProcessStatusUpdateService do
], ],
} }
end end
let(:json) { Oj.load(Oj.dump(payload)) } let(:json) { JSON.parse(JSON.dump(payload)) }
let(:alice) { Fabricate(:account) } let(:alice) { Fabricate(:account) }
let(:bob) { Fabricate(:account) } let(:bob) { Fabricate(:account) }

View File

@ -53,7 +53,7 @@ RSpec.describe ActivityPub::SynchronizeFollowersService do
describe '#call' do describe '#call' do
context 'when the endpoint is a Collection of actor URIs' do context 'when the endpoint is a Collection of actor URIs' do
before do before do
stub_request(:get, collection_uri).to_return(status: 200, body: Oj.dump(payload), headers: { 'Content-Type': 'application/activity+json' }) stub_request(:get, collection_uri).to_return(status: 200, body: JSON.dump(payload), headers: { 'Content-Type': 'application/activity+json' })
end end
it_behaves_like 'synchronizes followers' it_behaves_like 'synchronizes followers'
@ -70,7 +70,7 @@ RSpec.describe ActivityPub::SynchronizeFollowersService do
end end
before do before do
stub_request(:get, collection_uri).to_return(status: 200, body: Oj.dump(payload), headers: { 'Content-Type': 'application/activity+json' }) stub_request(:get, collection_uri).to_return(status: 200, body: JSON.dump(payload), headers: { 'Content-Type': 'application/activity+json' })
end end
it_behaves_like 'synchronizes followers' it_behaves_like 'synchronizes followers'
@ -91,7 +91,7 @@ RSpec.describe ActivityPub::SynchronizeFollowersService do
end end
before do before do
stub_request(:get, collection_uri).to_return(status: 200, body: Oj.dump(payload), headers: { 'Content-Type': 'application/activity+json' }) stub_request(:get, collection_uri).to_return(status: 200, body: JSON.dump(payload), headers: { 'Content-Type': 'application/activity+json' })
end end
it_behaves_like 'synchronizes followers' it_behaves_like 'synchronizes followers'

View File

@ -56,7 +56,7 @@ RSpec.describe BackupService do
def expect_outbox_export def expect_outbox_export
body = export_json_raw(:outbox) body = export_json_raw(:outbox)
json = Oj.load(body) json = JSON.parse(body)
aggregate_failures do aggregate_failures do
expect(body.scan('@context').count).to eq 1 expect(body.scan('@context').count).to eq 1
@ -93,7 +93,7 @@ RSpec.describe BackupService do
end end
def export_json(type) def export_json(type)
Oj.load(export_json_raw(type)) JSON.parse(export_json_raw(type))
end end
def include_create_item(status) def include_create_item(status)

View File

@ -19,7 +19,7 @@ RSpec.describe FetchRemoteStatusService do
context 'when protocol is :activitypub' do context 'when protocol is :activitypub' do
subject { described_class.new.call(note[:id], prefetched_body: prefetched_body) } subject { described_class.new.call(note[:id], prefetched_body: prefetched_body) }
let(:prefetched_body) { Oj.dump(note) } let(:prefetched_body) { JSON.dump(note) }
before do before do
subject subject

View File

@ -40,7 +40,7 @@ RSpec.describe RemoveStatusService, :inline_jobs do
.to_not include(status.id) .to_not include(status.id)
expect(redis) expect(redis)
.to have_received(:publish).with('timeline:public:media', Oj.dump(event: :delete, payload: status.id.to_s)) .to have_received(:publish).with('timeline:public:media', JSON.dump(event: :delete, payload: status.id.to_s))
expect(delete_delivery(hank, status)) expect(delete_delivery(hank, status))
.to have_been_made.once .to have_been_made.once

View File

@ -103,7 +103,7 @@ RSpec.describe ResolveAccountService do
context 'with a legitimate webfinger redirection' do context 'with a legitimate webfinger redirection' do
before do before do
webfinger = { subject: 'acct:foo@ap.example.com', links: [{ rel: 'self', href: 'https://ap.example.com/users/foo', type: 'application/activity+json' }] } webfinger = { subject: 'acct:foo@ap.example.com', links: [{ rel: 'self', href: 'https://ap.example.com/users/foo', type: 'application/activity+json' }] }
stub_request(:get, 'https://redirected.example.com/.well-known/webfinger?resource=acct:Foo@redirected.example.com').to_return(body: Oj.dump(webfinger), headers: { 'Content-Type': 'application/jrd+json' }) stub_request(:get, 'https://redirected.example.com/.well-known/webfinger?resource=acct:Foo@redirected.example.com').to_return(body: JSON.dump(webfinger), headers: { 'Content-Type': 'application/jrd+json' })
end end
it 'returns new remote account' do it 'returns new remote account' do
@ -121,7 +121,7 @@ RSpec.describe ResolveAccountService do
context 'with a misconfigured redirection' do context 'with a misconfigured redirection' do
before do before do
webfinger = { subject: 'acct:Foo@redirected.example.com', links: [{ rel: 'self', href: 'https://ap.example.com/users/foo', type: 'application/activity+json' }] } webfinger = { subject: 'acct:Foo@redirected.example.com', links: [{ rel: 'self', href: 'https://ap.example.com/users/foo', type: 'application/activity+json' }] }
stub_request(:get, 'https://redirected.example.com/.well-known/webfinger?resource=acct:Foo@redirected.example.com').to_return(body: Oj.dump(webfinger), headers: { 'Content-Type': 'application/jrd+json' }) stub_request(:get, 'https://redirected.example.com/.well-known/webfinger?resource=acct:Foo@redirected.example.com').to_return(body: JSON.dump(webfinger), headers: { 'Content-Type': 'application/jrd+json' })
end end
it 'returns new remote account' do it 'returns new remote account' do
@ -139,9 +139,9 @@ RSpec.describe ResolveAccountService do
context 'with too many webfinger redirections' do context 'with too many webfinger redirections' do
before do before do
webfinger = { subject: 'acct:foo@evil.example.com', links: [{ rel: 'self', href: 'https://ap.example.com/users/foo', type: 'application/activity+json' }] } webfinger = { subject: 'acct:foo@evil.example.com', links: [{ rel: 'self', href: 'https://ap.example.com/users/foo', type: 'application/activity+json' }] }
stub_request(:get, 'https://redirected.example.com/.well-known/webfinger?resource=acct:Foo@redirected.example.com').to_return(body: Oj.dump(webfinger), headers: { 'Content-Type': 'application/jrd+json' }) stub_request(:get, 'https://redirected.example.com/.well-known/webfinger?resource=acct:Foo@redirected.example.com').to_return(body: JSON.dump(webfinger), headers: { 'Content-Type': 'application/jrd+json' })
webfinger2 = { subject: 'acct:foo@ap.example.com', links: [{ rel: 'self', href: 'https://ap.example.com/users/foo', type: 'application/activity+json' }] } webfinger2 = { subject: 'acct:foo@ap.example.com', links: [{ rel: 'self', href: 'https://ap.example.com/users/foo', type: 'application/activity+json' }] }
stub_request(:get, 'https://evil.example.com/.well-known/webfinger?resource=acct:foo@evil.example.com').to_return(body: Oj.dump(webfinger2), headers: { 'Content-Type': 'application/jrd+json' }) stub_request(:get, 'https://evil.example.com/.well-known/webfinger?resource=acct:foo@evil.example.com').to_return(body: JSON.dump(webfinger2), headers: { 'Content-Type': 'application/jrd+json' })
end end
it 'does not return a new remote account' do it 'does not return a new remote account' do
@ -150,7 +150,7 @@ RSpec.describe ResolveAccountService do
end end
context 'with webfinger response subject missing a host value' do context 'with webfinger response subject missing a host value' do
let(:body) { Oj.dump({ subject: 'user@' }) } let(:body) { JSON.dump({ subject: 'user@' }) }
let(:url) { 'https://host.example/.well-known/webfinger?resource=acct:user@host.example' } let(:url) { 'https://host.example/.well-known/webfinger?resource=acct:user@host.example' }
before do before do

View File

@ -82,7 +82,7 @@ RSpec.describe SoftwareUpdateCheckService do
end end
before do before do
stub_request(:get, full_update_check_url).to_return(body: Oj.dump(server_json)) stub_request(:get, full_update_check_url).to_return(body: JSON.dump(server_json))
end end
it 'updates the list of known updates' do it 'updates the list of known updates' do

View File

@ -17,7 +17,7 @@ RSpec.describe ActivityPub::FetchRepliesWorker do
} }
end end
let(:json) { Oj.dump(payload) } let(:json) { JSON.dump(payload) }
describe 'perform' do describe 'perform' do
it 'performs a request if the collection URI is from the same host' do it 'performs a request if the collection URI is from the same host' do