From ea1c0feb86e3b1213b0808cef43446b5146d50da Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Wed, 10 Jan 2024 05:35:06 -0500 Subject: [PATCH 1/6] Remove `add_column_with_default` migration helper (#28654) --- ...16191202_add_hide_notifications_to_mute.rb | 6 +-- ...005171936_add_disabled_to_custom_emojis.rb | 6 +-- .../20171028221157_add_reblogs_to_follows.rb | 8 +--- ...20171107143332_add_memorial_to_accounts.rb | 6 +-- .../20171107143624_add_disabled_to_users.rb | 6 +-- ...0171109012327_add_moderator_to_accounts.rb | 6 +-- ...30000000_add_embed_url_to_preview_cards.rb | 6 +-- ...0180615122121_add_autofollow_to_invites.rb | 6 +-- ...7154237_add_whole_word_to_custom_filter.rb | 6 +-- ..._confidential_to_doorkeeper_application.rb | 8 +--- .../20181010141500_add_silent_to_mentions.rb | 8 +--- ...937_add_reject_reports_to_domain_blocks.rb | 6 +-- ...649_add_unread_to_account_conversations.rb | 8 +--- ...0181127165847_add_show_replies_to_lists.rb | 8 +--- ...20190201012802_add_overwrite_to_imports.rb | 6 +-- ...0190306145741_add_lock_version_to_polls.rb | 8 +--- .../20190307234537_add_approved_to_users.rb | 8 +--- ...13028_add_lock_version_to_account_stats.rb | 6 +-- ...58_add_title_to_account_warning_presets.rb | 6 +-- .../20200917192924_add_notify_to_follows.rb | 8 +--- ...18054746_add_obfuscate_to_domain_blocks.rb | 6 +-- .../20211231080958_add_category_to_reports.rb | 6 +-- ...0613110834_add_action_to_custom_filters.rb | 6 +-- .../20230605085710_add_exclusive_to_lists.rb | 6 +-- ..._add_image_description_to_preview_cards.rb | 6 +-- ...0230814223300_add_indexable_to_accounts.rb | 6 +-- ...2_remove_whole_word_from_custom_filters.rb | 6 +-- ...remove_irreversible_from_custom_filters.rb | 6 +-- lib/mastodon/migration_helpers.rb | 41 +------------------ 29 files changed, 37 insertions(+), 188 deletions(-) diff --git a/db/migrate/20170716191202_add_hide_notifications_to_mute.rb b/db/migrate/20170716191202_add_hide_notifications_to_mute.rb index b817d512d..2ef5d2579 100644 --- a/db/migrate/20170716191202_add_hide_notifications_to_mute.rb +++ b/db/migrate/20170716191202_add_hide_notifications_to_mute.rb @@ -1,14 +1,10 @@ # frozen_string_literal: true -require Rails.root.join('lib', 'mastodon', 'migration_helpers') - class AddHideNotificationsToMute < ActiveRecord::Migration[5.1] - include Mastodon::MigrationHelpers - disable_ddl_transaction! def up - add_column_with_default :mutes, :hide_notifications, :boolean, default: true, allow_null: false + add_column :mutes, :hide_notifications, :boolean, default: true, null: false end def down diff --git a/db/migrate/20171005171936_add_disabled_to_custom_emojis.rb b/db/migrate/20171005171936_add_disabled_to_custom_emojis.rb index d6fd228f9..eaf5f4ef2 100644 --- a/db/migrate/20171005171936_add_disabled_to_custom_emojis.rb +++ b/db/migrate/20171005171936_add_disabled_to_custom_emojis.rb @@ -1,14 +1,10 @@ # frozen_string_literal: true -require Rails.root.join('lib', 'mastodon', 'migration_helpers') - class AddDisabledToCustomEmojis < ActiveRecord::Migration[5.2] - include Mastodon::MigrationHelpers - disable_ddl_transaction! def up - safety_assured { add_column_with_default :custom_emojis, :disabled, :bool, default: false } + safety_assured { add_column :custom_emojis, :disabled, :bool, default: false, null: false } end def down diff --git a/db/migrate/20171028221157_add_reblogs_to_follows.rb b/db/migrate/20171028221157_add_reblogs_to_follows.rb index 0dab84c79..068d66d1d 100644 --- a/db/migrate/20171028221157_add_reblogs_to_follows.rb +++ b/db/migrate/20171028221157_add_reblogs_to_follows.rb @@ -1,16 +1,12 @@ # frozen_string_literal: true -require Rails.root.join('lib', 'mastodon', 'migration_helpers') - class AddReblogsToFollows < ActiveRecord::Migration[5.2] - include Mastodon::MigrationHelpers - disable_ddl_transaction! def up safety_assured do - add_column_with_default :follows, :show_reblogs, :boolean, default: true, allow_null: false - add_column_with_default :follow_requests, :show_reblogs, :boolean, default: true, allow_null: false + add_column :follows, :show_reblogs, :boolean, default: true, null: false + add_column :follow_requests, :show_reblogs, :boolean, default: true, null: false end end diff --git a/db/migrate/20171107143332_add_memorial_to_accounts.rb b/db/migrate/20171107143332_add_memorial_to_accounts.rb index 3cf782b81..35a98f45e 100644 --- a/db/migrate/20171107143332_add_memorial_to_accounts.rb +++ b/db/migrate/20171107143332_add_memorial_to_accounts.rb @@ -1,14 +1,10 @@ # frozen_string_literal: true -require Rails.root.join('lib', 'mastodon', 'migration_helpers') - class AddMemorialToAccounts < ActiveRecord::Migration[5.2] - include Mastodon::MigrationHelpers - disable_ddl_transaction! def up - safety_assured { add_column_with_default :accounts, :memorial, :bool, default: false } + safety_assured { add_column :accounts, :memorial, :bool, default: false, null: false } end def down diff --git a/db/migrate/20171107143624_add_disabled_to_users.rb b/db/migrate/20171107143624_add_disabled_to_users.rb index 4ab4df737..055d05b10 100644 --- a/db/migrate/20171107143624_add_disabled_to_users.rb +++ b/db/migrate/20171107143624_add_disabled_to_users.rb @@ -1,14 +1,10 @@ # frozen_string_literal: true -require Rails.root.join('lib', 'mastodon', 'migration_helpers') - class AddDisabledToUsers < ActiveRecord::Migration[5.2] - include Mastodon::MigrationHelpers - disable_ddl_transaction! def up - safety_assured { add_column_with_default :users, :disabled, :bool, default: false } + safety_assured { add_column :users, :disabled, :bool, default: false, null: false } end def down diff --git a/db/migrate/20171109012327_add_moderator_to_accounts.rb b/db/migrate/20171109012327_add_moderator_to_accounts.rb index e8fc313c8..6a29e5aaf 100644 --- a/db/migrate/20171109012327_add_moderator_to_accounts.rb +++ b/db/migrate/20171109012327_add_moderator_to_accounts.rb @@ -1,14 +1,10 @@ # frozen_string_literal: true -require Rails.root.join('lib', 'mastodon', 'migration_helpers') - class AddModeratorToAccounts < ActiveRecord::Migration[5.2] - include Mastodon::MigrationHelpers - disable_ddl_transaction! def up - safety_assured { add_column_with_default :users, :moderator, :bool, default: false } + safety_assured { add_column :users, :moderator, :bool, default: false, null: false } end def down diff --git a/db/migrate/20171130000000_add_embed_url_to_preview_cards.rb b/db/migrate/20171130000000_add_embed_url_to_preview_cards.rb index e78373b24..f2336e8e2 100644 --- a/db/migrate/20171130000000_add_embed_url_to_preview_cards.rb +++ b/db/migrate/20171130000000_add_embed_url_to_preview_cards.rb @@ -1,15 +1,11 @@ # frozen_string_literal: true -require Rails.root.join('lib', 'mastodon', 'migration_helpers') - class AddEmbedURLToPreviewCards < ActiveRecord::Migration[5.2] - include Mastodon::MigrationHelpers - disable_ddl_transaction! def up safety_assured do - add_column_with_default :preview_cards, :embed_url, :string, default: '', allow_null: false + add_column :preview_cards, :embed_url, :string, default: '', null: false end end diff --git a/db/migrate/20180615122121_add_autofollow_to_invites.rb b/db/migrate/20180615122121_add_autofollow_to_invites.rb index ef129003a..19a5f0d17 100644 --- a/db/migrate/20180615122121_add_autofollow_to_invites.rb +++ b/db/migrate/20180615122121_add_autofollow_to_invites.rb @@ -1,15 +1,11 @@ # frozen_string_literal: true -require Rails.root.join('lib', 'mastodon', 'migration_helpers') - class AddAutofollowToInvites < ActiveRecord::Migration[5.2] - include Mastodon::MigrationHelpers - disable_ddl_transaction! def up safety_assured do - add_column_with_default :invites, :autofollow, :bool, default: false, allow_null: false + add_column :invites, :autofollow, :bool, default: false, null: false end end diff --git a/db/migrate/20180707154237_add_whole_word_to_custom_filter.rb b/db/migrate/20180707154237_add_whole_word_to_custom_filter.rb index 793c3e6cf..519dfdfae 100644 --- a/db/migrate/20180707154237_add_whole_word_to_custom_filter.rb +++ b/db/migrate/20180707154237_add_whole_word_to_custom_filter.rb @@ -1,15 +1,11 @@ # frozen_string_literal: true -require Rails.root.join('lib', 'mastodon', 'migration_helpers') - class AddWholeWordToCustomFilter < ActiveRecord::Migration[5.2] - include Mastodon::MigrationHelpers - disable_ddl_transaction! def change safety_assured do - add_column_with_default :custom_filters, :whole_word, :boolean, default: true, allow_null: false + add_column :custom_filters, :whole_word, :boolean, default: true, null: false end end diff --git a/db/migrate/20180814171349_add_confidential_to_doorkeeper_application.rb b/db/migrate/20180814171349_add_confidential_to_doorkeeper_application.rb index 7360c71ac..6544b81c8 100644 --- a/db/migrate/20180814171349_add_confidential_to_doorkeeper_application.rb +++ b/db/migrate/20180814171349_add_confidential_to_doorkeeper_application.rb @@ -1,19 +1,15 @@ # frozen_string_literal: true -require Rails.root.join('lib', 'mastodon', 'migration_helpers') - class AddConfidentialToDoorkeeperApplication < ActiveRecord::Migration[5.2] - include Mastodon::MigrationHelpers - disable_ddl_transaction! def up safety_assured do - add_column_with_default( + add_column( :oauth_applications, :confidential, :boolean, - allow_null: false, + null: false, default: true # maintaining backwards compatibility: require secrets ) end diff --git a/db/migrate/20181010141500_add_silent_to_mentions.rb b/db/migrate/20181010141500_add_silent_to_mentions.rb index f9bfc5169..029119e79 100644 --- a/db/migrate/20181010141500_add_silent_to_mentions.rb +++ b/db/migrate/20181010141500_add_silent_to_mentions.rb @@ -1,19 +1,15 @@ # frozen_string_literal: true -require Rails.root.join('lib', 'mastodon', 'migration_helpers') - class AddSilentToMentions < ActiveRecord::Migration[5.2] - include Mastodon::MigrationHelpers - disable_ddl_transaction! def up safety_assured do - add_column_with_default( + add_column( :mentions, :silent, :boolean, - allow_null: false, + null: false, default: false ) end diff --git a/db/migrate/20181017170937_add_reject_reports_to_domain_blocks.rb b/db/migrate/20181017170937_add_reject_reports_to_domain_blocks.rb index b6cfd31d2..49bd2b02f 100644 --- a/db/migrate/20181017170937_add_reject_reports_to_domain_blocks.rb +++ b/db/migrate/20181017170937_add_reject_reports_to_domain_blocks.rb @@ -1,15 +1,11 @@ # frozen_string_literal: true -require Rails.root.join('lib', 'mastodon', 'migration_helpers') - class AddRejectReportsToDomainBlocks < ActiveRecord::Migration[5.2] - include Mastodon::MigrationHelpers - disable_ddl_transaction! def up safety_assured do - add_column_with_default :domain_blocks, :reject_reports, :boolean, default: false, allow_null: false + add_column :domain_blocks, :reject_reports, :boolean, default: false, null: false end end diff --git a/db/migrate/20181018205649_add_unread_to_account_conversations.rb b/db/migrate/20181018205649_add_unread_to_account_conversations.rb index fec947639..ae4576255 100644 --- a/db/migrate/20181018205649_add_unread_to_account_conversations.rb +++ b/db/migrate/20181018205649_add_unread_to_account_conversations.rb @@ -1,19 +1,15 @@ # frozen_string_literal: true -require Rails.root.join('lib', 'mastodon', 'migration_helpers') - class AddUnreadToAccountConversations < ActiveRecord::Migration[5.2] - include Mastodon::MigrationHelpers - disable_ddl_transaction! def up safety_assured do - add_column_with_default( + add_column( :account_conversations, :unread, :boolean, - allow_null: false, + null: false, default: false ) end diff --git a/db/migrate/20181127165847_add_show_replies_to_lists.rb b/db/migrate/20181127165847_add_show_replies_to_lists.rb index 45d457b74..a391d9f6f 100644 --- a/db/migrate/20181127165847_add_show_replies_to_lists.rb +++ b/db/migrate/20181127165847_add_show_replies_to_lists.rb @@ -1,19 +1,15 @@ # frozen_string_literal: true -require Rails.root.join('lib', 'mastodon', 'migration_helpers') - class AddShowRepliesToLists < ActiveRecord::Migration[5.2] - include Mastodon::MigrationHelpers - disable_ddl_transaction! def up safety_assured do - add_column_with_default( + add_column( :lists, :replies_policy, :integer, - allow_null: false, + null: false, default: 0 ) end diff --git a/db/migrate/20190201012802_add_overwrite_to_imports.rb b/db/migrate/20190201012802_add_overwrite_to_imports.rb index fe9423ed0..b497950ee 100644 --- a/db/migrate/20190201012802_add_overwrite_to_imports.rb +++ b/db/migrate/20190201012802_add_overwrite_to_imports.rb @@ -1,15 +1,11 @@ # frozen_string_literal: true -require Rails.root.join('lib', 'mastodon', 'migration_helpers') - class AddOverwriteToImports < ActiveRecord::Migration[5.2] - include Mastodon::MigrationHelpers - disable_ddl_transaction! def up safety_assured do - add_column_with_default :imports, :overwrite, :boolean, default: false, allow_null: false + add_column :imports, :overwrite, :boolean, default: false, null: false end end diff --git a/db/migrate/20190306145741_add_lock_version_to_polls.rb b/db/migrate/20190306145741_add_lock_version_to_polls.rb index 760818d97..ec4430ea9 100644 --- a/db/migrate/20190306145741_add_lock_version_to_polls.rb +++ b/db/migrate/20190306145741_add_lock_version_to_polls.rb @@ -1,19 +1,15 @@ # frozen_string_literal: true -require Rails.root.join('lib', 'mastodon', 'migration_helpers') - class AddLockVersionToPolls < ActiveRecord::Migration[5.2] - include Mastodon::MigrationHelpers - disable_ddl_transaction! def up safety_assured do - add_column_with_default( + add_column( :polls, :lock_version, :integer, - allow_null: false, + null: false, default: 0 ) end diff --git a/db/migrate/20190307234537_add_approved_to_users.rb b/db/migrate/20190307234537_add_approved_to_users.rb index 9abab29c9..ffdc24716 100644 --- a/db/migrate/20190307234537_add_approved_to_users.rb +++ b/db/migrate/20190307234537_add_approved_to_users.rb @@ -1,19 +1,15 @@ # frozen_string_literal: true -require Rails.root.join('lib', 'mastodon', 'migration_helpers') - class AddApprovedToUsers < ActiveRecord::Migration[5.2] - include Mastodon::MigrationHelpers - disable_ddl_transaction! def up safety_assured do - add_column_with_default( + add_column( :users, :approved, :bool, - allow_null: false, + null: false, default: true ) end diff --git a/db/migrate/20191001213028_add_lock_version_to_account_stats.rb b/db/migrate/20191001213028_add_lock_version_to_account_stats.rb index 0dc165559..3ffbacf25 100644 --- a/db/migrate/20191001213028_add_lock_version_to_account_stats.rb +++ b/db/migrate/20191001213028_add_lock_version_to_account_stats.rb @@ -1,14 +1,10 @@ # frozen_string_literal: true -require Rails.root.join('lib', 'mastodon', 'migration_helpers') - class AddLockVersionToAccountStats < ActiveRecord::Migration[5.2] - include Mastodon::MigrationHelpers - disable_ddl_transaction! def up - safety_assured { add_column_with_default :account_stats, :lock_version, :integer, allow_null: false, default: 0 } + safety_assured { add_column :account_stats, :lock_version, :integer, null: false, default: 0 } end def down diff --git a/db/migrate/20200312144258_add_title_to_account_warning_presets.rb b/db/migrate/20200312144258_add_title_to_account_warning_presets.rb index 78b854f82..63d339c49 100644 --- a/db/migrate/20200312144258_add_title_to_account_warning_presets.rb +++ b/db/migrate/20200312144258_add_title_to_account_warning_presets.rb @@ -1,14 +1,10 @@ # frozen_string_literal: true -require Rails.root.join('lib', 'mastodon', 'migration_helpers') - class AddTitleToAccountWarningPresets < ActiveRecord::Migration[5.2] - include Mastodon::MigrationHelpers - disable_ddl_transaction! def up - safety_assured { add_column_with_default :account_warning_presets, :title, :string, default: '', allow_null: false } + safety_assured { add_column :account_warning_presets, :title, :string, default: '', null: false } end def down diff --git a/db/migrate/20200917192924_add_notify_to_follows.rb b/db/migrate/20200917192924_add_notify_to_follows.rb index a57bb36dc..1dc831dc4 100644 --- a/db/migrate/20200917192924_add_notify_to_follows.rb +++ b/db/migrate/20200917192924_add_notify_to_follows.rb @@ -1,16 +1,12 @@ # frozen_string_literal: true -require Rails.root.join('lib', 'mastodon', 'migration_helpers') - class AddNotifyToFollows < ActiveRecord::Migration[5.2] - include Mastodon::MigrationHelpers - disable_ddl_transaction! def up safety_assured do - add_column_with_default :follows, :notify, :boolean, default: false, allow_null: false - add_column_with_default :follow_requests, :notify, :boolean, default: false, allow_null: false + add_column :follows, :notify, :boolean, default: false, null: false + add_column :follow_requests, :notify, :boolean, default: false, null: false end end diff --git a/db/migrate/20201218054746_add_obfuscate_to_domain_blocks.rb b/db/migrate/20201218054746_add_obfuscate_to_domain_blocks.rb index 91bba38c5..d7038c83d 100644 --- a/db/migrate/20201218054746_add_obfuscate_to_domain_blocks.rb +++ b/db/migrate/20201218054746_add_obfuscate_to_domain_blocks.rb @@ -1,14 +1,10 @@ # frozen_string_literal: true -require Rails.root.join('lib', 'mastodon', 'migration_helpers') - class AddObfuscateToDomainBlocks < ActiveRecord::Migration[5.2] - include Mastodon::MigrationHelpers - disable_ddl_transaction! def up - safety_assured { add_column_with_default :domain_blocks, :obfuscate, :boolean, default: false, allow_null: false } + safety_assured { add_column :domain_blocks, :obfuscate, :boolean, default: false, null: false } end def down diff --git a/db/migrate/20211231080958_add_category_to_reports.rb b/db/migrate/20211231080958_add_category_to_reports.rb index f114cda61..a20a3155d 100644 --- a/db/migrate/20211231080958_add_category_to_reports.rb +++ b/db/migrate/20211231080958_add_category_to_reports.rb @@ -1,15 +1,11 @@ # frozen_string_literal: true -require Rails.root.join('lib', 'mastodon', 'migration_helpers') - class AddCategoryToReports < ActiveRecord::Migration[6.1] - include Mastodon::MigrationHelpers - disable_ddl_transaction! def up safety_assured do - add_column_with_default :reports, :category, :int, default: 0, allow_null: false + add_column :reports, :category, :int, default: 0, null: false change_table(:reports, bulk: true) do |t| t.column :action_taken_at, :datetime t.column :rule_ids, :bigint, array: true diff --git a/db/migrate/20220613110834_add_action_to_custom_filters.rb b/db/migrate/20220613110834_add_action_to_custom_filters.rb index c1daf3c94..ab2f7c65e 100644 --- a/db/migrate/20220613110834_add_action_to_custom_filters.rb +++ b/db/migrate/20220613110834_add_action_to_custom_filters.rb @@ -1,15 +1,11 @@ # frozen_string_literal: true -require Rails.root.join('lib', 'mastodon', 'migration_helpers') - class AddActionToCustomFilters < ActiveRecord::Migration[6.1] - include Mastodon::MigrationHelpers - disable_ddl_transaction! def up safety_assured do - add_column_with_default :custom_filters, :action, :integer, allow_null: false, default: 0 + add_column :custom_filters, :action, :integer, null: false, default: 0 execute 'UPDATE custom_filters SET action = 1 WHERE irreversible IS TRUE' end end diff --git a/db/migrate/20230605085710_add_exclusive_to_lists.rb b/db/migrate/20230605085710_add_exclusive_to_lists.rb index 315c9d487..abcb8fae1 100644 --- a/db/migrate/20230605085710_add_exclusive_to_lists.rb +++ b/db/migrate/20230605085710_add_exclusive_to_lists.rb @@ -1,14 +1,10 @@ # frozen_string_literal: true -require Rails.root.join('lib', 'mastodon', 'migration_helpers') - class AddExclusiveToLists < ActiveRecord::Migration[6.1] - include Mastodon::MigrationHelpers - disable_ddl_transaction! def up - safety_assured { add_column_with_default :lists, :exclusive, :boolean, default: false, allow_null: false } + safety_assured { add_column :lists, :exclusive, :boolean, default: false, null: false } end def down diff --git a/db/migrate/20230725213448_add_image_description_to_preview_cards.rb b/db/migrate/20230725213448_add_image_description_to_preview_cards.rb index 03020db65..7445a0e7f 100644 --- a/db/migrate/20230725213448_add_image_description_to_preview_cards.rb +++ b/db/migrate/20230725213448_add_image_description_to_preview_cards.rb @@ -1,14 +1,10 @@ # frozen_string_literal: true -require Rails.root.join('lib', 'mastodon', 'migration_helpers') - class AddImageDescriptionToPreviewCards < ActiveRecord::Migration[7.0] - include Mastodon::MigrationHelpers - disable_ddl_transaction! def up - safety_assured { add_column_with_default :preview_cards, :image_description, :string, default: '', allow_null: false } + safety_assured { add_column :preview_cards, :image_description, :string, default: '', null: false } end def down diff --git a/db/migrate/20230814223300_add_indexable_to_accounts.rb b/db/migrate/20230814223300_add_indexable_to_accounts.rb index 6729c05ef..0544eb92f 100644 --- a/db/migrate/20230814223300_add_indexable_to_accounts.rb +++ b/db/migrate/20230814223300_add_indexable_to_accounts.rb @@ -1,14 +1,10 @@ # frozen_string_literal: true -require Rails.root.join('lib', 'mastodon', 'migration_helpers') - class AddIndexableToAccounts < ActiveRecord::Migration[7.0] - include Mastodon::MigrationHelpers - disable_ddl_transaction! def up - safety_assured { add_column_with_default :accounts, :indexable, :boolean, default: false, allow_null: false } + safety_assured { add_column :accounts, :indexable, :boolean, default: false, null: false } end def down diff --git a/db/post_migrate/20220613110802_remove_whole_word_from_custom_filters.rb b/db/post_migrate/20220613110802_remove_whole_word_from_custom_filters.rb index 99c3366a2..5e477d9b1 100644 --- a/db/post_migrate/20220613110802_remove_whole_word_from_custom_filters.rb +++ b/db/post_migrate/20220613110802_remove_whole_word_from_custom_filters.rb @@ -1,10 +1,6 @@ # frozen_string_literal: true -require Rails.root.join('lib', 'mastodon', 'migration_helpers') - class RemoveWholeWordFromCustomFilters < ActiveRecord::Migration[6.1] - include Mastodon::MigrationHelpers - disable_ddl_transaction! def up @@ -15,7 +11,7 @@ class RemoveWholeWordFromCustomFilters < ActiveRecord::Migration[6.1] def down safety_assured do - add_column_with_default :custom_filters, :whole_word, :boolean, default: true, allow_null: false + add_column :custom_filters, :whole_word, :boolean, default: true, null: false end end end diff --git a/db/post_migrate/20220613110903_remove_irreversible_from_custom_filters.rb b/db/post_migrate/20220613110903_remove_irreversible_from_custom_filters.rb index 1c366ee53..1ed009fe9 100644 --- a/db/post_migrate/20220613110903_remove_irreversible_from_custom_filters.rb +++ b/db/post_migrate/20220613110903_remove_irreversible_from_custom_filters.rb @@ -1,10 +1,6 @@ # frozen_string_literal: true -require Rails.root.join('lib', 'mastodon', 'migration_helpers') - class RemoveIrreversibleFromCustomFilters < ActiveRecord::Migration[6.1] - include Mastodon::MigrationHelpers - disable_ddl_transaction! def up @@ -15,7 +11,7 @@ class RemoveIrreversibleFromCustomFilters < ActiveRecord::Migration[6.1] def down safety_assured do - add_column_with_default :custom_filters, :irreversible, :boolean, allow_null: false, default: false + add_column :custom_filters, :irreversible, :boolean, null: false, default: false end end end diff --git a/lib/mastodon/migration_helpers.rb b/lib/mastodon/migration_helpers.rb index 7bc129883..1a2ce6420 100644 --- a/lib/mastodon/migration_helpers.rb +++ b/lib/mastodon/migration_helpers.rb @@ -104,18 +104,7 @@ module Mastodon 'in the body of your migration class' end - # If default value is presented, use `add_column_with_default` method instead. - if options[:default] - add_column_with_default( - table_name, - column_name, - :datetime_with_timezone, - default: options[:default], - allow_null: options[:null] - ) - else - add_column(table_name, column_name, :datetime_with_timezone, **options) - end + add_column(table_name, column_name, :datetime_with_timezone, **options) end end @@ -377,34 +366,6 @@ module Mastodon end end - # Adds a column with a default value without locking an entire table. - # - # This method runs the following steps: - # - # 1. Add the column with a default value of NULL. - # 2. Change the default value of the column to the specified value. - # 3. Update all existing rows in batches. - # 4. Set a `NOT NULL` constraint on the column if desired (the default). - # - # These steps ensure a column can be added to a large and commonly used - # table without locking the entire table for the duration of the table - # modification. - # - # table - The name of the table to update. - # column - The name of the column to add. - # type - The column type (e.g. `:integer`). - # default - The default value for the column. - # limit - Sets a column limit. For example, for :integer, the default is - # 4-bytes. Set `limit: 8` to allow 8-byte integers. - # allow_null - When set to `true` the column will allow NULL values, the - # default is to not allow NULL values. - # - # This method can also take a block which is passed directly to the - # `update_column_in_batches` method. - def add_column_with_default(table, column, type, default:, limit: nil, allow_null: false, &block) - add_column(table, column, type, default: default, limit: limit, null: allow_null) - end - # Renames a column without requiring downtime. # # Concurrent renames work by using database triggers to ensure both the From 00341c70ffea2cdef9d6e73f6897ffbab04401f0 Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Wed, 10 Jan 2024 06:06:58 -0500 Subject: [PATCH 2/6] Use Sidekiq `fake!` instead of `inline!` in specs (#25369) --- .../admin/disputes/appeals_controller_spec.rb | 4 ++-- .../admin/domain_blocks_controller_spec.rb | 2 +- spec/controllers/admin/resets_controller_spec.rb | 2 +- .../api/v1/conversations_controller_spec.rb | 2 +- .../api/v1/statuses/reblogs_controller_spec.rb | 4 ++-- spec/controllers/auth/sessions_controller_spec.rb | 2 +- .../concerns/user_tracking_concern_spec.rb | 2 +- spec/controllers/disputes/appeals_controller_spec.rb | 2 +- spec/controllers/settings/deletes_controller_spec.rb | 2 +- spec/controllers/settings/exports_controller_spec.rb | 2 +- spec/features/admin/accounts_spec.rb | 2 +- spec/lib/activitypub/activity/create_spec.rb | 2 +- spec/lib/activitypub/activity/delete_spec.rb | 2 +- spec/lib/activitypub/activity/move_spec.rb | 2 +- spec/models/admin/account_action_spec.rb | 2 +- spec/models/user_spec.rb | 4 ++-- spec/rails_helper.rb | 8 ++------ spec/requests/api/v1/featured_tags_spec.rb | 2 +- spec/requests/api/v1/notifications_spec.rb | 2 +- spec/requests/api/v1/statuses/favourites_spec.rb | 8 ++------ spec/requests/api/v1/timelines/home_spec.rb | 2 +- .../models/concerns/account/statuses_search_spec.rb | 2 +- .../activitypub/fetch_remote_status_service_spec.rb | 2 +- .../activitypub/process_account_service_spec.rb | 2 +- spec/services/authorize_follow_service_spec.rb | 2 +- spec/services/batched_remove_status_service_spec.rb | 2 +- spec/services/block_domain_service_spec.rb | 2 +- spec/services/block_service_spec.rb | 2 +- spec/services/bulk_import_service_spec.rb | 2 +- spec/services/delete_account_service_spec.rb | 4 ++-- spec/services/fan_out_on_write_service_spec.rb | 12 +++++------- spec/services/favourite_service_spec.rb | 2 +- spec/services/follow_service_spec.rb | 2 +- spec/services/import_service_spec.rb | 2 +- spec/services/mute_service_spec.rb | 2 +- spec/services/notify_service_spec.rb | 2 +- spec/services/reblog_service_spec.rb | 2 +- spec/services/reject_follow_service_spec.rb | 2 +- spec/services/remove_from_followers_service_spec.rb | 2 +- spec/services/remove_status_service_spec.rb | 2 +- spec/services/report_service_spec.rb | 2 +- spec/services/resolve_account_service_spec.rb | 2 +- spec/services/suspend_account_service_spec.rb | 2 +- spec/services/unallow_domain_service_spec.rb | 2 +- spec/services/unblock_service_spec.rb | 2 +- spec/services/unfollow_service_spec.rb | 4 ++-- spec/services/unsuspend_account_service_spec.rb | 2 +- spec/services/update_account_service_spec.rb | 2 +- spec/services/update_status_service_spec.rb | 2 +- spec/system/new_statuses_spec.rb | 2 +- spec/workers/backup_worker_spec.rb | 2 +- spec/workers/move_worker_spec.rb | 6 +++--- spec/workers/poll_expiration_notify_worker_spec.rb | 2 +- 53 files changed, 66 insertions(+), 76 deletions(-) diff --git a/spec/controllers/admin/disputes/appeals_controller_spec.rb b/spec/controllers/admin/disputes/appeals_controller_spec.rb index 4581d00d6..f830c3b95 100644 --- a/spec/controllers/admin/disputes/appeals_controller_spec.rb +++ b/spec/controllers/admin/disputes/appeals_controller_spec.rb @@ -44,7 +44,7 @@ RSpec.describe Admin::Disputes::AppealsController do expect(response).to redirect_to(disputes_strike_path(appeal.strike)) end - it 'notifies target account about approved appeal' do + it 'notifies target account about approved appeal', :sidekiq_inline do expect(UserMailer.deliveries.size).to eq(1) expect(UserMailer.deliveries.first.to.first).to eq(target_account.user.email) expect(UserMailer.deliveries.first.subject).to eq(I18n.t('user_mailer.appeal_approved.subject', date: I18n.l(appeal.created_at))) @@ -62,7 +62,7 @@ RSpec.describe Admin::Disputes::AppealsController do expect(response).to redirect_to(disputes_strike_path(appeal.strike)) end - it 'notifies target account about rejected appeal' do + it 'notifies target account about rejected appeal', :sidekiq_inline do expect(UserMailer.deliveries.size).to eq(1) expect(UserMailer.deliveries.first.to.first).to eq(target_account.user.email) expect(UserMailer.deliveries.first.subject).to eq(I18n.t('user_mailer.appeal_rejected.subject', date: I18n.l(appeal.created_at))) diff --git a/spec/controllers/admin/domain_blocks_controller_spec.rb b/spec/controllers/admin/domain_blocks_controller_spec.rb index 22960f531..87b08323d 100644 --- a/spec/controllers/admin/domain_blocks_controller_spec.rb +++ b/spec/controllers/admin/domain_blocks_controller_spec.rb @@ -176,7 +176,7 @@ RSpec.describe Admin::DomainBlocksController do end end - describe 'PUT #update' do + describe 'PUT #update', :sidekiq_inline do subject do post :update, params: { :id => domain_block.id, :domain_block => { domain: 'example.com', severity: new_severity }, 'confirm' => '' } end diff --git a/spec/controllers/admin/resets_controller_spec.rb b/spec/controllers/admin/resets_controller_spec.rb index 14826973c..e82a3a6af 100644 --- a/spec/controllers/admin/resets_controller_spec.rb +++ b/spec/controllers/admin/resets_controller_spec.rb @@ -11,7 +11,7 @@ describe Admin::ResetsController do sign_in Fabricate(:user, role: UserRole.find_by(name: 'Admin')), scope: :user end - describe 'POST #create' do + describe 'POST #create', :sidekiq_inline do it 'redirects to admin accounts page' do expect do post :create, params: { account_id: account.id } diff --git a/spec/controllers/api/v1/conversations_controller_spec.rb b/spec/controllers/api/v1/conversations_controller_spec.rb index 50e2a62ef..2734e4a07 100644 --- a/spec/controllers/api/v1/conversations_controller_spec.rb +++ b/spec/controllers/api/v1/conversations_controller_spec.rb @@ -13,7 +13,7 @@ RSpec.describe Api::V1::ConversationsController do allow(controller).to receive(:doorkeeper_token) { token } end - describe 'GET #index' do + describe 'GET #index', :sidekiq_inline do let(:scopes) { 'read:statuses' } before do diff --git a/spec/controllers/api/v1/statuses/reblogs_controller_spec.rb b/spec/controllers/api/v1/statuses/reblogs_controller_spec.rb index e3a9bdb50..014a03c1a 100644 --- a/spec/controllers/api/v1/statuses/reblogs_controller_spec.rb +++ b/spec/controllers/api/v1/statuses/reblogs_controller_spec.rb @@ -9,7 +9,7 @@ describe Api::V1::Statuses::ReblogsController do let(:app) { Fabricate(:application, name: 'Test app', website: 'http://testapp.com') } let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: 'write:statuses', application: app) } - context 'with an oauth token', :sidekiq_fake do + context 'with an oauth token' do before do allow(controller).to receive(:doorkeeper_token) { token } end @@ -46,7 +46,7 @@ describe Api::V1::Statuses::ReblogsController do end end - describe 'POST #destroy' do + describe 'POST #destroy', :sidekiq_inline do context 'with public status' do let(:status) { Fabricate(:status, account: user.account) } diff --git a/spec/controllers/auth/sessions_controller_spec.rb b/spec/controllers/auth/sessions_controller_spec.rb index 212cc4d5e..e3f2b278b 100644 --- a/spec/controllers/auth/sessions_controller_spec.rb +++ b/spec/controllers/auth/sessions_controller_spec.rb @@ -138,7 +138,7 @@ RSpec.describe Auth::SessionsController do expect(controller.current_user).to eq user end - it 'sends a suspicious sign-in mail' do + it 'sends a suspicious sign-in mail', :sidekiq_inline do expect(UserMailer.deliveries.size).to eq(1) expect(UserMailer.deliveries.first.to.first).to eq(user.email) expect(UserMailer.deliveries.first.subject).to eq(I18n.t('user_mailer.suspicious_sign_in.subject')) diff --git a/spec/controllers/concerns/user_tracking_concern_spec.rb b/spec/controllers/concerns/user_tracking_concern_spec.rb index dd0b3c042..b1de3cf4e 100644 --- a/spec/controllers/concerns/user_tracking_concern_spec.rb +++ b/spec/controllers/concerns/user_tracking_concern_spec.rb @@ -75,7 +75,7 @@ describe UserTrackingConcern do expect(redis.ttl("account:#{user.account_id}:regeneration")).to be >= 0 end - it 'regenerates feed when sign in is older than two weeks' do + it 'regenerates feed when sign in is older than two weeks', :sidekiq_inline do get :show expect_updated_sign_in_at(user) diff --git a/spec/controllers/disputes/appeals_controller_spec.rb b/spec/controllers/disputes/appeals_controller_spec.rb index c8444a2a9..452bd60dc 100644 --- a/spec/controllers/disputes/appeals_controller_spec.rb +++ b/spec/controllers/disputes/appeals_controller_spec.rb @@ -17,7 +17,7 @@ RSpec.describe Disputes::AppealsController do post :create, params: { strike_id: strike.id, appeal: { text: 'Foo' } } end - it 'notifies staff about new appeal' do + it 'notifies staff about new appeal', :sidekiq_inline do expect(ActionMailer::Base.deliveries.first.to).to eq([admin.email]) end diff --git a/spec/controllers/settings/deletes_controller_spec.rb b/spec/controllers/settings/deletes_controller_spec.rb index 2c1532ecd..ccca4564e 100644 --- a/spec/controllers/settings/deletes_controller_spec.rb +++ b/spec/controllers/settings/deletes_controller_spec.rb @@ -50,7 +50,7 @@ describe Settings::DeletesController do delete :destroy, params: { form_delete_confirmation: { password: 'petsmoldoggos' } } end - it 'removes user record and redirects', :aggregate_failures do + it 'removes user record and redirects', :aggregate_failures, :sidekiq_inline do expect(response).to redirect_to '/auth/sign_in' expect(User.find_by(id: user.id)).to be_nil expect(user.account.reload).to be_suspended diff --git a/spec/controllers/settings/exports_controller_spec.rb b/spec/controllers/settings/exports_controller_spec.rb index 0bd1e80c3..3399f78ac 100644 --- a/spec/controllers/settings/exports_controller_spec.rb +++ b/spec/controllers/settings/exports_controller_spec.rb @@ -38,7 +38,7 @@ describe Settings::ExportsController do expect(response).to redirect_to(settings_export_path) end - it 'queues BackupWorker job by 1', :sidekiq_fake do + it 'queues BackupWorker job by 1' do expect do post :create end.to change(BackupWorker.jobs, :size).by(1) diff --git a/spec/features/admin/accounts_spec.rb b/spec/features/admin/accounts_spec.rb index 6d7bab184..54d755b91 100644 --- a/spec/features/admin/accounts_spec.rb +++ b/spec/features/admin/accounts_spec.rb @@ -48,7 +48,7 @@ describe 'Admin::Accounts' do end end - context 'with action of `reject`' do + context 'with action of `reject`', :sidekiq_inline do it 'rejects and removes the account' do batch_checkbox_for(unapproved_user_account).check diff --git a/spec/lib/activitypub/activity/create_spec.rb b/spec/lib/activitypub/activity/create_spec.rb index 8084427d0..3e3a4978c 100644 --- a/spec/lib/activitypub/activity/create_spec.rb +++ b/spec/lib/activitypub/activity/create_spec.rb @@ -23,7 +23,7 @@ RSpec.describe ActivityPub::Activity::Create do stub_request(:get, 'http://example.com/emojib.png').to_return(body: attachment_fixture('emojo.png'), headers: { 'Content-Type' => 'application/octet-stream' }) end - describe 'processing posts received out of order', :sidekiq_fake do + describe 'processing posts received out of order' do let(:follower) { Fabricate(:account, username: 'bob') } let(:object_json) do diff --git a/spec/lib/activitypub/activity/delete_spec.rb b/spec/lib/activitypub/activity/delete_spec.rb index aec2c71e5..48421a116 100644 --- a/spec/lib/activitypub/activity/delete_spec.rb +++ b/spec/lib/activitypub/activity/delete_spec.rb @@ -47,7 +47,7 @@ RSpec.describe ActivityPub::Activity::Delete do expect(Status.find_by(id: status.id)).to be_nil end - it 'sends delete activity to followers of rebloggers' do + it 'sends delete activity to followers of rebloggers', :sidekiq_inline do expect(a_request(:post, 'http://example.com/inbox')).to have_been_made.once end diff --git a/spec/lib/activitypub/activity/move_spec.rb b/spec/lib/activitypub/activity/move_spec.rb index f3973c70c..4dda014a0 100644 --- a/spec/lib/activitypub/activity/move_spec.rb +++ b/spec/lib/activitypub/activity/move_spec.rb @@ -38,7 +38,7 @@ RSpec.describe ActivityPub::Activity::Move do subject.perform end - context 'when all conditions are met' do + context 'when all conditions are met', :sidekiq_inline do it 'sets moved account on old account' do expect(old_account.reload.moved_to_account_id).to eq new_account.id end diff --git a/spec/models/admin/account_action_spec.rb b/spec/models/admin/account_action_spec.rb index 5d64d565f..9bc9f8061 100644 --- a/spec/models/admin/account_action_spec.rb +++ b/spec/models/admin/account_action_spec.rb @@ -46,7 +46,7 @@ RSpec.describe Admin::AccountAction do expect(target_account).to be_suspended end - it 'queues Admin::SuspensionWorker by 1', :sidekiq_fake do + it 'queues Admin::SuspensionWorker by 1' do expect do subject end.to change { Admin::SuspensionWorker.jobs.size }.by 1 diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index ab5bd39b7..c8415df92 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -58,7 +58,7 @@ RSpec.describe User do end end - describe 'scopes' do + describe 'scopes', :sidekiq_inline do describe 'recent' do it 'returns an array of recent users ordered by id' do first_user = Fabricate(:user) @@ -452,7 +452,7 @@ RSpec.describe User do expect(user.confirmed_at).to be_present end - it 'delivers mails' do + it 'delivers mails', :sidekiq_inline do expect(ActionMailer::Base.deliveries.count).to eq 2 end end diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index e5d432b45..783258b3a 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -26,7 +26,6 @@ Dir[Rails.root.join('spec', 'support', '**', '*.rb')].each { |f| require f } ActiveRecord::Migration.maintain_test_schema! WebMock.disable_net_connect!(allow: Chewy.settings[:host], allow_localhost: RUN_SYSTEM_SPECS) -Sidekiq::Testing.inline! Sidekiq.logger = nil # System tests config @@ -96,11 +95,8 @@ RSpec.configure do |config| self.use_transactional_tests = true end - config.around(:each, :sidekiq_fake) do |example| - Sidekiq::Testing.fake! do - example.run - Sidekiq::Worker.clear_all - end + config.around(:each, :sidekiq_inline) do |example| + Sidekiq::Testing.inline!(&example) end config.before :each, type: :cli do diff --git a/spec/requests/api/v1/featured_tags_spec.rb b/spec/requests/api/v1/featured_tags_spec.rb index c4aa2c0a2..f499dd1d0 100644 --- a/spec/requests/api/v1/featured_tags_spec.rb +++ b/spec/requests/api/v1/featured_tags_spec.rb @@ -147,7 +147,7 @@ RSpec.describe 'FeaturedTags' do expect(body).to be_empty end - it 'deletes the featured tag' do + it 'deletes the featured tag', :sidekiq_inline do delete "/api/v1/featured_tags/#{id}", headers: headers featured_tag = FeaturedTag.find_by(id: id) diff --git a/spec/requests/api/v1/notifications_spec.rb b/spec/requests/api/v1/notifications_spec.rb index 7a904816e..222ff67fc 100644 --- a/spec/requests/api/v1/notifications_spec.rb +++ b/spec/requests/api/v1/notifications_spec.rb @@ -8,7 +8,7 @@ RSpec.describe 'Notifications' do let(:scopes) { 'read:notifications write:notifications' } let(:headers) { { 'Authorization' => "Bearer #{token.token}" } } - describe 'GET /api/v1/notifications' do + describe 'GET /api/v1/notifications', :sidekiq_inline do subject do get '/api/v1/notifications', headers: headers, params: params end diff --git a/spec/requests/api/v1/statuses/favourites_spec.rb b/spec/requests/api/v1/statuses/favourites_spec.rb index 8f3e6e5c4..033aed7e2 100644 --- a/spec/requests/api/v1/statuses/favourites_spec.rb +++ b/spec/requests/api/v1/statuses/favourites_spec.rb @@ -2,7 +2,7 @@ require 'rails_helper' -RSpec.describe 'Favourites' do +RSpec.describe 'Favourites', :sidekiq_inline do let(:user) { Fabricate(:user) } let(:scopes) { 'write:favourites' } let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: scopes) } @@ -70,7 +70,7 @@ RSpec.describe 'Favourites' do end end - describe 'POST /api/v1/statuses/:status_id/unfavourite', :sidekiq_fake do + describe 'POST /api/v1/statuses/:status_id/unfavourite' do subject do post "/api/v1/statuses/#{status.id}/unfavourite", headers: headers end @@ -88,9 +88,7 @@ RSpec.describe 'Favourites' do subject expect(response).to have_http_status(200) - expect(user.account.favourited?(status)).to be true - UnfavouriteWorker.drain expect(user.account.favourited?(status)).to be false end @@ -113,9 +111,7 @@ RSpec.describe 'Favourites' do subject expect(response).to have_http_status(200) - expect(user.account.favourited?(status)).to be true - UnfavouriteWorker.drain expect(user.account.favourited?(status)).to be false end diff --git a/spec/requests/api/v1/timelines/home_spec.rb b/spec/requests/api/v1/timelines/home_spec.rb index 5834b9095..e57e9643b 100644 --- a/spec/requests/api/v1/timelines/home_spec.rb +++ b/spec/requests/api/v1/timelines/home_spec.rb @@ -2,7 +2,7 @@ require 'rails_helper' -describe 'Home' do +describe 'Home', :sidekiq_inline do let(:user) { Fabricate(:user) } let(:scopes) { 'read:statuses' } let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: scopes) } diff --git a/spec/search/models/concerns/account/statuses_search_spec.rb b/spec/search/models/concerns/account/statuses_search_spec.rb index bf2606eec..915bc094c 100644 --- a/spec/search/models/concerns/account/statuses_search_spec.rb +++ b/spec/search/models/concerns/account/statuses_search_spec.rb @@ -2,7 +2,7 @@ require 'rails_helper' -describe Account::StatusesSearch do +describe Account::StatusesSearch, :sidekiq_inline do describe 'a non-indexable account becoming indexable' do let(:account) { Account.find_by(username: 'search_test_account_1') } diff --git a/spec/services/activitypub/fetch_remote_status_service_spec.rb b/spec/services/activitypub/fetch_remote_status_service_spec.rb index 3c64feaee..0fb32d20b 100644 --- a/spec/services/activitypub/fetch_remote_status_service_spec.rb +++ b/spec/services/activitypub/fetch_remote_status_service_spec.rb @@ -225,7 +225,7 @@ RSpec.describe ActivityPub::FetchRemoteStatusService, type: :service do end end - context 'with statuses referencing other statuses' do + context 'with statuses referencing other statuses', :sidekiq_inline do before do stub_const 'ActivityPub::FetchRemoteStatusService::DISCOVERIES_PER_REQUEST', 5 end diff --git a/spec/services/activitypub/process_account_service_spec.rb b/spec/services/activitypub/process_account_service_spec.rb index 58dd2badb..9abe03181 100644 --- a/spec/services/activitypub/process_account_service_spec.rb +++ b/spec/services/activitypub/process_account_service_spec.rb @@ -193,7 +193,7 @@ RSpec.describe ActivityPub::ProcessAccountService, type: :service do end end - it 'creates accounts without exceeding rate limit' do + it 'creates accounts without exceeding rate limit', :sidekiq_inline do expect { subject.call('user1', 'foo.test', payload) } .to create_some_remote_accounts .and create_fewer_than_rate_limit_accounts diff --git a/spec/services/authorize_follow_service_spec.rb b/spec/services/authorize_follow_service_spec.rb index d07645ab6..602250ee9 100644 --- a/spec/services/authorize_follow_service_spec.rb +++ b/spec/services/authorize_follow_service_spec.rb @@ -41,7 +41,7 @@ RSpec.describe AuthorizeFollowService, type: :service do expect(bob.following?(sender)).to be true end - it 'sends an accept activity' do + it 'sends an accept activity', :sidekiq_inline do expect(a_request(:post, bob.inbox_url)).to have_been_made.once end end diff --git a/spec/services/batched_remove_status_service_spec.rb b/spec/services/batched_remove_status_service_spec.rb index 991a852f0..1c59d5ed0 100644 --- a/spec/services/batched_remove_status_service_spec.rb +++ b/spec/services/batched_remove_status_service_spec.rb @@ -2,7 +2,7 @@ require 'rails_helper' -RSpec.describe BatchedRemoveStatusService, type: :service do +RSpec.describe BatchedRemoveStatusService, :sidekiq_inline, type: :service do subject { described_class.new } let!(:alice) { Fabricate(:account) } diff --git a/spec/services/block_domain_service_spec.rb b/spec/services/block_domain_service_spec.rb index fc3a1397d..7ad00fff6 100644 --- a/spec/services/block_domain_service_spec.rb +++ b/spec/services/block_domain_service_spec.rb @@ -68,7 +68,7 @@ RSpec.describe BlockDomainService, type: :service do expect(already_banned_account.reload.silenced_at).to_not eq DomainBlock.find_by(domain: 'evil.org').created_at end - it 'leaves the domains status and attachments, but clears media' do + it 'leaves the domains status and attachments, but clears media', :sidekiq_inline do expect { bad_status_plain.reload }.to_not raise_error expect { bad_status_with_attachment.reload }.to_not raise_error expect { bad_attachment.reload }.to_not raise_error diff --git a/spec/services/block_service_spec.rb b/spec/services/block_service_spec.rb index 5f7c2e8da..9e4ff8e59 100644 --- a/spec/services/block_service_spec.rb +++ b/spec/services/block_service_spec.rb @@ -31,7 +31,7 @@ RSpec.describe BlockService, type: :service do expect(sender.blocking?(bob)).to be true end - it 'sends a block activity' do + it 'sends a block activity', :sidekiq_inline do expect(a_request(:post, 'http://example.com/inbox')).to have_been_made.once end end diff --git a/spec/services/bulk_import_service_spec.rb b/spec/services/bulk_import_service_spec.rb index f703650c3..c3a716058 100644 --- a/spec/services/bulk_import_service_spec.rb +++ b/spec/services/bulk_import_service_spec.rb @@ -12,7 +12,7 @@ RSpec.describe BulkImportService do import.update(total_items: import.rows.count) end - describe '#call', :sidekiq_fake do + describe '#call' do context 'when importing follows' do let(:import_type) { 'following' } let(:overwrite) { false } diff --git a/spec/services/delete_account_service_spec.rb b/spec/services/delete_account_service_spec.rb index f04ba9cf1..1965b7daa 100644 --- a/spec/services/delete_account_service_spec.rb +++ b/spec/services/delete_account_service_spec.rb @@ -62,7 +62,7 @@ RSpec.describe DeleteAccountService, type: :service do end end - describe '#call on local account' do + describe '#call on local account', :sidekiq_inline do before do stub_request(:post, remote_alice.inbox_url).to_return(status: 201) stub_request(:post, remote_bob.inbox_url).to_return(status: 201) @@ -83,7 +83,7 @@ RSpec.describe DeleteAccountService, type: :service do end end - describe '#call on remote account' do + describe '#call on remote account', :sidekiq_inline do before do stub_request(:post, account.inbox_url).to_return(status: 201) end diff --git a/spec/services/fan_out_on_write_service_spec.rb b/spec/services/fan_out_on_write_service_spec.rb index 6ad041193..77237dffb 100644 --- a/spec/services/fan_out_on_write_service_spec.rb +++ b/spec/services/fan_out_on_write_service_spec.rb @@ -38,7 +38,7 @@ RSpec.describe FanOutOnWriteService, type: :service do expect(home_feed_of(alice)).to include status.id end - it 'is added to the home feed of a follower' do + it 'is added to the home feed of a follower', :sidekiq_inline do expect(home_feed_of(bob)).to include status.id expect(home_feed_of(tom)).to include status.id end @@ -62,7 +62,7 @@ RSpec.describe FanOutOnWriteService, type: :service do expect(home_feed_of(alice)).to include status.id end - it 'is added to the home feed of the mentioned follower' do + it 'is added to the home feed of the mentioned follower', :sidekiq_inline do expect(home_feed_of(bob)).to include status.id end @@ -83,7 +83,7 @@ RSpec.describe FanOutOnWriteService, type: :service do expect(home_feed_of(alice)).to include status.id end - it 'is added to the home feed of a follower' do + it 'is added to the home feed of a follower', :sidekiq_inline do expect(home_feed_of(bob)).to include status.id expect(home_feed_of(tom)).to include status.id end @@ -101,7 +101,7 @@ RSpec.describe FanOutOnWriteService, type: :service do expect(home_feed_of(alice)).to include status.id end - it 'is added to the home feed of the mentioned follower' do + it 'is added to the home feed of the mentioned follower', :sidekiq_inline do expect(home_feed_of(bob)).to include status.id end @@ -114,7 +114,7 @@ RSpec.describe FanOutOnWriteService, type: :service do expect(redis).to_not have_received(:publish).with('timeline:public', anything) end - context 'when handling status updates', :sidekiq_fake do + context 'when handling status updates' do before do subject.call(status) @@ -123,8 +123,6 @@ RSpec.describe FanOutOnWriteService, type: :service do status.snapshot!(account_id: status.account_id) redis.set("subscribed:timeline:#{eve.id}:notifications", '1') - - Sidekiq::Worker.clear_all end it 'pushes the update to mentioned users through the notifications streaming channel' do diff --git a/spec/services/favourite_service_spec.rb b/spec/services/favourite_service_spec.rb index 782c235c4..3143e7b66 100644 --- a/spec/services/favourite_service_spec.rb +++ b/spec/services/favourite_service_spec.rb @@ -33,7 +33,7 @@ RSpec.describe FavouriteService, type: :service do expect(status.favourites.first).to_not be_nil end - it 'sends a like activity' do + it 'sends a like activity', :sidekiq_inline do expect(a_request(:post, 'http://example.com/inbox')).to have_been_made.once end end diff --git a/spec/services/follow_service_spec.rb b/spec/services/follow_service_spec.rb index c2ad0d717..cf4de34c8 100644 --- a/spec/services/follow_service_spec.rb +++ b/spec/services/follow_service_spec.rb @@ -150,7 +150,7 @@ RSpec.describe FollowService, type: :service do expect(FollowRequest.find_by(account: sender, target_account: bob)).to_not be_nil end - it 'sends a follow activity to the inbox' do + it 'sends a follow activity to the inbox', :sidekiq_inline do expect(a_request(:post, 'http://example.com/inbox')).to have_been_made.once end end diff --git a/spec/services/import_service_spec.rb b/spec/services/import_service_spec.rb index d67da66ca..7d005c8a1 100644 --- a/spec/services/import_service_spec.rb +++ b/spec/services/import_service_spec.rb @@ -2,7 +2,7 @@ require 'rails_helper' -RSpec.describe ImportService, type: :service do +RSpec.describe ImportService, :sidekiq_inline, type: :service do include RoutingHelper let!(:account) { Fabricate(:account, locked: false) } diff --git a/spec/services/mute_service_spec.rb b/spec/services/mute_service_spec.rb index 50f74ff27..a2ca2ffe1 100644 --- a/spec/services/mute_service_spec.rb +++ b/spec/services/mute_service_spec.rb @@ -17,7 +17,7 @@ RSpec.describe MuteService, type: :service do redis.del(home_timeline_key) end - it "clears account's statuses" do + it "clears account's statuses", :sidekiq_inline do FeedManager.instance.push_to_home(account, status) FeedManager.instance.push_to_home(account, other_account_status) diff --git a/spec/services/notify_service_spec.rb b/spec/services/notify_service_spec.rb index 50055dafc..38a33c522 100644 --- a/spec/services/notify_service_spec.rb +++ b/spec/services/notify_service_spec.rb @@ -166,7 +166,7 @@ RSpec.describe NotifyService, type: :service do context 'when email notification is enabled' do let(:enabled) { true } - it 'sends email' do + it 'sends email', :sidekiq_inline do expect { subject }.to change(ActionMailer::Base.deliveries, :count).by(1) end end diff --git a/spec/services/reblog_service_spec.rb b/spec/services/reblog_service_spec.rb index 7b85e37ed..c6d13e5a1 100644 --- a/spec/services/reblog_service_spec.rb +++ b/spec/services/reblog_service_spec.rb @@ -87,7 +87,7 @@ RSpec.describe ReblogService, type: :service do expect(ActivityPub::DistributionWorker).to have_received(:perform_async) end - it 'sends an announce activity to the author' do + it 'sends an announce activity to the author', :sidekiq_inline do expect(a_request(:post, bob.inbox_url)).to have_been_made.once end end diff --git a/spec/services/reject_follow_service_spec.rb b/spec/services/reject_follow_service_spec.rb index d28104b2c..48316a6c4 100644 --- a/spec/services/reject_follow_service_spec.rb +++ b/spec/services/reject_follow_service_spec.rb @@ -41,7 +41,7 @@ RSpec.describe RejectFollowService, type: :service do expect(bob.following?(sender)).to be false end - it 'sends a reject activity' do + it 'sends a reject activity', :sidekiq_inline do expect(a_request(:post, bob.inbox_url)).to have_been_made.once end end diff --git a/spec/services/remove_from_followers_service_spec.rb b/spec/services/remove_from_followers_service_spec.rb index 1b29cdcbe..21da38a97 100644 --- a/spec/services/remove_from_followers_service_spec.rb +++ b/spec/services/remove_from_followers_service_spec.rb @@ -33,7 +33,7 @@ RSpec.describe RemoveFromFollowersService, type: :service do expect(bob.followed_by?(sender)).to be false end - it 'sends a reject activity' do + it 'sends a reject activity', :sidekiq_inline do expect(a_request(:post, sender.inbox_url)).to have_been_made.once end end diff --git a/spec/services/remove_status_service_spec.rb b/spec/services/remove_status_service_spec.rb index cd3224e02..63a9df548 100644 --- a/spec/services/remove_status_service_spec.rb +++ b/spec/services/remove_status_service_spec.rb @@ -2,7 +2,7 @@ require 'rails_helper' -RSpec.describe RemoveStatusService, type: :service do +RSpec.describe RemoveStatusService, :sidekiq_inline, type: :service do subject { described_class.new } let!(:alice) { Fabricate(:account) } diff --git a/spec/services/report_service_spec.rb b/spec/services/report_service_spec.rb index 2a919f640..39e14a6a1 100644 --- a/spec/services/report_service_spec.rb +++ b/spec/services/report_service_spec.rb @@ -23,7 +23,7 @@ RSpec.describe ReportService, type: :service do stub_request(:post, 'http://example.com/inbox').to_return(status: 200) end - context 'when forward is true' do + context 'when forward is true', :sidekiq_inline do let(:forward) { true } it 'sends ActivityPub payload when forward is true' do diff --git a/spec/services/resolve_account_service_spec.rb b/spec/services/resolve_account_service_spec.rb index 3c4b182e2..1c4c3b401 100644 --- a/spec/services/resolve_account_service_spec.rb +++ b/spec/services/resolve_account_service_spec.rb @@ -195,7 +195,7 @@ RSpec.describe ResolveAccountService, type: :service do expect(account.uri).to eq 'https://ap.example.com/users/foo' end - it 'merges accounts' do + it 'merges accounts', :sidekiq_inline do account = subject.call('foo@ap.example.com') expect(status.reload.account_id).to eq account.id diff --git a/spec/services/suspend_account_service_spec.rb b/spec/services/suspend_account_service_spec.rb index dcc8dbfd3..4a5f8a0b6 100644 --- a/spec/services/suspend_account_service_spec.rb +++ b/spec/services/suspend_account_service_spec.rb @@ -2,7 +2,7 @@ require 'rails_helper' -RSpec.describe SuspendAccountService, type: :service do +RSpec.describe SuspendAccountService, :sidekiq_inline, type: :service do shared_examples 'common behavior' do subject { described_class.new.call(account) } diff --git a/spec/services/unallow_domain_service_spec.rb b/spec/services/unallow_domain_service_spec.rb index d96e35418..6ac6bc401 100644 --- a/spec/services/unallow_domain_service_spec.rb +++ b/spec/services/unallow_domain_service_spec.rb @@ -12,7 +12,7 @@ RSpec.describe UnallowDomainService, type: :service do let!(:already_banned_account) { Fabricate(:account, username: 'badguy', domain: 'evil.org', suspended: true, silenced: true) } let!(:domain_allow) { Fabricate(:domain_allow, domain: 'evil.org') } - context 'with limited federation mode' do + context 'with limited federation mode', :sidekiq_inline do before do allow(Rails.configuration.x).to receive(:limited_federation_mode).and_return(true) end diff --git a/spec/services/unblock_service_spec.rb b/spec/services/unblock_service_spec.rb index 86632c393..9813c5e7f 100644 --- a/spec/services/unblock_service_spec.rb +++ b/spec/services/unblock_service_spec.rb @@ -33,7 +33,7 @@ RSpec.describe UnblockService, type: :service do expect(sender.blocking?(bob)).to be false end - it 'sends an unblock activity' do + it 'sends an unblock activity', :sidekiq_inline do expect(a_request(:post, 'http://example.com/inbox')).to have_been_made.once end end diff --git a/spec/services/unfollow_service_spec.rb b/spec/services/unfollow_service_spec.rb index 3e65e610b..18a25a676 100644 --- a/spec/services/unfollow_service_spec.rb +++ b/spec/services/unfollow_service_spec.rb @@ -20,7 +20,7 @@ RSpec.describe UnfollowService, type: :service do end end - describe 'remote ActivityPub' do + describe 'remote ActivityPub', :sidekiq_inline do let(:bob) { Fabricate(:account, username: 'bob', protocol: :activitypub, domain: 'example.com', inbox_url: 'http://example.com/inbox') } before do @@ -38,7 +38,7 @@ RSpec.describe UnfollowService, type: :service do end end - describe 'remote ActivityPub (reverse)' do + describe 'remote ActivityPub (reverse)', :sidekiq_inline do let(:bob) { Fabricate(:account, username: 'bob', protocol: :activitypub, domain: 'example.com', inbox_url: 'http://example.com/inbox') } before do diff --git a/spec/services/unsuspend_account_service_spec.rb b/spec/services/unsuspend_account_service_spec.rb index 211c39e6c..c848767cd 100644 --- a/spec/services/unsuspend_account_service_spec.rb +++ b/spec/services/unsuspend_account_service_spec.rb @@ -45,7 +45,7 @@ RSpec.describe UnsuspendAccountService, type: :service do remote_follower.follow!(account) end - it 'merges back into feeds of local followers and sends update' do + it 'merges back into feeds of local followers and sends update', :sidekiq_inline do subject expect_feeds_merged diff --git a/spec/services/update_account_service_spec.rb b/spec/services/update_account_service_spec.rb index 6318cc95f..9f4e36862 100644 --- a/spec/services/update_account_service_spec.rb +++ b/spec/services/update_account_service_spec.rb @@ -5,7 +5,7 @@ require 'rails_helper' RSpec.describe UpdateAccountService, type: :service do subject { described_class.new } - describe 'switching form locked to unlocked accounts' do + describe 'switching form locked to unlocked accounts', :sidekiq_inline do let(:account) { Fabricate(:account, locked: true) } let(:alice) { Fabricate(:account) } let(:bob) { Fabricate(:account) } diff --git a/spec/services/update_status_service_spec.rb b/spec/services/update_status_service_spec.rb index 7f9f746c2..55651c305 100644 --- a/spec/services/update_status_service_spec.rb +++ b/spec/services/update_status_service_spec.rb @@ -111,7 +111,7 @@ RSpec.describe UpdateStatusService, type: :service do end end - context 'when poll changes', :sidekiq_fake do + context 'when poll changes' do let(:account) { Fabricate(:account) } let!(:status) { Fabricate(:status, text: 'Foo', account: account, poll_attributes: { options: %w(Foo Bar), account: account, multiple: false, hide_totals: false, expires_at: 7.days.from_now }) } let!(:poll) { status.poll } diff --git a/spec/system/new_statuses_spec.rb b/spec/system/new_statuses_spec.rb index 02f2e2839..a3b816b4d 100644 --- a/spec/system/new_statuses_spec.rb +++ b/spec/system/new_statuses_spec.rb @@ -2,7 +2,7 @@ require 'rails_helper' -describe 'NewStatuses' do +describe 'NewStatuses', :sidekiq_inline do include ProfileStories subject { page } diff --git a/spec/workers/backup_worker_spec.rb b/spec/workers/backup_worker_spec.rb index 1a169513e..987cbc7d6 100644 --- a/spec/workers/backup_worker_spec.rb +++ b/spec/workers/backup_worker_spec.rb @@ -14,7 +14,7 @@ describe BackupWorker do let(:backup) { Fabricate(:backup) } let!(:other_backup) { Fabricate(:backup, user: backup.user) } - it 'sends the backup to the service and removes other backups' do + it 'sends the backup to the service and removes other backups', :sidekiq_inline do expect do worker.perform(backup.id) end.to change(UserMailer.deliveries, :size).by(1) diff --git a/spec/workers/move_worker_spec.rb b/spec/workers/move_worker_spec.rb index 34b342710..0513dc42e 100644 --- a/spec/workers/move_worker_spec.rb +++ b/spec/workers/move_worker_spec.rb @@ -104,7 +104,7 @@ describe MoveWorker do end shared_examples 'lists handling' do - it 'puts the new account on the list and makes valid lists', sidekiq: :inline do + it 'puts the new account on the list and makes valid lists', :sidekiq_inline do subject.perform(source_account.id, target_account.id) expect(list.accounts.include?(target_account)).to be true @@ -159,7 +159,7 @@ describe MoveWorker do describe '#perform' do context 'when both accounts are distant' do - it 'calls UnfollowFollowWorker', :sidekiq_fake do + it 'calls UnfollowFollowWorker' do subject.perform(source_account.id, target_account.id) expect(UnfollowFollowWorker).to have_enqueued_sidekiq_job(local_follower.id, source_account.id, target_account.id, false) end @@ -170,7 +170,7 @@ describe MoveWorker do context 'when target account is local' do let(:target_account) { Fabricate(:account) } - it 'calls UnfollowFollowWorker', :sidekiq_fake do + it 'calls UnfollowFollowWorker' do subject.perform(source_account.id, target_account.id) expect(UnfollowFollowWorker).to have_enqueued_sidekiq_job(local_follower.id, source_account.id, target_account.id, true) end diff --git a/spec/workers/poll_expiration_notify_worker_spec.rb b/spec/workers/poll_expiration_notify_worker_spec.rb index ca36a3759..4bd90270d 100644 --- a/spec/workers/poll_expiration_notify_worker_spec.rb +++ b/spec/workers/poll_expiration_notify_worker_spec.rb @@ -10,7 +10,7 @@ describe PollExpirationNotifyWorker do let(:remote?) { false } let(:poll_vote) { Fabricate(:poll_vote, poll: poll) } - describe '#perform', :sidekiq_fake do + describe '#perform' do it 'runs without error for missing record' do expect { worker.perform(nil) }.to_not raise_error end From 543d7890fd818ed8871b0f8e6adbf19b605edf70 Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Wed, 10 Jan 2024 08:36:06 -0500 Subject: [PATCH 3/6] Use normalizes to prepare `User` values (#28650) Co-authored-by: Claire --- app/models/user.rb | 22 ++++-------------- spec/models/user_spec.rb | 50 ++++++++++++++++++++++++++++++---------- 2 files changed, 42 insertions(+), 30 deletions(-) diff --git a/app/models/user.rb b/app/models/user.rb index 55f654137..0c589f806 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -118,14 +118,15 @@ class User < ApplicationRecord scope :matches_email, ->(value) { where(arel_table[:email].matches("#{value}%")) } scope :matches_ip, ->(value) { left_joins(:ips).where('user_ips.ip <<= ?', value).group('users.id') } - before_validation :sanitize_languages before_validation :sanitize_role - before_validation :sanitize_time_zone - before_validation :sanitize_locale before_create :set_approved after_commit :send_pending_devise_notifications after_create_commit :trigger_webhooks + normalizes :locale, with: ->(locale) { I18n.available_locales.exclude?(locale.to_sym) ? nil : locale } + normalizes :time_zone, with: ->(time_zone) { ActiveSupport::TimeZone[time_zone].nil? ? nil : time_zone } + normalizes :chosen_languages, with: ->(chosen_languages) { chosen_languages.compact_blank.presence } + # This avoids a deprecation warning from Rails 5.1 # It seems possible that a future release of devise-two-factor will # handle this itself, and this can be removed from our User class. @@ -447,25 +448,10 @@ class User < ApplicationRecord @bypass_invite_request_check end - def sanitize_languages - return if chosen_languages.nil? - - chosen_languages.compact_blank! - self.chosen_languages = nil if chosen_languages.empty? - end - def sanitize_role self.role = nil if role.present? && role.everyone? end - def sanitize_time_zone - self.time_zone = nil if time_zone.present? && ActiveSupport::TimeZone[time_zone].nil? - end - - def sanitize_locale - self.locale = nil if locale.present? && I18n.available_locales.exclude?(locale.to_sym) - end - def prepare_new_user! BootstrapTimelineWorker.perform_async(account_id) ActivityTracker.increment('activity:accounts:local') diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index c8415df92..7f68671df 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -38,23 +38,49 @@ RSpec.describe User do user.save(validate: false) expect(user.valid?).to be true end + end - it 'cleans out invalid locale' do - user = Fabricate.build(:user, locale: 'toto') - expect(user.valid?).to be true - expect(user.locale).to be_nil + describe 'Normalizations' do + describe 'locale' do + it 'preserves valid locale' do + user = Fabricate.build(:user, locale: 'en') + + expect(user.locale).to eq('en') + end + + it 'cleans out invalid locale' do + user = Fabricate.build(:user, locale: 'toto') + + expect(user.locale).to be_nil + end end - it 'cleans out invalid timezone' do - user = Fabricate.build(:user, time_zone: 'toto') - expect(user.valid?).to be true - expect(user.time_zone).to be_nil + describe 'time_zone' do + it 'preserves valid timezone' do + user = Fabricate.build(:user, time_zone: 'UTC') + + expect(user.time_zone).to eq('UTC') + end + + it 'cleans out invalid timezone' do + user = Fabricate.build(:user, time_zone: 'toto') + + expect(user.time_zone).to be_nil + end end - it 'cleans out empty string from languages' do - user = Fabricate.build(:user, chosen_languages: ['']) - user.valid? - expect(user.chosen_languages).to be_nil + describe 'languages' do + it 'preserves valid options for languages' do + user = Fabricate.build(:user, chosen_languages: ['en', 'fr', '']) + + expect(user.chosen_languages).to eq(['en', 'fr']) + end + + it 'cleans out empty string from languages' do + user = Fabricate.build(:user, chosen_languages: ['']) + + expect(user.chosen_languages).to be_nil + end end end From 8422b8ded0fa0ac1fdb70e6fb494ef5453b845d9 Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Wed, 10 Jan 2024 09:54:11 -0500 Subject: [PATCH 4/6] Extract capybara config and improve headless_chrome driver config (#28681) --- spec/rails_helper.rb | 2 -- spec/support/capybara.rb | 31 +++++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 2 deletions(-) create mode 100644 spec/support/capybara.rb diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index 783258b3a..aabb121fc 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -108,8 +108,6 @@ RSpec.configure do |config| end config.around :each, type: :system do |example| - driven_by :selenium, using: :headless_chrome, screen_size: [1600, 1200] - # The streaming server needs access to the database # but with use_transactional_tests every transaction # is rolled-back, so the streaming server never sees the data diff --git a/spec/support/capybara.rb b/spec/support/capybara.rb new file mode 100644 index 000000000..d4f27e209 --- /dev/null +++ b/spec/support/capybara.rb @@ -0,0 +1,31 @@ +# frozen_string_literal: true + +Capybara.server_host = 'localhost' +Capybara.server_port = 3000 +Capybara.app_host = "http://#{Capybara.server_host}:#{Capybara.server_port}" + +require 'selenium/webdriver' + +Capybara.register_driver :chrome do |app| + Capybara::Selenium::Driver.new(app, browser: :chrome) +end + +Capybara.register_driver :headless_chrome do |app| + options = Selenium::WebDriver::Chrome::Options.new + options.add_argument '--headless=new' + options.add_argument '--window-size=1680,1050' + + Capybara::Selenium::Driver.new( + app, + browser: :chrome, + options: options + ) +end + +Capybara.javascript_driver = :headless_chrome + +RSpec.configure do |config| + config.before(:each, type: :system) do + driven_by Capybara.javascript_driver + end +end From d7e13e248380704895674949bf870ac5e8d8387b Mon Sep 17 00:00:00 2001 From: Claire Date: Wed, 10 Jan 2024 16:05:46 +0100 Subject: [PATCH 5/6] Fix potential redirection loop of streaming endpoint (#28665) --- app/controllers/api/v1/streaming_controller.rb | 7 ++++++- spec/controllers/api/v1/streaming_controller_spec.rb | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/app/controllers/api/v1/streaming_controller.rb b/app/controllers/api/v1/streaming_controller.rb index 0cb6e856f..adb14676e 100644 --- a/app/controllers/api/v1/streaming_controller.rb +++ b/app/controllers/api/v1/streaming_controller.rb @@ -2,7 +2,7 @@ class Api::V1::StreamingController < Api::BaseController def index - if Rails.configuration.x.streaming_api_base_url == request.host + if same_host? not_found else redirect_to streaming_api_url, status: 301, allow_other_host: true @@ -11,6 +11,11 @@ class Api::V1::StreamingController < Api::BaseController private + def same_host? + base_url = Addressable::URI.parse(Rails.configuration.x.streaming_api_base_url) + request.host == base_url.host && request.port == (base_url.port || 80) + end + def streaming_api_url Addressable::URI.parse(request.url).tap do |uri| base_url = Addressable::URI.parse(Rails.configuration.x.streaming_api_base_url) diff --git a/spec/controllers/api/v1/streaming_controller_spec.rb b/spec/controllers/api/v1/streaming_controller_spec.rb index c3e7153ce..099f68a74 100644 --- a/spec/controllers/api/v1/streaming_controller_spec.rb +++ b/spec/controllers/api/v1/streaming_controller_spec.rb @@ -5,7 +5,7 @@ require 'rails_helper' describe Api::V1::StreamingController do around do |example| before = Rails.configuration.x.streaming_api_base_url - Rails.configuration.x.streaming_api_base_url = Rails.configuration.x.web_domain + Rails.configuration.x.streaming_api_base_url = "wss://#{Rails.configuration.x.web_domain}" example.run Rails.configuration.x.streaming_api_base_url = before end From 0a7cff53c2577b3e79599e069eeb344f2613ad8d Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Thu, 11 Jan 2024 04:30:29 -0500 Subject: [PATCH 6/6] Add coverage for `Account.followable_by` scope (#28689) --- spec/models/account_spec.rb | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/spec/models/account_spec.rb b/spec/models/account_spec.rb index 87aa8bc75..b4fcb805a 100644 --- a/spec/models/account_spec.rb +++ b/spec/models/account_spec.rb @@ -1009,4 +1009,27 @@ RSpec.describe Account do expect(subject.reload.followers_count).to eq 15 end end + + describe '.followable_by' do + context 'with follows and follow requests' do + let!(:account) { Fabricate(:account) } + let!(:eligible_account) { Fabricate(:account) } + let!(:following_account) { Fabricate(:account) } + let!(:follow_requested_account) { Fabricate(:account) } + + before do + Fabricate :follow, account: account, target_account: following_account + Fabricate :follow_request, account: account, target_account: follow_requested_account + end + + it 'returns accounts not already following or requested to follow' do + results = described_class.followable_by(account) + + expect(results) + .to include(eligible_account) + .and not_include(following_account) + .and not_include(follow_requested_account) + end + end + end end