From 3970a6f433ad3cf79ef41d84baf6d788d25bd246 Mon Sep 17 00:00:00 2001 From: Claire Date: Wed, 18 Jan 2023 16:43:58 +0100 Subject: Add option to make the landing page be /about even when trends are enabled (#20808) * Add option to make the landing page be /about even when trends are enabled * Restablish /explore as landing page by default --- app/serializers/initial_state_serializer.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'app/serializers/initial_state_serializer.rb') diff --git a/app/serializers/initial_state_serializer.rb b/app/serializers/initial_state_serializer.rb index 70f40088d..1bd62c26f 100644 --- a/app/serializers/initial_state_serializer.rb +++ b/app/serializers/initial_state_serializer.rb @@ -32,6 +32,7 @@ class InitialStateSerializer < ActiveModel::Serializer activity_api_enabled: Setting.activity_api_enabled, single_user_mode: Rails.configuration.x.single_user_mode, translation_enabled: TranslationService.configured?, + trends_as_landing_page: Setting.trends_as_landing_page, } if object.current_account -- cgit From 8f590b0a211716bcbfc0f2278a452469f3346f55 Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Sat, 4 Feb 2023 04:56:06 +0100 Subject: Add setting for status page URL (#23390) --- .../mastodon/features/ui/components/link_footer.js | 16 +++++++++++----- app/javascript/mastodon/initial_state.js | 1 + app/models/form/admin_settings.rb | 2 ++ app/presenters/instance_presenter.rb | 4 ++++ app/serializers/initial_state_serializer.rb | 1 + app/serializers/rest/instance_serializer.rb | 1 + app/views/admin/settings/about/show.html.haml | 3 +++ config/locales/simple_form.en.yml | 2 ++ 8 files changed, 25 insertions(+), 5 deletions(-) (limited to 'app/serializers/initial_state_serializer.rb') diff --git a/app/javascript/mastodon/features/ui/components/link_footer.js b/app/javascript/mastodon/features/ui/components/link_footer.js index db5945d6a..be2111207 100644 --- a/app/javascript/mastodon/features/ui/components/link_footer.js +++ b/app/javascript/mastodon/features/ui/components/link_footer.js @@ -3,7 +3,7 @@ import React from 'react'; import PropTypes from 'prop-types'; import { FormattedMessage, defineMessages, injectIntl } from 'react-intl'; import { Link } from 'react-router-dom'; -import { domain, version, source_url, profile_directory as profileDirectory } from 'mastodon/initial_state'; +import { domain, version, source_url, statusPageUrl, profile_directory as profileDirectory } from 'mastodon/initial_state'; import { logOut } from 'mastodon/utils/log_out'; import { openModal } from 'mastodon/actions/modal'; import { PERMISSION_INVITE_USERS } from 'mastodon/permissions'; @@ -59,21 +59,27 @@ class LinkFooter extends React.PureComponent {

{domain}: {' '} - + + {statusPageUrl && ( + <> + {DividingCircle} + + + )} {canInvite && ( <> {DividingCircle} - + )} {canProfileDirectory && ( <> {DividingCircle} - + )} {DividingCircle} - +

diff --git a/app/javascript/mastodon/initial_state.js b/app/javascript/mastodon/initial_state.js index 5bb8546eb..d04c4a42d 100644 --- a/app/javascript/mastodon/initial_state.js +++ b/app/javascript/mastodon/initial_state.js @@ -134,5 +134,6 @@ export const usePendingItems = getMeta('use_pending_items'); export const version = getMeta('version'); export const translationEnabled = getMeta('translation_enabled'); export const languages = initialState?.languages; +export const statusPageUrl = getMeta('status_page_url'); export default initialState; diff --git a/app/models/form/admin_settings.rb b/app/models/form/admin_settings.rb index 132b57b04..001caa376 100644 --- a/app/models/form/admin_settings.rb +++ b/app/models/form/admin_settings.rb @@ -32,6 +32,7 @@ class Form::AdminSettings media_cache_retention_period content_cache_retention_period backups_retention_period + status_page_url ).freeze INTEGER_KEYS = %i( @@ -68,6 +69,7 @@ class Form::AdminSettings validates :show_domain_blocks_rationale, inclusion: { in: %w(disabled users all) }, if: -> { defined?(@show_domain_blocks_rationale) } validates :media_cache_retention_period, :content_cache_retention_period, :backups_retention_period, numericality: { only_integer: true }, allow_blank: true, if: -> { defined?(@media_cache_retention_period) || defined?(@content_cache_retention_period) || defined?(@backups_retention_period) } validates :site_short_description, length: { maximum: 200 }, if: -> { defined?(@site_short_description) } + validates :status_page_url, url: true validate :validate_site_uploads KEYS.each do |key| diff --git a/app/presenters/instance_presenter.rb b/app/presenters/instance_presenter.rb index fba3cc734..e3ba984f7 100644 --- a/app/presenters/instance_presenter.rb +++ b/app/presenters/instance_presenter.rb @@ -38,6 +38,10 @@ class InstancePresenter < ActiveModelSerializers::Model Setting.site_terms end + def status_page_url + Setting.status_page_url + end + def domain Rails.configuration.x.local_domain end diff --git a/app/serializers/initial_state_serializer.rb b/app/serializers/initial_state_serializer.rb index 1bd62c26f..24417bca7 100644 --- a/app/serializers/initial_state_serializer.rb +++ b/app/serializers/initial_state_serializer.rb @@ -33,6 +33,7 @@ class InitialStateSerializer < ActiveModel::Serializer single_user_mode: Rails.configuration.x.single_user_mode, translation_enabled: TranslationService.configured?, trends_as_landing_page: Setting.trends_as_landing_page, + status_page_url: Setting.status_page_url, } if object.current_account diff --git a/app/serializers/rest/instance_serializer.rb b/app/serializers/rest/instance_serializer.rb index 5ae1099d0..fbb2fea0d 100644 --- a/app/serializers/rest/instance_serializer.rb +++ b/app/serializers/rest/instance_serializer.rb @@ -45,6 +45,7 @@ class REST::InstanceSerializer < ActiveModel::Serializer { urls: { streaming: Rails.configuration.x.streaming_api_base_url, + status: object.status_page_url, }, accounts: { diff --git a/app/views/admin/settings/about/show.html.haml b/app/views/admin/settings/about/show.html.haml index 366d213f6..2aaa64abe 100644 --- a/app/views/admin/settings/about/show.html.haml +++ b/app/views/admin/settings/about/show.html.haml @@ -26,6 +26,9 @@ .fields-row__column.fields-row__column-6.fields-group = f.input :show_domain_blocks_rationale, wrapper: :with_label, collection: %i(disabled users all), label_method: lambda { |value| t("admin.settings.domain_blocks.#{value}") }, include_blank: false, collection_wrapper_tag: 'ul', item_wrapper_tag: 'li' + .fields-group + = f.input :status_page_url, wrapper: :with_block_label, input_html: { placeholder: "https://status.#{Rails.configuration.x.local_domain}" } + .fields-group = f.input :site_terms, wrapper: :with_block_label, as: :text, input_html: { rows: 8 } diff --git a/config/locales/simple_form.en.yml b/config/locales/simple_form.en.yml index d01f0ae75..96b0131ef 100644 --- a/config/locales/simple_form.en.yml +++ b/config/locales/simple_form.en.yml @@ -91,6 +91,7 @@ en: site_short_description: A short description to help uniquely identify your server. Who is running it, who is it for? site_terms: Use your own privacy policy or leave blank to use the default. Can be structured with Markdown syntax. site_title: How people may refer to your server besides its domain name. + status_page_url: URL of a page where people can see the status of this server during an outage theme: Theme that logged out visitors and new users see. thumbnail: A roughly 2:1 image displayed alongside your server information. timeline_preview: Logged out visitors will be able to browse the most recent public posts available on the server. @@ -252,6 +253,7 @@ en: site_short_description: Server description site_terms: Privacy Policy site_title: Server name + status_page_url: Status page URL theme: Default theme thumbnail: Server thumbnail timeline_preview: Allow unauthenticated access to public timelines -- cgit From e2567df86063b537e4a3ab2afd5c28a54140f720 Mon Sep 17 00:00:00 2001 From: Nick Schonning Date: Fri, 17 Feb 2023 22:30:14 -0500 Subject: Enable Lint/RedundantCopDisableDirective (#23687) --- .rubocop_todo.yml | 4 ---- app/serializers/initial_state_serializer.rb | 1 - lib/mastodon/migration_helpers.rb | 4 +--- 3 files changed, 1 insertion(+), 8 deletions(-) (limited to 'app/serializers/initial_state_serializer.rb') diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 523570607..68d3f2bd7 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -3626,7 +3626,3 @@ Style/WordArray: - 'spec/services/activitypub/process_account_service_spec.rb' - 'spec/services/delete_account_service_spec.rb' - 'spec/workers/scheduler/accounts_statuses_cleanup_scheduler_spec.rb' - -# don't clean out the manual directives overridden by generated file -Lint/RedundantCopDisableDirective: - Enabled: false diff --git a/app/serializers/initial_state_serializer.rb b/app/serializers/initial_state_serializer.rb index 24417bca7..95b28fa15 100644 --- a/app/serializers/initial_state_serializer.rb +++ b/app/serializers/initial_state_serializer.rb @@ -10,7 +10,6 @@ class InitialStateSerializer < ActiveModel::Serializer has_one :push_subscription, serializer: REST::WebPushSubscriptionSerializer has_one :role, serializer: REST::RoleSerializer - # rubocop:disable Metrics/AbcSize def meta store = { streaming_api_base_url: Rails.configuration.x.streaming_api_base_url, diff --git a/lib/mastodon/migration_helpers.rb b/lib/mastodon/migration_helpers.rb index 2ab8150ec..5a252b351 100644 --- a/lib/mastodon/migration_helpers.rb +++ b/lib/mastodon/migration_helpers.rb @@ -289,8 +289,6 @@ module Mastodon # determines this method to be too complex while there's no way to make it # less "complex" without introducing extra methods (which actually will # make things _more_ complex). - # - # rubocop: disable Metrics/AbcSize def update_column_in_batches(table_name, column, value) if transaction_open? raise 'update_column_in_batches can not be run inside a transaction, ' \ @@ -573,7 +571,7 @@ module Mastodon o.conname as name, o.confdeltype as on_delete from pg_constraint o - left join pg_class f on f.oid = o.confrelid + left join pg_class f on f.oid = o.confrelid left join pg_class c on c.oid = o.conrelid left join pg_class m on m.oid = o.conrelid where o.contype = 'f' -- cgit From e2a3ebb271017d800a448ad3ef3e8324ac1fab3b Mon Sep 17 00:00:00 2001 From: Nick Schonning Date: Sat, 18 Feb 2023 06:37:47 -0500 Subject: Autofix Rubocop Style/IfUnlessModifier (#23697) --- .rubocop_todo.yml | 106 --------------------- app/controllers/admin/domain_blocks_controller.rb | 4 +- .../v1/accounts/follower_accounts_controller.rb | 8 +- .../v1/accounts/following_accounts_controller.rb | 8 +- .../api/v1/accounts/statuses_controller.rb | 8 +- .../api/v1/admin/accounts_controller.rb | 4 +- app/controllers/api/v1/blocks_controller.rb | 8 +- app/controllers/api/v1/conversations_controller.rb | 8 +- app/controllers/api/v1/domain_blocks_controller.rb | 8 +- app/controllers/api/v1/endorsements_controller.rb | 8 +- app/controllers/api/v1/favourites_controller.rb | 8 +- .../api/v1/follow_requests_controller.rb | 8 +- .../api/v1/lists/accounts_controller.rb | 8 +- app/controllers/api/v1/mutes_controller.rb | 8 +- app/controllers/api/v1/notifications_controller.rb | 8 +- .../api/v1/scheduled_statuses_controller.rb | 8 +- .../statuses/favourited_by_accounts_controller.rb | 8 +- .../statuses/reblogged_by_accounts_controller.rb | 8 +- .../api/v2/admin/accounts_controller.rb | 4 +- app/controllers/auth/registrations_controller.rb | 4 +- app/controllers/auth/sessions_controller.rb | 4 +- app/controllers/filters/statuses_controller.rb | 4 +- app/helpers/application_helper.rb | 4 +- app/lib/activitypub/linked_data_signature.rb | 4 +- .../activitypub/parser/media_attachment_parser.rb | 4 +- app/lib/status_finder.rb | 4 +- app/models/account.rb | 4 +- app/models/account_statuses_cleanup_policy.rb | 8 +- app/models/concerns/account_interactions.rb | 4 +- app/models/concerns/omniauthable.rb | 4 +- app/serializers/initial_state_serializer.rb | 4 +- app/serializers/rest/instance_serializer.rb | 4 +- .../activitypub/fetch_remote_actor_service.rb | 4 +- .../activitypub/process_status_update_service.rb | 4 +- app/services/remove_from_followers_service.rb | 4 +- app/services/resolve_account_service.rb | 4 +- app/services/search_service.rb | 4 +- lib/mastodon/media_cli.rb | 4 +- lib/mastodon/redis_config.rb | 4 +- .../matchers/model/model_have_error_on_field.rb | 4 +- 40 files changed, 55 insertions(+), 271 deletions(-) (limited to 'app/serializers/initial_state_serializer.rb') diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 9a9c420df..0e94741ae 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -2921,112 +2921,6 @@ Style/HashTransformValues: - 'app/serializers/rest/web_push_subscription_serializer.rb' - 'app/services/import_service.rb' -# Offense count: 176 -# This cop supports safe autocorrection (--autocorrect). -Style/IfUnlessModifier: - Exclude: - - 'app/controllers/admin/domain_blocks_controller.rb' - - 'app/controllers/api/v1/accounts/follower_accounts_controller.rb' - - 'app/controllers/api/v1/accounts/following_accounts_controller.rb' - - 'app/controllers/api/v1/accounts/statuses_controller.rb' - - 'app/controllers/api/v1/admin/accounts_controller.rb' - - 'app/controllers/api/v1/admin/domain_blocks_controller.rb' - - 'app/controllers/api/v1/blocks_controller.rb' - - 'app/controllers/api/v1/conversations_controller.rb' - - 'app/controllers/api/v1/domain_blocks_controller.rb' - - 'app/controllers/api/v1/emails/confirmations_controller.rb' - - 'app/controllers/api/v1/endorsements_controller.rb' - - 'app/controllers/api/v1/favourites_controller.rb' - - 'app/controllers/api/v1/filters_controller.rb' - - 'app/controllers/api/v1/follow_requests_controller.rb' - - 'app/controllers/api/v1/lists/accounts_controller.rb' - - 'app/controllers/api/v1/mutes_controller.rb' - - 'app/controllers/api/v1/notifications_controller.rb' - - 'app/controllers/api/v1/scheduled_statuses_controller.rb' - - 'app/controllers/api/v1/statuses/favourited_by_accounts_controller.rb' - - 'app/controllers/api/v1/statuses/reblogged_by_accounts_controller.rb' - - 'app/controllers/api/v1/trends/links_controller.rb' - - 'app/controllers/api/v1/trends/statuses_controller.rb' - - 'app/controllers/api/v1/trends/tags_controller.rb' - - 'app/controllers/api/v2/admin/accounts_controller.rb' - - 'app/controllers/api/v2/search_controller.rb' - - 'app/controllers/auth/registrations_controller.rb' - - 'app/controllers/auth/sessions_controller.rb' - - 'app/controllers/concerns/localized.rb' - - 'app/controllers/concerns/rate_limit_headers.rb' - - 'app/controllers/concerns/signature_verification.rb' - - 'app/controllers/filters/statuses_controller.rb' - - 'app/helpers/application_helper.rb' - - 'app/helpers/jsonld_helper.rb' - - 'app/lib/activitypub/activity/announce.rb' - - 'app/lib/activitypub/activity/create.rb' - - 'app/lib/activitypub/activity/like.rb' - - 'app/lib/activitypub/linked_data_signature.rb' - - 'app/lib/activitypub/parser/media_attachment_parser.rb' - - 'app/lib/feed_manager.rb' - - 'app/lib/status_cache_hydrator.rb' - - 'app/lib/status_finder.rb' - - 'app/models/account.rb' - - 'app/models/account_migration.rb' - - 'app/models/account_statuses_cleanup_policy.rb' - - 'app/models/admin/import.rb' - - 'app/models/admin/status_batch_action.rb' - - 'app/models/concerns/account_avatar.rb' - - 'app/models/concerns/account_counters.rb' - - 'app/models/concerns/account_header.rb' - - 'app/models/concerns/account_interactions.rb' - - 'app/models/concerns/attachmentable.rb' - - 'app/models/concerns/ldap_authenticable.rb' - - 'app/models/concerns/omniauthable.rb' - - 'app/models/form/redirect.rb' - - 'app/models/media_attachment.rb' - - 'app/models/scheduled_status.rb' - - 'app/models/status.rb' - - 'app/models/trends.rb' - - 'app/models/trends/links.rb' - - 'app/models/trends/statuses.rb' - - 'app/models/user_role.rb' - - 'app/presenters/status_relationships_presenter.rb' - - 'app/serializers/initial_state_serializer.rb' - - 'app/serializers/rest/instance_serializer.rb' - - 'app/services/activitypub/fetch_remote_actor_service.rb' - - 'app/services/activitypub/fetch_remote_status_service.rb' - - 'app/services/activitypub/prepare_followers_synchronization_service.rb' - - 'app/services/activitypub/process_status_update_service.rb' - - 'app/services/block_domain_service.rb' - - 'app/services/fetch_link_card_service.rb' - - 'app/services/fetch_resource_service.rb' - - 'app/services/notify_service.rb' - - 'app/services/post_status_service.rb' - - 'app/services/remove_from_followers_service.rb' - - 'app/services/report_service.rb' - - 'app/services/resolve_account_service.rb' - - 'app/services/search_service.rb' - - 'app/services/unblock_domain_service.rb' - - 'app/services/update_status_service.rb' - - 'app/validators/disallowed_hashtags_validator.rb' - - 'app/validators/existing_username_validator.rb' - - 'app/validators/follow_limit_validator.rb' - - 'app/validators/import_validator.rb' - - 'app/validators/note_length_validator.rb' - - 'app/validators/poll_validator.rb' - - 'app/validators/reaction_validator.rb' - - 'app/validators/registration_form_time_validator.rb' - - 'app/workers/activitypub/delivery_worker.rb' - - 'app/workers/move_worker.rb' - - 'db/migrate/20180514140000_revert_index_change_on_statuses_for_api_v1_accounts_account_id_statuses.rb' - - 'db/migrate/20180528141303_fix_accounts_unique_index.rb' - - 'db/migrate/20200510181721_remove_duplicated_indexes_pghero.rb' - - 'db/migrate/20200620164023_add_fixed_lowercase_index_to_accounts.rb' - - 'lib/cli.rb' - - 'lib/mastodon/accounts_cli.rb' - - 'lib/mastodon/domains_cli.rb' - - 'lib/mastodon/maintenance_cli.rb' - - 'lib/mastodon/media_cli.rb' - - 'lib/mastodon/redis_config.rb' - - 'lib/mastodon/statuses_cli.rb' - - 'spec/support/matchers/model/model_have_error_on_field.rb' - # Offense count: 3 # This cop supports unsafe autocorrection (--autocorrect-all). # Configuration parameters: InverseMethods, InverseBlocks. diff --git a/app/controllers/admin/domain_blocks_controller.rb b/app/controllers/admin/domain_blocks_controller.rb index 74764640b..060db11bb 100644 --- a/app/controllers/admin/domain_blocks_controller.rb +++ b/app/controllers/admin/domain_blocks_controller.rb @@ -90,9 +90,7 @@ module Admin end def action_from_button - if params[:save] - 'save' - end + 'save' if params[:save] end end end diff --git a/app/controllers/api/v1/accounts/follower_accounts_controller.rb b/app/controllers/api/v1/accounts/follower_accounts_controller.rb index b61de13b9..68952de89 100644 --- a/app/controllers/api/v1/accounts/follower_accounts_controller.rb +++ b/app/controllers/api/v1/accounts/follower_accounts_controller.rb @@ -45,15 +45,11 @@ class Api::V1::Accounts::FollowerAccountsController < Api::BaseController end def next_path - if records_continue? - api_v1_account_followers_url pagination_params(max_id: pagination_max_id) - end + api_v1_account_followers_url pagination_params(max_id: pagination_max_id) if records_continue? end def prev_path - unless @accounts.empty? - api_v1_account_followers_url pagination_params(since_id: pagination_since_id) - end + api_v1_account_followers_url pagination_params(since_id: pagination_since_id) unless @accounts.empty? end def pagination_max_id diff --git a/app/controllers/api/v1/accounts/following_accounts_controller.rb b/app/controllers/api/v1/accounts/following_accounts_controller.rb index 37d3c2d78..0a4d2ae7b 100644 --- a/app/controllers/api/v1/accounts/following_accounts_controller.rb +++ b/app/controllers/api/v1/accounts/following_accounts_controller.rb @@ -45,15 +45,11 @@ class Api::V1::Accounts::FollowingAccountsController < Api::BaseController end def next_path - if records_continue? - api_v1_account_following_index_url pagination_params(max_id: pagination_max_id) - end + api_v1_account_following_index_url pagination_params(max_id: pagination_max_id) if records_continue? end def prev_path - unless @accounts.empty? - api_v1_account_following_index_url pagination_params(since_id: pagination_since_id) - end + api_v1_account_following_index_url pagination_params(since_id: pagination_since_id) unless @accounts.empty? end def pagination_max_id diff --git a/app/controllers/api/v1/accounts/statuses_controller.rb b/app/controllers/api/v1/accounts/statuses_controller.rb index 38c9f5a20..7ed48cf65 100644 --- a/app/controllers/api/v1/accounts/statuses_controller.rb +++ b/app/controllers/api/v1/accounts/statuses_controller.rb @@ -39,15 +39,11 @@ class Api::V1::Accounts::StatusesController < Api::BaseController end def next_path - if records_continue? - api_v1_account_statuses_url pagination_params(max_id: pagination_max_id) - end + api_v1_account_statuses_url pagination_params(max_id: pagination_max_id) if records_continue? end def prev_path - unless @statuses.empty? - api_v1_account_statuses_url pagination_params(min_id: pagination_since_id) - end + api_v1_account_statuses_url pagination_params(min_id: pagination_since_id) unless @statuses.empty? end def records_continue? diff --git a/app/controllers/api/v1/admin/accounts_controller.rb b/app/controllers/api/v1/admin/accounts_controller.rb index f48300072..ff9cae639 100644 --- a/app/controllers/api/v1/admin/accounts_controller.rb +++ b/app/controllers/api/v1/admin/accounts_controller.rb @@ -120,9 +120,7 @@ class Api::V1::Admin::AccountsController < Api::BaseController translated_params[:status] = status.to_s if params[status].present? end - if params[:staff].present? - translated_params[:role_ids] = UserRole.that_can(:manage_reports).map(&:id) - end + translated_params[:role_ids] = UserRole.that_can(:manage_reports).map(&:id) if params[:staff].present? translated_params end diff --git a/app/controllers/api/v1/blocks_controller.rb b/app/controllers/api/v1/blocks_controller.rb index a65e762c9..06a8bfa89 100644 --- a/app/controllers/api/v1/blocks_controller.rb +++ b/app/controllers/api/v1/blocks_controller.rb @@ -33,15 +33,11 @@ class Api::V1::BlocksController < Api::BaseController end def next_path - if records_continue? - api_v1_blocks_url pagination_params(max_id: pagination_max_id) - end + api_v1_blocks_url pagination_params(max_id: pagination_max_id) if records_continue? end def prev_path - unless paginated_blocks.empty? - api_v1_blocks_url pagination_params(since_id: pagination_since_id) - end + api_v1_blocks_url pagination_params(since_id: pagination_since_id) unless paginated_blocks.empty? end def pagination_max_id diff --git a/app/controllers/api/v1/conversations_controller.rb b/app/controllers/api/v1/conversations_controller.rb index 6c7583403..9034e8a2f 100644 --- a/app/controllers/api/v1/conversations_controller.rb +++ b/app/controllers/api/v1/conversations_controller.rb @@ -40,15 +40,11 @@ class Api::V1::ConversationsController < Api::BaseController end def next_path - if records_continue? - api_v1_conversations_url pagination_params(max_id: pagination_max_id) - end + api_v1_conversations_url pagination_params(max_id: pagination_max_id) if records_continue? end def prev_path - unless @conversations.empty? - api_v1_conversations_url pagination_params(min_id: pagination_since_id) - end + api_v1_conversations_url pagination_params(min_id: pagination_since_id) unless @conversations.empty? end def pagination_max_id diff --git a/app/controllers/api/v1/domain_blocks_controller.rb b/app/controllers/api/v1/domain_blocks_controller.rb index 1891261b9..34def3c44 100644 --- a/app/controllers/api/v1/domain_blocks_controller.rb +++ b/app/controllers/api/v1/domain_blocks_controller.rb @@ -43,15 +43,11 @@ class Api::V1::DomainBlocksController < Api::BaseController end def next_path - if records_continue? - api_v1_domain_blocks_url pagination_params(max_id: pagination_max_id) - end + api_v1_domain_blocks_url pagination_params(max_id: pagination_max_id) if records_continue? end def prev_path - unless @blocks.empty? - api_v1_domain_blocks_url pagination_params(since_id: pagination_since_id) - end + api_v1_domain_blocks_url pagination_params(since_id: pagination_since_id) unless @blocks.empty? end def pagination_max_id diff --git a/app/controllers/api/v1/endorsements_controller.rb b/app/controllers/api/v1/endorsements_controller.rb index 9e80f468a..46e3fcd64 100644 --- a/app/controllers/api/v1/endorsements_controller.rb +++ b/app/controllers/api/v1/endorsements_controller.rb @@ -35,17 +35,13 @@ class Api::V1::EndorsementsController < Api::BaseController def next_path return if unlimited? - if records_continue? - api_v1_endorsements_url pagination_params(max_id: pagination_max_id) - end + api_v1_endorsements_url pagination_params(max_id: pagination_max_id) if records_continue? end def prev_path return if unlimited? - unless @accounts.empty? - api_v1_endorsements_url pagination_params(since_id: pagination_since_id) - end + api_v1_endorsements_url pagination_params(since_id: pagination_since_id) unless @accounts.empty? end def pagination_max_id diff --git a/app/controllers/api/v1/favourites_controller.rb b/app/controllers/api/v1/favourites_controller.rb index 2a873696c..bd7f3d775 100644 --- a/app/controllers/api/v1/favourites_controller.rb +++ b/app/controllers/api/v1/favourites_controller.rb @@ -36,15 +36,11 @@ class Api::V1::FavouritesController < Api::BaseController end def next_path - if records_continue? - api_v1_favourites_url pagination_params(max_id: pagination_max_id) - end + api_v1_favourites_url pagination_params(max_id: pagination_max_id) if records_continue? end def prev_path - unless results.empty? - api_v1_favourites_url pagination_params(min_id: pagination_since_id) - end + api_v1_favourites_url pagination_params(min_id: pagination_since_id) unless results.empty? end def pagination_max_id diff --git a/app/controllers/api/v1/follow_requests_controller.rb b/app/controllers/api/v1/follow_requests_controller.rb index 54ff0e11d..7c197ce6b 100644 --- a/app/controllers/api/v1/follow_requests_controller.rb +++ b/app/controllers/api/v1/follow_requests_controller.rb @@ -53,15 +53,11 @@ class Api::V1::FollowRequestsController < Api::BaseController end def next_path - if records_continue? - api_v1_follow_requests_url pagination_params(max_id: pagination_max_id) - end + api_v1_follow_requests_url pagination_params(max_id: pagination_max_id) if records_continue? end def prev_path - unless @accounts.empty? - api_v1_follow_requests_url pagination_params(since_id: pagination_since_id) - end + api_v1_follow_requests_url pagination_params(since_id: pagination_since_id) unless @accounts.empty? end def pagination_max_id diff --git a/app/controllers/api/v1/lists/accounts_controller.rb b/app/controllers/api/v1/lists/accounts_controller.rb index b66ea9bfe..8e12cb7b6 100644 --- a/app/controllers/api/v1/lists/accounts_controller.rb +++ b/app/controllers/api/v1/lists/accounts_controller.rb @@ -62,17 +62,13 @@ class Api::V1::Lists::AccountsController < Api::BaseController def next_path return if unlimited? - if records_continue? - api_v1_list_accounts_url pagination_params(max_id: pagination_max_id) - end + api_v1_list_accounts_url pagination_params(max_id: pagination_max_id) if records_continue? end def prev_path return if unlimited? - unless @accounts.empty? - api_v1_list_accounts_url pagination_params(since_id: pagination_since_id) - end + api_v1_list_accounts_url pagination_params(since_id: pagination_since_id) unless @accounts.empty? end def pagination_max_id diff --git a/app/controllers/api/v1/mutes_controller.rb b/app/controllers/api/v1/mutes_controller.rb index 6cde53a2a..555485823 100644 --- a/app/controllers/api/v1/mutes_controller.rb +++ b/app/controllers/api/v1/mutes_controller.rb @@ -33,15 +33,11 @@ class Api::V1::MutesController < Api::BaseController end def next_path - if records_continue? - api_v1_mutes_url pagination_params(max_id: pagination_max_id) - end + api_v1_mutes_url pagination_params(max_id: pagination_max_id) if records_continue? end def prev_path - unless paginated_mutes.empty? - api_v1_mutes_url pagination_params(since_id: pagination_since_id) - end + api_v1_mutes_url pagination_params(since_id: pagination_since_id) unless paginated_mutes.empty? end def pagination_max_id diff --git a/app/controllers/api/v1/notifications_controller.rb b/app/controllers/api/v1/notifications_controller.rb index 41f7f93af..2024d521c 100644 --- a/app/controllers/api/v1/notifications_controller.rb +++ b/app/controllers/api/v1/notifications_controller.rb @@ -58,15 +58,11 @@ class Api::V1::NotificationsController < Api::BaseController end def next_path - unless @notifications.empty? - api_v1_notifications_url pagination_params(max_id: pagination_max_id) - end + api_v1_notifications_url pagination_params(max_id: pagination_max_id) unless @notifications.empty? end def prev_path - unless @notifications.empty? - api_v1_notifications_url pagination_params(min_id: pagination_since_id) - end + api_v1_notifications_url pagination_params(min_id: pagination_since_id) unless @notifications.empty? end def pagination_max_id diff --git a/app/controllers/api/v1/scheduled_statuses_controller.rb b/app/controllers/api/v1/scheduled_statuses_controller.rb index f90642a73..2220b6d22 100644 --- a/app/controllers/api/v1/scheduled_statuses_controller.rb +++ b/app/controllers/api/v1/scheduled_statuses_controller.rb @@ -52,15 +52,11 @@ class Api::V1::ScheduledStatusesController < Api::BaseController end def next_path - if records_continue? - api_v1_scheduled_statuses_url pagination_params(max_id: pagination_max_id) - end + api_v1_scheduled_statuses_url pagination_params(max_id: pagination_max_id) if records_continue? end def prev_path - unless @statuses.empty? - api_v1_scheduled_statuses_url pagination_params(min_id: pagination_since_id) - end + api_v1_scheduled_statuses_url pagination_params(min_id: pagination_since_id) unless @statuses.empty? end def records_continue? diff --git a/app/controllers/api/v1/statuses/favourited_by_accounts_controller.rb b/app/controllers/api/v1/statuses/favourited_by_accounts_controller.rb index 2b614a837..b138fa265 100644 --- a/app/controllers/api/v1/statuses/favourited_by_accounts_controller.rb +++ b/app/controllers/api/v1/statuses/favourited_by_accounts_controller.rb @@ -41,15 +41,11 @@ class Api::V1::Statuses::FavouritedByAccountsController < Api::BaseController end def next_path - if records_continue? - api_v1_status_favourited_by_index_url pagination_params(max_id: pagination_max_id) - end + api_v1_status_favourited_by_index_url pagination_params(max_id: pagination_max_id) if records_continue? end def prev_path - unless @accounts.empty? - api_v1_status_favourited_by_index_url pagination_params(since_id: pagination_since_id) - end + api_v1_status_favourited_by_index_url pagination_params(since_id: pagination_since_id) unless @accounts.empty? end def pagination_max_id diff --git a/app/controllers/api/v1/statuses/reblogged_by_accounts_controller.rb b/app/controllers/api/v1/statuses/reblogged_by_accounts_controller.rb index 24db30fcc..4b545f982 100644 --- a/app/controllers/api/v1/statuses/reblogged_by_accounts_controller.rb +++ b/app/controllers/api/v1/statuses/reblogged_by_accounts_controller.rb @@ -37,15 +37,11 @@ class Api::V1::Statuses::RebloggedByAccountsController < Api::BaseController end def next_path - if records_continue? - api_v1_status_reblogged_by_index_url pagination_params(max_id: pagination_max_id) - end + api_v1_status_reblogged_by_index_url pagination_params(max_id: pagination_max_id) if records_continue? end def prev_path - unless @accounts.empty? - api_v1_status_reblogged_by_index_url pagination_params(since_id: pagination_since_id) - end + api_v1_status_reblogged_by_index_url pagination_params(since_id: pagination_since_id) unless @accounts.empty? end def pagination_max_id diff --git a/app/controllers/api/v2/admin/accounts_controller.rb b/app/controllers/api/v2/admin/accounts_controller.rb index b25831aa0..0c451f778 100644 --- a/app/controllers/api/v2/admin/accounts_controller.rb +++ b/app/controllers/api/v2/admin/accounts_controller.rb @@ -25,9 +25,7 @@ class Api::V2::Admin::AccountsController < Api::V1::Admin::AccountsController def translated_filter_params translated_params = filter_params.slice(*AccountFilter::KEYS) - if params[:permissions] == 'staff' - translated_params[:role_ids] = UserRole.that_can(:manage_reports).map(&:id) - end + translated_params[:role_ids] = UserRole.that_can(:manage_reports).map(&:id) if params[:permissions] == 'staff' translated_params end diff --git a/app/controllers/auth/registrations_controller.rb b/app/controllers/auth/registrations_controller.rb index 71c0cd827..c5418ba0c 100644 --- a/app/controllers/auth/registrations_controller.rb +++ b/app/controllers/auth/registrations_controller.rb @@ -30,9 +30,7 @@ class Auth::RegistrationsController < Devise::RegistrationsController def update super do |resource| - if resource.saved_change_to_encrypted_password? - resource.clear_other_sessions(current_session.session_id) - end + resource.clear_other_sessions(current_session.session_id) if resource.saved_change_to_encrypted_password? end end diff --git a/app/controllers/auth/sessions_controller.rb b/app/controllers/auth/sessions_controller.rb index afcf8b24b..3ce742638 100644 --- a/app/controllers/auth/sessions_controller.rb +++ b/app/controllers/auth/sessions_controller.rb @@ -110,9 +110,7 @@ class Auth::SessionsController < Devise::SessionsController def home_paths(resource) paths = [about_path] - if single_user_mode? && resource.is_a?(User) - paths << short_account_path(username: resource.account) - end + paths << short_account_path(username: resource.account) if single_user_mode? && resource.is_a?(User) paths end diff --git a/app/controllers/filters/statuses_controller.rb b/app/controllers/filters/statuses_controller.rb index cc493c22c..7779c6d95 100644 --- a/app/controllers/filters/statuses_controller.rb +++ b/app/controllers/filters/statuses_controller.rb @@ -38,9 +38,7 @@ class Filters::StatusesController < ApplicationController end def action_from_button - if params[:remove] - 'remove' - end + 'remove' if params[:remove] end def set_body_classes diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index b2687eddd..1f93b33f5 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -216,9 +216,7 @@ module ApplicationHelper state_params[:moved_to_account] = current_account.moved_to_account end - if single_user_mode? - state_params[:owner] = Account.local.without_suspended.where('id > 0').first - end + state_params[:owner] = Account.local.without_suspended.where('id > 0').first if single_user_mode? json = ActiveModelSerializers::SerializableResource.new(InitialStatePresenter.new(state_params), serializer: InitialStateSerializer).to_json # rubocop:disable Rails/OutputSafety diff --git a/app/lib/activitypub/linked_data_signature.rb b/app/lib/activitypub/linked_data_signature.rb index f90adaf6c..61759649a 100644 --- a/app/lib/activitypub/linked_data_signature.rb +++ b/app/lib/activitypub/linked_data_signature.rb @@ -27,9 +27,7 @@ class ActivityPub::LinkedDataSignature document_hash = hash(@json.without('signature')) to_be_verified = options_hash + document_hash - if creator.keypair.public_key.verify(OpenSSL::Digest.new('SHA256'), Base64.decode64(signature), to_be_verified) - creator - end + creator if creator.keypair.public_key.verify(OpenSSL::Digest.new('SHA256'), Base64.decode64(signature), to_be_verified) end def sign!(creator, sign_with: nil) diff --git a/app/lib/activitypub/parser/media_attachment_parser.rb b/app/lib/activitypub/parser/media_attachment_parser.rb index 656be84b7..56b8b23f8 100644 --- a/app/lib/activitypub/parser/media_attachment_parser.rb +++ b/app/lib/activitypub/parser/media_attachment_parser.rb @@ -50,9 +50,7 @@ class ActivityPub::Parser::MediaAttachmentParser components = begin blurhash = @json['blurhash'] - if blurhash.present? && /^[\w#$%*+,-.:;=?@\[\]^{|}~]+$/.match?(blurhash) - Blurhash.components(blurhash) - end + Blurhash.components(blurhash) if blurhash.present? && /^[\w#$%*+,-.:;=?@\[\]^{|}~]+$/.match?(blurhash) end components.present? && components.none? { |comp| comp > 5 } diff --git a/app/lib/status_finder.rb b/app/lib/status_finder.rb index 22ced8bf8..1a7f2fe69 100644 --- a/app/lib/status_finder.rb +++ b/app/lib/status_finder.rb @@ -27,8 +27,6 @@ class StatusFinder end def verify_action! - unless recognized_params[:action] == 'show' - raise ActiveRecord::RecordNotFound - end + raise ActiveRecord::RecordNotFound unless recognized_params[:action] == 'show' end end diff --git a/app/models/account.rb b/app/models/account.rb index 262285a09..a96e204fa 100644 --- a/app/models/account.rb +++ b/app/models/account.rb @@ -313,9 +313,7 @@ class Account < ApplicationRecord previous = old_fields.find { |item| item['value'] == attr[:value] } - if previous && previous['verified_at'].present? - attr[:verified_at] = previous['verified_at'] - end + attr[:verified_at] = previous['verified_at'] if previous && previous['verified_at'].present? fields << attr end diff --git a/app/models/account_statuses_cleanup_policy.rb b/app/models/account_statuses_cleanup_policy.rb index 49adc6ad0..14ce00abb 100644 --- a/app/models/account_statuses_cleanup_policy.rb +++ b/app/models/account_statuses_cleanup_policy.rb @@ -122,9 +122,7 @@ class AccountStatusesCleanupPolicy < ApplicationRecord # may need to be deleted, so we'll have to start again. redis.del("account_cleanup:#{account.id}") end - if EXCEPTION_THRESHOLDS.map { |name| attribute_change_to_be_saved(name) }.compact.any? { |old, new| old.present? && (new.nil? || new > old) } - redis.del("account_cleanup:#{account.id}") - end + redis.del("account_cleanup:#{account.id}") if EXCEPTION_THRESHOLDS.map { |name| attribute_change_to_be_saved(name) }.compact.any? { |old, new| old.present? && (new.nil? || new > old) } end def validate_local_account @@ -141,9 +139,7 @@ class AccountStatusesCleanupPolicy < ApplicationRecord # has switched to snowflake IDs significantly over 2 years ago anyway. snowflake_id = Mastodon::Snowflake.id_at(min_status_age.seconds.ago, with_random: false) - if max_id.nil? || snowflake_id < max_id - max_id = snowflake_id - end + max_id = snowflake_id if max_id.nil? || snowflake_id < max_id Status.where(Status.arel_table[:id].lteq(max_id)) end diff --git a/app/models/concerns/account_interactions.rb b/app/models/concerns/account_interactions.rb index de8bf338f..325619774 100644 --- a/app/models/concerns/account_interactions.rb +++ b/app/models/concerns/account_interactions.rb @@ -151,9 +151,7 @@ module AccountInteractions remove_potential_friendship(other_account) # When toggling a mute between hiding and allowing notifications, the mute will already exist, so the find_or_create_by! call will return the existing Mute without updating the hide_notifications attribute. Therefore, we check that hide_notifications? is what we want and set it if it isn't. - if mute.hide_notifications? != notifications - mute.update!(hide_notifications: notifications) - end + mute.update!(hide_notifications: notifications) if mute.hide_notifications? != notifications mute end diff --git a/app/models/concerns/omniauthable.rb b/app/models/concerns/omniauthable.rb index 7d54e9d6d..b0aa5be6f 100644 --- a/app/models/concerns/omniauthable.rb +++ b/app/models/concerns/omniauthable.rb @@ -56,9 +56,7 @@ module Omniauthable user = User.new(user_params_from_auth(email, auth)) begin - if /\A#{URI::DEFAULT_PARSER.make_regexp(%w(http https))}\z/.match?(auth.info.image) - user.account.avatar_remote_url = auth.info.image - end + user.account.avatar_remote_url = auth.info.image if /\A#{URI::DEFAULT_PARSER.make_regexp(%w(http https))}\z/.match?(auth.info.image) rescue Mastodon::UnexpectedResponseError user.account.avatar_remote_url = nil end diff --git a/app/serializers/initial_state_serializer.rb b/app/serializers/initial_state_serializer.rb index 95b28fa15..fa1ddc6d3 100644 --- a/app/serializers/initial_state_serializer.rb +++ b/app/serializers/initial_state_serializer.rb @@ -61,9 +61,7 @@ class InitialStateSerializer < ActiveModel::Serializer store[:disabled_account_id] = object.disabled_account.id.to_s if object.disabled_account store[:moved_to_account_id] = object.moved_to_account.id.to_s if object.moved_to_account - if Rails.configuration.x.single_user_mode - store[:owner] = object.owner&.id&.to_s - end + store[:owner] = object.owner&.id&.to_s if Rails.configuration.x.single_user_mode store end diff --git a/app/serializers/rest/instance_serializer.rb b/app/serializers/rest/instance_serializer.rb index e280f8eb6..a07840f0c 100644 --- a/app/serializers/rest/instance_serializer.rb +++ b/app/serializers/rest/instance_serializer.rb @@ -95,9 +95,7 @@ class REST::InstanceSerializer < ActiveModel::Serializer end def registrations_message - if Setting.closed_registrations_message.present? - markdown.render(Setting.closed_registrations_message) - end + markdown.render(Setting.closed_registrations_message) if Setting.closed_registrations_message.present? end def markdown diff --git a/app/services/activitypub/fetch_remote_actor_service.rb b/app/services/activitypub/fetch_remote_actor_service.rb index 8908d21e2..e8992b845 100644 --- a/app/services/activitypub/fetch_remote_actor_service.rb +++ b/app/services/activitypub/fetch_remote_actor_service.rb @@ -56,9 +56,7 @@ class ActivityPub::FetchRemoteActorService < BaseService webfinger = webfinger!("acct:#{confirmed_username}@#{confirmed_domain}") @username, @domain = split_acct(webfinger.subject) - unless confirmed_username.casecmp(@username).zero? && confirmed_domain.casecmp(@domain).zero? - raise Webfinger::RedirectError, "Too many webfinger redirects for URI #{@uri} (stopped at #{@username}@#{@domain})" - end + raise Webfinger::RedirectError, "Too many webfinger redirects for URI #{@uri} (stopped at #{@username}@#{@domain})" unless confirmed_username.casecmp(@username).zero? && confirmed_domain.casecmp(@domain).zero? raise Error, "Webfinger response for #{@username}@#{@domain} does not loop back to #{@uri}" if webfinger.link('self', 'href') != @uri rescue Webfinger::RedirectError => e diff --git a/app/services/activitypub/process_status_update_service.rb b/app/services/activitypub/process_status_update_service.rb index 1dc393e28..ac7372f74 100644 --- a/app/services/activitypub/process_status_update_service.rb +++ b/app/services/activitypub/process_status_update_service.rb @@ -80,9 +80,7 @@ class ActivityPub::ProcessStatusUpdateService < BaseService # If a previously existing media attachment was significantly updated, mark # media attachments as changed even if none were added or removed - if media_attachment_parser.significantly_changes?(media_attachment) - @media_attachments_changed = true - end + @media_attachments_changed = true if media_attachment_parser.significantly_changes?(media_attachment) media_attachment.description = media_attachment_parser.description media_attachment.focus = media_attachment_parser.focus diff --git a/app/services/remove_from_followers_service.rb b/app/services/remove_from_followers_service.rb index 3dac5467f..007d5b1fd 100644 --- a/app/services/remove_from_followers_service.rb +++ b/app/services/remove_from_followers_service.rb @@ -7,9 +7,7 @@ class RemoveFromFollowersService < BaseService source_account.passive_relationships.where(account_id: target_accounts).find_each do |follow| follow.destroy - if source_account.local? && !follow.account.local? && follow.account.activitypub? - create_notification(follow) - end + create_notification(follow) if source_account.local? && !follow.account.local? && follow.account.activitypub? end end diff --git a/app/services/resolve_account_service.rb b/app/services/resolve_account_service.rb index 1ba372cd6..c76df5a0e 100644 --- a/app/services/resolve_account_service.rb +++ b/app/services/resolve_account_service.rb @@ -96,9 +96,7 @@ class ResolveAccountService < BaseService @webfinger = webfinger!("acct:#{confirmed_username}@#{confirmed_domain}") @username, @domain = split_acct(@webfinger.subject) - unless confirmed_username.casecmp(@username).zero? && confirmed_domain.casecmp(@domain).zero? - raise Webfinger::RedirectError, "Too many webfinger redirects for URI #{uri} (stopped at #{@username}@#{@domain})" - end + raise Webfinger::RedirectError, "Too many webfinger redirects for URI #{uri} (stopped at #{@username}@#{@domain})" unless confirmed_username.casecmp(@username).zero? && confirmed_domain.casecmp(@domain).zero? rescue Webfinger::GoneError @gone = true end diff --git a/app/services/search_service.rb b/app/services/search_service.rb index 1a76cbb38..93b72fa0c 100644 --- a/app/services/search_service.rb +++ b/app/services/search_service.rb @@ -37,9 +37,7 @@ class SearchService < BaseService def perform_statuses_search! definition = parsed_query.apply(StatusesIndex.filter(term: { searchable_by: @account.id })) - if @options[:account_id].present? - definition = definition.filter(term: { account_id: @options[:account_id] }) - end + definition = definition.filter(term: { account_id: @options[:account_id] }) if @options[:account_id].present? if @options[:min_id].present? || @options[:max_id].present? range = {} diff --git a/lib/mastodon/media_cli.rb b/lib/mastodon/media_cli.rb index 24cc98964..a901a6ab9 100644 --- a/lib/mastodon/media_cli.rb +++ b/lib/mastodon/media_cli.rb @@ -277,9 +277,7 @@ module Mastodon exit(1) end - if options[:days].present? - scope = scope.where('media_attachments.id > ?', Mastodon::Snowflake.id_at(options[:days].days.ago, with_random: false)) - end + scope = scope.where('media_attachments.id > ?', Mastodon::Snowflake.id_at(options[:days].days.ago, with_random: false)) if options[:days].present? processed, aggregate = parallelize_with_progress(scope) do |media_attachment| next if media_attachment.remote_url.blank? || (!options[:force] && media_attachment.file_file_name.present?) diff --git a/lib/mastodon/redis_config.rb b/lib/mastodon/redis_config.rb index 3522fa11e..037ca5edc 100644 --- a/lib/mastodon/redis_config.rb +++ b/lib/mastodon/redis_config.rb @@ -46,6 +46,4 @@ REDIS_SIDEKIQ_PARAMS = { namespace: sidekiq_namespace, }.freeze -if Rails.env.test? - ENV['REDIS_NAMESPACE'] = "mastodon_test#{ENV['TEST_ENV_NUMBER']}" -end +ENV['REDIS_NAMESPACE'] = "mastodon_test#{ENV['TEST_ENV_NUMBER']}" if Rails.env.test? diff --git a/spec/support/matchers/model/model_have_error_on_field.rb b/spec/support/matchers/model/model_have_error_on_field.rb index 85bdd8215..d85db2fca 100644 --- a/spec/support/matchers/model/model_have_error_on_field.rb +++ b/spec/support/matchers/model/model_have_error_on_field.rb @@ -1,8 +1,6 @@ RSpec::Matchers.define :model_have_error_on_field do |expected| match do |record| - if record.errors.empty? - record.valid? - end + record.valid? if record.errors.empty? record.errors.has_key?(expected) end -- cgit From 38a1d8bb85da6c7a52a3bde28af368b8d2104d02 Mon Sep 17 00:00:00 2001 From: Nick Schonning Date: Sun, 19 Feb 2023 23:00:48 -0500 Subject: Autofix Rubocop RSpec/ImplicitSubject (#23721) --- .rubocop_todo.yml | 86 +++++++--------------- app/serializers/initial_state_serializer.rb | 1 - spec/controllers/admin/accounts_controller_spec.rb | 32 ++++---- .../controllers/admin/instances_controller_spec.rb | 4 +- spec/controllers/application_controller_spec.rb | 2 +- spec/controllers/home_controller_spec.rb | 4 +- spec/controllers/relationships_controller_spec.rb | 2 +- .../settings/featured_tags_controller_spec.rb | 2 +- .../settings/migrations_controller_spec.rb | 18 ++--- .../settings/sessions_controller_spec.rb | 4 +- spec/features/log_in_spec.rb | 6 +- spec/features/profile_spec.rb | 4 +- spec/lib/emoji_formatter_spec.rb | 8 +- spec/lib/entity_cache_spec.rb | 2 +- spec/lib/html_aware_formatter_spec.rb | 8 +- spec/lib/ostatus/tag_manager_spec.rb | 6 +- spec/lib/plain_text_formatter_spec.rb | 4 +- spec/lib/text_formatter_spec.rb | 78 ++++++++++---------- spec/models/concerns/account_interactions_spec.rb | 86 +++++++++++----------- spec/models/custom_emoji_spec.rb | 12 +-- spec/models/media_attachment_spec.rb | 10 +-- spec/models/notification_spec.rb | 2 +- spec/models/remote_follow_spec.rb | 10 +-- spec/models/report_spec.rb | 4 +- spec/models/session_activation_spec.rb | 6 +- spec/models/setting_spec.rb | 4 +- 26 files changed, 184 insertions(+), 221 deletions(-) (limited to 'app/serializers/initial_state_serializer.rb') diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 7cb4d55e0..4c3b3ecb6 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1,6 +1,6 @@ # This configuration was generated by # `rubocop --auto-gen-config --auto-gen-only-exclude --no-exclude-limit` -# on 2023-02-16 05:53:07 UTC using RuboCop version 1.45.1. +# on 2023-02-19 06:22:09 UTC using RuboCop version 1.45.1. # The point is for the user to remove these configuration records # one by one as the offenses are removed from the code base. # Note that changes in the inspected code, or installation of new @@ -162,7 +162,7 @@ Layout/HashAlignment: - 'spec/models/admin/account_action_spec.rb' - 'spec/models/concerns/account_interactions_spec.rb' -# Offense count: 577 +# Offense count: 581 # This cop supports safe autocorrection (--autocorrect). # Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, AllowedPatterns. # URISchemes: http, https @@ -305,18 +305,17 @@ Lint/Void: Exclude: - 'spec/services/resolve_account_service_spec.rb' -# Offense count: 65 +# Offense count: 66 # Configuration parameters: AllowedMethods, AllowedPatterns, CountRepeatedAttributes. Metrics/AbcSize: Enabled: false -# Offense count: 11 +# Offense count: 10 # Configuration parameters: CountComments, Max, CountAsOne, AllowedMethods, AllowedPatterns, inherit_mode. # AllowedMethods: refine Metrics/BlockLength: Exclude: - 'app/models/concerns/account_interactions.rb' - - 'app/models/concerns/omniauthable.rb' - 'db/post_migrate/20221101190723_backfill_admin_action_logs.rb' - 'db/post_migrate/20221206114142_backfill_admin_action_logs_again.rb' - 'lib/tasks/branding.rake' @@ -335,7 +334,7 @@ Metrics/BlockNesting: Metrics/CyclomaticComplexity: Enabled: false -# Offense count: 40 +# Offense count: 35 # Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns. Metrics/MethodLength: Enabled: false @@ -936,37 +935,6 @@ RSpec/HookArgument: - 'spec/services/import_service_spec.rb' - 'spec/spec_helper.rb' -# Offense count: 159 -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: EnforcedStyle. -# SupportedStyles: single_line_only, single_statement_only, disallow, require_implicit -RSpec/ImplicitSubject: - Exclude: - - 'spec/controllers/admin/accounts_controller_spec.rb' - - 'spec/controllers/admin/instances_controller_spec.rb' - - 'spec/controllers/application_controller_spec.rb' - - 'spec/controllers/home_controller_spec.rb' - - 'spec/controllers/relationships_controller_spec.rb' - - 'spec/controllers/settings/featured_tags_controller_spec.rb' - - 'spec/controllers/settings/migrations_controller_spec.rb' - - 'spec/controllers/settings/sessions_controller_spec.rb' - - 'spec/features/log_in_spec.rb' - - 'spec/features/profile_spec.rb' - - 'spec/lib/emoji_formatter_spec.rb' - - 'spec/lib/entity_cache_spec.rb' - - 'spec/lib/html_aware_formatter_spec.rb' - - 'spec/lib/ostatus/tag_manager_spec.rb' - - 'spec/lib/plain_text_formatter_spec.rb' - - 'spec/lib/text_formatter_spec.rb' - - 'spec/models/concerns/account_interactions_spec.rb' - - 'spec/models/custom_emoji_spec.rb' - - 'spec/models/media_attachment_spec.rb' - - 'spec/models/notification_spec.rb' - - 'spec/models/remote_follow_spec.rb' - - 'spec/models/report_spec.rb' - - 'spec/models/session_activation_spec.rb' - - 'spec/models/setting_spec.rb' - # Offense count: 101 # Configuration parameters: AssignmentOnly. RSpec/InstanceVariable: @@ -1199,7 +1167,7 @@ RSpec/MissingExampleGroupArgument: RSpec/MultipleExpectations: Max: 19 -# Offense count: 443 +# Offense count: 442 # Configuration parameters: AllowSubject. RSpec/MultipleMemoizedHelpers: Max: 21 @@ -1216,7 +1184,7 @@ RSpec/MultipleSubjects: - 'spec/controllers/follower_accounts_controller_spec.rb' - 'spec/controllers/following_accounts_controller_spec.rb' -# Offense count: 1252 +# Offense count: 1407 # Configuration parameters: EnforcedStyle, IgnoreSharedExamples. # SupportedStyles: always, named_only RSpec/NamedSubject: @@ -1226,6 +1194,7 @@ RSpec/NamedSubject: - 'spec/controllers/admin/confirmations_controller_spec.rb' - 'spec/controllers/admin/custom_emojis_controller_spec.rb' - 'spec/controllers/admin/domain_blocks_controller_spec.rb' + - 'spec/controllers/admin/instances_controller_spec.rb' - 'spec/controllers/admin/invites_controller_spec.rb' - 'spec/controllers/admin/report_notes_controller_spec.rb' - 'spec/controllers/api/v1/accounts/notes_controller_spec.rb' @@ -1233,13 +1202,18 @@ RSpec/NamedSubject: - 'spec/controllers/api/v1/admin/domain_blocks_controller_spec.rb' - 'spec/controllers/auth/passwords_controller_spec.rb' - 'spec/controllers/auth/registrations_controller_spec.rb' + - 'spec/controllers/home_controller_spec.rb' - 'spec/controllers/invites_controller_spec.rb' - 'spec/controllers/oauth/authorizations_controller_spec.rb' - 'spec/controllers/oauth/authorized_applications_controller_spec.rb' - 'spec/controllers/relationships_controller_spec.rb' - 'spec/controllers/settings/featured_tags_controller_spec.rb' + - 'spec/controllers/settings/migrations_controller_spec.rb' + - 'spec/controllers/settings/sessions_controller_spec.rb' - 'spec/controllers/settings/two_factor_authentication/confirmations_controller_spec.rb' - 'spec/controllers/well_known/webfinger_controller_spec.rb' + - 'spec/features/log_in_spec.rb' + - 'spec/features/profile_spec.rb' - 'spec/lib/activitypub/activity/accept_spec.rb' - 'spec/lib/activitypub/activity/add_spec.rb' - 'spec/lib/activitypub/activity/announce_spec.rb' @@ -1262,16 +1236,21 @@ RSpec/NamedSubject: - 'spec/lib/connection_pool/shared_timed_stack_spec.rb' - 'spec/lib/delivery_failure_tracker_spec.rb' - 'spec/lib/emoji_formatter_spec.rb' + - 'spec/lib/entity_cache_spec.rb' - 'spec/lib/fast_ip_map_spec.rb' - 'spec/lib/feed_manager_spec.rb' - 'spec/lib/hashtag_normalizer_spec.rb' + - 'spec/lib/html_aware_formatter_spec.rb' - 'spec/lib/link_details_extractor_spec.rb' + - 'spec/lib/ostatus/tag_manager_spec.rb' + - 'spec/lib/plain_text_formatter_spec.rb' - 'spec/lib/request_pool_spec.rb' - 'spec/lib/request_spec.rb' - 'spec/lib/sanitize_config_spec.rb' - 'spec/lib/status_finder_spec.rb' - 'spec/lib/status_reach_finder_spec.rb' - 'spec/lib/suspicious_sign_in_detector_spec.rb' + - 'spec/lib/text_formatter_spec.rb' - 'spec/lib/vacuum/access_tokens_vacuum_spec.rb' - 'spec/lib/vacuum/backups_vacuum_spec.rb' - 'spec/lib/vacuum/feeds_vacuum_spec.rb' @@ -1288,11 +1267,17 @@ RSpec/NamedSubject: - 'spec/models/canonical_email_block_spec.rb' - 'spec/models/concerns/account_interactions_spec.rb' - 'spec/models/custom_emoji_filter_spec.rb' + - 'spec/models/custom_emoji_spec.rb' - 'spec/models/follow_spec.rb' - 'spec/models/home_feed_spec.rb' + - 'spec/models/media_attachment_spec.rb' - 'spec/models/notification_spec.rb' - 'spec/models/public_feed_spec.rb' - 'spec/models/relationship_filter_spec.rb' + - 'spec/models/remote_follow_spec.rb' + - 'spec/models/report_spec.rb' + - 'spec/models/session_activation_spec.rb' + - 'spec/models/setting_spec.rb' - 'spec/models/status_spec.rb' - 'spec/models/tag_spec.rb' - 'spec/models/trends/statuses_spec.rb' @@ -2347,46 +2332,25 @@ Style/FormatStringToken: Style/FrozenStringLiteralComment: Enabled: false -# Offense count: 69 +# Offense count: 34 # This cop supports safe autocorrection (--autocorrect). # Configuration parameters: MinBodyLength, AllowConsecutiveConditionals. Style/GuardClause: Exclude: - 'app/controllers/admin/confirmations_controller.rb' - - 'app/controllers/admin/domain_blocks_controller.rb' - - 'app/controllers/api/v1/accounts/follower_accounts_controller.rb' - - 'app/controllers/api/v1/accounts/following_accounts_controller.rb' - - 'app/controllers/api/v1/accounts/statuses_controller.rb' - - 'app/controllers/api/v1/blocks_controller.rb' - - 'app/controllers/api/v1/conversations_controller.rb' - - 'app/controllers/api/v1/domain_blocks_controller.rb' - - 'app/controllers/api/v1/endorsements_controller.rb' - - 'app/controllers/api/v1/favourites_controller.rb' - - 'app/controllers/api/v1/follow_requests_controller.rb' - - 'app/controllers/api/v1/lists/accounts_controller.rb' - - 'app/controllers/api/v1/mutes_controller.rb' - - 'app/controllers/api/v1/notifications_controller.rb' - - 'app/controllers/api/v1/scheduled_statuses_controller.rb' - - 'app/controllers/api/v1/statuses/favourited_by_accounts_controller.rb' - - 'app/controllers/api/v1/statuses/reblogged_by_accounts_controller.rb' - 'app/controllers/auth/confirmations_controller.rb' - 'app/controllers/auth/passwords_controller.rb' - - 'app/controllers/filters/statuses_controller.rb' - 'app/controllers/settings/two_factor_authentication/webauthn_credentials_controller.rb' - 'app/lib/activitypub/activity/block.rb' - - 'app/lib/activitypub/linked_data_signature.rb' - 'app/lib/connection_pool/shared_connection_pool.rb' - 'app/lib/request.rb' - 'app/lib/request_pool.rb' - - 'app/lib/status_finder.rb' - 'app/lib/webfinger.rb' - 'app/lib/webfinger_resource.rb' - - 'app/models/account_statuses_cleanup_policy.rb' - 'app/models/concerns/account_counters.rb' - 'app/models/concerns/ldap_authenticable.rb' - 'app/models/tag.rb' - 'app/models/user.rb' - - 'app/serializers/rest/instance_serializer.rb' - 'app/services/fan_out_on_write_service.rb' - 'app/services/post_status_service.rb' - 'app/services/process_hashtags_service.rb' diff --git a/app/serializers/initial_state_serializer.rb b/app/serializers/initial_state_serializer.rb index fa1ddc6d3..7905444e9 100644 --- a/app/serializers/initial_state_serializer.rb +++ b/app/serializers/initial_state_serializer.rb @@ -65,7 +65,6 @@ class InitialStateSerializer < ActiveModel::Serializer store end - # rubocop:enable Metrics/AbcSize def compose store = {} diff --git a/spec/controllers/admin/accounts_controller_spec.rb b/spec/controllers/admin/accounts_controller_spec.rb index f5d68a8ad..fdc98ed46 100644 --- a/spec/controllers/admin/accounts_controller_spec.rb +++ b/spec/controllers/admin/accounts_controller_spec.rb @@ -83,7 +83,7 @@ RSpec.describe Admin::AccountsController, type: :controller do let(:target_role) { UserRole.find_by(name: 'Admin') } it 'fails to memorialize account' do - is_expected.to have_http_status 403 + expect(subject).to have_http_status 403 expect(account.reload).to_not be_memorial end end @@ -92,7 +92,7 @@ RSpec.describe Admin::AccountsController, type: :controller do let(:target_role) { UserRole.find_by(name: 'Moderator') } it 'succeeds in memorializing account' do - is_expected.to redirect_to admin_account_path(account.id) + expect(subject).to redirect_to admin_account_path(account.id) expect(account.reload).to be_memorial end end @@ -105,7 +105,7 @@ RSpec.describe Admin::AccountsController, type: :controller do let(:target_role) { UserRole.find_by(name: 'Admin') } it 'fails to memorialize account' do - is_expected.to have_http_status 403 + expect(subject).to have_http_status 403 expect(account.reload).to_not be_memorial end end @@ -114,7 +114,7 @@ RSpec.describe Admin::AccountsController, type: :controller do let(:target_role) { UserRole.find_by(name: 'Moderator') } it 'fails to memorialize account' do - is_expected.to have_http_status 403 + expect(subject).to have_http_status 403 expect(account.reload).to_not be_memorial end end @@ -132,7 +132,7 @@ RSpec.describe Admin::AccountsController, type: :controller do let(:role) { UserRole.find_by(name: 'Admin') } it 'succeeds in enabling account' do - is_expected.to redirect_to admin_account_path(account.id) + expect(subject).to redirect_to admin_account_path(account.id) expect(user.reload).to_not be_disabled end end @@ -141,7 +141,7 @@ RSpec.describe Admin::AccountsController, type: :controller do let(:role) { UserRole.everyone } it 'fails to enable account' do - is_expected.to have_http_status 403 + expect(subject).to have_http_status 403 expect(user.reload).to be_disabled end end @@ -162,12 +162,12 @@ RSpec.describe Admin::AccountsController, type: :controller do let(:role) { UserRole.find_by(name: 'Admin') } it 'succeeds in approving account' do - is_expected.to redirect_to admin_accounts_path(status: 'pending') + expect(subject).to redirect_to admin_accounts_path(status: 'pending') expect(user.reload).to be_approved end it 'logs action' do - is_expected.to have_http_status 302 + expect(subject).to have_http_status 302 log_item = Admin::ActionLog.last @@ -182,7 +182,7 @@ RSpec.describe Admin::AccountsController, type: :controller do let(:role) { UserRole.everyone } it 'fails to approve account' do - is_expected.to have_http_status 403 + expect(subject).to have_http_status 403 expect(user.reload).to_not be_approved end end @@ -203,11 +203,11 @@ RSpec.describe Admin::AccountsController, type: :controller do let(:role) { UserRole.find_by(name: 'Admin') } it 'succeeds in rejecting account' do - is_expected.to redirect_to admin_accounts_path(status: 'pending') + expect(subject).to redirect_to admin_accounts_path(status: 'pending') end it 'logs action' do - is_expected.to have_http_status 302 + expect(subject).to have_http_status 302 log_item = Admin::ActionLog.last @@ -222,7 +222,7 @@ RSpec.describe Admin::AccountsController, type: :controller do let(:role) { UserRole.everyone } it 'fails to reject account' do - is_expected.to have_http_status 403 + expect(subject).to have_http_status 403 expect(user.reload).to_not be_approved end end @@ -242,7 +242,7 @@ RSpec.describe Admin::AccountsController, type: :controller do let(:role) { UserRole.find_by(name: 'Admin') } it 'succeeds in redownloading' do - is_expected.to redirect_to admin_account_path(account.id) + expect(subject).to redirect_to admin_account_path(account.id) end end @@ -250,7 +250,7 @@ RSpec.describe Admin::AccountsController, type: :controller do let(:role) { UserRole.everyone } it 'fails to redownload' do - is_expected.to have_http_status 403 + expect(subject).to have_http_status 403 end end end @@ -265,7 +265,7 @@ RSpec.describe Admin::AccountsController, type: :controller do let(:role) { UserRole.find_by(name: 'Admin') } it 'succeeds in removing avatar' do - is_expected.to redirect_to admin_account_path(account.id) + expect(subject).to redirect_to admin_account_path(account.id) end end @@ -273,7 +273,7 @@ RSpec.describe Admin::AccountsController, type: :controller do let(:role) { UserRole.everyone } it 'fails to remove avatar' do - is_expected.to have_http_status 403 + expect(subject).to have_http_status 403 end end end diff --git a/spec/controllers/admin/instances_controller_spec.rb b/spec/controllers/admin/instances_controller_spec.rb index a7e348b1c..4716e486a 100644 --- a/spec/controllers/admin/instances_controller_spec.rb +++ b/spec/controllers/admin/instances_controller_spec.rb @@ -42,7 +42,7 @@ RSpec.describe Admin::InstancesController, type: :controller do let(:role) { UserRole.find_by(name: 'Admin') } it 'succeeds in purging instance' do - is_expected.to redirect_to admin_instances_path + expect(subject).to redirect_to admin_instances_path end end @@ -50,7 +50,7 @@ RSpec.describe Admin::InstancesController, type: :controller do let(:role) { nil } it 'fails to purge instance' do - is_expected.to have_http_status 403 + expect(subject).to have_http_status 403 end end end diff --git a/spec/controllers/application_controller_spec.rb b/spec/controllers/application_controller_spec.rb index f14c451de..e2a63002b 100644 --- a/spec/controllers/application_controller_spec.rb +++ b/spec/controllers/application_controller_spec.rb @@ -28,7 +28,7 @@ describe ApplicationController, type: :controller do end it 'renders template for http' do - is_expected.to render_template("errors/#{code}", layout: 'error') + expect(subject).to render_template("errors/#{code}", layout: 'error') end end diff --git a/spec/controllers/home_controller_spec.rb b/spec/controllers/home_controller_spec.rb index d845ae01d..2409bf42c 100644 --- a/spec/controllers/home_controller_spec.rb +++ b/spec/controllers/home_controller_spec.rb @@ -9,7 +9,7 @@ RSpec.describe HomeController, type: :controller do context 'when not signed in' do it 'returns http success' do @request.path = '/' - is_expected.to have_http_status(:success) + expect(subject).to have_http_status(:success) end end @@ -21,7 +21,7 @@ RSpec.describe HomeController, type: :controller do end it 'returns http success' do - is_expected.to have_http_status(:success) + expect(subject).to have_http_status(:success) end end end diff --git a/spec/controllers/relationships_controller_spec.rb b/spec/controllers/relationships_controller_spec.rb index cd09cf50b..4c4227d66 100644 --- a/spec/controllers/relationships_controller_spec.rb +++ b/spec/controllers/relationships_controller_spec.rb @@ -7,7 +7,7 @@ describe RelationshipsController do shared_examples 'authenticate user' do it 'redirects when not signed in' do - is_expected.to redirect_to '/auth/sign_in' + expect(subject).to redirect_to '/auth/sign_in' end end diff --git a/spec/controllers/settings/featured_tags_controller_spec.rb b/spec/controllers/settings/featured_tags_controller_spec.rb index 33b87f9f6..fc338672d 100644 --- a/spec/controllers/settings/featured_tags_controller_spec.rb +++ b/spec/controllers/settings/featured_tags_controller_spec.rb @@ -5,7 +5,7 @@ describe Settings::FeaturedTagsController do shared_examples 'authenticate user' do it 'redirects to sign_in page' do - is_expected.to redirect_to new_user_session_path + expect(subject).to redirect_to new_user_session_path end end diff --git a/spec/controllers/settings/migrations_controller_spec.rb b/spec/controllers/settings/migrations_controller_spec.rb index 4ce153c9d..8159bb21b 100644 --- a/spec/controllers/settings/migrations_controller_spec.rb +++ b/spec/controllers/settings/migrations_controller_spec.rb @@ -5,7 +5,7 @@ describe Settings::MigrationsController do shared_examples 'authenticate user' do it 'redirects to sign_in page' do - is_expected.to redirect_to new_user_session_path + expect(subject).to redirect_to new_user_session_path end end @@ -27,8 +27,8 @@ describe Settings::MigrationsController do let(:moved_to_account) { nil } it 'renders show page' do - is_expected.to have_http_status 200 - is_expected.to render_template :show + expect(subject).to have_http_status 200 + expect(subject).to render_template :show end end @@ -36,8 +36,8 @@ describe Settings::MigrationsController do let(:moved_to_account) { Fabricate(:account) } it 'renders show page' do - is_expected.to have_http_status 200 - is_expected.to render_template :show + expect(subject).to have_http_status 200 + expect(subject).to render_template :show end end end @@ -61,7 +61,7 @@ describe Settings::MigrationsController do let(:acct) { Fabricate(:account, also_known_as: [ActivityPub::TagManager.instance.uri_for(user.account)]) } it 'updates moved to account' do - is_expected.to redirect_to settings_migration_path + expect(subject).to redirect_to settings_migration_path expect(user.account.reload.moved_to_account_id).to eq acct.id end end @@ -70,7 +70,7 @@ describe Settings::MigrationsController do let(:acct) { user.account } it 'renders show' do - is_expected.to render_template :show + expect(subject).to render_template :show end it 'does not update the moved account' do @@ -82,7 +82,7 @@ describe Settings::MigrationsController do let(:acct) { Fabricate(:account, also_known_as: []) } it 'renders show' do - is_expected.to render_template :show + expect(subject).to render_template :show end it 'does not update the moved account' do @@ -99,7 +99,7 @@ describe Settings::MigrationsController do end it 'renders show' do - is_expected.to render_template :show + expect(subject).to render_template :show end it 'does not update the moved account' do diff --git a/spec/controllers/settings/sessions_controller_spec.rb b/spec/controllers/settings/sessions_controller_spec.rb index 59c18889e..fdf46d947 100644 --- a/spec/controllers/settings/sessions_controller_spec.rb +++ b/spec/controllers/settings/sessions_controller_spec.rb @@ -15,7 +15,7 @@ describe Settings::SessionsController do let(:id) { session_activation.id } it 'destroys session activation' do - is_expected.to redirect_to edit_user_registration_path + expect(subject).to redirect_to edit_user_registration_path expect(SessionActivation.find_by(id: id)).to be_nil end end @@ -24,7 +24,7 @@ describe Settings::SessionsController do let(:id) { session_activation.id + 1000 } it 'destroys session activation' do - is_expected.to have_http_status 404 + expect(subject).to have_http_status 404 end end end diff --git a/spec/features/log_in_spec.rb b/spec/features/log_in_spec.rb index 5ae738ee2..934575ea6 100644 --- a/spec/features/log_in_spec.rb +++ b/spec/features/log_in_spec.rb @@ -21,7 +21,7 @@ describe 'Log in' do fill_in 'user_password', with: password click_on I18n.t('auth.login') - is_expected.to have_css('div.app-holder') + expect(subject).to have_css('div.app-holder') end it 'A invalid email and password user is not able to log in' do @@ -29,7 +29,7 @@ describe 'Log in' do fill_in 'user_password', with: 'invalid_password' click_on I18n.t('auth.login') - is_expected.to have_css('.flash-message', text: failure_message('invalid')) + expect(subject).to have_css('.flash-message', text: failure_message('invalid')) end context do @@ -40,7 +40,7 @@ describe 'Log in' do fill_in 'user_password', with: password click_on I18n.t('auth.login') - is_expected.to have_css('div.admin-wrapper') + expect(subject).to have_css('div.admin-wrapper') end end diff --git a/spec/features/profile_spec.rb b/spec/features/profile_spec.rb index d1c6919c1..421b68a16 100644 --- a/spec/features/profile_spec.rb +++ b/spec/features/profile_spec.rb @@ -17,7 +17,7 @@ describe 'Profile' do it 'I can view Annes public account' do visit account_path('alice') - is_expected.to have_title("alice (@alice@#{local_domain})") + expect(subject).to have_title("alice (@alice@#{local_domain})") end it 'I can change my account' do @@ -28,6 +28,6 @@ describe 'Profile' do first('button[type=submit]').click - is_expected.to have_content 'Changes successfully saved!' + expect(subject).to have_content 'Changes successfully saved!' end end diff --git a/spec/lib/emoji_formatter_spec.rb b/spec/lib/emoji_formatter_spec.rb index e1747bdd9..c6fe8cf37 100644 --- a/spec/lib/emoji_formatter_spec.rb +++ b/spec/lib/emoji_formatter_spec.rb @@ -24,7 +24,7 @@ RSpec.describe EmojiFormatter do let(:text) { preformat_text(':coolcat: Beep boop') } it 'converts the shortcode to an image tag' do - is_expected.to match(/:coolcat:Foo bar

' + expect(subject).to eq '

Foo bar

' end end @@ -20,7 +20,7 @@ RSpec.describe HtmlAwareFormatter do let(:text) { 'Beep boop' } it 'keeps the plain text' do - is_expected.to include 'Beep boop' + expect(subject).to include 'Beep boop' end end @@ -28,7 +28,7 @@ RSpec.describe HtmlAwareFormatter do let(:text) { '' } it 'strips the scripts' do - is_expected.to_not include '' + expect(subject).to_not include '' end end @@ -36,7 +36,7 @@ RSpec.describe HtmlAwareFormatter do let(:text) { 'Show more' } it 'strips the malicious classes' do - is_expected.to_not include 'status__content__spoiler-link' + expect(subject).to_not include 'status__content__spoiler-link' end end end diff --git a/spec/lib/ostatus/tag_manager_spec.rb b/spec/lib/ostatus/tag_manager_spec.rb index 31195bae2..65ba7577a 100644 --- a/spec/lib/ostatus/tag_manager_spec.rb +++ b/spec/lib/ostatus/tag_manager_spec.rb @@ -45,7 +45,7 @@ describe OStatus::TagManager do it 'returns the unique tag for status' do expect(target.object_type).to eq :comment - is_expected.to eq target.uri + expect(subject).to eq target.uri end end @@ -54,7 +54,7 @@ describe OStatus::TagManager do it 'returns the unique tag for status' do expect(target.object_type).to eq :note - is_expected.to eq target.uri + expect(subject).to eq target.uri end end @@ -63,7 +63,7 @@ describe OStatus::TagManager do it 'returns the URL for account' do expect(target.object_type).to eq :person - is_expected.to eq 'https://cb6e6126.ngrok.io/users/alice' + expect(subject).to eq 'https://cb6e6126.ngrok.io/users/alice' end end end diff --git a/spec/lib/plain_text_formatter_spec.rb b/spec/lib/plain_text_formatter_spec.rb index c3d0ee630..0e5f39031 100644 --- a/spec/lib/plain_text_formatter_spec.rb +++ b/spec/lib/plain_text_formatter_spec.rb @@ -8,7 +8,7 @@ RSpec.describe PlainTextFormatter do let(:status) { Fabricate(:status, text: '

a text by a nerd who uses an HTML tag in text

', uri: nil) } it 'returns the raw text' do - is_expected.to eq '

a text by a nerd who uses an HTML tag in text

' + expect(subject).to eq '

a text by a nerd who uses an HTML tag in text

' end end @@ -17,7 +17,7 @@ RSpec.describe PlainTextFormatter do let(:status) { Fabricate(:status, account: remote_account, text: '

Hello

') } it 'returns tag-stripped text' do - is_expected.to eq 'Hello' + expect(subject).to eq 'Hello' end end end diff --git a/spec/lib/text_formatter_spec.rb b/spec/lib/text_formatter_spec.rb index cc742b65e..63a9075c7 100644 --- a/spec/lib/text_formatter_spec.rb +++ b/spec/lib/text_formatter_spec.rb @@ -10,7 +10,7 @@ RSpec.describe TextFormatter do let(:text) { 'text' } it 'paragraphizes the text' do - is_expected.to eq '

text

' + expect(subject).to eq '

text

' end end @@ -18,7 +18,7 @@ RSpec.describe TextFormatter do let(:text) { "line\nfeed" } it 'removes line feeds' do - is_expected.to_not include "\n" + expect(subject).to_not include "\n" end end @@ -27,7 +27,7 @@ RSpec.describe TextFormatter do let(:text) { '@alice' } it 'creates a mention link' do - is_expected.to include '@alice' + expect(subject).to include '@alice' end end @@ -36,7 +36,7 @@ RSpec.describe TextFormatter do let(:text) { '@alice' } it 'does not create a mention link' do - is_expected.to include '@alice' + expect(subject).to include '@alice' end end @@ -44,7 +44,7 @@ RSpec.describe TextFormatter do let(:text) { 'https://hackernoon.com/the-power-to-build-communities-a-response-to-mark-zuckerberg-3f2cac9148a4' } it 'matches the full URL' do - is_expected.to include 'href="https://hackernoon.com/the-power-to-build-communities-a-response-to-mark-zuckerberg-3f2cac9148a4"' + expect(subject).to include 'href="https://hackernoon.com/the-power-to-build-communities-a-response-to-mark-zuckerberg-3f2cac9148a4"' end end @@ -52,7 +52,7 @@ RSpec.describe TextFormatter do let(:text) { 'http://google.com' } it 'matches the full URL' do - is_expected.to include 'href="http://google.com"' + expect(subject).to include 'href="http://google.com"' end end @@ -60,7 +60,7 @@ RSpec.describe TextFormatter do let(:text) { 'http://example.gay' } it 'matches the full URL' do - is_expected.to include 'href="http://example.gay"' + expect(subject).to include 'href="http://example.gay"' end end @@ -68,11 +68,11 @@ RSpec.describe TextFormatter do let(:text) { 'https://nic.みんな/' } it 'matches the full URL' do - is_expected.to include 'href="https://nic.みんな/"' + expect(subject).to include 'href="https://nic.みんな/"' end it 'has display URL' do - is_expected.to include 'nic.みんな/' + expect(subject).to include 'nic.みんな/' end end @@ -80,7 +80,7 @@ RSpec.describe TextFormatter do let(:text) { 'http://www.mcmansionhell.com/post/156408871451/50-states-of-mcmansion-hell-scottsdale-arizona. ' } it 'matches the full URL but not the period' do - is_expected.to include 'href="http://www.mcmansionhell.com/post/156408871451/50-states-of-mcmansion-hell-scottsdale-arizona"' + expect(subject).to include 'href="http://www.mcmansionhell.com/post/156408871451/50-states-of-mcmansion-hell-scottsdale-arizona"' end end @@ -88,7 +88,7 @@ RSpec.describe TextFormatter do let(:text) { '(http://google.com/)' } it 'matches the full URL but not the parentheses' do - is_expected.to include 'href="http://google.com/"' + expect(subject).to include 'href="http://google.com/"' end end @@ -96,7 +96,7 @@ RSpec.describe TextFormatter do let(:text) { 'http://www.google.com!' } it 'matches the full URL but not the exclamation point' do - is_expected.to include 'href="http://www.google.com"' + expect(subject).to include 'href="http://www.google.com"' end end @@ -104,7 +104,7 @@ RSpec.describe TextFormatter do let(:text) { "http://www.google.com'" } it 'matches the full URL but not the single quote' do - is_expected.to include 'href="http://www.google.com"' + expect(subject).to include 'href="http://www.google.com"' end end @@ -112,7 +112,7 @@ RSpec.describe TextFormatter do let(:text) { 'http://www.google.com>' } it 'matches the full URL but not the angle bracket' do - is_expected.to include 'href="http://www.google.com"' + expect(subject).to include 'href="http://www.google.com"' end end @@ -121,7 +121,7 @@ RSpec.describe TextFormatter do let(:text) { 'https://www.ruby-toolbox.com/search?utf8=%E2%9C%93&q=autolink' } it 'matches the full URL' do - is_expected.to include 'href="https://www.ruby-toolbox.com/search?utf8=%E2%9C%93&q=autolink"' + expect(subject).to include 'href="https://www.ruby-toolbox.com/search?utf8=%E2%9C%93&q=autolink"' end end @@ -129,7 +129,7 @@ RSpec.describe TextFormatter do let(:text) { 'https://www.ruby-toolbox.com/search?utf8=✓&q=autolink' } it 'matches the full URL' do - is_expected.to include 'href="https://www.ruby-toolbox.com/search?utf8=✓&q=autolink"' + expect(subject).to include 'href="https://www.ruby-toolbox.com/search?utf8=✓&q=autolink"' end end @@ -137,7 +137,7 @@ RSpec.describe TextFormatter do let(:text) { 'https://www.ruby-toolbox.com/search?utf8=✓' } it 'matches the full URL' do - is_expected.to include 'href="https://www.ruby-toolbox.com/search?utf8=✓"' + expect(subject).to include 'href="https://www.ruby-toolbox.com/search?utf8=✓"' end end @@ -145,7 +145,7 @@ RSpec.describe TextFormatter do let(:text) { 'https://www.ruby-toolbox.com/search?utf8=%E2%9C%93&utf81=✓&q=autolink' } it 'preserves escaped unicode characters' do - is_expected.to include 'href="https://www.ruby-toolbox.com/search?utf8=%E2%9C%93&utf81=✓&q=autolink"' + expect(subject).to include 'href="https://www.ruby-toolbox.com/search?utf8=%E2%9C%93&utf81=✓&q=autolink"' end end end @@ -154,7 +154,7 @@ RSpec.describe TextFormatter do let(:text) { 'https://en.wikipedia.org/wiki/Diaspora_(software)' } it 'matches the full URL' do - is_expected.to include 'href="https://en.wikipedia.org/wiki/Diaspora_(software)"' + expect(subject).to include 'href="https://en.wikipedia.org/wiki/Diaspora_(software)"' end end @@ -162,7 +162,7 @@ RSpec.describe TextFormatter do let(:text) { '"https://example.com/"' } it 'does not match the quotation marks' do - is_expected.to include 'href="https://example.com/"' + expect(subject).to include 'href="https://example.com/"' end end @@ -170,7 +170,7 @@ RSpec.describe TextFormatter do let(:text) { '' } it 'does not match the angle brackets' do - is_expected.to include 'href="https://example.com/"' + expect(subject).to include 'href="https://example.com/"' end end @@ -178,7 +178,7 @@ RSpec.describe TextFormatter do let(:text) { 'https://ja.wikipedia.org/wiki/日本' } it 'matches the full URL' do - is_expected.to include 'href="https://ja.wikipedia.org/wiki/日本"' + expect(subject).to include 'href="https://ja.wikipedia.org/wiki/日本"' end end @@ -186,7 +186,7 @@ RSpec.describe TextFormatter do let(:text) { 'https://ko.wikipedia.org/wiki/대한민국' } it 'matches the full URL' do - is_expected.to include 'href="https://ko.wikipedia.org/wiki/대한민국"' + expect(subject).to include 'href="https://ko.wikipedia.org/wiki/대한민국"' end end @@ -194,7 +194,7 @@ RSpec.describe TextFormatter do let(:text) { 'https://example.com/ abc123' } it 'does not match the full-width space' do - is_expected.to include 'href="https://example.com/"' + expect(subject).to include 'href="https://example.com/"' end end @@ -202,7 +202,7 @@ RSpec.describe TextFormatter do let(:text) { '「[https://example.org/」' } it 'does not match the quotation marks' do - is_expected.to include 'href="https://example.org/"' + expect(subject).to include 'href="https://example.org/"' end end @@ -210,7 +210,7 @@ RSpec.describe TextFormatter do let(:text) { 'https://baike.baidu.com/item/中华人民共和国' } it 'matches the full URL' do - is_expected.to include 'href="https://baike.baidu.com/item/中华人民共和国"' + expect(subject).to include 'href="https://baike.baidu.com/item/中华人民共和国"' end end @@ -218,7 +218,7 @@ RSpec.describe TextFormatter do let(:text) { 'https://zh.wikipedia.org/wiki/臺灣' } it 'matches the full URL' do - is_expected.to include 'href="https://zh.wikipedia.org/wiki/臺灣"' + expect(subject).to include 'href="https://zh.wikipedia.org/wiki/臺灣"' end end @@ -226,11 +226,11 @@ RSpec.describe TextFormatter do let(:text) { 'http://example.com/bb' } it 'does not include the HTML in the URL' do - is_expected.to include '"http://example.com/b"' + expect(subject).to include '"http://example.com/b"' end it 'escapes the HTML' do - is_expected.to include '<del>b</del>' + expect(subject).to include '<del>b</del>' end end @@ -238,11 +238,11 @@ RSpec.describe TextFormatter do let(:text) { 'http://example.com/blahblahblahblah/a' } it 'does not include the HTML in the URL' do - is_expected.to include '"http://example.com/blahblahblahblah/a"' + expect(subject).to include '"http://example.com/blahblahblahblah/a"' end it 'escapes the HTML' do - is_expected.to include '<script>alert("Hello")</script>' + expect(subject).to include '<script>alert("Hello")</script>' end end @@ -250,7 +250,7 @@ RSpec.describe TextFormatter do let(:text) { '' } it 'escapes the HTML' do - is_expected.to include '

<script>alert("Hello")</script>

' + expect(subject).to include '

<script>alert("Hello")</script>

' end end @@ -258,7 +258,7 @@ RSpec.describe TextFormatter do let(:text) { %q{} } it 'escapes the HTML' do - is_expected.to include '

<img src="javascript:alert('XSS');">

' + expect(subject).to include '

<img src="javascript:alert('XSS');">

' end end @@ -266,7 +266,7 @@ RSpec.describe TextFormatter do let(:text) { 'http://www\.google\.com' } it 'outputs the raw URL' do - is_expected.to eq '

http://www\.google\.com

' + expect(subject).to eq '

http://www\.google\.com

' end end @@ -274,7 +274,7 @@ RSpec.describe TextFormatter do let(:text) { '#hashtag' } it 'creates a hashtag link' do - is_expected.to include '/tags/hashtag" class="mention hashtag" rel="tag">#hashtag' + expect(subject).to include '/tags/hashtag" class="mention hashtag" rel="tag">#hashtag' end end @@ -282,7 +282,7 @@ RSpec.describe TextFormatter do let(:text) { '#hashtagタグ' } it 'creates a hashtag link' do - is_expected.to include '/tags/hashtag%E3%82%BF%E3%82%B0" class="mention hashtag" rel="tag">#hashtagタグ' + expect(subject).to include '/tags/hashtag%E3%82%BF%E3%82%B0" class="mention hashtag" rel="tag">#hashtagタグ' end end @@ -290,7 +290,7 @@ RSpec.describe TextFormatter do let(:text) { 'xmpp:user@instance.com' } it 'matches the full URI' do - is_expected.to include 'href="xmpp:user@instance.com"' + expect(subject).to include 'href="xmpp:user@instance.com"' end end @@ -298,7 +298,7 @@ RSpec.describe TextFormatter do let(:text) { 'please join xmpp:muc@instance.com?join right now' } it 'matches the full URI' do - is_expected.to include 'href="xmpp:muc@instance.com?join"' + expect(subject).to include 'href="xmpp:muc@instance.com?join"' end end @@ -306,7 +306,7 @@ RSpec.describe TextFormatter do let(:text) { 'wikipedia gives this example of a magnet uri: magnet:?xt=urn:btih:c12fe1c06bba254a9dc9f519b335aa7c1367a88a' } it 'matches the full URI' do - is_expected.to include 'href="magnet:?xt=urn:btih:c12fe1c06bba254a9dc9f519b335aa7c1367a88a"' + expect(subject).to include 'href="magnet:?xt=urn:btih:c12fe1c06bba254a9dc9f519b335aa7c1367a88a"' end end end diff --git a/spec/models/concerns/account_interactions_spec.rb b/spec/models/concerns/account_interactions_spec.rb index b2d84308b..fbfc9fbbc 100644 --- a/spec/models/concerns/account_interactions_spec.rb +++ b/spec/models/concerns/account_interactions_spec.rb @@ -14,13 +14,13 @@ describe AccountInteractions do context 'account with Follow' do it 'returns { target_account_id => true }' do Fabricate(:follow, account: account, target_account: target_account) - is_expected.to eq(target_account_id => { reblogs: true, notify: false, languages: nil }) + expect(subject).to eq(target_account_id => { reblogs: true, notify: false, languages: nil }) end end context 'account without Follow' do it 'returns {}' do - is_expected.to eq({}) + expect(subject).to eq({}) end end end @@ -31,13 +31,13 @@ describe AccountInteractions do context 'account with Follow' do it 'returns { target_account_id => true }' do Fabricate(:follow, account: target_account, target_account: account) - is_expected.to eq(target_account_id => true) + expect(subject).to eq(target_account_id => true) end end context 'account without Follow' do it 'returns {}' do - is_expected.to eq({}) + expect(subject).to eq({}) end end end @@ -48,13 +48,13 @@ describe AccountInteractions do context 'account with Block' do it 'returns { target_account_id => true }' do Fabricate(:block, account: account, target_account: target_account) - is_expected.to eq(target_account_id => true) + expect(subject).to eq(target_account_id => true) end end context 'account without Block' do it 'returns {}' do - is_expected.to eq({}) + expect(subject).to eq({}) end end end @@ -71,7 +71,7 @@ describe AccountInteractions do let(:hide) { true } it 'returns { target_account_id => { notifications: true } }' do - is_expected.to eq(target_account_id => { notifications: true }) + expect(subject).to eq(target_account_id => { notifications: true }) end end @@ -79,14 +79,14 @@ describe AccountInteractions do let(:hide) { false } it 'returns { target_account_id => { notifications: false } }' do - is_expected.to eq(target_account_id => { notifications: false }) + expect(subject).to eq(target_account_id => { notifications: false }) end end end context 'account without Mute' do it 'returns {}' do - is_expected.to eq({}) + expect(subject).to eq({}) end end end @@ -231,7 +231,7 @@ describe AccountInteractions do it 'creates and returns ConversationMute' do expect do - is_expected.to be_a ConversationMute + expect(subject).to be_a ConversationMute end.to change { account.conversation_mutes.count }.by 1 end end @@ -243,7 +243,7 @@ describe AccountInteractions do it 'creates and returns AccountDomainBlock' do expect do - is_expected.to be_a AccountDomainBlock + expect(subject).to be_a AccountDomainBlock end.to change { account.domain_blocks.count }.by 1 end end @@ -254,14 +254,14 @@ describe AccountInteractions do context 'following target_account' do it 'returns destroyed Follow' do account.active_relationships.create(target_account: target_account) - is_expected.to be_a Follow + expect(subject).to be_a Follow expect(subject).to be_destroyed end end context 'not following target_account' do it 'returns nil' do - is_expected.to be_nil + expect(subject).to be_nil end end end @@ -272,14 +272,14 @@ describe AccountInteractions do context 'blocking target_account' do it 'returns destroyed Block' do account.block_relationships.create(target_account: target_account) - is_expected.to be_a Block + expect(subject).to be_a Block expect(subject).to be_destroyed end end context 'not blocking target_account' do it 'returns nil' do - is_expected.to be_nil + expect(subject).to be_nil end end end @@ -290,14 +290,14 @@ describe AccountInteractions do context 'muting target_account' do it 'returns destroyed Mute' do account.mute_relationships.create(target_account: target_account) - is_expected.to be_a Mute + expect(subject).to be_a Mute expect(subject).to be_destroyed end end context 'not muting target_account' do it 'returns nil' do - is_expected.to be_nil + expect(subject).to be_nil end end end @@ -310,14 +310,14 @@ describe AccountInteractions do context 'muting the conversation' do it 'returns destroyed ConversationMute' do account.conversation_mutes.create(conversation: conversation) - is_expected.to be_a ConversationMute + expect(subject).to be_a ConversationMute expect(subject).to be_destroyed end end context 'not muting the conversation' do it 'returns nil' do - is_expected.to be_nil + expect(subject).to be_nil end end end @@ -331,14 +331,14 @@ describe AccountInteractions do it 'returns destroyed AccountDomainBlock' do account_domain_block = Fabricate(:account_domain_block, domain: domain) account.domain_blocks << account_domain_block - is_expected.to be_a AccountDomainBlock + expect(subject).to be_a AccountDomainBlock expect(subject).to be_destroyed end end context 'unblocking the domain' do it 'returns nil' do - is_expected.to be_nil + expect(subject).to be_nil end end end @@ -349,13 +349,13 @@ describe AccountInteractions do context 'following target_account' do it 'returns true' do account.active_relationships.create(target_account: target_account) - is_expected.to be true + expect(subject).to be true end end context 'not following target_account' do it 'returns false' do - is_expected.to be false + expect(subject).to be false end end end @@ -366,13 +366,13 @@ describe AccountInteractions do context 'followed by target_account' do it 'returns true' do account.passive_relationships.create(account: target_account) - is_expected.to be true + expect(subject).to be true end end context 'not followed by target_account' do it 'returns false' do - is_expected.to be false + expect(subject).to be false end end end @@ -383,13 +383,13 @@ describe AccountInteractions do context 'blocking target_account' do it 'returns true' do account.block_relationships.create(target_account: target_account) - is_expected.to be true + expect(subject).to be true end end context 'not blocking target_account' do it 'returns false' do - is_expected.to be false + expect(subject).to be false end end end @@ -403,13 +403,13 @@ describe AccountInteractions do it 'returns true' do account_domain_block = Fabricate(:account_domain_block, domain: domain) account.domain_blocks << account_domain_block - is_expected.to be true + expect(subject).to be true end end context 'not blocking the domain' do it 'returns false' do - is_expected.to be false + expect(subject).to be false end end end @@ -421,13 +421,13 @@ describe AccountInteractions do it 'returns true' do mute = Fabricate(:mute, account: account, target_account: target_account) account.mute_relationships << mute - is_expected.to be true + expect(subject).to be true end end context 'not muting target_account' do it 'returns false' do - is_expected.to be false + expect(subject).to be false end end end @@ -440,13 +440,13 @@ describe AccountInteractions do context 'muting the conversation' do it 'returns true' do account.conversation_mutes.create(conversation: conversation) - is_expected.to be true + expect(subject).to be true end end context 'not muting the conversation' do it 'returns false' do - is_expected.to be false + expect(subject).to be false end end end @@ -463,7 +463,7 @@ describe AccountInteractions do let(:hide) { true } it 'returns true' do - is_expected.to be true + expect(subject).to be true end end @@ -471,7 +471,7 @@ describe AccountInteractions do let(:hide) { false } it 'returns false' do - is_expected.to be false + expect(subject).to be false end end end @@ -482,13 +482,13 @@ describe AccountInteractions do context 'requested by target_account' do it 'returns true' do Fabricate(:follow_request, account: account, target_account: target_account) - is_expected.to be true + expect(subject).to be true end end context 'not requested by target_account' do it 'returns false' do - is_expected.to be false + expect(subject).to be false end end end @@ -502,7 +502,7 @@ describe AccountInteractions do let(:favourites) { [Fabricate(:favourite, account: account)] } it 'returns true' do - is_expected.to be true + expect(subject).to be true end end @@ -510,7 +510,7 @@ describe AccountInteractions do let(:favourites) { [] } it 'returns false' do - is_expected.to be false + expect(subject).to be false end end end @@ -524,7 +524,7 @@ describe AccountInteractions do let(:reblogs) { [Fabricate(:status, account: account)] } it 'returns true' do - is_expected.to be true + expect(subject).to be true end end @@ -532,7 +532,7 @@ describe AccountInteractions do let(:reblogs) { [] } it 'returns false' do - is_expected.to be false + expect(subject).to be false end end end @@ -545,13 +545,13 @@ describe AccountInteractions do context 'pinned' do it 'returns true' do Fabricate(:status_pin, account: account, status: status) - is_expected.to be true + expect(subject).to be true end end context 'not pinned' do it 'returns false' do - is_expected.to be false + expect(subject).to be false end end end diff --git a/spec/models/custom_emoji_spec.rb b/spec/models/custom_emoji_spec.rb index f9e1099c6..1fc112db3 100644 --- a/spec/models/custom_emoji_spec.rb +++ b/spec/models/custom_emoji_spec.rb @@ -11,7 +11,7 @@ RSpec.describe CustomEmoji, type: :model do let(:search_term) { 'blobpats' } it 'finds emoji' do - is_expected.to include(custom_emoji) + expect(subject).to include(custom_emoji) end end @@ -20,7 +20,7 @@ RSpec.describe CustomEmoji, type: :model do let(:search_term) { 'blob' } it 'finds emoji' do - is_expected.to include(custom_emoji) + expect(subject).to include(custom_emoji) end end end @@ -34,7 +34,7 @@ RSpec.describe CustomEmoji, type: :model do let(:domain) { nil } it 'returns true' do - is_expected.to be true + expect(subject).to be true end end @@ -42,7 +42,7 @@ RSpec.describe CustomEmoji, type: :model do let(:domain) { 'example.com' } it 'returns false' do - is_expected.to be false + expect(subject).to be false end end end @@ -63,7 +63,7 @@ RSpec.describe CustomEmoji, type: :model do let(:text) { 'Hello :coolcat:' } it 'returns records used via shortcodes in text' do - is_expected.to include(emojo) + expect(subject).to include(emojo) end end @@ -71,7 +71,7 @@ RSpec.describe CustomEmoji, type: :model do let(:text) { '

Hello :coolcat:

' } it 'returns records used via shortcodes in text' do - is_expected.to include(emojo) + expect(subject).to include(emojo) end end end diff --git a/spec/models/media_attachment_spec.rb b/spec/models/media_attachment_spec.rb index d1a94d41a..8889d5f7c 100644 --- a/spec/models/media_attachment_spec.rb +++ b/spec/models/media_attachment_spec.rb @@ -10,7 +10,7 @@ RSpec.describe MediaAttachment, type: :model do let(:remote_url) { '' } it 'returns true' do - is_expected.to be true + expect(subject).to be true end end @@ -18,7 +18,7 @@ RSpec.describe MediaAttachment, type: :model do let(:remote_url) { 'remote_url' } it 'returns false' do - is_expected.to be false + expect(subject).to be false end end end @@ -35,7 +35,7 @@ RSpec.describe MediaAttachment, type: :model do let(:remote_url) { 'remote_url' } it 'returns true' do - is_expected.to be true + expect(subject).to be true end end end @@ -47,7 +47,7 @@ RSpec.describe MediaAttachment, type: :model do let(:remote_url) { '' } it 'returns false' do - is_expected.to be false + expect(subject).to be false end end @@ -55,7 +55,7 @@ RSpec.describe MediaAttachment, type: :model do let(:remote_url) { 'remote_url' } it 'returns true' do - is_expected.to be false + expect(subject).to be false end end end diff --git a/spec/models/notification_spec.rb b/spec/models/notification_spec.rb index 1e9e45d8d..a8fb77639 100644 --- a/spec/models/notification_spec.rb +++ b/spec/models/notification_spec.rb @@ -68,7 +68,7 @@ RSpec.describe Notification, type: :model do let(:notifications) { [] } it 'returns []' do - is_expected.to eq [] + expect(subject).to eq [] end end diff --git a/spec/models/remote_follow_spec.rb b/spec/models/remote_follow_spec.rb index 5b4c19b5b..c6bbecf25 100644 --- a/spec/models/remote_follow_spec.rb +++ b/spec/models/remote_follow_spec.rb @@ -17,7 +17,7 @@ RSpec.describe RemoteFollow do let(:attrs) { { acct: 'gargron@quitter.no' } } it 'returns acct' do - is_expected.to eq 'gargron@quitter.no' + expect(subject).to eq 'gargron@quitter.no' end end @@ -25,7 +25,7 @@ RSpec.describe RemoteFollow do let(:attrs) { {} } it do - is_expected.to be_nil + expect(subject).to be_nil end end end @@ -37,7 +37,7 @@ RSpec.describe RemoteFollow do let(:attrs) { { acct: 'gargron@quitter.no' } } it do - is_expected.to be true + expect(subject).to be true end end @@ -45,7 +45,7 @@ RSpec.describe RemoteFollow do let(:attrs) { {} } it do - is_expected.to be false + expect(subject).to be false end end end @@ -61,7 +61,7 @@ RSpec.describe RemoteFollow do subject { remote_follow.subscribe_address_for(account) } it 'returns subscribe address' do - is_expected.to eq 'https://quitter.no/main/ostatussub?profile=https%3A%2F%2Fcb6e6126.ngrok.io%2Fusers%2Falice' + expect(subject).to eq 'https://quitter.no/main/ostatussub?profile=https%3A%2F%2Fcb6e6126.ngrok.io%2Fusers%2Falice' end end end diff --git a/spec/models/report_spec.rb b/spec/models/report_spec.rb index 874be4132..317851297 100644 --- a/spec/models/report_spec.rb +++ b/spec/models/report_spec.rb @@ -33,7 +33,7 @@ describe Report do end it 'assigns to a given account' do - is_expected.to eq current_account.id + expect(subject).to eq current_account.id end end @@ -48,7 +48,7 @@ describe Report do end it 'unassigns' do - is_expected.to be_nil + expect(subject).to be_nil end end diff --git a/spec/models/session_activation_spec.rb b/spec/models/session_activation_spec.rb index 26f2b561a..375199d57 100644 --- a/spec/models/session_activation_spec.rb +++ b/spec/models/session_activation_spec.rb @@ -44,7 +44,7 @@ RSpec.describe SessionActivation, type: :model do let(:id) { nil } it 'returns nil' do - is_expected.to be_nil + expect(subject).to be_nil end end @@ -54,7 +54,7 @@ RSpec.describe SessionActivation, type: :model do context 'id exists as session_id' do it 'returns true' do - is_expected.to be true + expect(subject).to be true end end @@ -64,7 +64,7 @@ RSpec.describe SessionActivation, type: :model do end it 'returns false' do - is_expected.to be false + expect(subject).to be false end end end diff --git a/spec/models/setting_spec.rb b/spec/models/setting_spec.rb index 077223094..86fdf4e08 100644 --- a/spec/models/setting_spec.rb +++ b/spec/models/setting_spec.rb @@ -173,7 +173,7 @@ RSpec.describe Setting, type: :model do let(:enabled) { false } it 'returns {}' do - is_expected.to eq({}) + expect(subject).to eq({}) end end @@ -181,7 +181,7 @@ RSpec.describe Setting, type: :model do let(:enabled) { true } it 'returns instance of RailsSettings::Default' do - is_expected.to be_a RailsSettings::Default + expect(subject).to be_a RailsSettings::Default end end end -- cgit From 5a8c651e8f0252c7135042e79396f782361302d9 Mon Sep 17 00:00:00 2001 From: Christian Schmidt Date: Fri, 3 Mar 2023 21:06:31 +0100 Subject: Only offer translation for supported languages (#23879) --- .rubocop.yml | 4 + .../mastodon/components/status_content.jsx | 4 +- app/javascript/mastodon/initial_state.js | 2 - app/lib/translation_service.rb | 4 + app/lib/translation_service/deepl.rb | 46 +++++++--- app/lib/translation_service/libre_translate.rb | 38 +++++--- app/models/status.rb | 10 +++ app/serializers/initial_state_serializer.rb | 1 - app/serializers/rest/status_serializer.rb | 6 +- app/services/translate_status_service.rb | 2 +- spec/lib/translation_service/deepl_spec.rb | 100 +++++++++++++++++++++ .../translation_service/libre_translate_spec.rb | 71 +++++++++++++++ spec/models/status_spec.rb | 79 ++++++++++++++++ 13 files changed, 336 insertions(+), 31 deletions(-) create mode 100644 spec/lib/translation_service/deepl_spec.rb create mode 100644 spec/lib/translation_service/libre_translate_spec.rb (limited to 'app/serializers/initial_state_serializer.rb') diff --git a/.rubocop.yml b/.rubocop.yml index 27d778edf..0a41c54b9 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -97,6 +97,10 @@ Rails/Exit: - 'lib/mastodon/cli_helper.rb' - 'lib/cli.rb' +RSpec/FilePath: + CustomTransform: + DeepL: deepl + RSpec/NotToNot: EnforcedStyle: to_not diff --git a/app/javascript/mastodon/components/status_content.jsx b/app/javascript/mastodon/components/status_content.jsx index a1c38171f..f9c9fe079 100644 --- a/app/javascript/mastodon/components/status_content.jsx +++ b/app/javascript/mastodon/components/status_content.jsx @@ -6,7 +6,7 @@ import { Link } from 'react-router-dom'; import classnames from 'classnames'; import PollContainer from 'mastodon/containers/poll_container'; import Icon from 'mastodon/components/icon'; -import { autoPlayGif, languages as preloadedLanguages, translationEnabled } from 'mastodon/initial_state'; +import { autoPlayGif, languages as preloadedLanguages } from 'mastodon/initial_state'; const MAX_HEIGHT = 706; // 22px * 32 (+ 2px padding at the top) @@ -220,7 +220,7 @@ class StatusContent extends React.PureComponent { const hidden = this.props.onExpandedToggle ? !this.props.expanded : this.state.hidden; const renderReadMore = this.props.onClick && status.get('collapsed'); - const renderTranslate = translationEnabled && this.context.identity.signedIn && this.props.onTranslate && ['public', 'unlisted'].includes(status.get('visibility')) && status.get('contentHtml').length > 0 && status.get('language') !== null && intl.locale !== status.get('language'); + const renderTranslate = this.props.onTranslate && status.get('translatable'); const content = { __html: status.get('translation') ? status.getIn(['translation', 'content']) : status.get('contentHtml') }; const spoilerContent = { __html: status.get('spoilerHtml') }; diff --git a/app/javascript/mastodon/initial_state.js b/app/javascript/mastodon/initial_state.js index d04c4a42d..919e0fc28 100644 --- a/app/javascript/mastodon/initial_state.js +++ b/app/javascript/mastodon/initial_state.js @@ -80,7 +80,6 @@ * @property {boolean} use_blurhash * @property {boolean=} use_pending_items * @property {string} version - * @property {boolean} translation_enabled */ /** @@ -132,7 +131,6 @@ export const unfollowModal = getMeta('unfollow_modal'); export const useBlurhash = getMeta('use_blurhash'); export const usePendingItems = getMeta('use_pending_items'); export const version = getMeta('version'); -export const translationEnabled = getMeta('translation_enabled'); export const languages = initialState?.languages; export const statusPageUrl = getMeta('status_page_url'); diff --git a/app/lib/translation_service.rb b/app/lib/translation_service.rb index 285f30939..5ff93674a 100644 --- a/app/lib/translation_service.rb +++ b/app/lib/translation_service.rb @@ -21,6 +21,10 @@ class TranslationService ENV['DEEPL_API_KEY'].present? || ENV['LIBRE_TRANSLATE_ENDPOINT'].present? end + def supported?(_source_language, _target_language) + false + end + def translate(_text, _source_language, _target_language) raise NotImplementedError end diff --git a/app/lib/translation_service/deepl.rb b/app/lib/translation_service/deepl.rb index 151d33d90..deff95a1d 100644 --- a/app/lib/translation_service/deepl.rb +++ b/app/lib/translation_service/deepl.rb @@ -11,33 +11,53 @@ class TranslationService::DeepL < TranslationService end def translate(text, source_language, target_language) - request(text, source_language, target_language).perform do |res| + form = { text: text, source_lang: source_language&.upcase, target_lang: target_language, tag_handling: 'html' } + request(:post, '/v2/translate', form: form) do |res| + transform_response(res.body_with_limit) + end + end + + def supported?(source_language, target_language) + source_language.in?(languages('source')) && target_language.in?(languages('target')) + end + + private + + def languages(type) + Rails.cache.fetch("translation_service/deepl/languages/#{type}", expires_in: 7.days, race_condition_ttl: 1.minute) do + request(:get, "/v2/languages?type=#{type}") do |res| + # In DeepL, EN and PT are deprecated in favor of EN-GB/EN-US and PT-BR/PT-PT, so + # they are supported but not returned by the API. + extra = type == 'source' ? [nil] : %w(en pt) + languages = Oj.load(res.body_with_limit).map { |language| language['language'].downcase } + + languages + extra + end + end + end + + def request(verb, path, **options) + req = Request.new(verb, "#{base_url}#{path}", **options) + req.add_headers(Authorization: "DeepL-Auth-Key #{@api_key}") + req.perform do |res| case res.code when 429 raise TooManyRequestsError when 456 raise QuotaExceededError when 200...300 - transform_response(res.body_with_limit) + yield res else raise UnexpectedResponseError end end end - private - - def request(text, source_language, target_language) - req = Request.new(:post, endpoint_url, form: { text: text, source_lang: source_language&.upcase, target_lang: target_language, tag_handling: 'html' }) - req.add_headers(Authorization: "DeepL-Auth-Key #{@api_key}") - req - end - - def endpoint_url + def base_url if @plan == 'free' - 'https://api-free.deepl.com/v2/translate' + 'https://api-free.deepl.com' else - 'https://api.deepl.com/v2/translate' + 'https://api.deepl.com' end end diff --git a/app/lib/translation_service/libre_translate.rb b/app/lib/translation_service/libre_translate.rb index 4ebe21e45..743e4d77f 100644 --- a/app/lib/translation_service/libre_translate.rb +++ b/app/lib/translation_service/libre_translate.rb @@ -9,29 +9,45 @@ class TranslationService::LibreTranslate < TranslationService end def translate(text, source_language, target_language) - request(text, source_language, target_language).perform do |res| + body = Oj.dump(q: text, source: source_language.presence || 'auto', target: target_language, format: 'html', api_key: @api_key) + request(:post, '/translate', body: body) do |res| + transform_response(res.body_with_limit, source_language) + end + end + + def supported?(source_language, target_language) + languages.key?(source_language) && languages[source_language].include?(target_language) + end + + private + + def languages + Rails.cache.fetch('translation_service/libre_translate/languages', expires_in: 7.days, race_condition_ttl: 1.minute) do + request(:get, '/languages') do |res| + languages = Oj.load(res.body_with_limit).to_h { |language| [language['code'], language['targets']] } + languages[nil] = languages.values.flatten.uniq + languages + end + end + end + + def request(verb, path, **options) + req = Request.new(verb, "#{@base_url}#{path}", allow_local: true, **options) + req.add_headers('Content-Type': 'application/json') + req.perform do |res| case res.code when 429 raise TooManyRequestsError when 403 raise QuotaExceededError when 200...300 - transform_response(res.body_with_limit, source_language) + yield res else raise UnexpectedResponseError end end end - private - - def request(text, source_language, target_language) - body = Oj.dump(q: text, source: source_language.presence || 'auto', target: target_language, format: 'html', api_key: @api_key) - req = Request.new(:post, "#{@base_url}/translate", body: body, allow_local: true) - req.add_headers('Content-Type': 'application/json') - req - end - def transform_response(str, source_language) json = Oj.load(str, mode: :strict) diff --git a/app/models/status.rb b/app/models/status.rb index e7ea191a8..dd7ac2edb 100644 --- a/app/models/status.rb +++ b/app/models/status.rb @@ -232,6 +232,16 @@ class Status < ApplicationRecord public_visibility? || unlisted_visibility? end + def translatable? + translate_target_locale = I18n.locale.to_s.split(/[_-]/).first + + distributable? && + content.present? && + language != translate_target_locale && + TranslationService.configured? && + TranslationService.configured.supported?(language, translate_target_locale) + end + alias sign? distributable? def with_media? diff --git a/app/serializers/initial_state_serializer.rb b/app/serializers/initial_state_serializer.rb index 7905444e9..769ba653e 100644 --- a/app/serializers/initial_state_serializer.rb +++ b/app/serializers/initial_state_serializer.rb @@ -30,7 +30,6 @@ class InitialStateSerializer < ActiveModel::Serializer timeline_preview: Setting.timeline_preview, activity_api_enabled: Setting.activity_api_enabled, single_user_mode: Rails.configuration.x.single_user_mode, - translation_enabled: TranslationService.configured?, trends_as_landing_page: Setting.trends_as_landing_page, status_page_url: Setting.status_page_url, } diff --git a/app/serializers/rest/status_serializer.rb b/app/serializers/rest/status_serializer.rb index e0b8f32a6..a422f5b25 100644 --- a/app/serializers/rest/status_serializer.rb +++ b/app/serializers/rest/status_serializer.rb @@ -4,7 +4,7 @@ class REST::StatusSerializer < ActiveModel::Serializer include FormattingHelper attributes :id, :created_at, :in_reply_to_id, :in_reply_to_account_id, - :sensitive, :spoiler_text, :visibility, :language, + :sensitive, :spoiler_text, :visibility, :language, :translatable, :uri, :url, :replies_count, :reblogs_count, :favourites_count, :edited_at @@ -50,6 +50,10 @@ class REST::StatusSerializer < ActiveModel::Serializer object.account.user_shows_application? || (current_user? && current_user.account_id == object.account_id) end + def translatable + current_user? && object.translatable? + end + def visibility # This visibility is masked behind "private" # to avoid API changes because there are no diff --git a/app/services/translate_status_service.rb b/app/services/translate_status_service.rb index 539a0d9db..92d8b62a0 100644 --- a/app/services/translate_status_service.rb +++ b/app/services/translate_status_service.rb @@ -6,7 +6,7 @@ class TranslateStatusService < BaseService include FormattingHelper def call(status, target_language) - raise Mastodon::NotPermittedError unless status.public_visibility? || status.unlisted_visibility? + raise Mastodon::NotPermittedError unless status.translatable? @status = status @content = status_content_format(@status) diff --git a/spec/lib/translation_service/deepl_spec.rb b/spec/lib/translation_service/deepl_spec.rb new file mode 100644 index 000000000..aa2473186 --- /dev/null +++ b/spec/lib/translation_service/deepl_spec.rb @@ -0,0 +1,100 @@ +# frozen_string_literal: true + +require 'rails_helper' + +RSpec.describe TranslationService::DeepL do + subject(:service) { described_class.new(plan, 'my-api-key') } + + let(:plan) { 'advanced' } + + before do + stub_request(:get, 'https://api.deepl.com/v2/languages?type=source').to_return( + body: '[{"language":"EN","name":"English"},{"language":"UK","name":"Ukrainian"}]' + ) + stub_request(:get, 'https://api.deepl.com/v2/languages?type=target').to_return( + body: '[{"language":"EN-GB","name":"English (British)"},{"language":"ZH","name":"Chinese"}]' + ) + end + + describe '#supported?' do + it 'supports included languages as source and target languages' do + expect(service.supported?('uk', 'en')).to be true + end + + it 'supports auto-detecting source language' do + expect(service.supported?(nil, 'en')).to be true + end + + it 'supports "en" and "pt" as target languages though not included in language list' do + expect(service.supported?('uk', 'en')).to be true + expect(service.supported?('uk', 'pt')).to be true + end + + it 'does not support non-included language as target language' do + expect(service.supported?('uk', 'nl')).to be false + end + + it 'does not support non-included language as source language' do + expect(service.supported?('da', 'en')).to be false + end + end + + describe '#translate' do + it 'returns translation with specified source language' do + stub_request(:post, 'https://api.deepl.com/v2/translate') + .with(body: 'text=Hasta+la+vista&source_lang=ES&target_lang=en&tag_handling=html') + .to_return(body: '{"translations":[{"detected_source_language":"ES","text":"See you soon"}]}') + + translation = service.translate('Hasta la vista', 'es', 'en') + expect(translation.detected_source_language).to eq 'es' + expect(translation.provider).to eq 'DeepL.com' + expect(translation.text).to eq 'See you soon' + end + + it 'returns translation with auto-detected source language' do + stub_request(:post, 'https://api.deepl.com/v2/translate') + .with(body: 'text=Guten+Tag&source_lang&target_lang=en&tag_handling=html') + .to_return(body: '{"translations":[{"detected_source_language":"DE","text":"Good Morning"}]}') + + translation = service.translate('Guten Tag', nil, 'en') + expect(translation.detected_source_language).to eq 'de' + expect(translation.provider).to eq 'DeepL.com' + expect(translation.text).to eq 'Good Morning' + end + end + + describe '#languages?' do + it 'returns source languages' do + expect(service.send(:languages, 'source')).to eq ['en', 'uk', nil] + end + + it 'returns target languages' do + expect(service.send(:languages, 'target')).to eq %w(en-gb zh en pt) + end + end + + describe '#request' do + before do + stub_request(:any, //) + # rubocop:disable Lint/EmptyBlock + service.send(:request, :get, '/v2/languages') { |res| } + # rubocop:enable Lint/EmptyBlock + end + + it 'uses paid plan base URL' do + expect(a_request(:get, 'https://api.deepl.com/v2/languages')).to have_been_made.once + end + + context 'with free plan' do + let(:plan) { 'free' } + + it 'uses free plan base URL' do + expect(a_request(:get, 'https://api-free.deepl.com/v2/languages')).to have_been_made.once + end + end + + it 'sends API key' do + expect(a_request(:get, 'https://api.deepl.com/v2/languages').with(headers: { Authorization: 'DeepL-Auth-Key my-api-key' })).to have_been_made.once + end + end +end diff --git a/spec/lib/translation_service/libre_translate_spec.rb b/spec/lib/translation_service/libre_translate_spec.rb new file mode 100644 index 000000000..a6cb01884 --- /dev/null +++ b/spec/lib/translation_service/libre_translate_spec.rb @@ -0,0 +1,71 @@ +# frozen_string_literal: true + +require 'rails_helper' + +RSpec.describe TranslationService::LibreTranslate do + subject(:service) { described_class.new('https://libretranslate.example.com', 'my-api-key') } + + before do + stub_request(:get, 'https://libretranslate.example.com/languages').to_return( + body: '[{"code": "en","name": "English","targets": ["de","es"]},{"code": "da","name": "Danish","targets": ["en","de"]}]' + ) + end + + describe '#supported?' do + it 'supports included language pair' do + expect(service.supported?('en', 'de')).to be true + end + + it 'does not support reversed language pair' do + expect(service.supported?('de', 'en')).to be false + end + + it 'supports auto-detecting source language' do + expect(service.supported?(nil, 'de')).to be true + end + + it 'does not support auto-detecting for unsupported target language' do + expect(service.supported?(nil, 'pt')).to be false + end + end + + describe '#languages' do + subject(:languages) { service.send(:languages) } + + it 'includes supported source languages' do + expect(languages.keys).to eq ['en', 'da', nil] + end + + it 'includes supported target languages for source language' do + expect(languages['en']).to eq %w(de es) + end + + it 'includes supported target languages for auto-detected language' do + expect(languages[nil]).to eq %w(de es en) + end + end + + describe '#translate' do + it 'returns translation with specified source language' do + stub_request(:post, 'https://libretranslate.example.com/translate') + .with(body: '{"q":"Hasta la vista","source":"es","target":"en","format":"html","api_key":"my-api-key"}') + .to_return(body: '{"translatedText": "See you"}') + + translation = service.translate('Hasta la vista', 'es', 'en') + expect(translation.detected_source_language).to eq 'es' + expect(translation.provider).to eq 'LibreTranslate' + expect(translation.text).to eq 'See you' + end + + it 'returns translation with auto-detected source language' do + stub_request(:post, 'https://libretranslate.example.com/translate') + .with(body: '{"q":"Guten Morgen","source":"auto","target":"en","format":"html","api_key":"my-api-key"}') + .to_return(body: '{"detectedLanguage":{"confidence":92,"language":"de"},"translatedText":"Good morning"}') + + translation = service.translate('Guten Morgen', nil, 'en') + expect(translation.detected_source_language).to be_nil + expect(translation.provider).to eq 'LibreTranslate' + expect(translation.text).to eq 'Good morning' + end + end +end diff --git a/spec/models/status_spec.rb b/spec/models/status_spec.rb index 1e58c6d0d..1f6cfc796 100644 --- a/spec/models/status_spec.rb +++ b/spec/models/status_spec.rb @@ -114,6 +114,85 @@ RSpec.describe Status, type: :model do end end + describe '#translatable?' do + before do + allow(TranslationService).to receive(:configured?).and_return(true) + allow(TranslationService).to receive(:configured).and_return(TranslationService.new) + allow(TranslationService.configured).to receive(:supported?).with('es', 'en').and_return(true) + + subject.language = 'es' + subject.visibility = :public + end + + context 'all conditions are satisfied' do + it 'returns true' do + expect(subject.translatable?).to be true + end + end + + context 'translation service is not configured' do + it 'returns false' do + allow(TranslationService).to receive(:configured?).and_return(false) + allow(TranslationService).to receive(:configured).and_raise(TranslationService::NotConfiguredError) + expect(subject.translatable?).to be false + end + end + + context 'status language is nil' do + it 'returns true' do + subject.language = nil + allow(TranslationService.configured).to receive(:supported?).with(nil, 'en').and_return(true) + expect(subject.translatable?).to be true + end + end + + context 'status language is same as default locale' do + it 'returns false' do + subject.language = I18n.locale + expect(subject.translatable?).to be false + end + end + + context 'status language is unsupported' do + it 'returns false' do + subject.language = 'af' + allow(TranslationService.configured).to receive(:supported?).with('af', 'en').and_return(false) + expect(subject.translatable?).to be false + end + end + + context 'default locale is unsupported' do + it 'returns false' do + allow(TranslationService.configured).to receive(:supported?).with('es', 'af').and_return(false) + I18n.with_locale('af') do + expect(subject.translatable?).to be false + end + end + end + + context 'default locale has region' do + it 'returns true' do + I18n.with_locale('en-GB') do + expect(subject.translatable?).to be true + end + end + end + + context 'status text is blank' do + it 'returns false' do + subject.text = ' ' + expect(subject.translatable?).to be false + end + end + + context 'status visiblity is hidden' do + it 'returns false' do + subject.visibility = 'limited' + expect(subject.translatable?).to be false + end + end + end + describe '#content' do it 'returns the text of the status if it is not a reblog' do expect(subject.content).to eql subject.text -- cgit