~cytrogen/masto-fe

ref: 685270f3f7ea6d4a8a48ec641e8fdfd9fc2e2d7f masto-fe/spec/lib/activitypub/adapter_spec.rb -rw-r--r-- 3.5 KiB
685270f3 — Claire [Glitch] Fix clicking “Explore” or “Live feeds” column headers to scroll in advanced mode 2 years ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# 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) {}

    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