From 694b5f108bfd30dd3b3dc7e19b46805605770426 Mon Sep 17 00:00:00 2001 From: Jarek Radosz Date: Wed, 6 Dec 2023 23:25:00 +0100 Subject: [PATCH] DEV: Fix various rubocop lints (#24749) These (21 + 3 from previous PRs) are soon to be enabled in rubocop-discourse: Capybara/VisibilityMatcher Lint/DeprecatedOpenSSLConstant Lint/DisjunctiveAssignmentInConstructor Lint/EmptyConditionalBody Lint/EmptyEnsure Lint/LiteralInInterpolation Lint/NonLocalExitFromIterator Lint/ParenthesesAsGroupedExpression Lint/RedundantCopDisableDirective Lint/RedundantRequireStatement Lint/RedundantSafeNavigation Lint/RedundantStringCoercion Lint/RedundantWithIndex Lint/RedundantWithObject Lint/SafeNavigationChain Lint/SafeNavigationConsistency Lint/SelfAssignment Lint/UnreachableCode Lint/UselessMethodDefinition Lint/Void Previous PRs: Lint/ShadowedArgument Lint/DuplicateMethods Lint/BooleanSymbol RSpec/SpecFilePathSuffix --- .../admin/site_texts_controller.rb | 2 +- app/controllers/application_controller.rb | 2 +- app/controllers/list_controller.rb | 2 +- app/controllers/topics_controller.rb | 4 +- app/controllers/users_controller.rb | 4 +- app/controllers/users_email_controller.rb | 4 +- app/jobs/regular/critical_user_email.rb | 4 -- app/jobs/regular/sync_acls_for_uploads.rb | 2 +- app/jobs/scheduled/poll_mailbox.rb | 2 +- app/models/api_key_scope.rb | 2 +- app/models/badge.rb | 2 - app/models/color_scheme.rb | 4 -- app/models/concerns/second_factor_manager.rb | 10 ++-- app/models/incoming_email.rb | 6 +-- app/models/tag_user.rb | 2 +- app/models/theme_field.rb | 2 +- app/models/topic_timer.rb | 4 -- app/models/user.rb | 4 +- app/models/user_avatar.rb | 2 +- app/serializers/post_serializer.rb | 2 +- app/services/inline_uploads.rb | 2 +- app/services/notification_emailer.rb | 6 ++- app/services/post_alerter.rb | 8 +-- .../sidebar_site_settings_backfiller.rb | 4 +- app/services/staff_action_logger.rb | 2 +- config/initializers/100-logster.rb | 2 +- config/unicorn.conf.rb | 4 +- lib/autospec/manager.rb | 3 +- lib/bookmark_query.rb | 2 +- lib/demon/email_sync.rb | 2 +- lib/discourse_dev/record.rb | 6 ++- lib/email/styles.rb | 4 +- lib/file_store/s3_store.rb | 1 - lib/final_destination.rb | 6 +-- lib/freedom_patches/ip_addr.rb | 2 +- lib/guardian.rb | 2 +- lib/i18n/backend/discourse_i18n.rb | 2 +- lib/imap/providers/gmail.rb | 6 +-- lib/middleware/discourse_public_exceptions.rb | 4 -- lib/mini_sql_multisite_connection.rb | 6 +-- lib/onebox/domain_checker.rb | 2 +- lib/onebox/engine.rb | 1 - lib/onebox/engine/amazon_onebox.rb | 2 +- lib/onebox/engine/github_actions_onebox.rb | 1 - lib/plugin/instance.rb | 2 +- lib/pretty_text.rb | 2 +- lib/pretty_text/helpers.rb | 2 +- lib/secure_session.rb | 1 - lib/sidekiq/pausable.rb | 2 - lib/site_settings/defaults_provider.rb | 2 +- lib/site_settings/type_supervisor.rb | 2 +- lib/stylesheet/compiler.rb | 2 +- lib/stylesheet/manager.rb | 2 +- lib/stylesheet/manager/builder.rb | 2 +- lib/stylesheet/watcher.rb | 4 +- lib/tasks/emoji.rake | 2 +- lib/tasks/javascript.rake | 5 +- lib/tasks/version_bump.rake | 2 +- lib/theme_store/git_importer.rb | 2 +- lib/version.rb | 2 +- .../chat/app/services/chat/update_message.rb | 2 +- plugins/chat/app/services/service/base.rb | 2 +- plugins/chat/lib/chat/transcript_service.rb | 2 +- .../chat/spec/fabricators/chat_fabricator.rb | 2 +- .../spec/models/chat/direct_message_spec.rb | 2 +- .../api/channels_archives_controller_spec.rb | 2 +- .../spec/requests/chat_controller_spec.rb | 4 +- .../chat/spec/support/api_schema_matcher.rb | 2 +- .../system/channel_message_upload_spec.rb | 4 +- .../advanced_user_narrative.rb | 4 -- plugins/poll/lib/polls_updater.rb | 2 + script/bulk_import/base.rb | 5 -- script/bulk_import/vbulletin.rb | 1 - script/bulk_import/vbulletin5.rb | 1 - script/diff_heaps.rb | 1 - script/import_scripts/bbpress.rb | 2 +- script/import_scripts/getsatisfaction.rb | 1 - script/import_scripts/google_groups.rb | 1 - script/import_scripts/ipboard.rb | 4 +- script/import_scripts/mybb.rb | 6 +-- script/import_scripts/mylittleforum.rb | 2 +- script/import_scripts/sfn.rb | 4 -- script/import_scripts/smf2.rb | 3 +- script/import_scripts/socialcast/import.rb | 1 - script/import_scripts/socialcast/title.rb | 1 - .../support/convert_mysql_xml_to_mysql.rb | 1 - script/import_scripts/zendesk_api.rb | 1 - script/memory-analysis | 1 - spec/fabricators/user_profile_fabricator.rb | 2 +- spec/integration/facebook_omniauth_spec.rb | 2 +- spec/jobs/bump_topic_spec.rb | 8 +-- spec/jobs/delete_replies_spec.rb | 4 +- spec/jobs/delete_topic_spec.rb | 2 +- spec/jobs/enqueue_digest_emails_spec.rb | 4 +- spec/jobs/invite_email_spec.rb | 4 +- spec/jobs/problem_check_spec.rb | 1 - .../process_shelved_notifications_spec.rb | 2 +- .../default_current_user_provider_spec.rb | 3 -- spec/lib/content_security_policy_spec.rb | 1 - spec/lib/discourse_spec.rb | 6 +-- spec/lib/discourse_updates_spec.rb | 6 +-- spec/lib/email/authentication_results_spec.rb | 6 +-- spec/lib/email/receiver_spec.rb | 12 ++--- spec/lib/guardian_spec.rb | 5 +- .../onebox/engine/google_maps_onebox_spec.rb | 2 +- spec/lib/plugin/instance_spec.rb | 12 ++--- spec/lib/search_spec.rb | 4 +- spec/lib/secure_session_spec.rb | 4 +- spec/lib/theme_settings_parser_spec.rb | 2 +- spec/lib/topic_view_spec.rb | 2 +- spec/lib/topics_bulk_action_spec.rb | 2 +- .../lib/validators/password_validator_spec.rb | 2 +- spec/mailers/rejection_mailer_spec.rb | 12 ++--- spec/models/report_spec.rb | 50 ++++++++----------- spec/rails_helper.rb | 1 - spec/requests/admin/themes_controller_spec.rb | 14 +++--- spec/requests/metadata_controller_spec.rb | 1 - spec/requests/sitemap_controller_spec.rb | 2 +- spec/requests/static_controller_spec.rb | 4 +- spec/requests/users_controller_spec.rb | 14 ++---- spec/serializers/post_serializer_spec.rb | 2 +- spec/services/destroy_task_spec.rb | 6 +-- .../services/inline_uploads_multisite_spec.rb | 4 +- spec/services/inline_uploads_spec.rb | 2 +- spec/services/user_merger_spec.rb | 4 +- spec/support/concurrency.rb | 2 - .../editing_sidebar_tags_navigation_spec.rb | 2 +- spec/system/s3_uploads_spec.rb | 2 +- spec/system/viewing_sidebar_mobile_spec.rb | 4 +- 129 files changed, 196 insertions(+), 274 deletions(-) diff --git a/app/controllers/admin/site_texts_controller.rb b/app/controllers/admin/site_texts_controller.rb index c7700ab61c8..88f9d1e88dc 100644 --- a/app/controllers/admin/site_texts_controller.rb +++ b/app/controllers/admin/site_texts_controller.rb @@ -234,7 +234,7 @@ class Admin::SiteTextsController < Admin::AdminController translations.each do |key, value| next unless I18n.exists?(key, :en) - if value&.is_a?(Hash) + if value.is_a?(Hash) fix_plural_keys(key, value, locale).each do |plural| plural_key = plural[0] plural_value = plural[1] diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 398fad9d448..b379271f92f 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -463,7 +463,7 @@ class ApplicationController < ActionController::Base return unless guardian.can_enable_safe_mode? safe_mode = params[SAFE_MODE] - if safe_mode&.is_a?(String) + if safe_mode.is_a?(String) safe_mode = safe_mode.split(",") request.env[NO_THEMES] = safe_mode.include?(NO_THEMES) || safe_mode.include?(LEGACY_NO_THEMES) request.env[NO_PLUGINS] = safe_mode.include?(NO_PLUGINS) diff --git a/app/controllers/list_controller.rb b/app/controllers/list_controller.rb index e09b5e66cd5..3f1f94225fe 100644 --- a/app/controllers/list_controller.rb +++ b/app/controllers/list_controller.rb @@ -92,7 +92,7 @@ class ListController < ApplicationController # Note the first is the default and we don't add a title if (filter.to_s != current_homepage) && use_crawler_layout? - filter_title = I18n.t("js.filters.#{filter.to_s}.title", count: 0) + filter_title = I18n.t("js.filters.#{filter}.title", count: 0) if list_opts[:category] && @category @title = diff --git a/app/controllers/topics_controller.rb b/app/controllers/topics_controller.rb index adc60e0c940..91c50d76e84 100644 --- a/app/controllers/topics_controller.rb +++ b/app/controllers/topics_controller.rb @@ -121,7 +121,7 @@ class TopicsController < ApplicationController deleted = guardian.can_see_topic?(ex.obj, false) || - (!guardian.can_see_topic?(ex.obj) && ex.obj&.access_topic_via_group && ex.obj.deleted_at) + (!guardian.can_see_topic?(ex.obj) && ex.obj&.access_topic_via_group && ex.obj&.deleted_at) if SiteSetting.detailed_404 if deleted @@ -975,7 +975,7 @@ class TopicsController < ApplicationController rescue Discourse::InvalidAccess => ex deleted = guardian.can_see_topic?(ex.obj, false) || - (!guardian.can_see_topic?(ex.obj) && ex.obj&.access_topic_via_group && ex.obj.deleted_at) + (!guardian.can_see_topic?(ex.obj) && ex.obj&.access_topic_via_group && ex.obj&.deleted_at) raise Discourse::NotFound.new( nil, diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 099943fcc1a..947f7e7bdba 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -225,7 +225,7 @@ class UsersController < ApplicationController end end - if params[:external_ids]&.is_a?(ActionController::Parameters) && current_user&.admin? && is_api? + if params[:external_ids].is_a?(ActionController::Parameters) && current_user&.admin? && is_api? attributes[:user_associated_accounts] = [] params[:external_ids].each do |provider_name, provider_uid| @@ -716,7 +716,7 @@ class UsersController < ApplicationController # Handle associated accounts associations = [] - if params[:external_ids]&.is_a?(ActionController::Parameters) && current_user&.admin? && is_api? + if params[:external_ids].is_a?(ActionController::Parameters) && current_user&.admin? && is_api? params[:external_ids].each do |provider_name, provider_uid| authenticator = Discourse.enabled_authenticators.find { |a| a.name == provider_name } raise Discourse::InvalidParameters.new(:external_ids) if !authenticator&.is_managed? diff --git a/app/controllers/users_email_controller.rb b/app/controllers/users_email_controller.rb index 69957486877..3c428f7c6ab 100644 --- a/app/controllers/users_email_controller.rb +++ b/app/controllers/users_email_controller.rb @@ -192,10 +192,10 @@ class UsersEmailController < ApplicationController if token if type == :old @change_request = - token.user&.email_change_requests.where(old_email_token_id: token.id).first + token.user&.email_change_requests&.where(old_email_token_id: token.id)&.first elsif type == :new @change_request = - token.user&.email_change_requests.where(new_email_token_id: token.id).first + token.user&.email_change_requests&.where(new_email_token_id: token.id)&.first end end diff --git a/app/jobs/regular/critical_user_email.rb b/app/jobs/regular/critical_user_email.rb index 6911ff174aa..ca34c148447 100644 --- a/app/jobs/regular/critical_user_email.rb +++ b/app/jobs/regular/critical_user_email.rb @@ -7,9 +7,5 @@ module Jobs def quit_email_early? false end - - def execute(args) - super(args) - end end end diff --git a/app/jobs/regular/sync_acls_for_uploads.rb b/app/jobs/regular/sync_acls_for_uploads.rb index 435c9dbc5a8..e3fa666ced6 100644 --- a/app/jobs/regular/sync_acls_for_uploads.rb +++ b/app/jobs/regular/sync_acls_for_uploads.rb @@ -37,7 +37,7 @@ module Jobs end end Rails.logger.warn( - "Completed syncing ACL for upload ids in #{time.to_s}. IDs: #{args[:upload_ids].join(", ")}", + "Completed syncing ACL for upload ids in #{time}. IDs: #{args[:upload_ids].join(", ")}", ) end end diff --git a/app/jobs/scheduled/poll_mailbox.rb b/app/jobs/scheduled/poll_mailbox.rb index 48922da83fb..664eb788b53 100644 --- a/app/jobs/scheduled/poll_mailbox.rb +++ b/app/jobs/scheduled/poll_mailbox.rb @@ -14,7 +14,7 @@ module Jobs poll_pop3 if should_poll? DiscoursePluginRegistry.mail_pollers.each do |poller| - return if !poller.enabled? + next if !poller.enabled? poller.poll_mailbox(method(:process_popmail)) end diff --git a/app/models/api_key_scope.rb b/app/models/api_key_scope.rb index d3a844d7c29..bc3eb54ed7c 100644 --- a/app/models/api_key_scope.rb +++ b/app/models/api_key_scope.rb @@ -279,7 +279,7 @@ class ApiKeyScope < ActiveRecord::Base engine_mount_path = nil if engine_mount_path == "/" set.routes.each do |route| defaults = route.defaults - action = "#{defaults[:controller].to_s}##{defaults[:action]}" + action = "#{defaults[:controller]}##{defaults[:action]}" path = route.path.spec.to_s.gsub(/\(\.:format\)/, "") api_supported_path = ( diff --git a/app/models/badge.rb b/app/models/badge.rb index 6f97eeb1a9f..a4688b48464 100644 --- a/app/models/badge.rb +++ b/app/models/badge.rb @@ -296,7 +296,6 @@ class Badge < ActiveRecord::Base def long_description=(val) self[:long_description] = val if val != long_description - val end def description @@ -311,7 +310,6 @@ class Badge < ActiveRecord::Base def description=(val) self[:description] = val if val != description - val end def slug diff --git a/app/models/color_scheme.rb b/app/models/color_scheme.rb index 75640e2d95b..57dd6acd71f 100644 --- a/app/models/color_scheme.rb +++ b/app/models/color_scheme.rb @@ -1,8 +1,6 @@ # frozen_string_literal: true class ColorScheme < ActiveRecord::Base - # rubocop:disable Layout/HashAlignment - CUSTOM_SCHEMES = { Dark: { "primary" => "dddddd", @@ -279,8 +277,6 @@ class ColorScheme < ActiveRecord::Base }, } - # rubocop:enable Layout/HashAlignment - LIGHT_THEME_ID = "Light" def self.base_color_scheme_colors diff --git a/app/models/concerns/second_factor_manager.rb b/app/models/concerns/second_factor_manager.rb index e5aca5f2d29..0477bc54e19 100644 --- a/app/models/concerns/second_factor_manager.rb +++ b/app/models/concerns/second_factor_manager.rb @@ -38,7 +38,7 @@ module SecondFactorManager end def authenticate_totp(token) - totps = self&.user_second_factors.totps + totps = self&.user_second_factors&.totps authenticated = false totps.each do |totp| last_used = 0 @@ -64,20 +64,20 @@ module SecondFactorManager def totp_enabled? !SiteSetting.enable_discourse_connect && SiteSetting.enable_local_logins && - self&.user_second_factors.totps.exists? + self&.user_second_factors&.totps&.exists? end def backup_codes_enabled? !SiteSetting.enable_discourse_connect && SiteSetting.enable_local_logins && - self&.user_second_factors.backup_codes.exists? + self&.user_second_factors&.backup_codes&.exists? end def security_keys_enabled? !SiteSetting.enable_discourse_connect && SiteSetting.enable_local_logins && self &.security_keys - .where(factor_type: UserSecurityKey.factor_types[:second_factor], enabled: true) - .exists? + &.where(factor_type: UserSecurityKey.factor_types[:second_factor], enabled: true) + &.exists? end def has_any_second_factor_methods_enabled? diff --git a/app/models/incoming_email.rb b/app/models/incoming_email.rb index f565bbce67c..9092eb28349 100644 --- a/app/models/incoming_email.rb +++ b/app/models/incoming_email.rb @@ -54,17 +54,17 @@ class IncomingEmail < ActiveRecord::Base end def to_addresses=(to) - to = to.map(&:downcase).join(";") if to&.is_a?(Array) + to = to.map(&:downcase).join(";") if to.is_a?(Array) super(to) end def cc_addresses=(cc) - cc = cc.map(&:downcase).join(";") if cc&.is_a?(Array) + cc = cc.map(&:downcase).join(";") if cc.is_a?(Array) super(cc) end def from_address=(from) - from = from.first if from&.is_a?(Array) + from = from.first if from.is_a?(Array) super(from) end end diff --git a/app/models/tag_user.rb b/app/models/tag_user.rb index 5b55a261dd2..04993eef4ad 100644 --- a/app/models/tag_user.rb +++ b/app/models/tag_user.rb @@ -44,7 +44,7 @@ class TagUser < ActiveRecord::Base tag_ids = if tags.empty? [] - elsif tags.first&.is_a?(String) + elsif tags.first.is_a?(String) Tag.where_name(tags).pluck(:id) else tags diff --git a/app/models/theme_field.rb b/app/models/theme_field.rb index c3d02c7fa63..37e1ffc44d6 100644 --- a/app/models/theme_field.rb +++ b/app/models/theme_field.rb @@ -451,7 +451,7 @@ class ThemeField < ActiveRecord::Base self.theme.with_scss_load_paths do |load_paths| Stylesheet::Compiler.compile( - "#{prepended_scss} #{self.theme.scss_variables.to_s} #{self.value}", + "#{prepended_scss} #{self.theme.scss_variables} #{self.value}", "#{Theme.targets[self.target_id]}.scss", theme: self.theme, load_paths: load_paths, diff --git a/app/models/topic_timer.rb b/app/models/topic_timer.rb index 9d4b5c3105e..483064ad6c6 100644 --- a/app/models/topic_timer.rb +++ b/app/models/topic_timer.rb @@ -30,10 +30,6 @@ class TopicTimer < ActiveRecord::Base before_save do self.created_at ||= Time.zone.now if execute_at self.public_type = self.public_type? - - if (will_save_change_to_execute_at? && !attribute_in_database(:execute_at).nil?) || - will_save_change_to_user_id? - end end # These actions are in place to make sure the topic is in the correct diff --git a/app/models/user.rb b/app/models/user.rb index a4a868fda44..6c27b09719f 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -153,7 +153,7 @@ class User < ActiveRecord::Base validates :primary_email, presence: true, unless: :skip_email_validation validates :validatable_user_fields_values, watched_words: true, unless: :custom_fields_clean? validates_associated :primary_email, - message: ->(_, user_email) { user_email[:value]&.errors[:email]&.first } + message: ->(_, user_email) { user_email[:value]&.errors&.[](:email)&.first } after_initialize :add_trust_level @@ -1619,8 +1619,6 @@ class User < ActiveRecord::Base secondary_match.mark_for_destruction primary_email.skip_validate_unique_email = true end - - new_email end def emails diff --git a/app/models/user_avatar.rb b/app/models/user_avatar.rb index 90f396d384d..9b6df23fc65 100644 --- a/app/models/user_avatar.rb +++ b/app/models/user_avatar.rb @@ -78,7 +78,7 @@ class UserAvatar < ActiveRecord::Base end end rescue OpenURI::HTTPError => e - raise e if e.io&.status[0].to_i != 404 + raise e if e.io&.status&.[](0).to_i != 404 ensure tempfile&.close! end diff --git a/app/serializers/post_serializer.rb b/app/serializers/post_serializer.rb index 2998a074e5f..5da2ad41f8b 100644 --- a/app/serializers/post_serializer.rb +++ b/app/serializers/post_serializer.rb @@ -607,7 +607,7 @@ class PostSerializer < BasicPostSerializer end def reviewable_scores - reviewable&.reviewable_scores&.to_a || [] + reviewable&.reviewable_scores.to_a end def user_custom_fields_object diff --git a/app/services/inline_uploads.rb b/app/services/inline_uploads.rb index 8feb0efc935..8d5ef6aa857 100644 --- a/app/services/inline_uploads.rb +++ b/app/services/inline_uploads.rb @@ -210,7 +210,7 @@ class InlineUploads node["src"] = upload&.short_url || PLACEHOLDER spaces_before = match[1].present? ? match[1][/ +$/].size : 0 - replacement = +"#{" " * spaces_before}#{node.to_s}" + replacement = +"#{" " * spaces_before}#{node}" yield(match[2], src, replacement, $~.offset(0)[0]) if block_given? end diff --git a/app/services/notification_emailer.rb b/app/services/notification_emailer.rb index 4acd8f5e28e..0614a623530 100644 --- a/app/services/notification_emailer.rb +++ b/app/services/notification_emailer.rb @@ -139,8 +139,10 @@ class NotificationEmailer email_user = EmailUser.new(notification, no_delay: no_delay) email_method = Notification.types[notification.notification_type] - DiscoursePluginRegistry.email_notification_filters.each do |filter| - return unless filter.call(notification) + if DiscoursePluginRegistry.email_notification_filters.any? { |filter| + !filter.call(notification) + } + return end email_user.public_send(email_method) if email_user.respond_to? email_method diff --git a/app/services/post_alerter.rb b/app/services/post_alerter.rb index 871cff0526f..82597c550ba 100644 --- a/app/services/post_alerter.rb +++ b/app/services/post_alerter.rb @@ -51,8 +51,10 @@ class PostAlerter def self.push_notification(user, payload) return if user.do_not_disturb? - DiscoursePluginRegistry.push_notification_filters.each do |filter| - return unless filter.call(user, payload) + if DiscoursePluginRegistry.push_notification_filters.any? { |filter| + !filter.call(user, payload) + } + return end if user.push_subscriptions.exists? @@ -600,7 +602,7 @@ class PostAlerter display_username: opts[:display_username] || post.user.username, } - opts[:custom_data].each { |k, v| notification_data[k] = v } if opts[:custom_data]&.is_a?(Hash) + opts[:custom_data].each { |k, v| notification_data[k] = v } if opts[:custom_data].is_a?(Hash) if group = opts[:group] notification_data[:group_id] = group.id diff --git a/app/services/sidebar_site_settings_backfiller.rb b/app/services/sidebar_site_settings_backfiller.rb index 0a61ec1dac4..3fbcd51506c 100644 --- a/app/services/sidebar_site_settings_backfiller.rb +++ b/app/services/sidebar_site_settings_backfiller.rb @@ -67,7 +67,7 @@ class SidebarSiteSettingsBackfiller SELECT sidebar_section_links.user_id FROM sidebar_section_links - WHERE sidebar_section_links.linkable_type = '#{@linkable_klass.to_s}' + WHERE sidebar_section_links.linkable_type = '#{@linkable_klass}' AND sidebar_section_links.linkable_id IN (#{@removed_ids.join(",")}) SQL @@ -83,7 +83,7 @@ class SidebarSiteSettingsBackfiller SELECT DISTINCT(sidebar_section_links.user_id) FROM sidebar_section_links - WHERE sidebar_section_links.linkable_type = '#{@linkable_klass.to_s}' + WHERE sidebar_section_links.linkable_type = '#{@linkable_klass}' AND sidebar_section_links.linkable_id IN (#{@added_ids.join(",")}) ) AND users.id > 0 AND NOT users.staged SQL diff --git a/app/services/staff_action_logger.rb b/app/services/staff_action_logger.rb index f23d494161b..64a6d283a35 100644 --- a/app/services/staff_action_logger.rb +++ b/app/services/staff_action_logger.rb @@ -314,7 +314,7 @@ class StaffActionLogger UserHistory.create!( params(opts).merge( action: UserHistory.actions[:change_theme_setting], - subject: "#{theme.name}: #{setting_name.to_s}", + subject: "#{theme.name}: #{setting_name}", previous_value: previous_value, new_value: new_value, ), diff --git a/config/initializers/100-logster.rb b/config/initializers/100-logster.rb index 5c227b99834..5e08f664a69 100644 --- a/config/initializers/100-logster.rb +++ b/config/initializers/100-logster.rb @@ -126,7 +126,7 @@ Discourse.plugins.each do |plugin| next if !plugin.metadata.url Logster.config.project_directories << { - path: "#{Rails.root.to_s}/plugins/#{plugin.directory_name}", + path: "#{Rails.root}/plugins/#{plugin.directory_name}", url: plugin.metadata.url, } end diff --git a/config/unicorn.conf.rb b/config/unicorn.conf.rb index 68bb4e2efa5..9fd348b0745 100644 --- a/config/unicorn.conf.rb +++ b/config/unicorn.conf.rb @@ -23,12 +23,12 @@ listen ENV["UNICORN_LISTENER"] || "#{(ENV["UNICORN_BIND_ALL"] ? "" : "127.0.0.1: FileUtils.mkdir_p("#{discourse_path}/tmp/pids") if !File.exist?("#{discourse_path}/tmp/pids") # feel free to point this anywhere accessible on the filesystem -pid (ENV["UNICORN_PID_PATH"] || "#{discourse_path}/tmp/pids/unicorn.pid") +pid(ENV["UNICORN_PID_PATH"] || "#{discourse_path}/tmp/pids/unicorn.pid") if ENV["RAILS_ENV"] != "production" logger Logger.new(STDOUT) # we want a longer timeout in dev cause first request can be really slow - timeout (ENV["UNICORN_TIMEOUT"] && ENV["UNICORN_TIMEOUT"].to_i || 60) + timeout(ENV["UNICORN_TIMEOUT"] && ENV["UNICORN_TIMEOUT"].to_i || 60) else # By default, the Unicorn logger will write to stderr. # Additionally, some applications/frameworks log to stderr or stdout, diff --git a/lib/autospec/manager.rb b/lib/autospec/manager.rb index fba758be265..30e952c3509 100644 --- a/lib/autospec/manager.rb +++ b/lib/autospec/manager.rb @@ -1,7 +1,6 @@ # frozen_string_literal: true require "listen" -require "thread" require "fileutils" require "autospec/reload_css" require "autospec/base_runner" @@ -267,7 +266,9 @@ class Autospec::Manager if k.match(file) puts "@@@@@@@@@@@@ #{file} matched a reloader for #{runner}" if @debug runner.reload + # rubocop:disable Lint/NonLocalExitFromIterator return + # rubocop:enable Lint/NonLocalExitFromIterator end end # watchers diff --git a/lib/bookmark_query.rb b/lib/bookmark_query.rb index dd066f6bd2a..692860c9440 100644 --- a/lib/bookmark_query.rb +++ b/lib/bookmark_query.rb @@ -57,7 +57,7 @@ class BookmarkQuery # this is purely to make the query easy to read and debug, otherwise it's # all mashed up into a massive ball in MiniProfiler :) - "---- #{bookmarkable.model.to_s} bookmarkable ---\n\n #{interim_results.to_sql}" + "---- #{bookmarkable.model} bookmarkable ---\n\n #{interim_results.to_sql}" end .compact diff --git a/lib/demon/email_sync.rb b/lib/demon/email_sync.rb index 93a627c0330..8658ea7f673 100644 --- a/lib/demon/email_sync.rb +++ b/lib/demon/email_sync.rb @@ -169,7 +169,7 @@ class Demon::EmailSync < ::Demon::Base begin data[:syncer]&.disconnect! rescue Net::IMAP::ResponseError => err - puts "[EmailSync] Encountered a response error when disconnecting: #{err.to_s}" + puts "[EmailSync] Encountered a response error when disconnecting: #{err}" end end end diff --git a/lib/discourse_dev/record.rb b/lib/discourse_dev/record.rb index d01baa5fa3e..63752ffb21b 100644 --- a/lib/discourse_dev/record.rb +++ b/lib/discourse_dev/record.rb @@ -74,10 +74,12 @@ module DiscourseDev def self.random(model, use_existing_records: true) if !use_existing_records && model.new.respond_to?(:custom_fields) - model.joins(:_custom_fields).where("#{:type}_custom_fields.name = '#{AUTO_POPULATED}'") + model.joins(:_custom_fields).where( + "#{model.to_s.underscore}_custom_fields.name = '#{AUTO_POPULATED}'", + ) end count = model.count - raise "#{:type} records are not yet populated" if count == 0 + raise "#{model} records are not yet populated" if count == 0 offset = Faker::Number.between(from: 0, to: count - 1) model.offset(offset).first diff --git a/lib/email/styles.rb b/lib/email/styles.rb index c248e9cc595..03e78844656 100644 --- a/lib/email/styles.rb +++ b/lib/email/styles.rb @@ -202,7 +202,7 @@ module Email "#{src_uri.scheme || "https"}://#{src_uri.host}#{src_uri.path}#{src_uri.query.nil? ? "" : "?" + src_uri.query}#{src_uri.fragment.nil? ? "" : "#" + src_uri.fragment}" i.replace( Nokogiri::HTML5.fragment( - "

#{CGI.escapeHTML(display_src)}

", + "

#{CGI.escapeHTML(display_src)}

", ), ) rescue URI::Error @@ -517,9 +517,11 @@ module Email "style" ] = "background-color: #{bg_color}; color: #{SiteSetting.email_accent_fg_color}; border-top: 4px solid #{bg_color}; border-right: 6px solid #{bg_color}; border-bottom: 4px solid #{bg_color}; border-left: 6px solid #{bg_color}; display: inline-block; font-weight: bold;" end + # rubocop:disable Lint/NonLocalExitFromIterator return end return + # rubocop:enable Lint/NonLocalExitFromIterator end end diff --git a/lib/file_store/s3_store.rb b/lib/file_store/s3_store.rb index f8768065129..55f6668f156 100644 --- a/lib/file_store/s3_store.rb +++ b/lib/file_store/s3_store.rb @@ -163,7 +163,6 @@ module FileStore else return true end - return false end return false if SiteSetting.Upload.s3_cdn_url.blank? diff --git a/lib/final_destination.rb b/lib/final_destination.rb index 66c2ff4cf23..0c107af9503 100644 --- a/lib/final_destination.rb +++ b/lib/final_destination.rb @@ -245,10 +245,10 @@ class FinalDestination lambda do |chunk, _remaining_bytes, _total_bytes| response_body << chunk if response_body.bytesize > MAX_REQUEST_SIZE_BYTES - raise Excon::Errors::ExpectationFailed.new("response size too big: #{@uri.to_s}") + raise Excon::Errors::ExpectationFailed.new("response size too big: #{@uri}") end if Time.now - request_start_time > MAX_REQUEST_TIME_SECONDS - raise Excon::Errors::ExpectationFailed.new("connect timeout reached: #{@uri.to_s}") + raise Excon::Errors::ExpectationFailed.new("connect timeout reached: #{@uri}") end end @@ -427,7 +427,7 @@ class FinalDestination return true if @uri.port == 80 allowed_internal_hosts = - SiteSetting.allowed_internal_hosts&.split(/[|\n]/).filter_map { |aih| aih.strip.presence } + SiteSetting.allowed_internal_hosts&.split(/[|\n]/)&.filter_map { |aih| aih.strip.presence } return false if allowed_internal_hosts.empty? || SiteSetting.s3_endpoint.blank? return false if allowed_internal_hosts.none? { |aih| hostname_matches_s3_endpoint?(aih) } diff --git a/lib/freedom_patches/ip_addr.rb b/lib/freedom_patches/ip_addr.rb index 9c7053d66c2..bffadea3bfa 100644 --- a/lib/freedom_patches/ip_addr.rb +++ b/lib/freedom_patches/ip_addr.rb @@ -26,7 +26,7 @@ class IPAddr if mask == 32 to_s else - "#{to_s}/#{mask}" + "#{self}/#{mask}" end else nil diff --git a/lib/guardian.rb b/lib/guardian.rb index 6af80ee6233..a069ad8867a 100644 --- a/lib/guardian.rb +++ b/lib/guardian.rb @@ -420,7 +420,7 @@ class Guardian end if (category = object.category) && category.read_restricted - return category.groups&.where(automatic: false).any? { |g| can_edit_group?(g) } + return category.groups&.where(automatic: false)&.any? { |g| can_edit_group?(g) } end end diff --git a/lib/i18n/backend/discourse_i18n.rb b/lib/i18n/backend/discourse_i18n.rb index 4b1e24e9ec6..f72019e697e 100644 --- a/lib/i18n/backend/discourse_i18n.rb +++ b/lib/i18n/backend/discourse_i18n.rb @@ -38,7 +38,7 @@ module I18n def self.sort_locale_files(files) files.sort.sort_by do |filename| matches = /(?:client|server)-([1-9]|[1-9][0-9]|100)\..+\.yml/.match(filename) - matches&.[](1)&.to_i || 0 + matches&.[](1).to_i end end diff --git a/lib/imap/providers/gmail.rb b/lib/imap/providers/gmail.rb index fc888d66eda..d1648a0cc6e 100644 --- a/lib/imap/providers/gmail.rb +++ b/lib/imap/providers/gmail.rb @@ -141,7 +141,6 @@ module Imap # This is done so we can extract X-GM-LABELS, X-GM-MSGID, and # X-GM-THRID, all Gmail extended attributes. # - # rubocop:disable Style/RedundantReturn def msg_att(n) match(T_LPAR) attr = {} @@ -186,7 +185,7 @@ module Imap end attr[name] = val end - return attr + attr end def label_data @@ -214,9 +213,8 @@ module Imap result.push(atom) end end - return name, result + [name, result] end - # rubocop:enable Style/RedundantReturn end end end diff --git a/lib/middleware/discourse_public_exceptions.rb b/lib/middleware/discourse_public_exceptions.rb index 54e070c433a..1c3ec1b0204 100644 --- a/lib/middleware/discourse_public_exceptions.rb +++ b/lib/middleware/discourse_public_exceptions.rb @@ -14,10 +14,6 @@ module Middleware ], ) - def initialize(path) - super - end - def call(env) # this is so so gnarly # sometimes we leak out exceptions prior to creating a controller instance diff --git a/lib/mini_sql_multisite_connection.rb b/lib/mini_sql_multisite_connection.rb index 2b8ef82066a..675d372686f 100644 --- a/lib/mini_sql_multisite_connection.rb +++ b/lib/mini_sql_multisite_connection.rb @@ -2,10 +2,6 @@ class MiniSqlMultisiteConnection < MiniSql::ActiveRecordPostgres::Connection class CustomBuilder < MiniSql::Builder - def initialize(connection, sql) - super - end - def secure_category(secure_category_ids, category_alias = "c") if secure_category_ids.present? where( @@ -21,7 +17,7 @@ class MiniSqlMultisiteConnection < MiniSql::ActiveRecordPostgres::Connection class ParamEncoder def encode(*sql_array) - # use active record to avoid any discrepencies + # use active record to avoid any discrepancies ActiveRecord::Base.public_send(:sanitize_sql_array, sql_array) end end diff --git a/lib/onebox/domain_checker.rb b/lib/onebox/domain_checker.rb index 6e6c99c3e39..9d78c62bde1 100644 --- a/lib/onebox/domain_checker.rb +++ b/lib/onebox/domain_checker.rb @@ -6,7 +6,7 @@ module Onebox SiteSetting .blocked_onebox_domains &.split("|") - .any? { |blocked| hostname == blocked || hostname.end_with?(".#{blocked}") } + &.any? { |blocked| hostname == blocked || hostname.end_with?(".#{blocked}") } end end end diff --git a/lib/onebox/engine.rb b/lib/onebox/engine.rb index d4958068bea..b6dfb3bcee9 100644 --- a/lib/onebox/engine.rb +++ b/lib/onebox/engine.rb @@ -34,7 +34,6 @@ module Onebox return @options if opt.nil? # make sure options provided opt = opt.to_h if opt.instance_of?(OpenStruct) @options.merge!(opt) - @options end def initialize(url, timeout = nil) diff --git a/lib/onebox/engine/amazon_onebox.rb b/lib/onebox/engine/amazon_onebox.rb index ae3ae9e36f5..c7b7d23600c 100644 --- a/lib/onebox/engine/amazon_onebox.rb +++ b/lib/onebox/engine/amazon_onebox.rb @@ -82,7 +82,7 @@ module Onebox private def has_cached_body - body_cacher&.respond_to?("cache_response_body?") && + body_cacher.respond_to?("cache_response_body?") && body_cacher.cache_response_body?(uri.to_s) && body_cacher.cached_response_body_exists?(uri.to_s) end diff --git a/lib/onebox/engine/github_actions_onebox.rb b/lib/onebox/engine/github_actions_onebox.rb index 6630fefa4df..c6309b3c5e7 100644 --- a/lib/onebox/engine/github_actions_onebox.rb +++ b/lib/onebox/engine/github_actions_onebox.rb @@ -69,7 +69,6 @@ module Onebox status = "success" elsif raw["conclusion"] == "failure" status = "failure" - elsif raw["conclusion"] == "cancelled" end elsif raw["status"] == "in_progress" status = "pending" diff --git a/lib/plugin/instance.rb b/lib/plugin/instance.rb index 35acf3e5a1d..30424f6663c 100644 --- a/lib/plugin/instance.rb +++ b/lib/plugin/instance.rb @@ -145,7 +145,7 @@ class Plugin::Instance begin "#{serializer.to_s.classify}Serializer".constantize rescue StandardError - "#{serializer.to_s}Serializer".constantize + "#{serializer}Serializer".constantize end # we have to work through descendants cause serializers may already be baked and cached diff --git a/lib/pretty_text.rb b/lib/pretty_text.rb index 6beeefbbddb..e22824a1179 100644 --- a/lib/pretty_text.rb +++ b/lib/pretty_text.rb @@ -548,7 +548,7 @@ module PrettyText if a.classes.include?("lightbox") img = a.css("img[src]").first - srcset = img&.attributes["srcset"]&.value + srcset = img&.attributes&.[]("srcset")&.value if srcset # if available, use the first image from the srcset here # so we get the optimized image instead of the possibly huge original diff --git a/lib/pretty_text/helpers.rb b/lib/pretty_text/helpers.rb index b07951ed79a..c79814d6098 100644 --- a/lib/pretty_text/helpers.rb +++ b/lib/pretty_text/helpers.rb @@ -11,7 +11,7 @@ module PrettyText key = "js." + key return I18n.t(key) if opts.blank? str = I18n.t(key, Hash[opts.entries].symbolize_keys).dup - opts.each { |k, v| str.gsub!("{{#{k.to_s}}}", v.to_s) } + opts.each { |k, v| str.gsub!("{{#{k}}}", v.to_s) } str end diff --git a/lib/secure_session.rb b/lib/secure_session.rb index cd28dc7683b..eedddfa37ae 100644 --- a/lib/secure_session.rb +++ b/lib/secure_session.rb @@ -34,7 +34,6 @@ class SecureSession else Discourse.redis.setex(prefixed_key(key), SecureSession.expiry.to_i, val.to_s) end - val end private diff --git a/lib/sidekiq/pausable.rb b/lib/sidekiq/pausable.rb index cb97d53a272..eb06d5dcdaf 100644 --- a/lib/sidekiq/pausable.rb +++ b/lib/sidekiq/pausable.rb @@ -1,7 +1,5 @@ # frozen_string_literal: true -require "thread" - class SidekiqPauser TTL = 60 PAUSED_KEY = "sidekiq_is_paused_v2" diff --git a/lib/site_settings/defaults_provider.rb b/lib/site_settings/defaults_provider.rb index 6c8354110ac..5e5612f2472 100644 --- a/lib/site_settings/defaults_provider.rb +++ b/lib/site_settings/defaults_provider.rb @@ -63,7 +63,7 @@ class SiteSettings::DefaultsProvider end def has_setting?(name) - has_key?(name.to_sym) || has_key?("#{name.to_s}?".to_sym) || name.to_sym == :default_locale + has_key?(name.to_sym) || has_key?("#{name}?".to_sym) || name.to_sym == :default_locale end private diff --git a/lib/site_settings/type_supervisor.rb b/lib/site_settings/type_supervisor.rb index c06bd3bfb52..938fda2bf30 100644 --- a/lib/site_settings/type_supervisor.rb +++ b/lib/site_settings/type_supervisor.rb @@ -268,7 +268,7 @@ class SiteSettings::TypeSupervisor if (v = @validators[name]) validator = v[:class].new(v[:opts]) unless validator.valid_value?(val) - raise Discourse::InvalidParameters, "#{name.to_s}: #{validator.error_message}" + raise Discourse::InvalidParameters, "#{name}: #{validator.error_message}" end end diff --git a/lib/stylesheet/compiler.rb b/lib/stylesheet/compiler.rb index 8c67fd2dbb2..1e32c1806fc 100644 --- a/lib/stylesheet/compiler.rb +++ b/lib/stylesheet/compiler.rb @@ -15,7 +15,7 @@ module Stylesheet file += options[:theme_variables].to_s file += importer.theme_import(asset) elsif plugin_assets = Importer.plugin_assets[asset.to_s] - filename = "#{asset.to_s}.scss" + filename = "#{asset}.scss" options[:load_paths] = [] if options[:load_paths].nil? plugin_assets.each do |src| file += File.read src diff --git a/lib/stylesheet/manager.rb b/lib/stylesheet/manager.rb index 7f71831ba87..aaf7db8efcb 100644 --- a/lib/stylesheet/manager.rb +++ b/lib/stylesheet/manager.rb @@ -293,7 +293,7 @@ class Stylesheet::Manager data = { target: target, theme_id: theme_id, - theme_name: theme&.name.downcase, + theme_name: theme&.name&.downcase, remote: theme.remote_theme_id?, } builder = Builder.new(target: target, theme: theme, manager: self) diff --git a/lib/stylesheet/manager/builder.rb b/lib/stylesheet/manager/builder.rb index 5f4fbabbaa0..8bebf711bad 100644 --- a/lib/stylesheet/manager/builder.rb +++ b/lib/stylesheet/manager/builder.rb @@ -122,7 +122,7 @@ class Stylesheet::Manager::Builder if is_theme? "#{@target}_#{theme&.id}" elsif @color_scheme - "#{@target}_#{scheme_slug}_#{@color_scheme&.id.to_s}_#{@theme&.id}" + "#{@target}_#{scheme_slug}_#{@color_scheme&.id}_#{@theme&.id}" else scheme_string = theme&.color_scheme ? "_#{theme.color_scheme.id}" : "" "#{@target}#{scheme_string}" diff --git a/lib/stylesheet/watcher.rb b/lib/stylesheet/watcher.rb index 9740758d076..6bb5bad13b6 100644 --- a/lib/stylesheet/watcher.rb +++ b/lib/stylesheet/watcher.rb @@ -27,7 +27,7 @@ module Stylesheet else # if plugin doesn’t seem to be in our app, consider it as outside of the app # and ignore it - warn("[stylesheet watcher] Ignoring outside of rails root plugin: #{plugin.path.to_s}") + warn("[stylesheet watcher] Ignoring outside of rails root plugin: #{plugin.path}") end end @default_paths @@ -109,7 +109,7 @@ module Stylesheet targets = [] if target.present? if DiscoursePluginRegistry.stylesheets_exists?(plugin_name, target.to_sym) - targets.push("#{plugin_name}_#{target.to_s}") + targets.push("#{plugin_name}_#{target}") end else targets.push(plugin_name) diff --git a/lib/tasks/emoji.rake b/lib/tasks/emoji.rake index 4a123d18464..b1a2868f61c 100644 --- a/lib/tasks/emoji.rake +++ b/lib/tasks/emoji.rake @@ -480,7 +480,7 @@ class TestEmojiUpdate < Minitest::Test puts "Runnings tests..." reporter = Minitest::SummaryReporter.new TestEmojiUpdate.run(reporter) - puts reporter.to_s + puts reporter end def image_path(style, name) diff --git a/lib/tasks/javascript.rake b/lib/tasks/javascript.rake index be52705b2e8..c1a4667d328 100644 --- a/lib/tasks/javascript.rake +++ b/lib/tasks/javascript.rake @@ -180,8 +180,8 @@ def generate_admin_sidebar_nav_map end end + # rubocop:disable Lint/Void # Copy this JS to your browser to get the Ember routes. - # <<~JS let routeMap = {} for (const [key, value] of Object.entries( @@ -207,7 +207,8 @@ def generate_admin_sidebar_nav_map routeMap[key] = route; } console.log(JSON.stringify(routeMap)); -JS + JS + # rubocop:enable Lint/Void # Paste the output below between ROUTE_MAP. # diff --git a/lib/tasks/version_bump.rake b/lib/tasks/version_bump.rake index 6953ffc588b..6a9aa8b24dc 100644 --- a/lib/tasks/version_bump.rake +++ b/lib/tasks/version_bump.rake @@ -384,7 +384,7 @@ task "version_bump:stage_security_fixes", [:base] do |t, args| base = args[:base] raise "Unknown base: #{base.inspect}" unless %w[stable main].include?(base) - fix_refs = ENV["SECURITY_FIX_REFS"]&.split(",").map(&:strip) + fix_refs = ENV["SECURITY_FIX_REFS"]&.split(",")&.map(&:strip) raise "No branches specified in SECURITY_FIX_REFS env" if fix_refs.nil? || fix_refs.empty? fix_refs.each do |ref| diff --git a/lib/theme_store/git_importer.rb b/lib/theme_store/git_importer.rb index 407dcfadbea..9958d580acd 100644 --- a/lib/theme_store/git_importer.rb +++ b/lib/theme_store/git_importer.rb @@ -62,7 +62,7 @@ class ThemeStore::GitImporter < ThemeStore::BaseImporter redirected_uri = FinalDestination.resolve(first_clone_uri.to_s, http_verb: :get) - if redirected_uri&.path.ends_with?("/info/refs") + if redirected_uri&.path&.ends_with?("/info/refs") redirected_uri.path.gsub!(%r{/info/refs\z}, "") redirected_uri.query = nil redirected_uri diff --git a/lib/version.rb b/lib/version.rb index b62d87a87f5..71500106aeb 100644 --- a/lib/version.rb +++ b/lib/version.rb @@ -69,7 +69,7 @@ module Discourse "Invalid version specifier operator for '#{req_operator} #{req_version}'. Operator must be one of <= or <" end - resolved_requirement = Gem::Requirement.new("#{req_operator} #{req_version.to_s}") + resolved_requirement = Gem::Requirement.new("#{req_operator} #{req_version}") resolved_requirement.satisfied_by?(parsed_target_version) end diff --git a/plugins/chat/app/services/chat/update_message.rb b/plugins/chat/app/services/chat/update_message.rb index 75cb09368f6..871f17d66cb 100644 --- a/plugins/chat/app/services/chat/update_message.rb +++ b/plugins/chat/app/services/chat/update_message.rb @@ -111,7 +111,7 @@ module Chat def should_create_revision(new_message, prev_message, guardian) max_seconds = SiteSetting.chat_editing_grace_period - seconds_since_created = Time.now.to_i - new_message&.created_at.iso8601.to_time.to_i + seconds_since_created = Time.now.to_i - new_message&.created_at&.iso8601&.to_time.to_i return true if seconds_since_created > max_seconds max_edited_chars = diff --git a/plugins/chat/app/services/service/base.rb b/plugins/chat/app/services/service/base.rb index 445fad6e3b6..e64179d93cd 100644 --- a/plugins/chat/app/services/service/base.rb +++ b/plugins/chat/app/services/service/base.rb @@ -38,7 +38,7 @@ module Service # context.fail!("failure": "something went wrong") # @return [Context] def fail!(context = {}) - fail(context) + self.fail(context) raise Failure, self end diff --git a/plugins/chat/lib/chat/transcript_service.rb b/plugins/chat/lib/chat/transcript_service.rb index 5a7b587e80c..f45389f06f5 100644 --- a/plugins/chat/lib/chat/transcript_service.rb +++ b/plugins/chat/lib/chat/transcript_service.rb @@ -250,7 +250,7 @@ module Chat thread_id = message_group.first.thread_id if thread_id.present? thread = Chat::Thread.find(thread_id) - if thread&.replies_count > 0 + if thread&.replies_count&.> 0 open_bbcode_tag.add_thread_markdown( thread_id: thread_id, markdown: rendered_thread_markdown.join("\n"), diff --git a/plugins/chat/spec/fabricators/chat_fabricator.rb b/plugins/chat/spec/fabricators/chat_fabricator.rb index 2c3ba21f442..2d9cbfe9180 100644 --- a/plugins/chat/spec/fabricators/chat_fabricator.rb +++ b/plugins/chat/spec/fabricators/chat_fabricator.rb @@ -16,7 +16,7 @@ Fabricator(:chat_channel, class_name: "Chat::Channel") do end chatable { Fabricate(:category) } type do |attrs| - if attrs[:chatable_type] == "Category" || attrs[:chatable]&.is_a?(Category) + if attrs[:chatable_type] == "Category" || attrs[:chatable].is_a?(Category) "CategoryChannel" else "DirectMessageChannel" diff --git a/plugins/chat/spec/models/chat/direct_message_spec.rb b/plugins/chat/spec/models/chat/direct_message_spec.rb index 9d526f3bb1c..037b1c2bbfc 100644 --- a/plugins/chat/spec/models/chat/direct_message_spec.rb +++ b/plugins/chat/spec/models/chat/direct_message_spec.rb @@ -30,7 +30,7 @@ describe Chat::DirectMessage do user3 = Fabricate.build(:user, username: "chatdmregent") users = [user1, user2, user3].concat( - 5.times.map.with_index { |i| Fabricate(:user, username: "chatdmuser#{i}") }, + 5.times.map { |i| Fabricate(:user, username: "chatdmuser#{i}") }, ) direct_message = Fabricate(:direct_message, users: users) diff --git a/plugins/chat/spec/requests/chat/api/channels_archives_controller_spec.rb b/plugins/chat/spec/requests/chat/api/channels_archives_controller_spec.rb index df4b6d4f5ac..0bb71ee9ab4 100644 --- a/plugins/chat/spec/requests/chat/api/channels_archives_controller_spec.rb +++ b/plugins/chat/spec/requests/chat/api/channels_archives_controller_spec.rb @@ -153,7 +153,7 @@ RSpec.describe Chat::Api::ChannelsArchivesController do expect { post "/chat/api/channels/#{channel.id}/archives" }.to change( Jobs::Chat::ChannelArchive.jobs, :size, - ).by (1) + ).by(1) expect(response.status).to eq(200) end end diff --git a/plugins/chat/spec/requests/chat_controller_spec.rb b/plugins/chat/spec/requests/chat_controller_spec.rb index 2aa353b7d63..08d052f78d1 100644 --- a/plugins/chat/spec/requests/chat_controller_spec.rb +++ b/plugins/chat/spec/requests/chat_controller_spec.rb @@ -354,14 +354,14 @@ RSpec.describe Chat::ChatController do sign_in(user) expect { post "/chat/dismiss-retention-reminder.json", params: { chatable_type: "Category" } - }.to change { user.user_option.reload.dismissed_channel_retention_reminder }.to (true) + }.to change { user.user_option.reload.dismissed_channel_retention_reminder }.to(true) end it "sets `dismissed_dm_retention_reminder` to true" do sign_in(user) expect { post "/chat/dismiss-retention-reminder.json", params: { chatable_type: "DirectMessage" } - }.to change { user.user_option.reload.dismissed_dm_retention_reminder }.to (true) + }.to change { user.user_option.reload.dismissed_dm_retention_reminder }.to(true) end it "doesn't error if the fields are already true" do diff --git a/plugins/chat/spec/support/api_schema_matcher.rb b/plugins/chat/spec/support/api_schema_matcher.rb index 2c36fe40d6f..e78e158d79c 100644 --- a/plugins/chat/spec/support/api_schema_matcher.rb +++ b/plugins/chat/spec/support/api_schema_matcher.rb @@ -9,7 +9,7 @@ RSpec::Matchers.define :match_response_schema do |schema| JSON::Validator.validate!(schema_path, object, strict: true) rescue JSON::Schema::ValidationError => e puts "-- Printing response body after validation error\n" - pp object # rubocop:disable Lint/Debugger + pp object raise e end end diff --git a/plugins/chat/spec/system/channel_message_upload_spec.rb b/plugins/chat/spec/system/channel_message_upload_spec.rb index bae748e7868..4c4f33e3438 100644 --- a/plugins/chat/spec/system/channel_message_upload_spec.rb +++ b/plugins/chat/spec/system/channel_message_upload_spec.rb @@ -28,12 +28,12 @@ RSpec.describe "Channel message selection", type: :system do chat.visit_channel(channel_1) find(".chat-message-collapser-button").click - expect(page).to have_css(".chat-message-collapser-body.hidden", visible: false) + expect(page).to have_css(".chat-message-collapser-body.hidden", visible: :hidden) find(".chat-message-collapser-button").click expect(page).to have_no_css(".chat-message-collapser-body.hidden") find(".chat-img-upload").click # visible false is because the upload doesn’t exist but it's enough to know lightbox is working - expect(page).to have_css(".mfp-image-holder img[src*='#{image.url}']", visible: false) + expect(page).to have_css(".mfp-image-holder img[src*='#{image.url}']", visible: :hidden) end end diff --git a/plugins/discourse-narrative-bot/lib/discourse_narrative_bot/advanced_user_narrative.rb b/plugins/discourse-narrative-bot/lib/discourse_narrative_bot/advanced_user_narrative.rb index be66ba9ff77..65012aa2885 100644 --- a/plugins/discourse-narrative-bot/lib/discourse_narrative_bot/advanced_user_narrative.rb +++ b/plugins/discourse-narrative-bot/lib/discourse_narrative_bot/advanced_user_narrative.rb @@ -181,10 +181,6 @@ module DiscourseNarrativeBot archetype: Archetype.private_message, } - if @post && @post.topic.private_message? && - @post.topic.topic_allowed_users.pluck(:user_id).include?(@user.id) - end - if @data[:topic_id] opts = opts.merge(topic_id: @data[:topic_id]).except(:title, :target_usernames, :archetype) end diff --git a/plugins/poll/lib/polls_updater.rb b/plugins/poll/lib/polls_updater.rb index 22c74fd8104..6c9a370b675 100644 --- a/plugins/poll/lib/polls_updater.rb +++ b/plugins/poll/lib/polls_updater.rb @@ -67,7 +67,9 @@ module DiscoursePoll ) post.errors.add(:base, error) + # rubocop:disable Lint/NonLocalExitFromIterator return + # rubocop:enable Lint/NonLocalExitFromIterator end end diff --git a/script/bulk_import/base.rb b/script/bulk_import/base.rb index 1f78e54d258..cc4b607fb1d 100644 --- a/script/bulk_import/base.rb +++ b/script/bulk_import/base.rb @@ -14,7 +14,6 @@ if ARGV.include?("bbcode-to-md") end require "pg" -require "set" require "redcarpet" require "htmlentities" @@ -29,8 +28,6 @@ class BulkImport::Base NOW ||= "now()" PRIVATE_OFFSET ||= 2**30 - # rubocop:disable Layout/HashAlignment - CHARSET_MAP = { "armscii8" => nil, "ascii" => Encoding::US_ASCII, @@ -70,8 +67,6 @@ class BulkImport::Base "utf8" => Encoding::UTF_8, } - # rubocop:enable Layout/HashAlignment - def initialize charset = ENV["DB_CHARSET"] || "utf8" db = ActiveRecord::Base.connection_db_config.configuration_hash diff --git a/script/bulk_import/vbulletin.rb b/script/bulk_import/vbulletin.rb index b836338a516..6428b79cb1f 100644 --- a/script/bulk_import/vbulletin.rb +++ b/script/bulk_import/vbulletin.rb @@ -1,7 +1,6 @@ # frozen_string_literal: true require_relative "base" -require "set" require "mysql2" require "htmlentities" require "parallel" diff --git a/script/bulk_import/vbulletin5.rb b/script/bulk_import/vbulletin5.rb index e952ab5d764..d7dba8c680f 100644 --- a/script/bulk_import/vbulletin5.rb +++ b/script/bulk_import/vbulletin5.rb @@ -2,7 +2,6 @@ require_relative "base" require "cgi" -require "set" require "mysql2" require "htmlentities" require "ruby-bbcode-to-md" diff --git a/script/diff_heaps.rb b/script/diff_heaps.rb index 8433773d7f5..8c390e3c31f 100644 --- a/script/diff_heaps.rb +++ b/script/diff_heaps.rb @@ -6,7 +6,6 @@ # rbtrace -p 15193 -e 'Thread.new{require "objspace"; ObjectSpace.trace_object_allocations_start; GC.start(full_mark: true); ObjectSpace.dump_all(output: File.open("heap.json","w"))}.join' # # -require "set" require "json" if ARGV.length != 2 diff --git a/script/import_scripts/bbpress.rb b/script/import_scripts/bbpress.rb index 9fa95b0c50c..c5eecf9b03e 100644 --- a/script/import_scripts/bbpress.rb +++ b/script/import_scripts/bbpress.rb @@ -139,7 +139,7 @@ class ImportScripts::Bbpress < ImportScripts::Base # make sure every user name has a unique email address anon_names.each do |k, name| if not emails.include? name["email"] - emails.push (name["email"]) + emails.push(name["email"]) else name["email"] = "anonymous_#{SecureRandom.hex}@no-email.invalid" end diff --git a/script/import_scripts/getsatisfaction.rb b/script/import_scripts/getsatisfaction.rb index 0458c84f946..2bc6585f86e 100644 --- a/script/import_scripts/getsatisfaction.rb +++ b/script/import_scripts/getsatisfaction.rb @@ -23,7 +23,6 @@ # You should run `rake posts:reorder_posts` after the import. require "csv" -require "set" require File.expand_path(File.dirname(__FILE__) + "/base.rb") require "reverse_markdown" # gem 'reverse_markdown' diff --git a/script/import_scripts/google_groups.rb b/script/import_scripts/google_groups.rb index 1b6fa4b420a..3f04bec872d 100755 --- a/script/import_scripts/google_groups.rb +++ b/script/import_scripts/google_groups.rb @@ -12,7 +12,6 @@ end require "fileutils" require "optparse" -require "set" require "yaml" DEFAULT_OUTPUT_PATH = "/shared/import/data" diff --git a/script/import_scripts/ipboard.rb b/script/import_scripts/ipboard.rb index 4f5c5ed0bd4..8555387a48b 100644 --- a/script/import_scripts/ipboard.rb +++ b/script/import_scripts/ipboard.rb @@ -620,7 +620,7 @@ class ImportScripts::IpboardSQL < ImportScripts::Base if DEBUG raw = "Gallery ID: #{last_id}\n" + clean_up(gallery["raw"]) raw += - "Cat: #{last_gallery["category"].to_s} - #{category_id_from_imported_category_id(last_gallery["category"].to_s + "gal")}" + "Cat: #{last_gallery["category"]} - #{category_id_from_imported_category_id(last_gallery["category"].to_s + "gal")}" end raw += "#{clean_up(images.first["description"])}\n" raw += "### #{gallery["caption"]}\n" @@ -628,7 +628,7 @@ class ImportScripts::IpboardSQL < ImportScripts::Base raw += "#{UPLOADS}/#{gallery["orig"]}\n" gallery_count += 1 unless QUIET - puts "#{gallery_count}--Cat: #{last_gallery["category"].to_s} ==> #{category_id_from_imported_category_id(last_gallery["category"].to_s + "gal")}" + puts "#{gallery_count}--Cat: #{last_gallery["category"]} ==> #{category_id_from_imported_category_id(last_gallery["category"].to_s + "gal")}" end { id: "gallery#" + last_gallery["tid"].to_s + last_gallery["image_id"].to_s, diff --git a/script/import_scripts/mybb.rb b/script/import_scripts/mybb.rb index 10061d63e96..28dc1b0b089 100644 --- a/script/import_scripts/mybb.rb +++ b/script/import_scripts/mybb.rb @@ -93,7 +93,7 @@ class ImportScripts::MyBB < ImportScripts::Base UserAvatar.import_url_for_user(avatar, newuser) else filename = File.join(UPLOADS_DIR, avatar) - @uploader.create_avatar(newuser, filename) if File.exists?(filename) + @uploader.create_avatar(newuser, filename) if File.exist?(filename) end end end, @@ -300,7 +300,7 @@ class ImportScripts::MyBB < ImportScripts::Base ccf = cat.custom_fields count += 1 next unless id = ccf["import_id"] - puts ("forum-#{id}.html --> /c/#{cat.id}") unless QUIET + puts("forum-#{id}.html --> /c/#{cat.id}") unless QUIET begin Permalink.create(url: "#{BASE}/forum-#{id}.html", category_id: cat.id) rescue StandardError @@ -340,7 +340,7 @@ class ImportScripts::MyBB < ImportScripts::Base nil end unless QUIET - puts ("#{BASE}/thread-#{id}.html --> http://localhost:3000/t/#{topic[:topic_id]}") + puts("#{BASE}/thread-#{id}.html --> http://localhost:3000/t/#{topic[:topic_id]}") end print_status(count, total_posts, start_time) end diff --git a/script/import_scripts/mylittleforum.rb b/script/import_scripts/mylittleforum.rb index 5f3fce06579..4509f37c8c5 100644 --- a/script/import_scripts/mylittleforum.rb +++ b/script/import_scripts/mylittleforum.rb @@ -158,7 +158,7 @@ class ImportScripts::MylittleforumSQL < ImportScripts::Base username.gsub!(/[._]+/, "_") # can't have 2 special in a row username.gsub!(/_+/, "_") # could result in dupes, but wtf? username.gsub!(/_$/, "") # could result in dupes, but wtf? - print_warning ("#{olduser} --> #{username}") if olduser != username + print_warning("#{olduser} --> #{username}") if olduser != username username end diff --git a/script/import_scripts/sfn.rb b/script/import_scripts/sfn.rb index e10c9c1b0aa..9f371110e36 100644 --- a/script/import_scripts/sfn.rb +++ b/script/import_scripts/sfn.rb @@ -11,10 +11,6 @@ class ImportScripts::Sfn < ImportScripts::Base BATCH_SIZE = 100_000 MIN_CREATED_AT = "2003-11-01" - def initialize - super - end - def execute load_external_users import_users diff --git a/script/import_scripts/smf2.rb b/script/import_scripts/smf2.rb index 287b5a8af0d..defa13292f6 100644 --- a/script/import_scripts/smf2.rb +++ b/script/import_scripts/smf2.rb @@ -6,7 +6,6 @@ require File.expand_path(File.dirname(__FILE__) + "/base.rb") require "htmlentities" require "tsort" -require "set" require "optparse" require "etc" require "open3" @@ -369,7 +368,7 @@ class ImportScripts::Smf2 < ImportScripts::Base end body.gsub!(XListPattern) do |s| r = +"\n[ul]" - s.lines.each { |l| "#{r}[li]#{l.strip.sub(/^\[x\]\s*/, "")}[/li]" } + s.lines.each { |l| r += "[li]#{l.strip.sub(/^\[x\]\s*/, "")}[/li]" } "#{r}[/ul]\n" end diff --git a/script/import_scripts/socialcast/import.rb b/script/import_scripts/socialcast/import.rb index c20237f66ce..da36461a54f 100644 --- a/script/import_scripts/socialcast/import.rb +++ b/script/import_scripts/socialcast/import.rb @@ -2,7 +2,6 @@ require_relative "./socialcast_message.rb" require_relative "./socialcast_user.rb" -require "set" require File.expand_path(File.dirname(__FILE__) + "/../base.rb") class ImportScripts::Socialcast < ImportScripts::Base diff --git a/script/import_scripts/socialcast/title.rb b/script/import_scripts/socialcast/title.rb index 9f2c3dd82d5..e24b3f4519a 100644 --- a/script/import_scripts/socialcast/title.rb +++ b/script/import_scripts/socialcast/title.rb @@ -2,7 +2,6 @@ require_relative "./socialcast_message.rb" require_relative "./socialcast_user.rb" -require "set" require File.expand_path(File.dirname(__FILE__) + "/../base.rb") MESSAGES_DIR = "output/messages" diff --git a/script/import_scripts/support/convert_mysql_xml_to_mysql.rb b/script/import_scripts/support/convert_mysql_xml_to_mysql.rb index 070bfb41232..1089f517c3a 100644 --- a/script/import_scripts/support/convert_mysql_xml_to_mysql.rb +++ b/script/import_scripts/support/convert_mysql_xml_to_mysql.rb @@ -4,7 +4,6 @@ # require "ox" -require "set" class Saxy < Ox::Sax def initialize diff --git a/script/import_scripts/zendesk_api.rb b/script/import_scripts/zendesk_api.rb index ae9d948413d..9b111dffa8e 100644 --- a/script/import_scripts/zendesk_api.rb +++ b/script/import_scripts/zendesk_api.rb @@ -382,7 +382,6 @@ class ImportScripts::ZendeskApi < ImportScripts::Base html else puts "Error creating image upload" - "![](#{$1})" exit end end diff --git a/script/memory-analysis b/script/memory-analysis index 894436bf71c..84e47676aa3 100755 --- a/script/memory-analysis +++ b/script/memory-analysis @@ -5,7 +5,6 @@ require 'fileutils' require 'pathname' require 'tmpdir' require 'json' -require 'set' def usage STDERR.puts "Usage: memory-analysis [PID|DUMPFILE]" diff --git a/spec/fabricators/user_profile_fabricator.rb b/spec/fabricators/user_profile_fabricator.rb index ada2483eebe..0e4aed5ebcf 100644 --- a/spec/fabricators/user_profile_fabricator.rb +++ b/spec/fabricators/user_profile_fabricator.rb @@ -5,4 +5,4 @@ Fabricator(:user_profile) do user end -Fabricator(:user_profile_long, from: :user_profile) { bio_raw ("trout" * 1000) } +Fabricator(:user_profile_long, from: :user_profile) { bio_raw("trout" * 1000) } diff --git a/spec/integration/facebook_omniauth_spec.rb b/spec/integration/facebook_omniauth_spec.rb index 5f596af6eec..fefa91e60e4 100644 --- a/spec/integration/facebook_omniauth_spec.rb +++ b/spec/integration/facebook_omniauth_spec.rb @@ -6,7 +6,7 @@ describe "Facebook OAuth2" do let(:app_secret) { "adddcccdddd99922" } let(:temp_code) { "facebook_temp_code_544254" } let(:appsecret_proof) do - OpenSSL::HMAC.hexdigest(OpenSSL::Digest::SHA256.new, app_secret, access_token) + OpenSSL::HMAC.hexdigest(OpenSSL::Digest.new("SHA256"), app_secret, access_token) end fab!(:user1) { Fabricate(:user) } diff --git a/spec/jobs/bump_topic_spec.rb b/spec/jobs/bump_topic_spec.rb index ecd65ec9336..753f6b54bb4 100644 --- a/spec/jobs/bump_topic_spec.rb +++ b/spec/jobs/bump_topic_spec.rb @@ -8,11 +8,11 @@ RSpec.describe Jobs::BumpTopic do topic = Fabricate(:topic_timer, user: admin).topic create_post(topic: topic) - freeze_time (2.hours.from_now) + freeze_time(2.hours.from_now) expect do described_class.new.execute(topic_timer_id: topic.public_topic_timer.id) - end.to change { topic.posts.count }.by (1) + end.to change { topic.posts.count }.by(1) expect(topic.reload.public_topic_timer).to eq(nil) end @@ -23,11 +23,11 @@ RSpec.describe Jobs::BumpTopic do topic.category = Fabricate(:private_category, group: Fabricate(:group)) topic.save! - freeze_time (2.hours.from_now) + freeze_time(2.hours.from_now) expect do described_class.new.execute(topic_timer_id: topic.public_topic_timer.id) - end.to change { topic.posts.count }.by (0) + end.not_to change { topic.posts.count } expect(topic.reload.public_topic_timer).to eq(nil) end diff --git a/spec/jobs/delete_replies_spec.rb b/spec/jobs/delete_replies_spec.rb index 6f464c18b51..7dfb7b62b22 100644 --- a/spec/jobs/delete_replies_spec.rb +++ b/spec/jobs/delete_replies_spec.rb @@ -20,7 +20,7 @@ RSpec.describe Jobs::DeleteReplies do it "can delete replies of a topic" do SiteSetting.skip_auto_delete_reply_likes = 0 - freeze_time (2.days.from_now) + freeze_time(2.days.from_now) expect { described_class.new.execute(topic_timer_id: topic_timer.id) }.to change { topic.posts.count @@ -33,7 +33,7 @@ RSpec.describe Jobs::DeleteReplies do it "does not delete posts with likes over the threshold" do SiteSetting.skip_auto_delete_reply_likes = 3 - freeze_time (2.days.from_now) + freeze_time(2.days.from_now) topic.posts.last.update!(like_count: SiteSetting.skip_auto_delete_reply_likes + 1) diff --git a/spec/jobs/delete_topic_spec.rb b/spec/jobs/delete_topic_spec.rb index 7aa9b29bd31..21f82329987 100644 --- a/spec/jobs/delete_topic_spec.rb +++ b/spec/jobs/delete_topic_spec.rb @@ -10,7 +10,7 @@ RSpec.describe Jobs::DeleteTopic do it "can delete a topic" do first_post - freeze_time (2.hours.from_now) + freeze_time(2.hours.from_now) described_class.new.execute(topic_timer_id: topic.public_topic_timer.id) expect(topic.reload).to be_trashed diff --git a/spec/jobs/enqueue_digest_emails_spec.rb b/spec/jobs/enqueue_digest_emails_spec.rb index 681060b9a60..abe1802d2d2 100644 --- a/spec/jobs/enqueue_digest_emails_spec.rb +++ b/spec/jobs/enqueue_digest_emails_spec.rb @@ -161,7 +161,7 @@ RSpec.describe Jobs::EnqueueDigestEmails do expect { Jobs::EnqueueDigestEmails.new.execute(nil) }.to change( Jobs::UserEmail.jobs, :size, - ).by (1) + ).by(1) end # The job didn't actually run, so fake the user_stat update @@ -171,7 +171,7 @@ RSpec.describe Jobs::EnqueueDigestEmails do expect { Jobs::EnqueueDigestEmails.new.execute(nil) }.to change( Jobs::UserEmail.jobs, :size, - ).by (1) + ).by(1) end user1.user_stat.update(digest_attempted_at: Time.zone.now) diff --git a/spec/jobs/invite_email_spec.rb b/spec/jobs/invite_email_spec.rb index 17b41f34aa5..05a93636f20 100644 --- a/spec/jobs/invite_email_spec.rb +++ b/spec/jobs/invite_email_spec.rb @@ -7,9 +7,7 @@ RSpec.describe Jobs::InviteEmail do end context "with an invite id" do - let (:mailer) { - Mail::Message.new(to: "eviltrout@test.domain") - } + let(:mailer) { Mail::Message.new(to: "eviltrout@test.domain") } fab!(:invite) it "delegates to the test mailer" do diff --git a/spec/jobs/problem_check_spec.rb b/spec/jobs/problem_check_spec.rb index 1f879a4bbb3..80108ad593d 100644 --- a/spec/jobs/problem_check_spec.rb +++ b/spec/jobs/problem_check_spec.rb @@ -92,7 +92,6 @@ RSpec.describe Jobs::ProblemCheck do it "handles errors from a troublesome check" do AdminDashboardData.add_scheduled_problem_check(:test_identifier, TestCheck) do raise StandardError.new("something went wrong") - AdminDashboardData::Problem.new("polling issue") end described_class.new.execute(check_identifier: :test_identifier) diff --git a/spec/jobs/process_shelved_notifications_spec.rb b/spec/jobs/process_shelved_notifications_spec.rb index f1dbbbc6ea9..575e1b4b9c5 100644 --- a/spec/jobs/process_shelved_notifications_spec.rb +++ b/spec/jobs/process_shelved_notifications_spec.rb @@ -10,7 +10,7 @@ RSpec.describe Jobs::ProcessShelvedNotifications do future = Fabricate(:do_not_disturb_timing, ends_at: 1.day.from_now) past = Fabricate(:do_not_disturb_timing, starts_at: 2.day.ago, ends_at: 1.minute.ago) - expect { job.execute({}) }.to change { DoNotDisturbTiming.count }.by (-1) + expect { job.execute({}) }.to change { DoNotDisturbTiming.count }.by(-1) expect(DoNotDisturbTiming.find_by(id: future.id)).to eq(future) expect(DoNotDisturbTiming.find_by(id: past.id)).to eq(nil) end diff --git a/spec/lib/auth/default_current_user_provider_spec.rb b/spec/lib/auth/default_current_user_provider_spec.rb index 9893401e3cc..12559647e9f 100644 --- a/spec/lib/auth/default_current_user_provider_spec.rb +++ b/spec/lib/auth/default_current_user_provider_spec.rb @@ -8,9 +8,6 @@ RSpec.describe Auth::DefaultCurrentUserProvider do class TestProvider < Auth::DefaultCurrentUserProvider attr_reader :env - def initialize(env) - super(env) - end def cookie_jar @cookie_jar ||= ActionDispatch::Request.new(env).cookie_jar diff --git a/spec/lib/content_security_policy_spec.rb b/spec/lib/content_security_policy_spec.rb index c6c6cdc5b39..f542340f12e 100644 --- a/spec/lib/content_security_policy_spec.rb +++ b/spec/lib/content_security_policy_spec.rb @@ -205,7 +205,6 @@ RSpec.describe ContentSecurityPolicy do end it "includes all EmbeddableHost" do - EmbeddableHost frame_ancestors = parse(policy)["frame-ancestors"] expect(frame_ancestors).to include("https://a.org") expect(frame_ancestors).to include("https://b.org") diff --git a/spec/lib/discourse_spec.rb b/spec/lib/discourse_spec.rb index 7448b88b3a1..13edcda3a9c 100644 --- a/spec/lib/discourse_spec.rb +++ b/spec/lib/discourse_spec.rb @@ -451,7 +451,7 @@ RSpec.describe Discourse do it "works for individual commands" do expect(Discourse::Utils.execute_command("pwd").strip).to eq(Rails.root.to_s) expect(Discourse::Utils.execute_command("pwd", chdir: "plugins").strip).to eq( - "#{Rails.root.to_s}/plugins", + "#{Rails.root}/plugins", ) end @@ -477,12 +477,12 @@ RSpec.describe Discourse do result = Discourse::Utils.execute_command(chdir: "plugins") do |runner| - expect(runner.exec("pwd").strip).to eq("#{Rails.root.to_s}/plugins") + expect(runner.exec("pwd").strip).to eq("#{Rails.root}/plugins") runner.exec("pwd") end # Should return output of block - expect(result.strip).to eq("#{Rails.root.to_s}/plugins") + expect(result.strip).to eq("#{Rails.root}/plugins") end it "does not leak chdir between threads" do diff --git a/spec/lib/discourse_updates_spec.rb b/spec/lib/discourse_updates_spec.rb index 5411c95b6e7..e23b4dc6fac 100644 --- a/spec/lib/discourse_updates_spec.rb +++ b/spec/lib/discourse_updates_spec.rb @@ -191,9 +191,9 @@ RSpec.describe DiscourseUpdates do it "correctly sees newly added features as unseen" do DiscourseUpdates.mark_new_features_as_seen(admin.id) expect(DiscourseUpdates.has_unseen_features?(admin.id)).to eq(false) - expect(DiscourseUpdates.new_features_last_seen(admin.id)).to be_within(1.second).of ( - last_item_date - ) + expect(DiscourseUpdates.new_features_last_seen(admin.id)).to be_within(1.second).of( + last_item_date, + ) updated_features = [ { "emoji" => "🤾", "title" => "Brand New Item", "created_at" => 2.minutes.ago }, diff --git a/spec/lib/email/authentication_results_spec.rb b/spec/lib/email/authentication_results_spec.rb index d8cdcc54519..2794674f162 100644 --- a/spec/lib/email/authentication_results_spec.rb +++ b/spec/lib/email/authentication_results_spec.rb @@ -269,19 +269,19 @@ RSpec.describe Email::AuthenticationResults do it "enqueues a fail verdict" do results = described_class.new("") results.expects(:verdict).returns(:fail) - expect(results.action).to eq (:enqueue) + expect(results.action).to eq(:enqueue) end it "accepts a pass verdict" do results = described_class.new("") results.expects(:verdict).returns(:pass) - expect(results.action).to eq (:accept) + expect(results.action).to eq(:accept) end it "accepts a gray verdict" do results = described_class.new("") results.expects(:verdict).returns(:gray) - expect(results.action).to eq (:accept) + expect(results.action).to eq(:accept) end end end diff --git a/spec/lib/email/receiver_spec.rb b/spec/lib/email/receiver_spec.rb index 5313fcb10e2..497d6d7be38 100644 --- a/spec/lib/email/receiver_spec.rb +++ b/spec/lib/email/receiver_spec.rb @@ -2298,8 +2298,7 @@ RSpec.describe Email::Receiver do let(:user) { Fabricate(:user) } let(:group) { Fabricate(:group, users: [user]) } - let (:email_1) { - <<~EMAIL + let(:email_1) { <<~EMAIL } MIME-Version: 1.0 Date: Wed, 01 Jan 2019 12:00:00 +0200 Message-ID: <7aN1uwcokt2xkfG3iYrpKmiuVhy4w9b5@mail.gmail.com> @@ -2318,9 +2317,8 @@ RSpec.describe Email::Receiver do libero quis, congue viverra sapien. Nulla sodales ac tellus a suscipit. EMAIL - } - let (:post_2) { + let(:post_2) do incoming_email = IncomingEmail.find_by(message_id: "7aN1uwcokt2xkfG3iYrpKmiuVhy4w9b5@mail.gmail.com") @@ -2330,10 +2328,9 @@ RSpec.describe Email::Receiver do "Vestibulum rutrum tortor vitae arcu varius, non vestibulum ipsum tempor. Integer nibh libero, dignissim eu velit vel, interdum posuere mi. Aliquam erat volutpat. Pellentesque id nulla ultricies, eleifend ipsum non, fringilla purus. Aliquam pretium dolor lobortis urna volutpat, vel consectetur arcu porta. In non erat quis nibh gravida pharetra consequat vel risus. Aliquam rutrum consectetur est ac posuere. Praesent mattis nunc risus, a molestie lectus accumsan porta.", topic_id: incoming_email.topic_id, ) - } + end - let (:email_3) { - <<~EMAIL + let(:email_3) { <<~EMAIL } MIME-Version: 1.0 Date: Wed, 01 Jan 2019 12:00:00 +0200 References: <7aN1uwcokt2xkfG3iYrpKmiuVhy4w9b5@mail.gmail.com> @@ -2357,7 +2354,6 @@ RSpec.describe Email::Receiver do iaculis mi, at hendrerit nisi turpis sit amet metus. Nulla egestas ante eget nisi luctus consectetur. EMAIL - } def receive(email_string) Email::Receiver.new(email_string, destinations: [group]).process! diff --git a/spec/lib/guardian_spec.rb b/spec/lib/guardian_spec.rb index 4143c5839ee..a3b471463e8 100644 --- a/spec/lib/guardian_spec.rb +++ b/spec/lib/guardian_spec.rb @@ -1389,9 +1389,7 @@ RSpec.describe Guardian do end describe "a Post" do - let (:guardian) do - Guardian.new(user) - end + let(:guardian) { Guardian.new(user) } it "isn't allowed when not logged in" do expect(Guardian.new(nil).post_can_act?(post, :vote)).to be_falsey @@ -2519,7 +2517,6 @@ RSpec.describe Guardian do end let(:other_users_post_action) do - user.id = user.id post.id = 1 a = diff --git a/spec/lib/onebox/engine/google_maps_onebox_spec.rb b/spec/lib/onebox/engine/google_maps_onebox_spec.rb index 1a6fc66f36a..7332990dbf0 100644 --- a/spec/lib/onebox/engine/google_maps_onebox_spec.rb +++ b/spec/lib/onebox/engine/google_maps_onebox_spec.rb @@ -78,7 +78,7 @@ RSpec.describe Onebox::Engine::GoogleMapsOnebox do include_context "an engine", urltype: :short URLS.each do |kind, t| - it "processes #{kind.to_s} url correctly", urltype: kind do + it "processes #{kind} url correctly", urltype: kind do expect(onebox.url).to eq t[:expect] expect(onebox.streetview?).to t[:streetview] ? be_truthy : be_falsey expect(onebox.to_html).to include(" [old_category_id, category.id] }) + expect(revision.modifications).to eq({ "category_id" => [old_category_id, category.id] }) end it "doesn't do anything when category stays the same" do diff --git a/spec/lib/validators/password_validator_spec.rb b/spec/lib/validators/password_validator_spec.rb index ce27c633a8d..2248efbe5a4 100644 --- a/spec/lib/validators/password_validator_spec.rb +++ b/spec/lib/validators/password_validator_spec.rb @@ -2,7 +2,7 @@ RSpec.describe PasswordValidator do def password_error_message(key) - I18n.t("activerecord.errors.models.user.attributes.password.#{key.to_s}") + I18n.t("activerecord.errors.models.user.attributes.password.#{key}") end subject(:validate) { validator.validate_each(record, :password, @password) } diff --git a/spec/mailers/rejection_mailer_spec.rb b/spec/mailers/rejection_mailer_spec.rb index aa132d26fc7..841766df8cd 100644 --- a/spec/mailers/rejection_mailer_spec.rb +++ b/spec/mailers/rejection_mailer_spec.rb @@ -3,15 +3,13 @@ RSpec.describe RejectionMailer do describe "send_rejection" do context "when sending rejection email" do - fab! (:user) { - Fabricate(:user) - } - let (:template_args) { + fab!(:user) { Fabricate(:user) } + let(:template_args) do { former_title: "Mail Subject", destination: user.email, site_name: SiteSetting.title } - } - let (:reject_mail) { + end + let(:reject_mail) do RejectionMailer.send_rejection("email_reject_topic_not_found", user.email, template_args) - } + end it "renders the senders email" do expect(reject_mail.to).to eql([user.email]) diff --git a/spec/models/report_spec.rb b/spec/models/report_spec.rb index 19fe0f58d45..4d8c30cd715 100644 --- a/spec/models/report_spec.rb +++ b/spec/models/report_spec.rb @@ -61,32 +61,28 @@ RSpec.describe Report do ] # 60 complete days: - 30 - .times - .each_with_object(application_requests) do |i| - application_requests.concat( - [ - { - date: (i + 1).days.ago.to_time, - req_type: ApplicationRequest.req_types["http_total"], - count: 10, - }, - ], - ) - end - 30 - .times - .each_with_object(application_requests) do |i| - application_requests.concat( - [ - { - date: (31 + i).days.ago.to_time, - req_type: ApplicationRequest.req_types["http_total"], - count: 100, - }, - ], - ) - end + 30.times.each do |i| + application_requests.concat( + [ + { + date: (i + 1).days.ago.to_time, + req_type: ApplicationRequest.req_types["http_total"], + count: 10, + }, + ], + ) + end + 30.times.each do |i| + application_requests.concat( + [ + { + date: (31 + i).days.ago.to_time, + req_type: ApplicationRequest.req_types["http_total"], + count: 100, + }, + ], + ) + end ApplicationRequest.insert_all(application_requests) end @@ -1333,7 +1329,6 @@ RSpec.describe Report do expect(page_view_anon_report[:color]).to eql("#9BC53D") expect(page_view_anon_report[:data][0][:y]).to eql(1) - ensure end end end @@ -1378,7 +1373,6 @@ RSpec.describe Report do expect(user_api_report[:color]).to eql("#9BC53D") expect(user_api_report[:data][0][:y]).to eql(1) - ensure end end end diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index a2d2e18319c..dd83e36b74c 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -49,7 +49,6 @@ class RspecErrorTracker RspecErrorTracker.last_exception = e raise e end - ensure end end diff --git a/spec/requests/admin/themes_controller_spec.rb b/spec/requests/admin/themes_controller_spec.rb index 6e8f8561330..0277703fb29 100644 --- a/spec/requests/admin/themes_controller_spec.rb +++ b/spec/requests/admin/themes_controller_spec.rb @@ -133,7 +133,7 @@ RSpec.describe Admin::ThemesController do expect do post "/admin/themes/import.json", params: { theme: uploaded_file } expect(response.status).to eq(201) - end.to change { Theme.count }.by (1) + end.to change { Theme.count }.by(1) json = response.parsed_body @@ -319,9 +319,9 @@ RSpec.describe Admin::ThemesController do it "fails to import with an error if uploads are not allowed" do SiteSetting.theme_authorized_extensions = "nothing" - expect do post "/admin/themes/import.json", params: { theme: theme_archive } end.to change { - Theme.count - }.by (0) + expect do + post "/admin/themes/import.json", params: { theme: theme_archive } + end.not_to change { Theme.count } expect(response.status).to eq(422) end @@ -331,7 +331,7 @@ RSpec.describe Admin::ThemesController do expect do post "/admin/themes/import.json", params: { theme: theme_archive } end.to change { Theme.count - }.by (1) + }.by(1) expect(response.status).to eq(201) json = response.parsed_body @@ -354,7 +354,7 @@ RSpec.describe Admin::ThemesController do bundle: theme_archive, theme_id: other_existing_theme.id, } - end.to change { Theme.count }.by (0) + end.not_to change { Theme.count } end expect(response.status).to eq(201) json = response.parsed_body @@ -377,7 +377,7 @@ RSpec.describe Admin::ThemesController do expect do post "/admin/themes/import.json", params: { bundle: theme_archive, theme_id: nil } - end.to change { Theme.count }.by (1) + end.to change { Theme.count }.by(1) expect(response.status).to eq(201) json = response.parsed_body diff --git a/spec/requests/metadata_controller_spec.rb b/spec/requests/metadata_controller_spec.rb index fac857601c3..15c9525e8ee 100644 --- a/spec/requests/metadata_controller_spec.rb +++ b/spec/requests/metadata_controller_spec.rb @@ -1,5 +1,4 @@ # frozen_string_literal: true -# rubocop:disable Discourse/NoJsonParseResponse RSpec.describe MetadataController do describe "manifest.webmanifest" do diff --git a/spec/requests/sitemap_controller_spec.rb b/spec/requests/sitemap_controller_spec.rb index bdb108163d9..308090c85c4 100644 --- a/spec/requests/sitemap_controller_spec.rb +++ b/spec/requests/sitemap_controller_spec.rb @@ -50,7 +50,7 @@ RSpec.describe SitemapController do end describe "#page" do - before { Discourse.cache.delete("sitemap/#{1}/#{SiteSetting.sitemap_page_size}") } + before { Discourse.cache.delete("sitemap/1/#{SiteSetting.sitemap_page_size}") } it "returns a 404 if the sitemap doesn't exist" do get "/sitemap_999.xml" diff --git a/spec/requests/static_controller_spec.rb b/spec/requests/static_controller_spec.rb index 2f6d13553f0..849faff7ca7 100644 --- a/spec/requests/static_controller_spec.rb +++ b/spec/requests/static_controller_spec.rb @@ -58,9 +58,7 @@ RSpec.describe StaticController do end describe "#cdn_asset" do - let (:site) { - RailsMultisite::ConnectionManagement.current_db - } + let(:site) { RailsMultisite::ConnectionManagement.current_db } it "can serve assets" do begin diff --git a/spec/requests/users_controller_spec.rb b/spec/requests/users_controller_spec.rb index 8275ddd95a8..9c10ad4d875 100644 --- a/spec/requests/users_controller_spec.rb +++ b/spec/requests/users_controller_spec.rb @@ -312,7 +312,7 @@ RSpec.describe UsersController do params: { password: "hg9ow8yhg98oadminlonger", } - end.to change { UserHistory.count }.by (1) + end.to change { UserHistory.count }.by(1) user_history = UserHistory.last expect(user_history.target_user_id).to eq(user1.id) @@ -836,15 +836,9 @@ RSpec.describe UsersController do end context "when normalize_emails is enabled" do - let (:email) { - "jane+100@gmail.com" - } - let (:dupe_email) { - "jane+191@gmail.com" - } - let! (:user) { - Fabricate(:user, email: email, password: "strongpassword") - } + let(:email) { "jane+100@gmail.com" } + let(:dupe_email) { "jane+191@gmail.com" } + let!(:user) { Fabricate(:user, email: email, password: "strongpassword") } before do SiteSetting.hide_email_address_taken = true diff --git a/spec/serializers/post_serializer_spec.rb b/spec/serializers/post_serializer_spec.rb index 70bf416fa7f..f984c71e2a8 100644 --- a/spec/serializers/post_serializer_spec.rb +++ b/spec/serializers/post_serializer_spec.rb @@ -94,7 +94,7 @@ RSpec.describe PostSerializer do expect(serializer[:user_suspended]).to eq(true) - freeze_time (2.months.from_now) + freeze_time(2.months.from_now) expect(serializer[:user_suspended]).to be_nil end diff --git a/spec/services/destroy_task_spec.rb b/spec/services/destroy_task_spec.rb index 4bf4d11e89f..e4fccb804d8 100644 --- a/spec/services/destroy_task_spec.rb +++ b/spec/services/destroy_task_spec.rb @@ -16,7 +16,7 @@ RSpec.describe DestroyTask do destroy_task = DestroyTask.new(StringIO.new) expect { destroy_task.destroy_topics(c.slug) }.to change { Topic.where(category_id: c.id).count - }.by (-1) + }.by(-1) end it "destroys all topics in a sub category" do @@ -55,7 +55,7 @@ RSpec.describe DestroyTask do expect { destroy_task.destroy_category(c.id) }.to change { Category.where(id: c.id).count - }.by (-1) + }.by(-1) end it "destroys sub-categories when destroying parent category" do @@ -63,7 +63,7 @@ RSpec.describe DestroyTask do expect { destroy_task.destroy_category(c2.id) }.to change { Category.where(id: sc.id).count - }.by (-1) + }.by(-1) end end diff --git a/spec/services/inline_uploads_multisite_spec.rb b/spec/services/inline_uploads_multisite_spec.rb index dc7f9ecc30d..f616cf70042 100644 --- a/spec/services/inline_uploads_multisite_spec.rb +++ b/spec/services/inline_uploads_multisite_spec.rb @@ -18,10 +18,10 @@ RSpec.describe InlineUploads, type: :multisite do it "should correct image URLs in multisite" do md = <<~MD https:#{upload2.url} https:#{upload2.url} - #{URI.join(SiteSetting.s3_cdn_url, URI.parse(upload2.url).path).to_s} + #{URI.join(SiteSetting.s3_cdn_url, URI.parse(upload2.url).path)} some image - some image + some image MD diff --git a/spec/services/inline_uploads_spec.rb b/spec/services/inline_uploads_spec.rb index 412ed7c7606..dcc0d42fabd 100644 --- a/spec/services/inline_uploads_spec.rb +++ b/spec/services/inline_uploads_spec.rb @@ -673,7 +673,7 @@ RSpec.describe InlineUploads do #{upload.url} some image testsome imagetest - some image + some image MD expect(InlineUploads.process(md)).to eq(<<~MD) diff --git a/spec/services/user_merger_spec.rb b/spec/services/user_merger_spec.rb index f5ad015cbe5..cdff8552a9f 100644 --- a/spec/services/user_merger_spec.rb +++ b/spec/services/user_merger_spec.rb @@ -133,8 +133,8 @@ RSpec.describe UserMerger do end it "merges drafts" do - key_topic_17 = "#{Draft::EXISTING_TOPIC}#{17}" - key_topic_19 = "#{Draft::EXISTING_TOPIC}#{19}" + key_topic_17 = "#{Draft::EXISTING_TOPIC}17" + key_topic_19 = "#{Draft::EXISTING_TOPIC}19" create_draft(source_user, Draft::NEW_TOPIC, "new topic draft by alice1") create_draft(source_user, key_topic_17, "draft by alice1") diff --git a/spec/support/concurrency.rb b/spec/support/concurrency.rb index b0f7a514a96..2ef8d6b80e1 100644 --- a/spec/support/concurrency.rb +++ b/spec/support/concurrency.rb @@ -1,7 +1,5 @@ # frozen_string_literal: true -require "fiber" - module Concurrency module Logic class DeadEnd < StandardError diff --git a/spec/system/editing_sidebar_tags_navigation_spec.rb b/spec/system/editing_sidebar_tags_navigation_spec.rb index ed0e8de4be1..59e153e0fd3 100644 --- a/spec/system/editing_sidebar_tags_navigation_spec.rb +++ b/spec/system/editing_sidebar_tags_navigation_spec.rb @@ -181,7 +181,7 @@ RSpec.describe "Editing sidebar tags navigation", type: :system do Tag.delete_all tags = - (TagsController::LIST_LIMIT + 50).times.map.with_index do |index| + (TagsController::LIST_LIMIT + 50).times.map do |index| Fabricate(:tag, name: "Tag #{sprintf("%03d", index)}") end diff --git a/spec/system/s3_uploads_spec.rb b/spec/system/s3_uploads_spec.rb index 71cdc10b77e..66e98e40475 100644 --- a/spec/system/s3_uploads_spec.rb +++ b/spec/system/s3_uploads_spec.rb @@ -27,7 +27,7 @@ describe "Uploading files in the composer to S3", type: :system do expect(modal).to be_closed expect(page).to have_css( "#user-avatar-uploads[data-custom-avatar-upload-id]", - visible: false, + visible: :hidden, ) expect(current_user.reload.uploaded_avatar_id).to eq( find("#user-avatar-uploads", visible: false)["data-custom-avatar-upload-id"].to_i, diff --git a/spec/system/viewing_sidebar_mobile_spec.rb b/spec/system/viewing_sidebar_mobile_spec.rb index b3182c53e99..5519c4f70be 100644 --- a/spec/system/viewing_sidebar_mobile_spec.rb +++ b/spec/system/viewing_sidebar_mobile_spec.rb @@ -59,14 +59,14 @@ describe "Viewing sidebar mobile", type: :system, mobile: true do end it "toggles to desktop view after clicking on the toggle to desktop view button" do - visit ("/latest") + visit("/latest") expect(page).to have_css(".mobile-view") sidebar_dropdown.click sidebar_dropdown.click_toggle_to_desktop_view_button - visit ("/latest") + visit("/latest") expect(page).to have_css(".desktop-view") end