blob: 0c873a5c18ae1dc3077912e9cfc0331c6165917c (
plain)
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
|
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe ActivityPub::ReleasesSubscription, type: :model, feature_category: :release_orchestration do
describe 'factory' do
subject { build(:activity_pub_releases_subscription) }
it { is_expected.to be_valid }
end
describe 'associations' do
it { is_expected.to belong_to(:project).optional(false) }
end
describe 'validations' do
it { is_expected.to validate_presence_of(:subscriber_url) }
describe 'subscriber_url' do
subject { build(:activity_pub_releases_subscription) }
it { is_expected.to validate_uniqueness_of(:subscriber_url).case_insensitive.scoped_to([:project_id]) }
it { is_expected.to allow_value("http://example.com/actor").for(:subscriber_url) }
it { is_expected.not_to allow_values("I'm definitely not a URL").for(:subscriber_url) }
end
describe 'subscriber_inbox_url' do
subject { build(:activity_pub_releases_subscription) }
it { is_expected.to validate_uniqueness_of(:subscriber_inbox_url).case_insensitive.scoped_to([:project_id]) }
it { is_expected.to allow_value("http://example.com/actor").for(:subscriber_inbox_url) }
it { is_expected.not_to allow_values("I'm definitely not a URL").for(:subscriber_inbox_url) }
end
describe 'shared_inbox_url' do
subject { build(:activity_pub_releases_subscription) }
it { is_expected.to allow_value("http://example.com/actor").for(:shared_inbox_url) }
it { is_expected.not_to allow_values("I'm definitely not a URL").for(:shared_inbox_url) }
end
describe 'payload' do
it { is_expected.not_to allow_value("string").for(:payload) }
it { is_expected.not_to allow_value(1.0).for(:payload) }
it do
is_expected.to allow_value({
'@context': 'https://www.w3.org/ns/activitystreams',
id: 'https://example.com/actor#follow/1',
type: 'Follow',
actor: 'https://example.com/actor',
object: 'http://localhost/user/project/-/releases'
}).for(:payload)
end
end
end
describe '.find_by_subscriber_url' do
let_it_be(:subscription) { create(:activity_pub_releases_subscription) }
it 'returns a record if arguments match' do
result = described_class.find_by_subscriber_url(subscription.subscriber_url)
expect(result).to eq(subscription)
end
it 'returns a record if arguments match case insensitively' do
result = described_class.find_by_subscriber_url(subscription.subscriber_url.upcase)
expect(result).to eq(subscription)
end
it 'returns nil if project does not match' do
result = described_class.find_by_subscriber_url('I really should not exist')
expect(result).to be(nil)
end
end
end
|