2
2
3
3
require 'rails_helper'
4
4
5
- def poll_option_json ( name , votes )
6
- { type : 'Note' , name : name , replies : { type : 'Collection' , totalItems : votes } }
7
- end
8
-
9
5
RSpec . describe ActivityPub ::ProcessStatusUpdateService do
10
6
subject { described_class . new }
11
7
@@ -294,7 +290,6 @@ def poll_option_json(name, votes)
294
290
context 'when originally without media attachments' do
295
291
before do
296
292
stub_request ( :get , 'https://example.com/foo.png' ) . to_return ( body : attachment_fixture ( 'emojo.png' ) )
297
- subject . call ( status , json , json )
298
293
end
299
294
300
295
let ( :payload ) do
@@ -310,19 +305,18 @@ def poll_option_json(name, votes)
310
305
}
311
306
end
312
307
313
- it 'updates media attachments' do
314
- media_attachment = status . reload . ordered_media_attachments . first
308
+ it 'updates media attachments, fetches attachment, records media change in edit ' do
309
+ subject . call ( status , json , json )
315
310
316
- expect ( media_attachment ) . to_not be_nil
317
- expect ( media_attachment . remote_url ) . to eq 'https://example.com/foo.png'
318
- end
311
+ expect ( status . reload . ordered_media_attachments . first )
312
+ . to be_present
313
+ . and ( have_attributes ( remote_url : 'https://example.com/foo.png' ) )
319
314
320
- it 'fetches the attachment' do
321
- expect ( a_request ( :get , 'https://example.com/foo.png' ) ) . to have_been_made
322
- end
315
+ expect ( a_request ( :get , 'https://example.com/foo.png' ) )
316
+ . to have_been_made
323
317
324
- it 'records media change in edit' do
325
- expect ( status . edits . reload . last . ordered_media_attachment_ids ) . to_not be_empty
318
+ expect ( status . edits . reload . last . ordered_media_attachment_ids )
319
+ . to_not be_empty
326
320
end
327
321
end
328
322
@@ -344,38 +338,38 @@ def poll_option_json(name, votes)
344
338
345
339
before do
346
340
allow ( RedownloadMediaWorker ) . to receive ( :perform_async )
347
- subject . call ( status , json , json )
348
341
end
349
342
350
- it 'updates the existing media attachment in-place' do
351
- media_attachment = status . media_attachments . ordered . reload . first
343
+ it 'updates the existing media attachment in-place, does not queue redownload, updates media, records media change ' do
344
+ subject . call ( status , json , json )
352
345
353
- expect ( media_attachment ) . to_not be_nil
354
- expect ( media_attachment . remote_url ) . to eq 'https://example.com/foo.png'
355
- expect ( media_attachment . description ) . to eq 'A picture'
356
- end
346
+ expect ( status . media_attachments . ordered . reload . first )
347
+ . to be_present
348
+ . and have_attributes (
349
+ remote_url : 'https://example.com/foo.png' ,
350
+ description : 'A picture'
351
+ )
357
352
358
- it 'does not queue redownload for the existing media attachment' do
359
- expect ( RedownloadMediaWorker ) . to_not have_received ( :perform_async )
360
- end
353
+ expect ( RedownloadMediaWorker )
354
+ . to_not have_received ( :perform_async )
361
355
362
- it 'updates media attachments' do
363
- expect ( status . ordered_media_attachments . map ( &:remote_url ) ) . to eq %w( https://example.com/foo.png )
364
- end
356
+ expect ( status . ordered_media_attachments . map ( &:remote_url ) )
357
+ . to eq %w( https://example.com/foo.png )
365
358
366
- it 'records media change in edit' do
367
- expect ( status . edits . reload . last . ordered_media_attachment_ids ) . to_not be_empty
359
+ expect ( status . edits . reload . last . ordered_media_attachment_ids )
360
+ . to_not be_empty
368
361
end
369
362
end
370
363
371
364
context 'when originally with a poll' do
372
365
before do
373
366
poll = Fabricate ( :poll , status : status )
374
367
status . update ( preloadable_poll : poll )
375
- subject . call ( status , json , json )
376
368
end
377
369
378
370
it 'removes poll and records media change in edit' do
371
+ subject . call ( status , json , json )
372
+
379
373
expect ( status . reload . poll ) . to be_nil
380
374
expect ( status . edits . reload . last . poll_options ) . to be_nil
381
375
end
@@ -398,15 +392,13 @@ def poll_option_json(name, votes)
398
392
}
399
393
end
400
394
401
- before do
395
+ it 'creates a poll and records media change in edit' do
402
396
subject . call ( status , json , json )
403
- end
404
397
405
- it 'creates a poll and records media change in edit' do
406
- poll = status . reload . poll
398
+ expect ( status . reload . poll )
399
+ . to be_present
400
+ . and have_attributes ( options : %w( Foo Bar Baz ) )
407
401
408
- expect ( poll ) . to_not be_nil
409
- expect ( poll . options ) . to eq %w( Foo Bar Baz )
410
402
expect ( status . edits . reload . last . poll_options ) . to eq %w( Foo Bar Baz )
411
403
end
412
404
end
@@ -419,4 +411,8 @@ def poll_option_json(name, votes)
419
411
. to eq '2021-09-08 22:39:25 UTC'
420
412
end
421
413
end
414
+
415
+ def poll_option_json ( name , votes )
416
+ { type : 'Note' , name : name , replies : { type : 'Collection' , totalItems : votes } }
417
+ end
422
418
end
0 commit comments