Files
jcoffey-dev 319ed76dbd
Crowdin / Upload translations / upload-translations (push) Skipped
Historical data migration test / test (14-alpine) (push) Canceled after 0s
Historical data migration test / test (15-alpine) (push) Canceled after 0s
Historical data migration test / test (16-alpine) (push) Canceled after 0s
Historical data migration test / test (17-alpine) (push) Canceled after 0s
Bundler Audit / security (push) Canceled after 0s
Haml Linting / lint (push) Canceled after 0s
JavaScript Linting / lint (push) Canceled after 0s
Ruby Linting / lint (push) Canceled after 0s
JavaScript Testing / test (push) Canceled after 0s
Ruby Testing / build (production) (push) Canceled after 0s
Ruby Testing / test (.ruby-version) (push) Canceled after 0s
Ruby Testing / test (3.3) (push) Canceled after 0s
Ruby Testing / test (3.4) (push) Canceled after 0s
Ruby Testing / End to End testing (.ruby-version) (push) Canceled after 0s
Ruby Testing / End to End testing (3.3) (push) Canceled after 0s
Ruby Testing / End to End testing (3.4) (push) Canceled after 0s
Ruby Testing / Elastic Search integration testing (.ruby-version, docker.elastic.co/elasticsearch/elasticsearch:7.17.29) (push) Canceled after 0s
Check i18n / check-i18n (push) Canceled after 0s
CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (javascript) (push) Canceled after 0s
CodeQL / Analyze (ruby) (push) Canceled after 0s
Ruby Testing / Elastic Search integration testing (.ruby-version, opensearchproject/opensearch:2) (push) Canceled after 0s
Ruby Testing / Elastic Search integration testing (3.3, docker.elastic.co/elasticsearch/elasticsearch:7.17.29) (push) Canceled after 0s
Ruby Testing / Elastic Search integration testing (3.4, docker.elastic.co/elasticsearch/elasticsearch:7.17.29) (push) Canceled after 0s
Check formatting / lint (push) Canceled after 0s
CSS Linting / lint (push) Canceled after 0s
Ruby Testing / Elastic Search integration testing (.ruby-version, docker.elastic.co/elasticsearch/elasticsearch:8.19.2) (push) Canceled after 0s
Chromatic / Check for relevant changes (push) Canceled after 0s
Chromatic / Run Chromatic (push) Canceled after 0s
Import Mastodon v4.7.3
Snapshot of upstream tag v4.7.3 (commit 8ff11c2bb7b9f0714e947b10fa3629c6542c7121) from
https://github.com/mastodon/mastodon, unmodified.
2026-10-05 22:03:13 -07:00

99 lines
3.5 KiB
Ruby

# frozen_string_literal: true
require 'rails_helper'
RSpec.describe ActivityPub::Adapter do
before do
test_object_class = Class.new(ActiveModelSerializers::Model) do
attributes :foo
end
stub_const('TestObject', test_object_class)
test_with_basic_context_serializer = Class.new(ActivityPub::Serializer) do
attributes :foo
end
stub_const('TestWithBasicContextSerializer', test_with_basic_context_serializer)
test_with_named_context_serializer = Class.new(ActivityPub::Serializer) do
context :security
attributes :foo
end
stub_const('TestWithNamedContextSerializer', test_with_named_context_serializer)
test_with_nested_named_context_serializer = Class.new(ActivityPub::Serializer) do
attributes :foo
has_one :virtual_object, key: :baz, serializer: TestWithNamedContextSerializer
def virtual_object
object
end
end
stub_const('TestWithNestedNamedContextSerializer', test_with_nested_named_context_serializer)
test_with_context_extension_serializer = Class.new(ActivityPub::Serializer) do
context_extensions :sensitive
attributes :foo
end
stub_const('TestWithContextExtensionSerializer', test_with_context_extension_serializer)
test_with_nested_context_extension_serializer = Class.new(ActivityPub::Serializer) do
context_extensions :manually_approves_followers
attributes :foo
has_one :virtual_object, key: :baz, serializer: TestWithContextExtensionSerializer
def virtual_object
object
end
end
stub_const('TestWithNestedContextExtensionSerializer', test_with_nested_context_extension_serializer)
end
describe '#serializable_hash' do
subject { ActiveModelSerializers::SerializableResource.new(TestObject.new(foo: 'bar'), serializer: serializer_class, adapter: described_class).as_json }
let(:serializer_class) { nil }
context 'when serializer defines no context' do
let(:serializer_class) { TestWithBasicContextSerializer }
it 'renders a basic @context' do
expect(subject).to include({ '@context': 'https://www.w3.org/ns/activitystreams' })
end
end
context 'when serializer defines a named context' do
let(:serializer_class) { TestWithNamedContextSerializer }
it 'renders a @context with both items' do
expect(subject).to include({ '@context': ['https://www.w3.org/ns/activitystreams', 'https://w3id.org/security/v1'] })
end
end
context 'when serializer has children that define a named context' do
let(:serializer_class) { TestWithNestedNamedContextSerializer }
it 'renders a @context with both items' do
expect(subject).to include({ '@context': ['https://www.w3.org/ns/activitystreams', 'https://w3id.org/security/v1'] })
end
end
context 'when serializer defines context extensions' do
let(:serializer_class) { TestWithContextExtensionSerializer }
it 'renders a @context with the extension' do
expect(subject).to include({ '@context': ['https://www.w3.org/ns/activitystreams', { 'sensitive' => 'as:sensitive' }] })
end
end
context 'when serializer has children that define context extensions' do
let(:serializer_class) { TestWithNestedContextExtensionSerializer }
it 'renders a @context with both extensions' do
expect(subject).to include({ '@context': ['https://www.w3.org/ns/activitystreams', { 'manuallyApprovesFollowers' => 'as:manuallyApprovesFollowers', 'sensitive' => 'as:sensitive' }] })
end
end
end
end