Merge remote-tracking branch 'parent/main' into upstream-20240117
This commit is contained in:
commit
5d79bd078c
150 changed files with 2982 additions and 1485 deletions
|
@ -182,12 +182,9 @@ RSpec.describe ActivityPub::Activity::Create do
|
|||
|
||||
context 'when object publication date is below ISO8601 range' do
|
||||
let(:object_json) do
|
||||
{
|
||||
id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
|
||||
type: 'Note',
|
||||
content: 'Lorem ipsum',
|
||||
published: '-0977-11-03T08:31:22Z',
|
||||
}
|
||||
build_object(
|
||||
published: '-0977-11-03T08:31:22Z'
|
||||
)
|
||||
end
|
||||
|
||||
it 'creates status with a valid creation date', :aggregate_failures do
|
||||
|
@ -204,12 +201,9 @@ RSpec.describe ActivityPub::Activity::Create do
|
|||
|
||||
context 'when object publication date is above ISO8601 range' do
|
||||
let(:object_json) do
|
||||
{
|
||||
id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
|
||||
type: 'Note',
|
||||
content: 'Lorem ipsum',
|
||||
published: '10000-11-03T08:31:22Z',
|
||||
}
|
||||
build_object(
|
||||
published: '10000-11-03T08:31:22Z'
|
||||
)
|
||||
end
|
||||
|
||||
it 'creates status with a valid creation date', :aggregate_failures do
|
||||
|
@ -226,13 +220,10 @@ RSpec.describe ActivityPub::Activity::Create do
|
|||
|
||||
context 'when object has been edited' do
|
||||
let(:object_json) do
|
||||
{
|
||||
id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
|
||||
type: 'Note',
|
||||
content: 'Lorem ipsum',
|
||||
build_object(
|
||||
published: '2022-01-22T15:00:00Z',
|
||||
updated: '2022-01-22T16:00:00Z',
|
||||
}
|
||||
updated: '2022-01-22T16:00:00Z'
|
||||
)
|
||||
end
|
||||
|
||||
it 'creates status with appropriate creation and edition dates', :aggregate_failures do
|
||||
|
@ -252,13 +243,10 @@ RSpec.describe ActivityPub::Activity::Create do
|
|||
|
||||
context 'when object has update date equal to creation date' do
|
||||
let(:object_json) do
|
||||
{
|
||||
id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
|
||||
type: 'Note',
|
||||
content: 'Lorem ipsum',
|
||||
build_object(
|
||||
published: '2022-01-22T15:00:00Z',
|
||||
updated: '2022-01-22T15:00:00Z',
|
||||
}
|
||||
updated: '2022-01-22T15:00:00Z'
|
||||
)
|
||||
end
|
||||
|
||||
it 'creates status and does not mark it as edited' do
|
||||
|
@ -274,11 +262,9 @@ RSpec.describe ActivityPub::Activity::Create do
|
|||
|
||||
context 'with an unknown object type' do
|
||||
let(:object_json) do
|
||||
{
|
||||
id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
|
||||
type: 'Banana',
|
||||
content: 'Lorem ipsum',
|
||||
}
|
||||
build_object(
|
||||
type: 'Banana'
|
||||
)
|
||||
end
|
||||
|
||||
it 'does not create a status' do
|
||||
|
@ -287,13 +273,7 @@ RSpec.describe ActivityPub::Activity::Create do
|
|||
end
|
||||
|
||||
context 'with a standalone' do
|
||||
let(:object_json) do
|
||||
{
|
||||
id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
|
||||
type: 'Note',
|
||||
content: 'Lorem ipsum',
|
||||
}
|
||||
end
|
||||
let(:object_json) { build_object }
|
||||
|
||||
it 'creates status' do
|
||||
expect { subject.perform }.to change(sender.statuses, :count).by(1)
|
||||
|
@ -316,12 +296,9 @@ RSpec.describe ActivityPub::Activity::Create do
|
|||
|
||||
context 'when public with explicit public address' do
|
||||
let(:object_json) do
|
||||
{
|
||||
id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
|
||||
type: 'Note',
|
||||
content: 'Lorem ipsum',
|
||||
to: 'https://www.w3.org/ns/activitystreams#Public',
|
||||
}
|
||||
build_object(
|
||||
to: 'https://www.w3.org/ns/activitystreams#Public'
|
||||
)
|
||||
end
|
||||
|
||||
it 'creates status' do
|
||||
|
@ -336,12 +313,9 @@ RSpec.describe ActivityPub::Activity::Create do
|
|||
|
||||
context 'when public with as:Public' do
|
||||
let(:object_json) do
|
||||
{
|
||||
id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
|
||||
type: 'Note',
|
||||
content: 'Lorem ipsum',
|
||||
to: 'as:Public',
|
||||
}
|
||||
build_object(
|
||||
to: 'as:Public'
|
||||
)
|
||||
end
|
||||
|
||||
it 'creates status' do
|
||||
|
@ -356,12 +330,9 @@ RSpec.describe ActivityPub::Activity::Create do
|
|||
|
||||
context 'when public with Public' do
|
||||
let(:object_json) do
|
||||
{
|
||||
id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
|
||||
type: 'Note',
|
||||
content: 'Lorem ipsum',
|
||||
to: 'Public',
|
||||
}
|
||||
build_object(
|
||||
to: 'Public'
|
||||
)
|
||||
end
|
||||
|
||||
it 'creates status' do
|
||||
|
@ -376,12 +347,9 @@ RSpec.describe ActivityPub::Activity::Create do
|
|||
|
||||
context 'when unlisted with explicit public address' do
|
||||
let(:object_json) do
|
||||
{
|
||||
id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
|
||||
type: 'Note',
|
||||
content: 'Lorem ipsum',
|
||||
cc: 'https://www.w3.org/ns/activitystreams#Public',
|
||||
}
|
||||
build_object(
|
||||
cc: 'https://www.w3.org/ns/activitystreams#Public'
|
||||
)
|
||||
end
|
||||
|
||||
it 'creates status' do
|
||||
|
@ -396,12 +364,9 @@ RSpec.describe ActivityPub::Activity::Create do
|
|||
|
||||
context 'when unlisted with as:Public' do
|
||||
let(:object_json) do
|
||||
{
|
||||
id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
|
||||
type: 'Note',
|
||||
content: 'Lorem ipsum',
|
||||
cc: 'as:Public',
|
||||
}
|
||||
build_object(
|
||||
cc: 'as:Public'
|
||||
)
|
||||
end
|
||||
|
||||
it 'creates status' do
|
||||
|
@ -416,12 +381,9 @@ RSpec.describe ActivityPub::Activity::Create do
|
|||
|
||||
context 'when unlisted with Public' do
|
||||
let(:object_json) do
|
||||
{
|
||||
id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
|
||||
type: 'Note',
|
||||
content: 'Lorem ipsum',
|
||||
cc: 'Public',
|
||||
}
|
||||
build_object(
|
||||
cc: 'Public'
|
||||
)
|
||||
end
|
||||
|
||||
it 'creates status' do
|
||||
|
@ -479,12 +441,9 @@ RSpec.describe ActivityPub::Activity::Create do
|
|||
|
||||
context 'when private' do
|
||||
let(:object_json) do
|
||||
{
|
||||
id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
|
||||
type: 'Note',
|
||||
content: 'Lorem ipsum',
|
||||
to: 'http://example.com/followers',
|
||||
}
|
||||
build_object(
|
||||
to: 'http://example.com/followers'
|
||||
)
|
||||
end
|
||||
|
||||
it 'creates status' do
|
||||
|
@ -499,16 +458,13 @@ RSpec.describe ActivityPub::Activity::Create do
|
|||
|
||||
context 'when private with inlined Collection in audience' do
|
||||
let(:object_json) do
|
||||
{
|
||||
id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
|
||||
type: 'Note',
|
||||
content: 'Lorem ipsum',
|
||||
build_object(
|
||||
to: {
|
||||
type: 'OrderedCollection',
|
||||
id: 'http://example.com/followers',
|
||||
first: 'http://example.com/followers?page=true',
|
||||
},
|
||||
}
|
||||
}
|
||||
)
|
||||
end
|
||||
|
||||
it 'creates status' do
|
||||
|
@ -525,12 +481,9 @@ RSpec.describe ActivityPub::Activity::Create do
|
|||
let(:recipient) { Fabricate(:account) }
|
||||
|
||||
let(:object_json) do
|
||||
{
|
||||
id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
|
||||
type: 'Note',
|
||||
content: 'Lorem ipsum',
|
||||
to: ActivityPub::TagManager.instance.uri_for(recipient),
|
||||
}
|
||||
build_object(
|
||||
to: ActivityPub::TagManager.instance.uri_for(recipient)
|
||||
)
|
||||
end
|
||||
|
||||
it 'creates status with a silent mention' do
|
||||
|
@ -597,16 +550,13 @@ RSpec.describe ActivityPub::Activity::Create do
|
|||
let(:recipient) { Fabricate(:account) }
|
||||
|
||||
let(:object_json) do
|
||||
{
|
||||
id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
|
||||
type: 'Note',
|
||||
content: 'Lorem ipsum',
|
||||
build_object(
|
||||
to: ActivityPub::TagManager.instance.uri_for(recipient),
|
||||
tag: {
|
||||
type: 'Mention',
|
||||
href: ActivityPub::TagManager.instance.uri_for(recipient),
|
||||
},
|
||||
}
|
||||
}
|
||||
)
|
||||
end
|
||||
|
||||
it 'creates status' do
|
||||
|
@ -921,12 +871,9 @@ RSpec.describe ActivityPub::Activity::Create do
|
|||
let(:original_status) { Fabricate(:status) }
|
||||
|
||||
let(:object_json) do
|
||||
{
|
||||
id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
|
||||
type: 'Note',
|
||||
content: 'Lorem ipsum',
|
||||
inReplyTo: ActivityPub::TagManager.instance.uri_for(original_status),
|
||||
}
|
||||
build_object(
|
||||
inReplyTo: ActivityPub::TagManager.instance.uri_for(original_status)
|
||||
)
|
||||
end
|
||||
|
||||
it 'creates status' do
|
||||
|
@ -946,17 +893,14 @@ RSpec.describe ActivityPub::Activity::Create do
|
|||
let(:recipient) { Fabricate(:account) }
|
||||
|
||||
let(:object_json) do
|
||||
{
|
||||
id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
|
||||
type: 'Note',
|
||||
content: 'Lorem ipsum',
|
||||
build_object(
|
||||
tag: [
|
||||
{
|
||||
type: 'Mention',
|
||||
href: ActivityPub::TagManager.instance.uri_for(recipient),
|
||||
},
|
||||
],
|
||||
}
|
||||
]
|
||||
)
|
||||
end
|
||||
|
||||
it 'creates status' do
|
||||
|
@ -971,16 +915,13 @@ RSpec.describe ActivityPub::Activity::Create do
|
|||
|
||||
context 'with mentions missing href' do
|
||||
let(:object_json) do
|
||||
{
|
||||
id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
|
||||
type: 'Note',
|
||||
content: 'Lorem ipsum',
|
||||
build_object(
|
||||
tag: [
|
||||
{
|
||||
type: 'Mention',
|
||||
},
|
||||
],
|
||||
}
|
||||
]
|
||||
)
|
||||
end
|
||||
|
||||
it 'creates status' do
|
||||
|
@ -1301,10 +1242,7 @@ RSpec.describe ActivityPub::Activity::Create do
|
|||
|
||||
context 'with media attachments' do
|
||||
let(:object_json) do
|
||||
{
|
||||
id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
|
||||
type: 'Note',
|
||||
content: 'Lorem ipsum',
|
||||
build_object(
|
||||
attachment: [
|
||||
{
|
||||
type: 'Document',
|
||||
|
@ -1316,8 +1254,8 @@ RSpec.describe ActivityPub::Activity::Create do
|
|||
mediaType: 'image/png',
|
||||
url: 'http://example.com/emoji.png',
|
||||
},
|
||||
],
|
||||
}
|
||||
]
|
||||
)
|
||||
end
|
||||
|
||||
it 'creates status with correctly-ordered media attachments' do
|
||||
|
@ -1333,10 +1271,7 @@ RSpec.describe ActivityPub::Activity::Create do
|
|||
|
||||
context 'with media attachments with long description' do
|
||||
let(:object_json) do
|
||||
{
|
||||
id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
|
||||
type: 'Note',
|
||||
content: 'Lorem ipsum',
|
||||
build_object(
|
||||
attachment: [
|
||||
{
|
||||
type: 'Document',
|
||||
|
@ -1344,8 +1279,8 @@ RSpec.describe ActivityPub::Activity::Create do
|
|||
url: 'http://example.com/attachment.png',
|
||||
name: '*' * MediaAttachment::MAX_DESCRIPTION_LENGTH,
|
||||
},
|
||||
],
|
||||
}
|
||||
]
|
||||
)
|
||||
end
|
||||
|
||||
it 'creates status' do
|
||||
|
@ -1360,10 +1295,7 @@ RSpec.describe ActivityPub::Activity::Create do
|
|||
|
||||
context 'with media attachments with long description as summary' do
|
||||
let(:object_json) do
|
||||
{
|
||||
id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
|
||||
type: 'Note',
|
||||
content: 'Lorem ipsum',
|
||||
build_object(
|
||||
attachment: [
|
||||
{
|
||||
type: 'Document',
|
||||
|
@ -1371,8 +1303,8 @@ RSpec.describe ActivityPub::Activity::Create do
|
|||
url: 'http://example.com/attachment.png',
|
||||
summary: '*' * MediaAttachment::MAX_DESCRIPTION_LENGTH,
|
||||
},
|
||||
],
|
||||
}
|
||||
]
|
||||
)
|
||||
end
|
||||
|
||||
it 'creates status' do
|
||||
|
@ -1387,10 +1319,7 @@ RSpec.describe ActivityPub::Activity::Create do
|
|||
|
||||
context 'with media attachments with focal points' do
|
||||
let(:object_json) do
|
||||
{
|
||||
id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
|
||||
type: 'Note',
|
||||
content: 'Lorem ipsum',
|
||||
build_object(
|
||||
attachment: [
|
||||
{
|
||||
type: 'Document',
|
||||
|
@ -1398,8 +1327,8 @@ RSpec.describe ActivityPub::Activity::Create do
|
|||
url: 'http://example.com/attachment.png',
|
||||
focalPoint: [0.5, -0.7],
|
||||
},
|
||||
],
|
||||
}
|
||||
]
|
||||
)
|
||||
end
|
||||
|
||||
it 'creates status' do
|
||||
|
@ -1414,17 +1343,14 @@ RSpec.describe ActivityPub::Activity::Create do
|
|||
|
||||
context 'with media attachments missing url' do
|
||||
let(:object_json) do
|
||||
{
|
||||
id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
|
||||
type: 'Note',
|
||||
content: 'Lorem ipsum',
|
||||
build_object(
|
||||
attachment: [
|
||||
{
|
||||
type: 'Document',
|
||||
mediaType: 'image/png',
|
||||
},
|
||||
],
|
||||
}
|
||||
]
|
||||
)
|
||||
end
|
||||
|
||||
it 'creates status' do
|
||||
|
@ -1437,18 +1363,15 @@ RSpec.describe ActivityPub::Activity::Create do
|
|||
|
||||
context 'with hashtags' do
|
||||
let(:object_json) do
|
||||
{
|
||||
id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
|
||||
type: 'Note',
|
||||
content: 'Lorem ipsum',
|
||||
build_object(
|
||||
tag: [
|
||||
{
|
||||
type: 'Hashtag',
|
||||
href: 'http://example.com/blah',
|
||||
name: '#test',
|
||||
},
|
||||
],
|
||||
}
|
||||
]
|
||||
)
|
||||
end
|
||||
|
||||
it 'creates status' do
|
||||
|
@ -1463,10 +1386,7 @@ RSpec.describe ActivityPub::Activity::Create do
|
|||
|
||||
context 'with featured hashtags' do
|
||||
let(:object_json) do
|
||||
{
|
||||
id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
|
||||
type: 'Note',
|
||||
content: 'Lorem ipsum',
|
||||
build_object(
|
||||
to: 'https://www.w3.org/ns/activitystreams#Public',
|
||||
tag: [
|
||||
{
|
||||
|
@ -1474,8 +1394,8 @@ RSpec.describe ActivityPub::Activity::Create do
|
|||
href: 'http://example.com/blah',
|
||||
name: '#test',
|
||||
},
|
||||
],
|
||||
}
|
||||
]
|
||||
)
|
||||
end
|
||||
|
||||
before do
|
||||
|
@ -1512,17 +1432,14 @@ RSpec.describe ActivityPub::Activity::Create do
|
|||
|
||||
context 'with hashtags missing name' do
|
||||
let(:object_json) do
|
||||
{
|
||||
id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
|
||||
type: 'Note',
|
||||
content: 'Lorem ipsum',
|
||||
build_object(
|
||||
tag: [
|
||||
{
|
||||
type: 'Hashtag',
|
||||
href: 'http://example.com/blah',
|
||||
},
|
||||
],
|
||||
}
|
||||
]
|
||||
)
|
||||
end
|
||||
|
||||
it 'creates status' do
|
||||
|
@ -1535,18 +1452,15 @@ RSpec.describe ActivityPub::Activity::Create do
|
|||
|
||||
context 'with hashtags invalid name' do
|
||||
let(:object_json) do
|
||||
{
|
||||
id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
|
||||
type: 'Note',
|
||||
content: 'Lorem ipsum',
|
||||
build_object(
|
||||
tag: [
|
||||
{
|
||||
type: 'Hashtag',
|
||||
href: 'http://example.com/blah',
|
||||
name: 'foo, #eh !',
|
||||
},
|
||||
],
|
||||
}
|
||||
]
|
||||
)
|
||||
end
|
||||
|
||||
it 'creates status' do
|
||||
|
@ -1559,9 +1473,7 @@ RSpec.describe ActivityPub::Activity::Create do
|
|||
|
||||
context 'with emojis' do
|
||||
let(:object_json) do
|
||||
{
|
||||
id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
|
||||
type: 'Note',
|
||||
build_object(
|
||||
content: 'Lorem ipsum :tinking:',
|
||||
tag: [
|
||||
{
|
||||
|
@ -1571,8 +1483,8 @@ RSpec.describe ActivityPub::Activity::Create do
|
|||
},
|
||||
name: 'tinking',
|
||||
},
|
||||
],
|
||||
}
|
||||
]
|
||||
)
|
||||
end
|
||||
|
||||
it 'creates status' do
|
||||
|
@ -1587,9 +1499,7 @@ RSpec.describe ActivityPub::Activity::Create do
|
|||
|
||||
context 'with emojis served with invalid content-type' do
|
||||
let(:object_json) do
|
||||
{
|
||||
id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
|
||||
type: 'Note',
|
||||
build_object(
|
||||
content: 'Lorem ipsum :tinkong:',
|
||||
tag: [
|
||||
{
|
||||
|
@ -1599,8 +1509,8 @@ RSpec.describe ActivityPub::Activity::Create do
|
|||
},
|
||||
name: 'tinkong',
|
||||
},
|
||||
],
|
||||
}
|
||||
]
|
||||
)
|
||||
end
|
||||
|
||||
it 'creates status' do
|
||||
|
@ -1615,9 +1525,7 @@ RSpec.describe ActivityPub::Activity::Create do
|
|||
|
||||
context 'with emojis missing name' do
|
||||
let(:object_json) do
|
||||
{
|
||||
id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
|
||||
type: 'Note',
|
||||
build_object(
|
||||
content: 'Lorem ipsum :tinking:',
|
||||
tag: [
|
||||
{
|
||||
|
@ -1626,8 +1534,8 @@ RSpec.describe ActivityPub::Activity::Create do
|
|||
url: 'http://example.com/emoji.png',
|
||||
},
|
||||
},
|
||||
],
|
||||
}
|
||||
]
|
||||
)
|
||||
end
|
||||
|
||||
it 'creates status' do
|
||||
|
@ -1640,17 +1548,15 @@ RSpec.describe ActivityPub::Activity::Create do
|
|||
|
||||
context 'with emojis missing icon' do
|
||||
let(:object_json) do
|
||||
{
|
||||
id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
|
||||
type: 'Note',
|
||||
build_object(
|
||||
content: 'Lorem ipsum :tinking:',
|
||||
tag: [
|
||||
{
|
||||
type: 'Emoji',
|
||||
name: 'tinking',
|
||||
},
|
||||
],
|
||||
}
|
||||
]
|
||||
)
|
||||
end
|
||||
|
||||
it 'creates status' do
|
||||
|
@ -1663,8 +1569,7 @@ RSpec.describe ActivityPub::Activity::Create do
|
|||
|
||||
context 'with poll' do
|
||||
let(:object_json) do
|
||||
{
|
||||
id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
|
||||
build_object(
|
||||
type: 'Question',
|
||||
content: 'Which color was the submarine?',
|
||||
oneOf: [
|
||||
|
@ -1682,8 +1587,8 @@ RSpec.describe ActivityPub::Activity::Create do
|
|||
totalItems: 3,
|
||||
},
|
||||
},
|
||||
],
|
||||
}
|
||||
]
|
||||
)
|
||||
end
|
||||
|
||||
it 'creates status with a poll' do
|
||||
|
@ -1706,12 +1611,10 @@ RSpec.describe ActivityPub::Activity::Create do
|
|||
let!(:local_status) { Fabricate(:status, poll: poll) }
|
||||
|
||||
let(:object_json) do
|
||||
{
|
||||
id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
|
||||
type: 'Note',
|
||||
build_object(
|
||||
name: 'Yellow',
|
||||
inReplyTo: ActivityPub::TagManager.instance.uri_for(local_status),
|
||||
}
|
||||
inReplyTo: ActivityPub::TagManager.instance.uri_for(local_status)
|
||||
).except(:content)
|
||||
end
|
||||
|
||||
it 'adds a vote to the poll with correct uri' do
|
||||
|
@ -1759,12 +1662,10 @@ RSpec.describe ActivityPub::Activity::Create do
|
|||
let!(:local_status) { Fabricate(:status, poll: poll) }
|
||||
|
||||
let(:object_json) do
|
||||
{
|
||||
id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
|
||||
type: 'Note',
|
||||
build_object(
|
||||
name: 'Yellow',
|
||||
inReplyTo: ActivityPub::TagManager.instance.uri_for(local_status),
|
||||
}
|
||||
inReplyTo: ActivityPub::TagManager.instance.uri_for(local_status)
|
||||
).except(:content)
|
||||
end
|
||||
|
||||
it 'does not add a vote to the poll' do
|
||||
|
@ -2509,10 +2410,7 @@ RSpec.describe ActivityPub::Activity::Create do
|
|||
|
||||
context 'with counts' do
|
||||
let(:object_json) do
|
||||
{
|
||||
id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
|
||||
type: 'Note',
|
||||
content: 'Lorem ipsum',
|
||||
build_object(
|
||||
likes: {
|
||||
id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar', '/likes'].join,
|
||||
type: 'Collection',
|
||||
|
@ -2522,8 +2420,8 @@ RSpec.describe ActivityPub::Activity::Create do
|
|||
id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar', '/shares'].join,
|
||||
type: 'Collection',
|
||||
totalItems: 100,
|
||||
},
|
||||
}
|
||||
}
|
||||
)
|
||||
end
|
||||
|
||||
it 'uses the counts from the created object' do
|
||||
|
@ -2552,12 +2450,9 @@ RSpec.describe ActivityPub::Activity::Create do
|
|||
end
|
||||
|
||||
let(:object_json) do
|
||||
{
|
||||
id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
|
||||
type: 'Note',
|
||||
content: 'Lorem ipsum',
|
||||
to: 'https://www.w3.org/ns/activitystreams#Public',
|
||||
}
|
||||
build_object(
|
||||
to: 'https://www.w3.org/ns/activitystreams#Public'
|
||||
)
|
||||
end
|
||||
|
||||
before do
|
||||
|
@ -2623,13 +2518,7 @@ RSpec.describe ActivityPub::Activity::Create do
|
|||
subject.perform
|
||||
end
|
||||
|
||||
let(:object_json) do
|
||||
{
|
||||
id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
|
||||
type: 'Note',
|
||||
content: 'Lorem ipsum',
|
||||
}
|
||||
end
|
||||
let(:object_json) { build_object }
|
||||
|
||||
it 'creates status' do
|
||||
status = sender.statuses.first
|
||||
|
@ -2644,12 +2533,9 @@ RSpec.describe ActivityPub::Activity::Create do
|
|||
|
||||
let!(:local_status) { Fabricate(:status) }
|
||||
let(:object_json) do
|
||||
{
|
||||
id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
|
||||
type: 'Note',
|
||||
content: 'Lorem ipsum',
|
||||
inReplyTo: ActivityPub::TagManager.instance.uri_for(local_status),
|
||||
}
|
||||
build_object(
|
||||
inReplyTo: ActivityPub::TagManager.instance.uri_for(local_status)
|
||||
)
|
||||
end
|
||||
|
||||
before do
|
||||
|
@ -2715,13 +2601,11 @@ RSpec.describe ActivityPub::Activity::Create do
|
|||
subject { described_class.new(json, sender, delivery: true) }
|
||||
|
||||
let!(:local_account) { Fabricate(:account) }
|
||||
|
||||
let(:object_json) do
|
||||
{
|
||||
id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
|
||||
type: 'Note',
|
||||
content: 'Lorem ipsum',
|
||||
to: ActivityPub::TagManager.instance.uri_for(local_account),
|
||||
}
|
||||
build_object(
|
||||
to: ActivityPub::TagManager.instance.uri_for(local_account)
|
||||
)
|
||||
end
|
||||
|
||||
before do
|
||||
|
@ -2741,12 +2625,9 @@ RSpec.describe ActivityPub::Activity::Create do
|
|||
|
||||
let!(:local_account) { Fabricate(:account) }
|
||||
let(:object_json) do
|
||||
{
|
||||
id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
|
||||
type: 'Note',
|
||||
content: 'Lorem ipsum',
|
||||
cc: ActivityPub::TagManager.instance.uri_for(local_account),
|
||||
}
|
||||
build_object(
|
||||
cc: ActivityPub::TagManager.instance.uri_for(local_account)
|
||||
)
|
||||
end
|
||||
|
||||
before do
|
||||
|
@ -2797,17 +2678,19 @@ RSpec.describe ActivityPub::Activity::Create do
|
|||
subject.perform
|
||||
end
|
||||
|
||||
let(:object_json) do
|
||||
{
|
||||
id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
|
||||
type: 'Note',
|
||||
content: 'Lorem ipsum',
|
||||
}
|
||||
end
|
||||
let(:object_json) { build_object }
|
||||
|
||||
it 'does not create anything' do
|
||||
expect(sender.statuses.count).to eq 0
|
||||
end
|
||||
end
|
||||
|
||||
def build_object(options = {})
|
||||
{
|
||||
id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
|
||||
type: 'Note',
|
||||
content: 'Lorem ipsum',
|
||||
}.merge(options)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -7,17 +7,50 @@ RSpec.describe ActivityPub::TagManager do
|
|||
|
||||
subject { described_class.instance }
|
||||
|
||||
let(:domain) { "#{Rails.configuration.x.use_https ? 'https' : 'http'}://#{Rails.configuration.x.web_domain}" }
|
||||
|
||||
describe '#public_collection?' do
|
||||
it 'returns true for the special public collection and common shorthands' do
|
||||
expect(subject.public_collection?('https://www.w3.org/ns/activitystreams#Public')).to be true
|
||||
expect(subject.public_collection?('as:Public')).to be true
|
||||
expect(subject.public_collection?('Public')).to be true
|
||||
end
|
||||
|
||||
it 'returns false for other URIs' do
|
||||
expect(subject.public_collection?('https://example.com/foo/bar')).to be false
|
||||
end
|
||||
end
|
||||
|
||||
describe '#url_for' do
|
||||
it 'returns a string' do
|
||||
it 'returns a string starting with web domain' do
|
||||
account = Fabricate(:account)
|
||||
expect(subject.url_for(account)).to be_a String
|
||||
expect(subject.url_for(account)).to be_a(String)
|
||||
.and start_with(domain)
|
||||
end
|
||||
end
|
||||
|
||||
describe '#uri_for' do
|
||||
it 'returns a string' do
|
||||
it 'returns a string starting with web domain' do
|
||||
account = Fabricate(:account)
|
||||
expect(subject.uri_for(account)).to be_a String
|
||||
expect(subject.uri_for(account)).to be_a(String)
|
||||
.and start_with(domain)
|
||||
end
|
||||
end
|
||||
|
||||
describe '#activity_uri_for' do
|
||||
context 'when given an account' do
|
||||
it 'raises an exception' do
|
||||
account = Fabricate(:account)
|
||||
expect { subject.activity_uri_for(account) }.to raise_error(ArgumentError)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when given a local activity' do
|
||||
it 'returns a string starting with web domain' do
|
||||
status = Fabricate(:status)
|
||||
expect(subject.uri_for(status)).to be_a(String)
|
||||
.and start_with(domain)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -13,4 +13,13 @@ RSpec.describe AnnualReport do
|
|||
.to change(GeneratedAnnualReport, :count).by(1)
|
||||
end
|
||||
end
|
||||
|
||||
describe '.prepare' do
|
||||
before { Fabricate :status }
|
||||
|
||||
it 'generates records from source class which prepare data' do
|
||||
expect { described_class.prepare(Time.current.year) }
|
||||
.to change(AnnualReport::StatusesPerAccountCount, :count).by(1)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -42,8 +42,8 @@ RSpec.describe DeliveryFailureTracker do
|
|||
Fabricate(:unavailable_domain, domain: 'foo.bar')
|
||||
end
|
||||
|
||||
it 'removes URLs that are unavailable' do
|
||||
results = described_class.without_unavailable(['http://example.com/good/inbox', 'http://foo.bar/unavailable/inbox'])
|
||||
it 'removes URLs that are bogus or unavailable' do
|
||||
results = described_class.without_unavailable(['http://example.com/good/inbox', 'http://foo.bar/unavailable/inbox', '{foo:'])
|
||||
|
||||
expect(results).to include('http://example.com/good/inbox')
|
||||
expect(results).to_not include('http://foo.bar/unavailable/inbox')
|
||||
|
|
|
@ -89,10 +89,8 @@ RSpec.describe Mastodon::CLI::Maintenance do
|
|||
|
||||
def prepare_duplicate_data
|
||||
ActiveRecord::Base.connection.remove_index :accounts, name: :index_accounts_on_username_and_domain_lower
|
||||
_remote_account = Fabricate(:account, username: duplicate_account_username, domain: duplicate_account_domain)
|
||||
_remote_account_dupe = Fabricate.build(:account, username: duplicate_account_username, domain: duplicate_account_domain).save(validate: false)
|
||||
_local_account = Fabricate(:account, username: duplicate_account_username, domain: nil)
|
||||
_local_account_dupe = Fabricate.build(:account, username: duplicate_account_username, domain: nil).save(validate: false)
|
||||
duplicate_record(:account, username: duplicate_account_username, domain: duplicate_account_domain)
|
||||
duplicate_record(:account, username: duplicate_account_username, domain: nil)
|
||||
end
|
||||
|
||||
def choose_local_account_to_keep
|
||||
|
@ -127,8 +125,7 @@ RSpec.describe Mastodon::CLI::Maintenance do
|
|||
|
||||
def prepare_duplicate_data
|
||||
ActiveRecord::Base.connection.remove_index :users, :email
|
||||
Fabricate(:user, email: duplicate_email)
|
||||
Fabricate.build(:user, email: duplicate_email).save(validate: false)
|
||||
duplicate_record(:user, email: duplicate_email)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -156,8 +153,7 @@ RSpec.describe Mastodon::CLI::Maintenance do
|
|||
|
||||
def prepare_duplicate_data
|
||||
ActiveRecord::Base.connection.remove_index :users, :confirmation_token
|
||||
Fabricate(:user, confirmation_token: duplicate_confirmation_token)
|
||||
Fabricate.build(:user, confirmation_token: duplicate_confirmation_token).save(validate: false)
|
||||
duplicate_record(:user, confirmation_token: duplicate_confirmation_token)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -185,8 +181,7 @@ RSpec.describe Mastodon::CLI::Maintenance do
|
|||
|
||||
def prepare_duplicate_data
|
||||
ActiveRecord::Base.connection.remove_index :users, :reset_password_token
|
||||
Fabricate(:user, reset_password_token: duplicate_reset_password_token)
|
||||
Fabricate.build(:user, reset_password_token: duplicate_reset_password_token).save(validate: false)
|
||||
duplicate_record(:user, reset_password_token: duplicate_reset_password_token)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -214,8 +209,7 @@ RSpec.describe Mastodon::CLI::Maintenance do
|
|||
|
||||
def prepare_duplicate_data
|
||||
ActiveRecord::Base.connection.remove_index :account_domain_blocks, [:account_id, :domain]
|
||||
Fabricate(:account_domain_block, account: account, domain: duplicate_domain)
|
||||
Fabricate.build(:account_domain_block, account: account, domain: duplicate_domain).save(validate: false)
|
||||
duplicate_record(:account_domain_block, account: account, domain: duplicate_domain)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -244,8 +238,7 @@ RSpec.describe Mastodon::CLI::Maintenance do
|
|||
|
||||
def prepare_duplicate_data
|
||||
ActiveRecord::Base.connection.remove_index :announcement_reactions, [:account_id, :announcement_id, :name]
|
||||
Fabricate(:announcement_reaction, account: account, announcement: announcement, name: name)
|
||||
Fabricate.build(:announcement_reaction, account: account, announcement: announcement, name: name).save(validate: false)
|
||||
duplicate_record(:announcement_reaction, account: account, announcement: announcement, name: name)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -272,8 +265,7 @@ RSpec.describe Mastodon::CLI::Maintenance do
|
|||
|
||||
def prepare_duplicate_data
|
||||
ActiveRecord::Base.connection.remove_index :conversations, :uri
|
||||
Fabricate(:conversation, uri: uri)
|
||||
Fabricate.build(:conversation, uri: uri).save(validate: false)
|
||||
duplicate_record(:conversation, uri: uri)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -301,8 +293,7 @@ RSpec.describe Mastodon::CLI::Maintenance do
|
|||
|
||||
def prepare_duplicate_data
|
||||
ActiveRecord::Base.connection.remove_index :custom_emojis, [:shortcode, :domain]
|
||||
Fabricate(:custom_emoji, shortcode: duplicate_shortcode, domain: duplicate_domain)
|
||||
Fabricate.build(:custom_emoji, shortcode: duplicate_shortcode, domain: duplicate_domain).save(validate: false)
|
||||
duplicate_record(:custom_emoji, shortcode: duplicate_shortcode, domain: duplicate_domain)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -329,8 +320,7 @@ RSpec.describe Mastodon::CLI::Maintenance do
|
|||
|
||||
def prepare_duplicate_data
|
||||
ActiveRecord::Base.connection.remove_index :custom_emoji_categories, :name
|
||||
Fabricate(:custom_emoji_category, name: duplicate_name)
|
||||
Fabricate.build(:custom_emoji_category, name: duplicate_name).save(validate: false)
|
||||
duplicate_record(:custom_emoji_category, name: duplicate_name)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -357,8 +347,7 @@ RSpec.describe Mastodon::CLI::Maintenance do
|
|||
|
||||
def prepare_duplicate_data
|
||||
ActiveRecord::Base.connection.remove_index :domain_allows, :domain
|
||||
Fabricate(:domain_allow, domain: domain)
|
||||
Fabricate.build(:domain_allow, domain: domain).save(validate: false)
|
||||
duplicate_record(:domain_allow, domain: domain)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -385,8 +374,7 @@ RSpec.describe Mastodon::CLI::Maintenance do
|
|||
|
||||
def prepare_duplicate_data
|
||||
ActiveRecord::Base.connection.remove_index :domain_blocks, :domain
|
||||
Fabricate(:domain_block, domain: domain)
|
||||
Fabricate.build(:domain_block, domain: domain).save(validate: false)
|
||||
duplicate_record(:domain_block, domain: domain)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -413,8 +401,7 @@ RSpec.describe Mastodon::CLI::Maintenance do
|
|||
|
||||
def prepare_duplicate_data
|
||||
ActiveRecord::Base.connection.remove_index :email_domain_blocks, :domain
|
||||
Fabricate(:email_domain_block, domain: domain)
|
||||
Fabricate.build(:email_domain_block, domain: domain).save(validate: false)
|
||||
duplicate_record(:email_domain_block, domain: domain)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -441,8 +428,7 @@ RSpec.describe Mastodon::CLI::Maintenance do
|
|||
|
||||
def prepare_duplicate_data
|
||||
ActiveRecord::Base.connection.remove_index :media_attachments, :shortcode
|
||||
Fabricate(:media_attachment, shortcode: shortcode)
|
||||
Fabricate.build(:media_attachment, shortcode: shortcode).save(validate: false)
|
||||
duplicate_record(:media_attachment, shortcode: shortcode)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -469,8 +455,7 @@ RSpec.describe Mastodon::CLI::Maintenance do
|
|||
|
||||
def prepare_duplicate_data
|
||||
ActiveRecord::Base.connection.remove_index :preview_cards, :url
|
||||
Fabricate(:preview_card, url: url)
|
||||
Fabricate.build(:preview_card, url: url).save(validate: false)
|
||||
duplicate_record(:preview_card, url: url)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -530,8 +515,7 @@ RSpec.describe Mastodon::CLI::Maintenance do
|
|||
|
||||
def prepare_duplicate_data
|
||||
ActiveRecord::Base.connection.remove_index :tags, name: 'index_tags_on_name_lower_btree'
|
||||
Fabricate(:tag, name: name)
|
||||
Fabricate.build(:tag, name: name).save(validate: false)
|
||||
duplicate_record(:tag, name: name)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -558,8 +542,7 @@ RSpec.describe Mastodon::CLI::Maintenance do
|
|||
|
||||
def prepare_duplicate_data
|
||||
ActiveRecord::Base.connection.remove_index :webauthn_credentials, :external_id
|
||||
Fabricate(:webauthn_credential, external_id: external_id)
|
||||
Fabricate.build(:webauthn_credential, external_id: external_id).save(validate: false)
|
||||
duplicate_record(:webauthn_credential, external_id: external_id)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -586,11 +569,15 @@ RSpec.describe Mastodon::CLI::Maintenance do
|
|||
|
||||
def prepare_duplicate_data
|
||||
ActiveRecord::Base.connection.remove_index :webhooks, :url
|
||||
Fabricate(:webhook, url: url)
|
||||
Fabricate.build(:webhook, url: url).save(validate: false)
|
||||
duplicate_record(:webhook, url: url)
|
||||
end
|
||||
end
|
||||
|
||||
def duplicate_record(fabricator, options = {})
|
||||
Fabricate(fabricator, options)
|
||||
Fabricate.build(fabricator, options).save(validate: false)
|
||||
end
|
||||
|
||||
def agree_to_backup_warning
|
||||
allow(cli.shell)
|
||||
.to receive(:yes?)
|
||||
|
|
|
@ -4,7 +4,9 @@ require 'rails_helper'
|
|||
require 'securerandom'
|
||||
|
||||
RSpec.describe Request do
|
||||
subject { described_class.new(:get, 'http://example.com') }
|
||||
subject { described_class.new(:get, 'http://example.com', **options) }
|
||||
|
||||
let(:options) { {} }
|
||||
|
||||
describe '#headers' do
|
||||
it 'returns user agent' do
|
||||
|
@ -39,8 +41,8 @@ RSpec.describe Request do
|
|||
end
|
||||
|
||||
describe '#perform' do
|
||||
context 'with valid host' do
|
||||
before { stub_request(:get, 'http://example.com') }
|
||||
context 'with valid host and non-persistent connection' do
|
||||
before { stub_request(:get, 'http://example.com').to_return(body: 'lorem ipsum') }
|
||||
|
||||
it 'executes a HTTP request' do
|
||||
expect { |block| subject.perform(&block) }.to yield_control
|
||||
|
@ -71,9 +73,9 @@ RSpec.describe Request do
|
|||
expect(subject.send(:http_client)).to have_received(:close)
|
||||
end
|
||||
|
||||
it 'returns response which implements body_with_limit' do
|
||||
it 'yields response' do
|
||||
subject.perform do |response|
|
||||
expect(response).to respond_to :body_with_limit
|
||||
expect(response.body_with_limit).to eq 'lorem ipsum'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -95,6 +97,43 @@ RSpec.describe Request do
|
|||
expect { subject.perform }.to raise_error Mastodon::ValidationError
|
||||
end
|
||||
end
|
||||
|
||||
context 'with persistent connection' do
|
||||
before { stub_request(:get, 'http://example.com').to_return(body: SecureRandom.random_bytes(2.megabytes)) }
|
||||
|
||||
let(:http_client) { described_class.http_client.persistent('http://example.com') }
|
||||
let(:options) { { http_client: http_client } }
|
||||
|
||||
it 'leaves connection open after completely consumed response' do
|
||||
allow(http_client).to receive(:close)
|
||||
|
||||
subject.perform { |response| response.truncated_body(3.megabytes) }
|
||||
|
||||
expect(http_client).to_not have_received(:close)
|
||||
end
|
||||
|
||||
it 'leaves connection open after nearly consumed response' do
|
||||
allow(http_client).to receive(:close)
|
||||
|
||||
subject.perform { |response| response.truncated_body(1.8.megabytes) }
|
||||
|
||||
expect(http_client).to_not have_received(:close)
|
||||
end
|
||||
|
||||
it 'closes connection after unconsumed response' do
|
||||
allow(http_client).to receive(:close)
|
||||
|
||||
subject.perform
|
||||
|
||||
expect(http_client).to have_received(:close)
|
||||
end
|
||||
|
||||
it 'yields response' do
|
||||
subject.perform do |response|
|
||||
expect(response.body_with_limit(2.megabytes).size).to eq 2.megabytes
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "response's body_with_limit method" do
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue