From f32d672d2ffc33fc4b07a6e36f5d9dcbc3f26e4c Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Thu, 21 Dec 2023 04:28:41 -0500 Subject: [PATCH] Clean up of `RSpec/LetSetup` within `spec/controllers` (#28446) --- .rubocop_todo.yml | 5 ---- .../follower_accounts_controller_spec.rb | 7 +++++ .../following_accounts_controller_spec.rb | 7 +++++ ...authorized_applications_controller_spec.rb | 4 +++ .../oauth/tokens_controller_spec.rb | 4 +++ .../settings/imports_controller_spec.rb | 26 ++++++++++--------- 6 files changed, 36 insertions(+), 17 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index bb2715f96e..f834c55620 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -55,11 +55,6 @@ RSpec/LetSetup: - 'spec/controllers/auth/confirmations_controller_spec.rb' - 'spec/controllers/auth/passwords_controller_spec.rb' - 'spec/controllers/auth/sessions_controller_spec.rb' - - 'spec/controllers/follower_accounts_controller_spec.rb' - - 'spec/controllers/following_accounts_controller_spec.rb' - - 'spec/controllers/oauth/authorized_applications_controller_spec.rb' - - 'spec/controllers/oauth/tokens_controller_spec.rb' - - 'spec/controllers/settings/imports_controller_spec.rb' - 'spec/lib/activitypub/activity/delete_spec.rb' - 'spec/lib/vacuum/applications_vacuum_spec.rb' - 'spec/lib/vacuum/preview_cards_vacuum_spec.rb' diff --git a/spec/controllers/follower_accounts_controller_spec.rb b/spec/controllers/follower_accounts_controller_spec.rb index cb8c2a0e5b..dd78c96c05 100644 --- a/spec/controllers/follower_accounts_controller_spec.rb +++ b/spec/controllers/follower_accounts_controller_spec.rb @@ -48,6 +48,13 @@ describe FollowerAccountsController do it 'returns followers' do expect(response).to have_http_status(200) + expect(body_as_json) + .to include( + orderedItems: contain_exactly( + include(follow_from_bob.account.username), + include(follow_from_chris.account.username) + ) + ) expect(body['totalItems']).to eq 2 expect(body['partOf']).to be_present end diff --git a/spec/controllers/following_accounts_controller_spec.rb b/spec/controllers/following_accounts_controller_spec.rb index 095528ed07..7bb78fb420 100644 --- a/spec/controllers/following_accounts_controller_spec.rb +++ b/spec/controllers/following_accounts_controller_spec.rb @@ -48,6 +48,13 @@ describe FollowingAccountsController do it 'returns followers' do expect(response).to have_http_status(200) + expect(body_as_json) + .to include( + orderedItems: contain_exactly( + include(follow_of_bob.target_account.username), + include(follow_of_chris.target_account.username) + ) + ) expect(body['totalItems']).to eq 2 expect(body['partOf']).to be_present end diff --git a/spec/controllers/oauth/authorized_applications_controller_spec.rb b/spec/controllers/oauth/authorized_applications_controller_spec.rb index b54610604c..b46b944d0e 100644 --- a/spec/controllers/oauth/authorized_applications_controller_spec.rb +++ b/spec/controllers/oauth/authorized_applications_controller_spec.rb @@ -63,5 +63,9 @@ describe Oauth::AuthorizedApplicationsController do it 'removes subscriptions for the application\'s access tokens' do expect(Web::PushSubscription.where(user: user).count).to eq 0 end + + it 'removes the web_push_subscription' do + expect { web_push_subscription.reload }.to raise_error(ActiveRecord::RecordNotFound) + end end end diff --git a/spec/controllers/oauth/tokens_controller_spec.rb b/spec/controllers/oauth/tokens_controller_spec.rb index 973393bcf2..dd2d8ca70c 100644 --- a/spec/controllers/oauth/tokens_controller_spec.rb +++ b/spec/controllers/oauth/tokens_controller_spec.rb @@ -20,5 +20,9 @@ RSpec.describe Oauth::TokensController do it 'removes web push subscription for token' do expect(Web::PushSubscription.where(access_token: access_token).count).to eq 0 end + + it 'removes the web_push_subscription' do + expect { web_push_subscription.reload }.to raise_error(ActiveRecord::RecordNotFound) + end end end diff --git a/spec/controllers/settings/imports_controller_spec.rb b/spec/controllers/settings/imports_controller_spec.rb index 1e7b758931..89ec39e54d 100644 --- a/spec/controllers/settings/imports_controller_spec.rb +++ b/spec/controllers/settings/imports_controller_spec.rb @@ -22,6 +22,7 @@ RSpec.describe Settings::ImportsController do it 'assigns the expected imports', :aggregate_failures do expect(response).to have_http_status(200) expect(assigns(:recent_imports)).to eq [import] + expect(assigns(:recent_imports)).to_not include(other_import) expect(response.headers['Cache-Control']).to include('private, no-store') end end @@ -138,6 +139,7 @@ RSpec.describe Settings::ImportsController do let(:bulk_import) { Fabricate(:bulk_import, account: user.account, type: import_type, state: :finished) } before do + rows.each { |data| Fabricate(:bulk_import_row, bulk_import: bulk_import, data: data) } bulk_import.update(total_items: bulk_import.rows.count, processed_items: bulk_import.rows.count, imported_items: 0) end @@ -152,11 +154,11 @@ RSpec.describe Settings::ImportsController do context 'with follows' do let(:import_type) { 'following' } - let!(:rows) do + let(:rows) do [ { 'acct' => 'foo@bar' }, { 'acct' => 'user@bar', 'show_reblogs' => false, 'notify' => true, 'languages' => %w(fr de) }, - ].map { |data| Fabricate(:bulk_import_row, bulk_import: bulk_import, data: data) } + ] end include_examples 'export failed rows', "Account address,Show boosts,Notify on new posts,Languages\nfoo@bar,true,false,\nuser@bar,false,true,\"fr, de\"\n" @@ -165,11 +167,11 @@ RSpec.describe Settings::ImportsController do context 'with blocks' do let(:import_type) { 'blocking' } - let!(:rows) do + let(:rows) do [ { 'acct' => 'foo@bar' }, { 'acct' => 'user@bar' }, - ].map { |data| Fabricate(:bulk_import_row, bulk_import: bulk_import, data: data) } + ] end include_examples 'export failed rows', "foo@bar\nuser@bar\n" @@ -178,11 +180,11 @@ RSpec.describe Settings::ImportsController do context 'with mutes' do let(:import_type) { 'muting' } - let!(:rows) do + let(:rows) do [ { 'acct' => 'foo@bar' }, { 'acct' => 'user@bar', 'hide_notifications' => false }, - ].map { |data| Fabricate(:bulk_import_row, bulk_import: bulk_import, data: data) } + ] end include_examples 'export failed rows', "Account address,Hide notifications\nfoo@bar,true\nuser@bar,false\n" @@ -191,11 +193,11 @@ RSpec.describe Settings::ImportsController do context 'with domain blocks' do let(:import_type) { 'domain_blocking' } - let!(:rows) do + let(:rows) do [ { 'domain' => 'bad.domain' }, { 'domain' => 'evil.domain' }, - ].map { |data| Fabricate(:bulk_import_row, bulk_import: bulk_import, data: data) } + ] end include_examples 'export failed rows', "bad.domain\nevil.domain\n" @@ -204,11 +206,11 @@ RSpec.describe Settings::ImportsController do context 'with bookmarks' do let(:import_type) { 'bookmarks' } - let!(:rows) do + let(:rows) do [ { 'uri' => 'https://foo.com/1' }, { 'uri' => 'https://foo.com/2' }, - ].map { |data| Fabricate(:bulk_import_row, bulk_import: bulk_import, data: data) } + ] end include_examples 'export failed rows', "https://foo.com/1\nhttps://foo.com/2\n" @@ -217,11 +219,11 @@ RSpec.describe Settings::ImportsController do context 'with lists' do let(:import_type) { 'lists' } - let!(:rows) do + let(:rows) do [ { 'list_name' => 'Amigos', 'acct' => 'user@example.com' }, { 'list_name' => 'Frenemies', 'acct' => 'user@org.org' }, - ].map { |data| Fabricate(:bulk_import_row, bulk_import: bulk_import, data: data) } + ] end include_examples 'export failed rows', "Amigos,user@example.com\nFrenemies,user@org.org\n"