From 448be26b34c965fcae65eb4c5227b35d97120537 Mon Sep 17 00:00:00 2001 From: Claire Date: Mon, 23 Jan 2023 13:05:30 +0100 Subject: Add missing `policy` attribute to `WebPushSubscriptionSerializer` (#23210) * Add missing `policy` attribute to `WebPushSubscriptionSerializer` Fixes #23145 * Add tests --- spec/controllers/api/v1/push/subscriptions_controller_spec.rb | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'spec/controllers/api/v1/push/subscriptions_controller_spec.rb') diff --git a/spec/controllers/api/v1/push/subscriptions_controller_spec.rb b/spec/controllers/api/v1/push/subscriptions_controller_spec.rb index 534d02879..9487251e1 100644 --- a/spec/controllers/api/v1/push/subscriptions_controller_spec.rb +++ b/spec/controllers/api/v1/push/subscriptions_controller_spec.rb @@ -61,6 +61,10 @@ describe Api::V1::Push::SubscriptionsController do post :create, params: create_payload expect(Web::PushSubscription.where(endpoint: create_payload[:subscription][:endpoint]).count).to eq 1 end + + it 'returns the expected JSON' do + expect(body_as_json.with_indifferent_access).to include({ endpoint: create_payload[:subscription][:endpoint], alerts: {}, policy: 'all' }) + end end describe 'PUT #update' do @@ -78,6 +82,10 @@ describe Api::V1::Push::SubscriptionsController do expect(push_subscription.data['alerts'][type]).to eq(alerts_payload[:data][:alerts][type.to_sym].to_s) end end + + it 'returns the expected JSON' do + expect(body_as_json.with_indifferent_access).to include({ endpoint: create_payload[:subscription][:endpoint], alerts: alerts_payload[:data][:alerts], policy: alerts_payload[:data][:policy] }) + end end describe 'DELETE #destroy' do -- cgit From 5069769cbe7295268e8b87ce34fa0a753bfbb233 Mon Sep 17 00:00:00 2001 From: Nick Schonning Date: Sat, 18 Feb 2023 09:33:41 -0500 Subject: Autofix Rubocop Style/TrailingCommaInHashLiteral (#23693) --- .rubocop_todo.yml | 28 ------------------ spec/controllers/admin/accounts_controller_spec.rb | 2 +- .../admin/domain_blocks_controller_spec.rb | 6 ++-- .../api/v1/accounts/credentials_controller_spec.rb | 2 +- .../api/v1/push/subscriptions_controller_spec.rb | 6 ++-- .../api/web/push_subscriptions_controller_spec.rb | 6 ++-- .../settings/applications_controller_spec.rb | 20 ++++++------- .../settings/imports_controller_spec.rb | 8 ++--- .../preferences/notifications_controller_spec.rb | 2 +- .../settings/preferences/other_controller_spec.rb | 2 +- spec/lib/activitypub/activity/announce_spec.rb | 2 +- spec/lib/activitypub/activity/create_spec.rb | 8 ++--- .../fetch_featured_collection_service_spec.rb | 2 +- .../fetch_featured_tags_collection_service_spec.rb | 2 +- .../fetch_remote_status_service_spec.rb | 2 +- .../activitypub/fetch_replies_service_spec.rb | 2 +- .../activitypub/process_account_service_spec.rb | 2 +- .../activitypub/process_collection_service_spec.rb | 34 +++++++++++----------- .../process_status_update_service_spec.rb | 8 ++--- .../synchronize_followers_service_spec.rb | 2 +- spec/services/fetch_resource_service_spec.rb | 2 +- spec/spec_helper.rb | 2 +- 22 files changed, 61 insertions(+), 89 deletions(-) (limited to 'spec/controllers/api/v1/push/subscriptions_controller_spec.rb') diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index f35336332..ca2b085c9 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -3417,34 +3417,6 @@ Style/TrailingCommaInArrayLiteral: - 'spec/services/activitypub/process_collection_service_spec.rb' - 'spec/workers/activitypub/move_distribution_worker_spec.rb' -# Offense count: 61 -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: EnforcedStyleForMultiline. -# SupportedStylesForMultiline: comma, consistent_comma, no_comma -Style/TrailingCommaInHashLiteral: - Exclude: - - 'spec/controllers/admin/accounts_controller_spec.rb' - - 'spec/controllers/admin/domain_blocks_controller_spec.rb' - - 'spec/controllers/api/v1/accounts/credentials_controller_spec.rb' - - 'spec/controllers/api/v1/push/subscriptions_controller_spec.rb' - - 'spec/controllers/api/web/push_subscriptions_controller_spec.rb' - - 'spec/controllers/settings/applications_controller_spec.rb' - - 'spec/controllers/settings/imports_controller_spec.rb' - - 'spec/controllers/settings/preferences/notifications_controller_spec.rb' - - 'spec/controllers/settings/preferences/other_controller_spec.rb' - - 'spec/lib/activitypub/activity/announce_spec.rb' - - 'spec/lib/activitypub/activity/create_spec.rb' - - 'spec/services/activitypub/fetch_featured_collection_service_spec.rb' - - 'spec/services/activitypub/fetch_featured_tags_collection_service_spec.rb' - - 'spec/services/activitypub/fetch_remote_status_service_spec.rb' - - 'spec/services/activitypub/fetch_replies_service_spec.rb' - - 'spec/services/activitypub/process_account_service_spec.rb' - - 'spec/services/activitypub/process_collection_service_spec.rb' - - 'spec/services/activitypub/process_status_update_service_spec.rb' - - 'spec/services/activitypub/synchronize_followers_service_spec.rb' - - 'spec/services/fetch_resource_service_spec.rb' - - 'spec/spec_helper.rb' - # Offense count: 4 # This cop supports safe autocorrection (--autocorrect). Style/UnpackFirst: diff --git a/spec/controllers/admin/accounts_controller_spec.rb b/spec/controllers/admin/accounts_controller_spec.rb index 81d592ddd..48204b7b6 100644 --- a/spec/controllers/admin/accounts_controller_spec.rb +++ b/spec/controllers/admin/accounts_controller_spec.rb @@ -39,7 +39,7 @@ RSpec.describe Admin::AccountsController, type: :controller do username: 'username', display_name: 'display name', email: 'local-part@domain', - ip: '0.0.0.42' + ip: '0.0.0.42', } end diff --git a/spec/controllers/admin/domain_blocks_controller_spec.rb b/spec/controllers/admin/domain_blocks_controller_spec.rb index f432060d9..3b2fd6c5d 100644 --- a/spec/controllers/admin/domain_blocks_controller_spec.rb +++ b/spec/controllers/admin/domain_blocks_controller_spec.rb @@ -26,9 +26,9 @@ RSpec.describe Admin::DomainBlocksController, type: :controller do domain_blocks_attributes: { '0' => { enabled: '1', domain: 'example.com', severity: 'silence' }, '1' => { enabled: '0', domain: 'mastodon.social', severity: 'suspend' }, - '2' => { enabled: '1', domain: 'mastodon.online', severity: 'suspend' } - } - } + '2' => { enabled: '1', domain: 'mastodon.online', severity: 'suspend' }, + }, + }, } expect(DomainBlockWorker).to have_received(:perform_async).exactly(2).times diff --git a/spec/controllers/api/v1/accounts/credentials_controller_spec.rb b/spec/controllers/api/v1/accounts/credentials_controller_spec.rb index 89cc8acad..d8aa00a07 100644 --- a/spec/controllers/api/v1/accounts/credentials_controller_spec.rb +++ b/spec/controllers/api/v1/accounts/credentials_controller_spec.rb @@ -35,7 +35,7 @@ describe Api::V1::Accounts::CredentialsController do source: { privacy: 'unlisted', sensitive: true, - } + }, } end diff --git a/spec/controllers/api/v1/push/subscriptions_controller_spec.rb b/spec/controllers/api/v1/push/subscriptions_controller_spec.rb index 9487251e1..67f09da2d 100644 --- a/spec/controllers/api/v1/push/subscriptions_controller_spec.rb +++ b/spec/controllers/api/v1/push/subscriptions_controller_spec.rb @@ -20,7 +20,7 @@ describe Api::V1::Push::SubscriptionsController do p256dh: 'BEm_a0bdPDhf0SOsrnB2-ategf1hHoCnpXgQsFj5JCkcoMrMt2WHoPfEYOYPzOIs9mZE8ZUaD7VA5vouy0kEkr8=', auth: 'eH_C8rq2raXqlcBVDa1gLg==', }, - } + }, }.with_indifferent_access end @@ -37,8 +37,8 @@ describe Api::V1::Push::SubscriptionsController do mention: false, poll: true, status: false, - } - } + }, + }, }.with_indifferent_access end diff --git a/spec/controllers/api/web/push_subscriptions_controller_spec.rb b/spec/controllers/api/web/push_subscriptions_controller_spec.rb index bda4a7661..9f027ede9 100644 --- a/spec/controllers/api/web/push_subscriptions_controller_spec.rb +++ b/spec/controllers/api/web/push_subscriptions_controller_spec.rb @@ -15,7 +15,7 @@ describe Api::Web::PushSubscriptionsController do p256dh: 'BEm_a0bdPDhf0SOsrnB2-ategf1hHoCnpXgQsFj5JCkcoMrMt2WHoPfEYOYPzOIs9mZE8ZUaD7VA5vouy0kEkr8=', auth: 'eH_C8rq2raXqlcBVDa1gLg==', }, - } + }, } end @@ -32,8 +32,8 @@ describe Api::Web::PushSubscriptionsController do mention: false, poll: true, status: false, - } - } + }, + }, } end diff --git a/spec/controllers/settings/applications_controller_spec.rb b/spec/controllers/settings/applications_controller_spec.rb index b79a38ea1..75d3240f9 100644 --- a/spec/controllers/settings/applications_controller_spec.rb +++ b/spec/controllers/settings/applications_controller_spec.rb @@ -51,8 +51,8 @@ describe Settings::ApplicationsController do name: 'My New App', redirect_uri: 'urn:ietf:wg:oauth:2.0:oob', website: 'http://google.com', - scopes: 'read write follow' - } + scopes: 'read write follow', + }, } response end @@ -73,8 +73,8 @@ describe Settings::ApplicationsController do name: 'My New App', redirect_uri: 'urn:ietf:wg:oauth:2.0:oob', website: 'http://google.com', - scopes: ['read', 'write', 'follow'] - } + scopes: ['read', 'write', 'follow'], + }, } response end @@ -95,8 +95,8 @@ describe Settings::ApplicationsController do name: '', redirect_uri: '', website: '', - scopes: [] - } + scopes: [], + }, } end @@ -114,14 +114,14 @@ describe Settings::ApplicationsController do context 'success' do let(:opts) { { - website: 'https://foo.bar/' + website: 'https://foo.bar/', } } def call_update patch :update, params: { id: app.id, - doorkeeper_application: opts + doorkeeper_application: opts, } response end @@ -144,8 +144,8 @@ describe Settings::ApplicationsController do name: '', redirect_uri: '', website: '', - scopes: [] - } + scopes: [], + }, } end diff --git a/spec/controllers/settings/imports_controller_spec.rb b/spec/controllers/settings/imports_controller_spec.rb index b8caf5941..8070a35db 100644 --- a/spec/controllers/settings/imports_controller_spec.rb +++ b/spec/controllers/settings/imports_controller_spec.rb @@ -21,8 +21,8 @@ RSpec.describe Settings::ImportsController, type: :controller do post :create, params: { import: { type: 'following', - data: fixture_file_upload('imports.txt') - } + data: fixture_file_upload('imports.txt'), + }, } expect(response).to redirect_to(settings_import_path) @@ -34,8 +34,8 @@ RSpec.describe Settings::ImportsController, type: :controller do post :create, params: { import: { type: 'blocking', - data: fixture_file_upload('imports.txt') - } + data: fixture_file_upload('imports.txt'), + }, } expect(response).to redirect_to(settings_import_path) diff --git a/spec/controllers/settings/preferences/notifications_controller_spec.rb b/spec/controllers/settings/preferences/notifications_controller_spec.rb index 02180b383..a821052ed 100644 --- a/spec/controllers/settings/preferences/notifications_controller_spec.rb +++ b/spec/controllers/settings/preferences/notifications_controller_spec.rb @@ -25,7 +25,7 @@ describe Settings::Preferences::NotificationsController do user: { notification_emails: { follow: '1' }, interactions: { must_be_follower: '0' }, - } + }, } expect(response).to redirect_to(settings_preferences_notifications_path) diff --git a/spec/controllers/settings/preferences/other_controller_spec.rb b/spec/controllers/settings/preferences/other_controller_spec.rb index 960378a01..dd7f01847 100644 --- a/spec/controllers/settings/preferences/other_controller_spec.rb +++ b/spec/controllers/settings/preferences/other_controller_spec.rb @@ -34,7 +34,7 @@ describe Settings::Preferences::OtherController do user: { setting_boost_modal: '1', setting_delete_modal: '0', - } + }, } expect(response).to redirect_to(settings_preferences_other_path) diff --git a/spec/lib/activitypub/activity/announce_spec.rb b/spec/lib/activitypub/activity/announce_spec.rb index 1b3485384..461c3757b 100644 --- a/spec/lib/activitypub/activity/announce_spec.rb +++ b/spec/lib/activitypub/activity/announce_spec.rb @@ -85,7 +85,7 @@ RSpec.describe ActivityPub::Activity::Announce do type: 'OrderedCollection', id: 'http://example.com/followers', first: 'http://example.com/followers?page=true', - } + }, } end diff --git a/spec/lib/activitypub/activity/create_spec.rb b/spec/lib/activitypub/activity/create_spec.rb index 074aa54ca..132e0c31c 100644 --- a/spec/lib/activitypub/activity/create_spec.rb +++ b/spec/lib/activitypub/activity/create_spec.rb @@ -255,7 +255,7 @@ RSpec.describe ActivityPub::Activity::Create do type: 'OrderedCollection', id: 'http://example.com/followers', first: 'http://example.com/followers?page=true', - } + }, } end @@ -686,7 +686,7 @@ RSpec.describe ActivityPub::Activity::Create do replies: { type: 'Collection', totalItems: 3, - } + }, }, ], } @@ -716,7 +716,7 @@ RSpec.describe ActivityPub::Activity::Create do id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join, type: 'Note', name: 'Yellow', - inReplyTo: ActivityPub::TagManager.instance.uri_for(local_status) + inReplyTo: ActivityPub::TagManager.instance.uri_for(local_status), } end @@ -741,7 +741,7 @@ RSpec.describe ActivityPub::Activity::Create do id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join, type: 'Note', name: 'Yellow', - inReplyTo: ActivityPub::TagManager.instance.uri_for(local_status) + inReplyTo: ActivityPub::TagManager.instance.uri_for(local_status), } end diff --git a/spec/services/activitypub/fetch_featured_collection_service_spec.rb b/spec/services/activitypub/fetch_featured_collection_service_spec.rb index e6336dc1b..23d90a9a2 100644 --- a/spec/services/activitypub/fetch_featured_collection_service_spec.rb +++ b/spec/services/activitypub/fetch_featured_collection_service_spec.rb @@ -109,7 +109,7 @@ RSpec.describe ActivityPub::FetchFeaturedCollectionService, type: :service do type: 'CollectionPage', partOf: actor.featured_collection_url, items: items, - } + }, }.with_indifferent_access end diff --git a/spec/services/activitypub/fetch_featured_tags_collection_service_spec.rb b/spec/services/activitypub/fetch_featured_tags_collection_service_spec.rb index 6ca22c9fc..692866bce 100644 --- a/spec/services/activitypub/fetch_featured_tags_collection_service_spec.rb +++ b/spec/services/activitypub/fetch_featured_tags_collection_service_spec.rb @@ -81,7 +81,7 @@ RSpec.describe ActivityPub::FetchFeaturedTagsCollectionService, type: :service d type: 'CollectionPage', partOf: collection_url, items: items, - } + }, }.with_indifferent_access end diff --git a/spec/services/activitypub/fetch_remote_status_service_spec.rb b/spec/services/activitypub/fetch_remote_status_service_spec.rb index d6145c9b8..e02054672 100644 --- a/spec/services/activitypub/fetch_remote_status_service_spec.rb +++ b/spec/services/activitypub/fetch_remote_status_service_spec.rb @@ -115,7 +115,7 @@ RSpec.describe ActivityPub::FetchRemoteStatusService, type: :service do id: "https://foo.bar/@foo/1234", type: 'Event', name: "Let's change the world", - attributedTo: ActivityPub::TagManager.instance.uri_for(sender) + attributedTo: ActivityPub::TagManager.instance.uri_for(sender), } end diff --git a/spec/services/activitypub/fetch_replies_service_spec.rb b/spec/services/activitypub/fetch_replies_service_spec.rb index fe49b18c1..5741e0c3f 100644 --- a/spec/services/activitypub/fetch_replies_service_spec.rb +++ b/spec/services/activitypub/fetch_replies_service_spec.rb @@ -90,7 +90,7 @@ RSpec.describe ActivityPub::FetchRepliesService, type: :service do type: 'CollectionPage', partOf: collection_uri, items: items, - } + }, }.with_indifferent_access end diff --git a/spec/services/activitypub/process_account_service_spec.rb b/spec/services/activitypub/process_account_service_spec.rb index 40caa6eb0..8e6ed178e 100644 --- a/spec/services/activitypub/process_account_service_spec.rb +++ b/spec/services/activitypub/process_account_service_spec.rb @@ -175,7 +175,7 @@ RSpec.describe ActivityPub::ProcessAccountService, type: :service do name: "@user#{i + 1}", } ], - to: ['as:Public', "https://foo.test/users/#{i + 1}"] + to: ['as:Public', "https://foo.test/users/#{i + 1}"], }.with_indifferent_access featured_json = { '@context': ['https://www.w3.org/ns/activitystreams'], diff --git a/spec/services/activitypub/process_collection_service_spec.rb b/spec/services/activitypub/process_collection_service_spec.rb index cb7deb626..0fa5321bc 100644 --- a/spec/services/activitypub/process_collection_service_spec.rb +++ b/spec/services/activitypub/process_collection_service_spec.rb @@ -123,15 +123,15 @@ RSpec.describe ActivityPub::ProcessCollectionService, type: :service do type: 'RsaSignature2017', creator: 'https://example.com/users/bob#main-key', created: '2022-03-09T21:57:25Z', - signatureValue: 'WculK0LelTQ0MvGwU9TPoq5pFzFfGYRDCJqjZ232/Udj4CHqDTGOSw5UTDLShqBOyycCkbZGrQwXG+dpyDpQLSe1UVPZ5TPQtc/9XtI57WlS2nMNpdvRuxGnnb2btPdesXZ7n3pCxo0zjaXrJMe0mqQh5QJO22mahb4bDwwmfTHgbD3nmkD+fBfGi+UV2qWwqr+jlV4L4JqNkh0gWljF5KTePLRRZCuWiQ/FAt7c67636cdIPf7fR+usjuZltTQyLZKEGuK8VUn2Gkfsx5qns7Vcjvlz1JqlAjyO8HPBbzTTHzUG2nUOIgC3PojCSWv6mNTmRGoLZzOscCAYQA6cKw==' + signatureValue: 'WculK0LelTQ0MvGwU9TPoq5pFzFfGYRDCJqjZ232/Udj4CHqDTGOSw5UTDLShqBOyycCkbZGrQwXG+dpyDpQLSe1UVPZ5TPQtc/9XtI57WlS2nMNpdvRuxGnnb2btPdesXZ7n3pCxo0zjaXrJMe0mqQh5QJO22mahb4bDwwmfTHgbD3nmkD+fBfGi+UV2qWwqr+jlV4L4JqNkh0gWljF5KTePLRRZCuWiQ/FAt7c67636cdIPf7fR+usjuZltTQyLZKEGuK8VUn2Gkfsx5qns7Vcjvlz1JqlAjyO8HPBbzTTHzUG2nUOIgC3PojCSWv6mNTmRGoLZzOscCAYQA6cKw==', }, '@id': 'https://example.com/users/bob/statuses/107928807471117876/activity', '@type': 'https://www.w3.org/ns/activitystreams#Create', 'https://www.w3.org/ns/activitystreams#actor': { - '@id': 'https://example.com/users/bob' + '@id': 'https://example.com/users/bob', }, 'https://www.w3.org/ns/activitystreams#cc': { - '@id': 'https://example.com/users/bob/followers' + '@id': 'https://example.com/users/bob/followers', }, object: { id: 'https://example.com/users/bob/fake-status', @@ -156,21 +156,21 @@ RSpec.describe ActivityPub::ProcessCollectionService, type: :service do 'http://ostatus.org#conversation': 'tag:example.com,2022-03-09:objectId=15:objectType=Conversation', 'https://www.w3.org/ns/activitystreams#attachment': [], 'https://www.w3.org/ns/activitystreams#attributedTo': { - '@id': 'https://example.com/users/bob' + '@id': 'https://example.com/users/bob', }, 'https://www.w3.org/ns/activitystreams#cc': { - '@id': 'https://example.com/users/bob/followers' + '@id': 'https://example.com/users/bob/followers', }, 'https://www.w3.org/ns/activitystreams#content': [ '

hello world

', { '@value': '

hello world

', - '@language': 'en' + '@language': 'en', } ], 'https://www.w3.org/ns/activitystreams#published': { '@type': 'http://www.w3.org/2001/XMLSchema#dateTime', - '@value': '2022-03-09T21:55:07Z' + '@value': '2022-03-09T21:55:07Z', }, 'https://www.w3.org/ns/activitystreams#replies': { '@id': 'https://example.com/users/bob/statuses/107928807471117876/replies', @@ -179,29 +179,29 @@ RSpec.describe ActivityPub::ProcessCollectionService, type: :service do '@type': 'https://www.w3.org/ns/activitystreams#CollectionPage', 'https://www.w3.org/ns/activitystreams#items': [], 'https://www.w3.org/ns/activitystreams#next': { - '@id': 'https://example.com/users/bob/statuses/107928807471117876/replies?only_other_accounts=true&page=true' + '@id': 'https://example.com/users/bob/statuses/107928807471117876/replies?only_other_accounts=true&page=true', }, 'https://www.w3.org/ns/activitystreams#partOf': { - '@id': 'https://example.com/users/bob/statuses/107928807471117876/replies' - } - } + '@id': 'https://example.com/users/bob/statuses/107928807471117876/replies', + }, + }, }, 'https://www.w3.org/ns/activitystreams#sensitive': false, 'https://www.w3.org/ns/activitystreams#tag': [], 'https://www.w3.org/ns/activitystreams#to': { - '@id': 'https://www.w3.org/ns/activitystreams#Public' + '@id': 'https://www.w3.org/ns/activitystreams#Public', }, 'https://www.w3.org/ns/activitystreams#url': { - '@id': 'https://example.com/@bob/107928807471117876' - } + '@id': 'https://example.com/@bob/107928807471117876', + }, }, 'https://www.w3.org/ns/activitystreams#published': { '@type': 'http://www.w3.org/2001/XMLSchema#dateTime', - '@value': '2022-03-09T21:55:07Z' + '@value': '2022-03-09T21:55:07Z', }, 'https://www.w3.org/ns/activitystreams#to': { - '@id': 'https://www.w3.org/ns/activitystreams#Public' - } + '@id': 'https://www.w3.org/ns/activitystreams#Public', + }, } end diff --git a/spec/services/activitypub/process_status_update_service_spec.rb b/spec/services/activitypub/process_status_update_service_spec.rb index 04292c507..5d15f6ffe 100644 --- a/spec/services/activitypub/process_status_update_service_spec.rb +++ b/spec/services/activitypub/process_status_update_service_spec.rb @@ -115,7 +115,7 @@ RSpec.describe ActivityPub::ProcessStatusUpdateService, type: :service do account: account, multiple: false, hide_totals: false, - expires_at: expiration + expires_at: expiration, }) end @@ -166,7 +166,7 @@ RSpec.describe ActivityPub::ProcessStatusUpdateService, type: :service do account: account, multiple: false, hide_totals: false, - expires_at: expiration + expires_at: expiration, }) end @@ -342,7 +342,7 @@ RSpec.describe ActivityPub::ProcessStatusUpdateService, type: :service do updated: '2021-09-08T22:39:25Z', attachment: [ { type: 'Image', mediaType: 'image/png', url: 'https://example.com/foo.png' }, - ] + ], } end @@ -374,7 +374,7 @@ RSpec.describe ActivityPub::ProcessStatusUpdateService, type: :service do updated: '2021-09-08T22:39:25Z', attachment: [ { type: 'Image', mediaType: 'image/png', url: 'https://example.com/foo.png', name: 'A picture' }, - ] + ], } end diff --git a/spec/services/activitypub/synchronize_followers_service_spec.rb b/spec/services/activitypub/synchronize_followers_service_spec.rb index 75dcf204b..5a37f0733 100644 --- a/spec/services/activitypub/synchronize_followers_service_spec.rb +++ b/spec/services/activitypub/synchronize_followers_service_spec.rb @@ -91,7 +91,7 @@ RSpec.describe ActivityPub::SynchronizeFollowersService, type: :service do type: 'CollectionPage', partOf: collection_uri, items: items, - } + }, }.with_indifferent_access end diff --git a/spec/services/fetch_resource_service_spec.rb b/spec/services/fetch_resource_service_spec.rb index 8cd4a3bfb..6f24e6418 100644 --- a/spec/services/fetch_resource_service_spec.rb +++ b/spec/services/fetch_resource_service_spec.rb @@ -91,7 +91,7 @@ RSpec.describe FetchResourceService, type: :service do end context 'when link header is present' do - let(:headers) { { 'Link' => '; rel="alternate"; type="application/activity+json"', } } + let(:headers) { { 'Link' => '; rel="alternate"; type="application/activity+json"' } } it { is_expected.to eq [1, { prefetched_body: json, id: true }] } end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 0414ba9ed..72c9ce8ae 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -61,6 +61,6 @@ end def expect_push_bulk_to_match(klass, matcher) expect(Sidekiq::Client).to receive(:push_bulk).with(hash_including({ "class" => klass, - "args" => matcher + "args" => matcher, })) end -- cgit From 5179c47087e7807162f1466ec61a797586de007f Mon Sep 17 00:00:00 2001 From: Nick Schonning Date: Sun, 19 Feb 2023 21:17:41 -0500 Subject: Autofix Rubocops RSpec/ScatteredLet (#23725) --- .rubocop_todo.yml | 13 ------ .../admin/domain_blocks_controller_spec.rb | 9 ++--- .../api/v1/admin/domain_blocks_controller_spec.rb | 9 ++--- .../api/v1/push/subscriptions_controller_spec.rb | 14 +++---- spec/lib/activitypub/activity/create_spec.rb | 46 ++++++++++------------ spec/lib/vacuum/media_attachments_vacuum_spec.rb | 5 +-- .../process_status_update_service_spec.rb | 28 ++++++------- spec/services/fan_out_on_write_service_spec.rb | 3 +- spec/services/import_service_spec.rb | 12 +++--- 9 files changed, 56 insertions(+), 83 deletions(-) (limited to 'spec/controllers/api/v1/push/subscriptions_controller_spec.rb') diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 521608de6..308e0e69e 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1629,19 +1629,6 @@ RSpec/RepeatedExampleGroupDescription: - 'spec/controllers/admin/reports/actions_controller_spec.rb' - 'spec/policies/report_note_policy_spec.rb' -# Offense count: 18 -# This cop supports safe autocorrection (--autocorrect). -RSpec/ScatteredLet: - Exclude: - - 'spec/controllers/admin/domain_blocks_controller_spec.rb' - - 'spec/controllers/api/v1/admin/domain_blocks_controller_spec.rb' - - 'spec/controllers/api/v1/push/subscriptions_controller_spec.rb' - - 'spec/lib/activitypub/activity/create_spec.rb' - - 'spec/lib/vacuum/media_attachments_vacuum_spec.rb' - - 'spec/services/activitypub/process_status_update_service_spec.rb' - - 'spec/services/fan_out_on_write_service_spec.rb' - - 'spec/services/import_service_spec.rb' - # Offense count: 12 RSpec/ScatteredSetup: Exclude: diff --git a/spec/controllers/admin/domain_blocks_controller_spec.rb b/spec/controllers/admin/domain_blocks_controller_spec.rb index 92fc19efa..d58a0cafc 100644 --- a/spec/controllers/admin/domain_blocks_controller_spec.rb +++ b/spec/controllers/admin/domain_blocks_controller_spec.rb @@ -72,16 +72,15 @@ RSpec.describe Admin::DomainBlocksController, type: :controller do describe 'PUT #update' do let!(:remote_account) { Fabricate(:account, domain: 'example.com') } - let(:domain_block) { Fabricate(:domain_block, domain: 'example.com', severity: original_severity) } + let(:subject) do + post :update, params: { id: domain_block.id, domain_block: { domain: 'example.com', severity: new_severity } } + end + let(:domain_block) { Fabricate(:domain_block, domain: 'example.com', severity: original_severity) } before do BlockDomainService.new.call(domain_block) end - let(:subject) do - post :update, params: { id: domain_block.id, domain_block: { domain: 'example.com', severity: new_severity } } - end - context 'downgrading a domain suspension to silence' do let(:original_severity) { 'suspend' } let(:new_severity) { 'silence' } diff --git a/spec/controllers/api/v1/admin/domain_blocks_controller_spec.rb b/spec/controllers/api/v1/admin/domain_blocks_controller_spec.rb index 606def602..b367ab9ce 100644 --- a/spec/controllers/api/v1/admin/domain_blocks_controller_spec.rb +++ b/spec/controllers/api/v1/admin/domain_blocks_controller_spec.rb @@ -73,16 +73,15 @@ RSpec.describe Api::V1::Admin::DomainBlocksController, type: :controller do describe 'PUT #update' do let!(:remote_account) { Fabricate(:account, domain: 'example.com') } - let(:domain_block) { Fabricate(:domain_block, domain: 'example.com', severity: original_severity) } + let(:subject) do + post :update, params: { id: domain_block.id, domain: 'example.com', severity: new_severity } + end + let(:domain_block) { Fabricate(:domain_block, domain: 'example.com', severity: original_severity) } before do BlockDomainService.new.call(domain_block) end - let(:subject) do - post :update, params: { id: domain_block.id, domain: 'example.com', severity: new_severity } - end - context 'downgrading a domain suspension to silence' do let(:original_severity) { 'suspend' } let(:new_severity) { 'silence' } diff --git a/spec/controllers/api/v1/push/subscriptions_controller_spec.rb b/spec/controllers/api/v1/push/subscriptions_controller_spec.rb index 67f09da2d..168191468 100644 --- a/spec/controllers/api/v1/push/subscriptions_controller_spec.rb +++ b/spec/controllers/api/v1/push/subscriptions_controller_spec.rb @@ -5,13 +5,7 @@ require 'rails_helper' describe Api::V1::Push::SubscriptionsController do render_views - let(:user) { Fabricate(:user) } - let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: 'push') } - - before do - allow(controller).to receive(:doorkeeper_token) { token } - end - + let(:user) { Fabricate(:user) } let(:create_payload) do { subscription: { @@ -23,7 +17,6 @@ describe Api::V1::Push::SubscriptionsController do }, }.with_indifferent_access end - let(:alerts_payload) do { data: { @@ -41,6 +34,11 @@ describe Api::V1::Push::SubscriptionsController do }, }.with_indifferent_access end + let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: 'push') } + + before do + allow(controller).to receive(:doorkeeper_token) { token } + end describe 'POST #create' do before do diff --git a/spec/lib/activitypub/activity/create_spec.rb b/spec/lib/activitypub/activity/create_spec.rb index 132e0c31c..ddbdb07aa 100644 --- a/spec/lib/activitypub/activity/create_spec.rb +++ b/spec/lib/activitypub/activity/create_spec.rb @@ -753,10 +753,6 @@ RSpec.describe ActivityPub::Activity::Create do context 'with an encrypted message' do let(:recipient) { Fabricate(:account) } - let(:target_device) { Fabricate(:device, account: recipient) } - - subject { described_class.new(json, sender, delivery: true, delivered_to_account_id: recipient.id) } - let(:object_json) do { id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join, @@ -778,6 +774,9 @@ RSpec.describe ActivityPub::Activity::Create do }, } end + let(:target_device) { Fabricate(:device, account: recipient) } + + subject { described_class.new(json, sender, delivery: true, delivered_to_account_id: recipient.id) } before do subject.perform @@ -833,13 +832,6 @@ RSpec.describe ActivityPub::Activity::Create do context 'when sender replies to local status' do let!(:local_status) { Fabricate(:status) } - - subject { described_class.new(json, sender, delivery: true) } - - before do - subject.perform - end - let(:object_json) do { id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join, @@ -849,6 +841,12 @@ RSpec.describe ActivityPub::Activity::Create do } end + subject { described_class.new(json, sender, delivery: true) } + + before do + subject.perform + end + it 'creates status' do status = sender.statuses.first @@ -859,13 +857,6 @@ RSpec.describe ActivityPub::Activity::Create do context 'when sender targets a local user' do let!(:local_account) { Fabricate(:account) } - - subject { described_class.new(json, sender, delivery: true) } - - before do - subject.perform - end - let(:object_json) do { id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join, @@ -875,6 +866,12 @@ RSpec.describe ActivityPub::Activity::Create do } end + subject { described_class.new(json, sender, delivery: true) } + + before do + subject.perform + end + it 'creates status' do status = sender.statuses.first @@ -885,13 +882,6 @@ RSpec.describe ActivityPub::Activity::Create do context 'when sender cc\'s a local user' do let!(:local_account) { Fabricate(:account) } - - subject { described_class.new(json, sender, delivery: true) } - - before do - subject.perform - end - let(:object_json) do { id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join, @@ -901,6 +891,12 @@ RSpec.describe ActivityPub::Activity::Create do } end + subject { described_class.new(json, sender, delivery: true) } + + before do + subject.perform + end + it 'creates status' do status = sender.statuses.first diff --git a/spec/lib/vacuum/media_attachments_vacuum_spec.rb b/spec/lib/vacuum/media_attachments_vacuum_spec.rb index be8458d9b..436237b25 100644 --- a/spec/lib/vacuum/media_attachments_vacuum_spec.rb +++ b/spec/lib/vacuum/media_attachments_vacuum_spec.rb @@ -2,12 +2,11 @@ require 'rails_helper' RSpec.describe Vacuum::MediaAttachmentsVacuum do let(:retention_period) { 7.days } - - subject { described_class.new(retention_period) } - let(:remote_status) { Fabricate(:status, account: Fabricate(:account, domain: 'example.com')) } let(:local_status) { Fabricate(:status) } + subject { described_class.new(retention_period) } + describe '#perform' do let!(:old_remote_media) { Fabricate(:media_attachment, remote_url: 'https://example.com/foo.png', status: remote_status, created_at: (retention_period + 1.day).ago, updated_at: (retention_period + 1.day).ago) } let!(:old_local_media) { Fabricate(:media_attachment, status: local_status, created_at: (retention_period + 1.day).ago, updated_at: (retention_period + 1.day).ago) } diff --git a/spec/services/activitypub/process_status_update_service_spec.rb b/spec/services/activitypub/process_status_update_service_spec.rb index ae7db88bf..9a6d75ec0 100644 --- a/spec/services/activitypub/process_status_update_service_spec.rb +++ b/spec/services/activitypub/process_status_update_service_spec.rb @@ -6,20 +6,6 @@ end RSpec.describe ActivityPub::ProcessStatusUpdateService, type: :service do let!(:status) { Fabricate(:status, text: 'Hello world', account: Fabricate(:account, domain: 'example.com')) } - - let(:alice) { Fabricate(:account) } - let(:bob) { Fabricate(:account) } - - let(:mentions) { [] } - let(:tags) { [] } - let(:media_attachments) { [] } - - before do - mentions.each { |a| Fabricate(:mention, status: status, account: a) } - tags.each { |t| status.tags << t } - media_attachments.each { |m| status.media_attachments << m } - end - let(:payload) do { '@context': 'https://www.w3.org/ns/activitystreams', @@ -34,9 +20,21 @@ RSpec.describe ActivityPub::ProcessStatusUpdateService, type: :service do ], } end - let(:json) { Oj.load(Oj.dump(payload)) } + let(:alice) { Fabricate(:account) } + let(:bob) { Fabricate(:account) } + + let(:mentions) { [] } + let(:tags) { [] } + let(:media_attachments) { [] } + + before do + mentions.each { |a| Fabricate(:mention, status: status, account: a) } + tags.each { |t| status.tags << t } + media_attachments.each { |m| status.media_attachments << m } + end + subject { described_class.new } describe '#call' do diff --git a/spec/services/fan_out_on_write_service_spec.rb b/spec/services/fan_out_on_write_service_spec.rb index 59e15d230..3c294cf95 100644 --- a/spec/services/fan_out_on_write_service_spec.rb +++ b/spec/services/fan_out_on_write_service_spec.rb @@ -2,6 +2,7 @@ require 'rails_helper' RSpec.describe FanOutOnWriteService, type: :service do let(:last_active_at) { Time.now.utc } + let(:status) { Fabricate(:status, account: alice, visibility: visibility, text: 'Hello @bob #hoge') } let!(:alice) { Fabricate(:user, current_sign_in_at: last_active_at).account } let!(:bob) { Fabricate(:user, current_sign_in_at: last_active_at, account_attributes: { username: 'bob' }).account } @@ -9,8 +10,6 @@ RSpec.describe FanOutOnWriteService, type: :service do subject { described_class.new } - let(:status) { Fabricate(:status, account: alice, visibility: visibility, text: 'Hello @bob #hoge') } - before do bob.follow!(alice) tom.follow!(alice) diff --git a/spec/services/import_service_spec.rb b/spec/services/import_service_spec.rb index 2b1516ff0..4a517fb93 100644 --- a/spec/services/import_service_spec.rb +++ b/spec/services/import_service_spec.rb @@ -183,15 +183,14 @@ RSpec.describe ImportService, type: :service do subject { ImportService.new } let!(:nare) { Fabricate(:account, username: 'nare', domain: 'թութ.հայ', locked: false, protocol: :activitypub, inbox_url: 'https://թութ.հայ/inbox') } + let(:csv) { attachment_fixture('utf8-followers.txt') } + let(:import) { Import.create(account: account, type: 'following', data: csv) } # Make sure to not actually go to the remote server before do stub_request(:post, 'https://թութ.հայ/inbox').to_return(status: 200) end - let(:csv) { attachment_fixture('utf8-followers.txt') } - let(:import) { Import.create(account: account, type: 'following', data: csv) } - it 'follows the listed account' do expect(account.follow_requests.count).to eq 0 subject.call(import) @@ -203,6 +202,9 @@ RSpec.describe ImportService, type: :service do subject { ImportService.new } let(:csv) { attachment_fixture('bookmark-imports.txt') } + let(:local_account) { Fabricate(:account, username: 'foo', domain: '') } + let!(:remote_status) { Fabricate(:status, uri: 'https://example.com/statuses/1312') } + let!(:direct_status) { Fabricate(:status, uri: 'https://example.com/statuses/direct', visibility: :direct) } around(:each) do |example| local_before = Rails.configuration.x.local_domain @@ -214,10 +216,6 @@ RSpec.describe ImportService, type: :service do Rails.configuration.x.local_domain = local_before end - let(:local_account) { Fabricate(:account, username: 'foo', domain: '') } - let!(:remote_status) { Fabricate(:status, uri: 'https://example.com/statuses/1312') } - let!(:direct_status) { Fabricate(:status, uri: 'https://example.com/statuses/direct', visibility: :direct) } - before do service = double allow(ActivityPub::FetchRemoteStatusService).to receive(:new).and_return(service) -- cgit