Skip to content

A platform for community discussion. Free, open, simple.

DEV: Update to lastest rubocop-discourse

Loïc Guitaut2a28cda15c4a
diff --git a/.github/workflows/migration-tests.yml b/.github/workflows/migration-tests.yml
index 246cf3d5eac..07d443f055f 100644
--- a/.github/workflows/migration-tests.yml
+++ b/.github/workflows/migration-tests.yml
@@ -164,6 +164,10 @@ jobs:
with:
fetch-depth: 1
+ - name: Modify path for libpq
+ if: matrix.os == 'macos-latest'
+ run: echo "/opt/homebrew/opt/libpq/bin" >> $GITHUB_PATH
+
- name: Setup Ruby
uses: ruby/setup-ruby@v1
with:
diff --git a/Gemfile.lock b/Gemfile.lock
index f28b4e5df98..76544cbb942 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -429,14 +429,20 @@ GEM
parser (>= 3.3.1.0)
rubocop-capybara (2.20.0)
rubocop (~> 1.41)
- rubocop-discourse (3.7.1)
+ rubocop-discourse (3.8.0)
activesupport (>= 6.1)
rubocop (>= 1.59.0)
rubocop-capybara (>= 2.0.0)
rubocop-factory_bot (>= 2.0.0)
+ rubocop-rails (>= 2.25.0)
rubocop-rspec (>= 2.25.0)
rubocop-factory_bot (2.25.1)
rubocop (~> 1.41)
+ rubocop-rails (2.25.0)
+ activesupport (>= 4.2.0)
+ rack (>= 1.1)
+ rubocop (>= 1.33.0, < 2.0)
+ rubocop-ast (>= 1.31.1, < 2.0)
rubocop-rspec (2.29.2)
rubocop (~> 1.40)
rubocop-capybara (~> 2.17)
diff --git a/app/controllers/admin/email_templates_controller.rb b/app/controllers/admin/email_templates_controller.rb
index f1050e885c3..c4241e4d180 100644
--- a/app/controllers/admin/email_templates_controller.rb
+++ b/app/controllers/admin/email_templates_controller.rb
@@ -73,7 +73,7 @@ class Admin::EmailTemplatesController < Admin::AdminController
def update
et = params[:email_template]
key = params[:id]
- raise Discourse::NotFound unless self.class.email_keys.include?(params[:id])
+ raise Discourse::NotFound if self.class.email_keys.exclude?(params[:id])
subject_result = update_key("#{key}.subject_template", et[:subject])
body_result = update_key("#{key}.text_body_template", et[:body])
@@ -110,7 +110,7 @@ class Admin::EmailTemplatesController < Admin::AdminController
def revert
key = params[:id]
- raise Discourse::NotFound unless self.class.email_keys.include?(params[:id])
+ raise Discourse::NotFound if self.class.email_keys.exclude?(params[:id])
revert_and_log("#{key}.subject_template", "#{key}.text_body_template")
render_serialized(
diff --git a/app/controllers/admin/groups_controller.rb b/app/controllers/admin/groups_controller.rb
index bcc17c9fcc3..341c7cc13cd 100644
--- a/app/controllers/admin/groups_controller.rb
+++ b/app/controllers/admin/groups_controller.rb
@@ -137,7 +137,7 @@ class Admin::GroupsController < Admin::StaffController
notify_users
]
custom_fields = DiscoursePluginRegistry.editable_group_custom_fields
- permitted << { custom_fields: custom_fields } unless custom_fields.blank?
+ permitted << { custom_fields: custom_fields } if custom_fields.present?
permitted << { associated_group_ids: [] } if guardian.can_associate_groups?
diff --git a/app/controllers/admin/themes_controller.rb b/app/controllers/admin/themes_controller.rb
index 16c1c50729b..045cc6de0b6 100644
--- a/app/controllers/admin/themes_controller.rb
+++ b/app/controllers/admin/themes_controller.rb
@@ -279,7 +279,7 @@ class Admin::ThemesController < Admin::AdminController
def bulk_destroy
themes = Theme.where(id: params[:theme_ids])
- raise Discourse::InvalidParameters.new(:id) unless themes.present?
+ raise Discourse::InvalidParameters.new(:id) if themes.blank?
ActiveRecord::Base.transaction do
themes.each { |theme| StaffActionLogger.new(current_user).log_theme_destroy(theme) }
@@ -313,7 +313,7 @@ class Admin::ThemesController < Admin::AdminController
def get_translations
params.require(:locale)
- unless I18n.available_locales.include?(params[:locale].to_sym)
+ if I18n.available_locales.exclude?(params[:locale].to_sym)
raise Discourse::InvalidParameters.new(:locale)
end
@@ -445,7 +445,7 @@ class Admin::ThemesController < Admin::AdminController
locale = theme_params[:locale].presence
if locale
- unless I18n.available_locales.include?(locale.to_sym)
+ if I18n.available_locales.exclude?(locale.to_sym)
raise Discourse::InvalidParameters.new(:locale)
end
I18n.locale = locale
diff --git a/app/controllers/admin/users_controller.rb b/app/controllers/admin/users_controller.rb
index 01ef6bb0728..1338cd63f46 100644
--- a/app/controllers/admin/users_controller.rb
+++ b/app/controllers/admin/users_controller.rb
@@ -619,7 +619,7 @@ class Admin::UsersController < Admin::StaffController
private
def perform_post_action
- return unless params[:post_id].present? && params[:post_action].present?
+ return if params[:post_id].blank? || params[:post_action].blank?
if post = Post.where(id: params[:post_id]).first
case params[:post_action]
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb
index 7406d3d4c18..4767cdd11fe 100644
--- a/app/controllers/application_controller.rb
+++ b/app/controllers/application_controller.rb
@@ -837,7 +837,7 @@ class ApplicationController < ActionController::Base
end
def ensure_logged_in
- raise Discourse::NotLoggedIn.new unless current_user.present?
+ raise Discourse::NotLoggedIn.new if current_user.blank?
end
def ensure_staff
diff --git a/app/controllers/categories_controller.rb b/app/controllers/categories_controller.rb
index 03cacb920da..b6ac1017ea4 100644
--- a/app/controllers/categories_controller.rb
+++ b/app/controllers/categories_controller.rb
@@ -269,7 +269,7 @@ class CategoriesController < ApplicationController
@category =
Category.includes(:category_setting).find_by_slug_path(params[:category_slug].split("/"))
- raise Discourse::NotFound unless @category.present?
+ raise Discourse::NotFound if @category.blank?
if !guardian.can_see?(@category)
if SiteSetting.detailed_404 && group = @category.access_category_via_group
diff --git a/app/controllers/embed_controller.rb b/app/controllers/embed_controller.rb
index 952b2a58a9d..8974e4be1b6 100644
--- a/app/controllers/embed_controller.rb
+++ b/app/controllers/embed_controller.rb
@@ -144,7 +144,7 @@ class EmbedController < ApplicationController
topic_embeds.each do |te|
url = te.embed_url
- url = "#{url}#discourse-comments" unless params[:embed_url].include?(url)
+ url = "#{url}#discourse-comments" if params[:embed_url].exclude?(url)
if te.topic.present?
by_url[url] = I18n.t("embed.replies", count: te.topic.posts_count - 1)
else
diff --git a/app/controllers/finish_installation_controller.rb b/app/controllers/finish_installation_controller.rb
index cdc6d8990f2..d584710ff86 100644
--- a/app/controllers/finish_installation_controller.rb
+++ b/app/controllers/finish_installation_controller.rb
@@ -15,7 +15,7 @@ class FinishInstallationController < ApplicationController
@user = User.new
if request.post?
email = params[:email].strip
- raise Discourse::InvalidParameters.new unless @allowed_emails.include?(email)
+ raise Discourse::InvalidParameters.new if @allowed_emails.exclude?(email)
if existing_user = User.find_by_email(email)
@user = existing_user
diff --git a/app/controllers/list_controller.rb b/app/controllers/list_controller.rb
index d650d18519e..139c5eeac41 100644
--- a/app/controllers/list_controller.rb
+++ b/app/controllers/list_controller.rb
@@ -145,7 +145,7 @@ class ListController < ApplicationController
def category_default
canonical_url "#{Discourse.base_url_no_prefix}#{@category.url}"
view_method = @category.default_view
- view_method = "latest" unless %w[latest top].include?(view_method)
+ view_method = "latest" if %w[latest top].exclude?(view_method)
self.public_send(view_method, category: @category.id)
end
diff --git a/app/controllers/metadata_controller.rb b/app/controllers/metadata_controller.rb
index 0e6eda9c366..7a1fffb7dc7 100644
--- a/app/controllers/metadata_controller.rb
+++ b/app/controllers/metadata_controller.rb
@@ -15,13 +15,13 @@ class MetadataController < ApplicationController
end
def app_association_android
- raise Discourse::NotFound unless SiteSetting.app_association_android.present?
+ raise Discourse::NotFound if SiteSetting.app_association_android.blank?
expires_in 1.minutes
render plain: SiteSetting.app_association_android, content_type: "application/json"
end
def app_association_ios
- raise Discourse::NotFound unless SiteSetting.app_association_ios.present?
+ raise Discourse::NotFound if SiteSetting.app_association_ios.blank?
expires_in 1.minutes
render plain: SiteSetting.app_association_ios, content_type: "application/json"
end
diff --git a/app/controllers/posts_controller.rb b/app/controllers/posts_controller.rb
index 39d84c88b3c..6585ed2ae4b 100644
--- a/app/controllers/posts_controller.rb
+++ b/app/controllers/posts_controller.rb
@@ -477,7 +477,7 @@ class PostsController < ApplicationController
post = find_post_from_params
raise Discourse::InvalidParameters.new(:post) if post.blank?
- raise Discourse::NotFound unless post.revisions.present?
+ raise Discourse::NotFound if post.revisions.blank?
RateLimiter.new(
current_user,
diff --git a/app/controllers/reviewables_controller.rb b/app/controllers/reviewables_controller.rb
index 455cb1ed554..ced8d1f215d 100644
--- a/app/controllers/reviewables_controller.rb
+++ b/app/controllers/reviewables_controller.rb
@@ -16,7 +16,7 @@ class ReviewablesController < ApplicationController
end
status = (params[:status] || "pending").to_sym
- raise Discourse::InvalidParameters.new(:status) unless allowed_statuses.include?(status)
+ raise Discourse::InvalidParameters.new(:status) if allowed_statuses.exclude?(status)
topic_id = params[:topic_id] ? params[:topic_id].to_i : nil
category_id = params[:category_id] ? params[:category_id].to_i : nil
@@ -185,7 +185,7 @@ class ReviewablesController < ApplicationController
end
editable = reviewable.editable_for(guardian)
- raise Discourse::InvalidAccess.new unless editable.present?
+ raise Discourse::InvalidAccess.new if editable.blank?
# Validate parameters are all editable
edit_params = params[:reviewable] || {}
diff --git a/app/controllers/search_controller.rb b/app/controllers/search_controller.rb
index 521e52b6f13..8de199f6af2 100644
--- a/app/controllers/search_controller.rb
+++ b/app/controllers/search_controller.rb
@@ -220,7 +220,7 @@ class SearchController < ApplicationController
end
if search_context.present?
- unless SearchController.valid_context_types.include?(search_context[:type])
+ if SearchController.valid_context_types.exclude?(search_context[:type])
raise Discourse::InvalidParameters.new(:search_context)
end
raise Discourse::InvalidParameters.new(:search_context) if search_context[:id].blank?
diff --git a/app/controllers/tags_controller.rb b/app/controllers/tags_controller.rb
index dae4b9790ec..10b105acc2c 100644
--- a/app/controllers/tags_controller.rb
+++ b/app/controllers/tags_controller.rb
@@ -231,7 +231,7 @@ class TagsController < ::ApplicationController
if tag_group_name
tag_group =
TagGroup.find_by(name: tag_group_name) || TagGroup.create!(name: tag_group_name)
- tag.tag_groups << tag_group unless tag.tag_groups.include?(tag_group)
+ tag.tag_groups << tag_group if tag.tag_groups.exclude?(tag_group)
end
end
end
diff --git a/app/controllers/theme_javascripts_controller.rb b/app/controllers/theme_javascripts_controller.rb
index f311ebfe391..6706db2cbe0 100644
--- a/app/controllers/theme_javascripts_controller.rb
+++ b/app/controllers/theme_javascripts_controller.rb
@@ -15,7 +15,7 @@ class ThemeJavascriptsController < ApplicationController
before_action :is_asset_path, :no_cookies, :apply_cdn_headers, only: %i[show show_map show_tests]
def show
- raise Discourse::NotFound unless last_modified.present?
+ raise Discourse::NotFound if last_modified.blank?
return render body: nil, status: 304 if not_modified?
# Security: safe due to route constraint
@@ -34,7 +34,7 @@ class ThemeJavascriptsController < ApplicationController
end
def show_map
- raise Discourse::NotFound unless last_modified.present?
+ raise Discourse::NotFound if last_modified.blank?
return render body: nil, status: 304 if not_modified?
# Security: safe due to route constraint
diff --git a/app/controllers/topics_controller.rb b/app/controllers/topics_controller.rb
index e706cec7d56..0123a065184 100644
--- a/app/controllers/topics_controller.rb
+++ b/app/controllers/topics_controller.rb
@@ -1394,7 +1394,7 @@ class TopicsController < ApplicationController
end
def check_for_status_presence(key, attr)
- invalid_param(key) unless %w[pinned pinned_globally visible closed archived].include?(attr)
+ invalid_param(key) if %w[pinned pinned_globally visible closed archived].exclude?(attr)
end
def invalid_param(key)
diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb
index c842b8731b5..c4b4d38bd02 100644
--- a/app/controllers/users_controller.rb
+++ b/app/controllers/users_controller.rb
@@ -1143,7 +1143,7 @@ class UsersController < ApplicationController
1.hour,
).performed!
@user = User.find_by_username_or_email(params[:username])
- raise Discourse::InvalidAccess.new unless @user.present?
+ raise Discourse::InvalidAccess.new if @user.blank?
raise Discourse::InvalidAccess.new unless @user.confirm_password?(params[:password])
elsif user_key = session[SessionController::ACTIVATE_USER_KEY]
RateLimiter.new(nil, "activate-edit-email-hr-user-key-#{user_key}", 5, 1.hour).performed!
@@ -1342,9 +1342,7 @@ class UsersController < ApplicationController
return render json: failed_json, status: 422
end
- unless SiteSetting.selectable_avatars.include?(upload)
- return render json: failed_json, status: 422
- end
+ return render json: failed_json, status: 422 if SiteSetting.selectable_avatars.exclude?(upload)
user.uploaded_avatar_id = upload.id
@@ -2096,7 +2094,7 @@ class UsersController < ApplicationController
]
editable_custom_fields = User.editable_user_custom_fields(by_staff: current_user.try(:staff?))
- permitted << { custom_fields: editable_custom_fields } unless editable_custom_fields.blank?
+ permitted << { custom_fields: editable_custom_fields } if editable_custom_fields.present?
permitted.concat UserUpdater::OPTION_ATTR
permitted.concat UserUpdater::CATEGORY_IDS.keys.map { |k| { k => [] } }
permitted.concat UserUpdater::TAG_NAMES.keys
diff --git a/app/helpers/user_notifications_helper.rb b/app/helpers/user_notifications_helper.rb
index deb40425015..381bd197796 100644
--- a/app/helpers/user_notifications_helper.rb
+++ b/app/helpers/user_notifications_helper.rb
@@ -45,7 +45,7 @@ module UserNotificationsHelper
end
end
- return result unless result.blank?
+ return result if result.present?
# If there is no first paragraph with text, return the first paragraph with
# something else (an image) or div (a onebox).
@@ -66,7 +66,7 @@ module UserNotificationsHelper
def show_username_on_post(post)
return true unless SiteSetting.enable_names?
return true unless SiteSetting.display_name_on_posts?
- return true unless post.user.name.present?
+ return true if post.user.name.blank?
normalize_name(post.user.name) != normalize_name(post.user.username)
end
diff --git a/app/jobs/onceoff/onceoff.rb b/app/jobs/onceoff/onceoff.rb
index efbc0ae5f5e..a8a75421468 100644
--- a/app/jobs/onceoff/onceoff.rb
+++ b/app/jobs/onceoff/onceoff.rb
@@ -36,7 +36,7 @@ class Jobs::Onceoff < ::Jobs::Base
.select { |klass| klass < self }
.each do |klass|
job_name = name_for(klass)
- Jobs.enqueue(job_name.underscore.to_sym) unless previously_ran.include?(job_name)
+ Jobs.enqueue(job_name.underscore.to_sym) if previously_ran.exclude?(job_name)
end
end
end
diff --git a/app/jobs/regular/change_display_name.rb b/app/jobs/regular/change_display_name.rb
index 2c1aea46f80..d087defd6a8 100644
--- a/app/jobs/regular/change_display_name.rb
+++ b/app/jobs/regular/change_display_name.rb
@@ -11,7 +11,7 @@ module Jobs
def execute(args)
@user = User.find_by(id: args[:user_id])
- return unless user.present?
+ return if user.blank?
# We need to account for the case where the instance allows
# name to be empty by falling back to username.
diff --git a/app/jobs/regular/crawl_topic_link.rb b/app/jobs/regular/crawl_topic_link.rb
index 40cf4f86474..a6241d380ba 100644
--- a/app/jobs/regular/crawl_topic_link.rb
+++ b/app/jobs/regular/crawl_topic_link.rb
@@ -9,7 +9,7 @@ module Jobs
sidekiq_options queue: "low"
def execute(args)
- raise Discourse::InvalidParameters.new(:topic_link_id) unless args[:topic_link_id].present?
+ raise Discourse::InvalidParameters.new(:topic_link_id) if args[:topic_link_id].blank?
topic_link = TopicLink.find_by(id: args[:topic_link_id], internal: false, crawled_at: nil)
return if topic_link.blank?
diff --git a/app/jobs/regular/create_linked_topic.rb b/app/jobs/regular/create_linked_topic.rb
index f5edca6efce..c26bf7c7db1 100644
--- a/app/jobs/regular/create_linked_topic.rb
+++ b/app/jobs/regular/create_linked_topic.rb
@@ -4,7 +4,7 @@ module Jobs
class CreateLinkedTopic < ::Jobs::Base
def execute(args)
reference_post = Post.find_by(id: args[:post_id])
- return unless reference_post.present?
+ return if reference_post.blank?
parent_topic = reference_post.topic
return unless parent_topic.present? && parent_topic.regular?
parent_topic_id = parent_topic.id
diff --git a/app/jobs/regular/create_user_reviewable.rb b/app/jobs/regular/create_user_reviewable.rb
index 5d4a69fbded..346f9d69688 100644
--- a/app/jobs/regular/create_user_reviewable.rb
+++ b/app/jobs/regular/create_user_reviewable.rb
@@ -4,7 +4,7 @@ class Jobs::CreateUserReviewable < ::Jobs::Base
attr_reader :reviewable
def execute(args)
- raise Discourse::InvalidParameters unless args[:user_id].present?
+ raise Discourse::InvalidParameters if args[:user_id].blank?
reason = nil
reason ||= :must_approve_users if SiteSetting.must_approve_users?
diff --git a/app/jobs/regular/emit_web_hook_event.rb b/app/jobs/regular/emit_web_hook_event.rb
index 74c097cff79..bb26403fb09 100644
--- a/app/jobs/regular/emit_web_hook_event.rb
+++ b/app/jobs/regular/emit_web_hook_event.rb
@@ -38,7 +38,7 @@ module Jobs
end
def validate_argument!(key)
- raise Discourse::InvalidParameters.new(key) unless @arguments[key].present?
+ raise Discourse::InvalidParameters.new(key) if @arguments[key].blank?
end
def send_webhook!
diff --git a/app/jobs/regular/feature_topic_users.rb b/app/jobs/regular/feature_topic_users.rb
index 83266c725b2..234d3fec30f 100644
--- a/app/jobs/regular/feature_topic_users.rb
+++ b/app/jobs/regular/feature_topic_users.rb
@@ -4,14 +4,14 @@ module Jobs
class FeatureTopicUsers < ::Jobs::Base
def execute(args)
topic_id = args[:topic_id]
- raise Discourse::InvalidParameters.new(:topic_id) unless topic_id.present?
+ raise Discourse::InvalidParameters.new(:topic_id) if topic_id.blank?
topic = Topic.find_by(id: topic_id)
# Topic may be hard deleted due to spam, no point complaining
# we would have to look at the topics table id sequence to find cases
# where this was called with an invalid id, no point really
- return unless topic.present?
+ return if topic.blank?
topic.feature_topic_users(args)
end
diff --git a/app/jobs/regular/invite_email.rb b/app/jobs/regular/invite_email.rb
index ad33a9ee5ce..6b81d621b35 100644
--- a/app/jobs/regular/invite_email.rb
+++ b/app/jobs/regular/invite_email.rb
@@ -4,10 +4,10 @@ module Jobs
# Asynchronously send an email
class InviteEmail < ::Jobs::Base
def execute(args)
- raise Discourse::InvalidParameters.new(:invite_id) unless args[:invite_id].present?
+ raise Discourse::InvalidParameters.new(:invite_id) if args[:invite_id].blank?
invite = Invite.find_by(id: args[:invite_id])
- return unless invite.present?
+ return if invite.blank?
message = InviteMailer.send_invite(invite, invite_to_topic: args[:invite_to_topic])
Email::Sender.new(message, :invite).send
diff --git a/app/jobs/regular/invite_password_instructions_email.rb b/app/jobs/regular/invite_password_instructions_email.rb
index 8989772ba8d..e861aa67475 100644
--- a/app/jobs/regular/invite_password_instructions_email.rb
+++ b/app/jobs/regular/invite_password_instructions_email.rb
@@ -4,7 +4,7 @@ module Jobs
# Asynchronously send an email
class InvitePasswordInstructionsEmail < ::Jobs::Base
def execute(args)
- raise Discourse::InvalidParameters.new(:username) unless args[:username].present?
+ raise Discourse::InvalidParameters.new(:username) if args[:username].blank?
user = User.find_by_username_or_email(args[:username])
message = InviteMailer.send_password_instructions(user)
Email::Sender.new(message, :invite_password_instructions).send
diff --git a/app/jobs/regular/notify_moved_posts.rb b/app/jobs/regular/notify_moved_posts.rb
index d97b52f2168..41179209014 100644
--- a/app/jobs/regular/notify_moved_posts.rb
+++ b/app/jobs/regular/notify_moved_posts.rb
@@ -17,7 +17,7 @@ module Jobs
moved_by = User.find_by(id: args[:moved_by_id])
posts.each do |p|
- unless users_notified.include?(p.user_id)
+ if users_notified.exclude?(p.user_id)
p.user.notifications.create(
notification_type: Notification.types[:moved_post],
topic_id: p.topic_id,
diff --git a/app/jobs/regular/process_post.rb b/app/jobs/regular/process_post.rb
index 976d2f75bbf..f51acb11ea0 100644
--- a/app/jobs/regular/process_post.rb
+++ b/app/jobs/regular/process_post.rb
@@ -8,7 +8,7 @@ module Jobs
DistributedMutex.synchronize("process_post_#{args[:post_id]}", validity: 10.minutes) do
post = Post.find_by(id: args[:post_id])
# two levels of deletion
- return unless post.present? && post.topic.present?
+ return if post.blank? || post.topic.blank?
orig_cooked = post.cooked
recooked = nil
diff --git a/app/jobs/regular/pull_hotlinked_images.rb b/app/jobs/regular/pull_hotlinked_images.rb
index 1bd41e71cf2..19e216f22e6 100644
--- a/app/jobs/regular/pull_hotlinked_images.rb
+++ b/app/jobs/regular/pull_hotlinked_images.rb
@@ -152,7 +152,7 @@ module Jobs
def should_download_image?(src, post = nil)
# make sure we actually have a url
- return false unless src.present?
+ return false if src.blank?
local_bases =
[Discourse.base_url, Discourse.asset_host, SiteSetting.external_emoji_url.presence].compact
diff --git a/app/jobs/regular/push_notification.rb b/app/jobs/regular/push_notification.rb
index 1459bebc2b8..c3d514e9df7 100644
--- a/app/jobs/regular/push_notification.rb
+++ b/app/jobs/regular/push_notification.rb
@@ -22,7 +22,7 @@ module Jobs
.each do |push_url, group|
notifications = group.map { |client_id, _| notification.merge(client_id: client_id) }
- next unless push_url.present?
+ next if push_url.blank?
result =
Excon.post(
diff --git a/app/jobs/regular/remove_banner.rb b/app/jobs/regular/remove_banner.rb
index a8c1405a688..6ef278e6d5f 100644
--- a/app/jobs/regular/remove_banner.rb
+++ b/app/jobs/regular/remove_banner.rb
@@ -5,7 +5,7 @@ module Jobs
def execute(args)
topic_id = args[:topic_id]
- return unless topic_id.present?
+ return if topic_id.blank?
topic = Topic.find_by(id: topic_id)
topic.remove_banner!(Discourse.system_user) if topic.present?
diff --git a/app/jobs/regular/retrieve_topic.rb b/app/jobs/regular/retrieve_topic.rb
index 5cdcd3496b0..e41d3119521 100644
--- a/app/jobs/regular/retrieve_topic.rb
+++ b/app/jobs/regular/retrieve_topic.rb
@@ -4,7 +4,7 @@ module Jobs
# Asynchronously retrieve a topic from an embedded site
class RetrieveTopic < ::Jobs::Base
def execute(args)
- raise Discourse::InvalidParameters.new(:embed_url) unless args[:embed_url].present?
+ raise Discourse::InvalidParameters.new(:embed_url) if args[:embed_url].blank?
user = nil
user = User.find_by(id: args[:user_id]) if args[:user_id]
diff --git a/app/jobs/regular/send_system_message.rb b/app/jobs/regular/send_system_message.rb
index 2ee6559dca6..7ea4cbe3b11 100644
--- a/app/jobs/regular/send_system_message.rb
+++ b/app/jobs/regular/send_system_message.rb
@@ -5,8 +5,8 @@ require "image_sizer"
module Jobs
class SendSystemMessage < ::Jobs::Base
def execute(args)
- raise Discourse::InvalidParameters.new(:user_id) unless args[:user_id].present?
- raise Discourse::InvalidParameters.new(:message_type) unless args[:message_type].present?
+ raise Discourse::InvalidParameters.new(:user_id) if args[:user_id].blank?
+ raise Discourse::InvalidParameters.new(:message_type) if args[:message_type].blank?
user = User.find_by(id: args[:user_id])
return if user.blank?
diff --git a/app/jobs/regular/sync_topic_user_bookmarked.rb b/app/jobs/regular/sync_topic_user_bookmarked.rb
index 5c4aab6ca00..251bf8088e6 100644
--- a/app/jobs/regular/sync_topic_user_bookmarked.rb
+++ b/app/jobs/regular/sync_topic_user_bookmarked.rb
@@ -3,7 +3,7 @@
module Jobs
class SyncTopicUserBookmarked < ::Jobs::Base
def execute(args = {})
- raise Discourse::InvalidParameters.new(:topic_id) unless args[:topic_id].present?
+ raise Discourse::InvalidParameters.new(:topic_id) if args[:topic_id].blank?
DB.exec(<<~SQL, topic_id: args[:topic_id])
SELECT bookmarks.user_id, COUNT(*)
diff --git a/app/jobs/regular/truncate_user_flag_stats.rb b/app/jobs/regular/truncate_user_flag_stats.rb
index 95a00ede7d7..083cd2b7256 100644
--- a/app/jobs/regular/truncate_user_flag_stats.rb
+++ b/app/jobs/regular/truncate_user_flag_stats.rb
@@ -7,7 +7,7 @@ class Jobs::TruncateUserFlagStats < ::Jobs::Base
# To give users a chance to improve, we limit their flag stats to the last N flags
def execute(args)
- raise Discourse::InvalidParameters.new(:user_ids) unless args[:user_ids].present?
+ raise Discourse::InvalidParameters.new(:user_ids) if args[:user_ids].blank?
args[:user_ids].each do |u|
user_stat = UserStat.find_by(user_id: u)
diff --git a/app/jobs/regular/unpin_topic.rb b/app/jobs/regular/unpin_topic.rb
index 8e804b1a94d..ebf093e82fa 100644
--- a/app/jobs/regular/unpin_topic.rb
+++ b/app/jobs/regular/unpin_topic.rb
@@ -5,7 +5,7 @@ module Jobs
def execute(args)
topic_id = args[:topic_id]
- return unless topic_id.present?
+ return if topic_id.blank?
topic = Topic.find_by(id: topic_id)
topic.update_pinned(false) if topic.present?
diff --git a/app/jobs/regular/update_username.rb b/app/jobs/regular/update_username.rb
index df7cd667b11..98191a516f3 100644
--- a/app/jobs/regular/update_username.rb
+++ b/app/jobs/regular/update_username.rb
@@ -70,7 +70,7 @@ module Jobs
.with_deleted
.joins(quoted("posts.id"))
.where("p.user_id = :user_id", user_id: @user_id)
- .find_each { |post| update_post(post) unless updated_post_ids.include?(post.id) }
+ .find_each { |post| update_post(post) if updated_post_ids.exclude?(post.id) }
end
def update_revisions
diff --git a/app/jobs/regular/user_email.rb b/app/jobs/regular/user_email.rb
index 1f3f7f6801d..33fce796304 100644
--- a/app/jobs/regular/user_email.rb
+++ b/app/jobs/regular/user_email.rb
@@ -27,8 +27,8 @@ module Jobs
end
def execute(args)
- raise Discourse::InvalidParameters.new(:user_id) unless args[:user_id].present?
- raise Discourse::InvalidParameters.new(:type) unless args[:type].present?
+ raise Discourse::InvalidParameters.new(:user_id) if args[:user_id].blank?
+ raise Discourse::InvalidParameters.new(:type) if args[:type].blank?
# This is for performance. Quit out fast without doing a bunch
# of extra work when emails are disabled.
diff --git a/app/mailers/user_notifications.rb b/app/mailers/user_notifications.rb
index 01f90cbc022..724d9172afd 100644
--- a/app/mailers/user_notifications.rb
+++ b/app/mailers/user_notifications.rb
@@ -506,7 +506,7 @@ class UserNotifications < ActionMailer::Base
if post && SiteSetting.enable_names && SiteSetting.display_name_on_email_from
name = User.where(id: notification_data[:original_user_id] || post.user_id).pick(:name)
- user_name = name unless name.blank?
+ user_name = name if name.present?
end
allow_reply_by_email = opts[:allow_reply_by_email] unless user.suspended?
diff --git a/app/models/application_request.rb b/app/models/application_request.rb
index 8b7f966a56f..cb62c885c52 100644
--- a/app/models/application_request.rb
+++ b/app/models/application_request.rb
@@ -1,24 +1,24 @@
# frozen_string_literal: true
class ApplicationRequest < ActiveRecord::Base
- enum req_type: %i[
- http_total
- http_2xx
- http_background
- http_3xx
- http_4xx
- http_5xx
- page_view_crawler
- page_view_logged_in
- page_view_anon
- page_view_logged_in_mobile
- page_view_anon_mobile
- api
- user_api
- page_view_anon_browser
- page_view_anon_browser_mobile
- page_view_logged_in_browser
- page_view_logged_in_browser_mobile
- ]
+ enum req_type: {
+ http_total: 0,
+ http_2xx: 1,
+ http_background: 2,
+ http_3xx: 3,
+ http_4xx: 4,
+ http_5xx: 5,
+ page_view_crawler: 6,
+ page_view_logged_in: 7,
+ page_view_anon: 8,
+ page_view_logged_in_mobile: 9,
+ page_view_anon_mobile: 10,
+ api: 11,
+ user_api: 12,
+ page_view_anon_browser: 13,
+ page_view_anon_browser_mobile: 14,
+ page_view_logged_in_browser: 15,
+ page_view_logged_in_browser_mobile: 16,
+ }
include CachedCounting
diff --git a/app/models/category.rb b/app/models/category.rb
index b2fa9d56e05..8c562260cc6 100644
--- a/app/models/category.rb
+++ b/app/models/category.rb
@@ -542,7 +542,7 @@ class Category < ActiveRecord::Base
end
def ensure_slug
- return unless name.present?
+ return if name.blank?
self.name.strip!
@@ -948,7 +948,7 @@ class Category < ActiveRecord::Base
# If the name changes, try and update the category definition topic too if it's an exact match
def rename_category_definition
- return unless topic.present?
+ return if topic.blank?
old_name = saved_changes.transform_values(&:first)["name"]
if topic.title == I18n.t("category.topic_prefix", category: old_name)
topic.update_attribute(:title, I18n.t("category.topic_prefix", category: name))
diff --git a/app/models/directory_column.rb b/app/models/directory_column.rb
index 0722be0fd95..d13dd26b5d1 100644
--- a/app/models/directory_column.rb
+++ b/app/models/directory_column.rb
@@ -49,7 +49,7 @@ class DirectoryColumn < ActiveRecord::Base
column.enabled = false
end
- unless @@plugin_directory_columns.include?(directory_column.name)
+ if @@plugin_directory_columns.exclude?(directory_column.name)
@@plugin_directory_columns << directory_column.name
DirectoryItem.add_plugin_query(attrs[:query])
end
diff --git a/app/models/embeddable_host.rb b/app/models/embeddable_host.rb
index 90dcb85b123..734db1f591e 100644
--- a/app/models/embeddable_host.rb
+++ b/app/models/embeddable_host.rb
@@ -24,10 +24,10 @@ class EmbeddableHost < ActiveRecord::Base
end
end
- return false unless uri.present?
+ return false if uri.blank?
host = uri.host
- return false unless host.present?
+ return false if host.blank?
host << ":#{uri.port}" if uri.port.present? && uri.port != 80 && uri.port != 443
diff --git a/app/models/group.rb b/app/models/group.rb
index 6d10b189a23..445df74c5df 100644
--- a/app/models/group.rb
+++ b/app/models/group.rb
@@ -857,7 +857,7 @@ class Group < ActiveRecord::Base
end
def bulk_add(user_ids)
- return unless user_ids.present?
+ return if user_ids.blank?
Group.transaction do
sql = <<~SQL
diff --git a/app/models/group_history.rb b/app/models/group_history.rb
index 9f58072e581..016306738dd 100644
--- a/app/models/group_history.rb
+++ b/app/models/group_history.rb
@@ -33,13 +33,13 @@ class GroupHistory < ActiveRecord::Base
if !params.blank?
params = params.slice(*filters)
- records = records.where(action: self.actions[params[:action].to_sym]) unless params[
+ records = records.where(action: self.actions[params[:action].to_sym]) if params[
:action
- ].blank?
- records = records.where(subject: params[:subject]) unless params[:subject].blank?
+ ].present?
+ records = records.where(subject: params[:subject]) if params[:subject].present?
%i[acting_user target_user].each do |filter|
- unless params[filter].blank?
+ if params[filter].present?
id = User.where(username_lower: params[filter]).pluck(:id)
records = records.where("#{filter}_id" => id)
end
diff --git a/app/models/incoming_domain.rb b/app/models/incoming_domain.rb
index 94d56cecd9f..93e552a9b3b 100644
--- a/app/models/incoming_domain.rb
+++ b/app/models/incoming_domain.rb
@@ -3,7 +3,7 @@
class IncomingDomain < ActiveRecord::Base
def self.add!(uri)
name = uri.host
- return unless name.present?
+ return if name.blank?
https = uri.scheme == "https"
port = uri.port
diff --git a/app/models/incoming_link.rb b/app/models/incoming_link.rb
index 694ce06e503..a98d0adbba3 100644
--- a/app/models/incoming_link.rb
+++ b/app/models/incoming_link.rb
@@ -60,7 +60,7 @@ class IncomingLink < ActiveRecord::Base
self.incoming_referer_id = nil
# will set incoming_referer_id
- return unless referer.present?
+ return if referer.blank?
parsed = URI.parse(referer)
diff --git a/app/models/invite_redeemer.rb b/app/models/invite_redeemer.rb
index 31978978912..d5ff38f106a 100644
--- a/app/models/invite_redeemer.rb
+++ b/app/models/invite_redeemer.rb
@@ -129,7 +129,7 @@ class InviteRedeemer
field_val = field_params[f.id.to_s]
fields["#{User::USER_FIELD_PREFIX}#{f.id}"] = field_val[
0...UserField.max_length
- ] unless field_val.blank?
+ ] if field_val.present?
end
user.custom_fields = fields
end
diff --git a/app/models/post.rb b/app/models/post.rb
index 51f9f1ad1a7..e8ab24491b9 100644
--- a/app/models/post.rb
+++ b/app/models/post.rb
@@ -1326,14 +1326,14 @@ class Post < ActiveRecord::Base
private
def parse_quote_into_arguments(quote)
- return {} unless quote.present?
+ return {} if quote.blank?
args = HashWithIndifferentAccess.new
quote.first.scan(/([a-z]+)\:(\d+)/).each { |arg| args[arg[0]] = arg[1].to_i }
args
end
def add_to_quoted_post_numbers(num)
- return unless num.present?
+ return if num.blank?
self.quoted_post_numbers ||= []
self.quoted_post_numbers << num
end
diff --git a/app/models/post_analyzer.rb b/app/models/post_analyzer.rb
index a129f442d9e..a3a8d2e7e59 100644
--- a/app/models/post_analyzer.rb
+++ b/app/models/post_analyzer.rb
@@ -13,7 +13,7 @@ class PostAnalyzer
end
def has_oneboxes?
- return false unless @raw.present?
+ return false if @raw.blank?
cooked_stripped
found_oneboxes?
@@ -56,7 +56,7 @@ class PostAnalyzer
# How many images are present in the post
def embedded_media_count
- return 0 unless @raw.present?
+ return 0 if @raw.blank?
# TODO - do we need to look for tags other than img, video and audio?
cooked_stripped
@@ -71,7 +71,7 @@ class PostAnalyzer
# How many attachments are present in the post
def attachment_count
- return 0 unless @raw.present?
+ return 0 if @raw.blank?
attachments =
cooked_stripped.css("a.attachment[href^=\"#{Discourse.store.absolute_base_url}\"]")
@@ -119,7 +119,7 @@ class PostAnalyzer
# Returns an array of all links in a post excluding mentions
def raw_links
- return [] unless @raw.present?
+ return [] if @raw.blank?
return @raw_links if @raw_links.present?
@raw_links = []
diff --git a/app/models/post_mover.rb b/app/models/post_mover.rb
index 40dd4696768..cf16286bd15 100644
--- a/app/models/post_mover.rb
+++ b/app/models/post_mover.rb
@@ -676,7 +676,7 @@ class PostMover
end
def add_allowed_users(usernames)
- return unless usernames.present?
+ return if usernames.blank?
names = usernames.split(",").flatten
User
diff --git a/app/models/post_timing.rb b/app/models/post_timing.rb
index 3d5c2a0f611..69d74dacc76 100644
--- a/app/models/post_timing.rb
+++ b/app/models/post_timing.rb
@@ -207,7 +207,7 @@ SQL
new_posts_read = timings.size - existing.size if is_regular
timings.each_with_index do |(post_number, time), index|
- unless existing.include?(index)
+ if existing.exclude?(index)
PostTiming.record_new_timing(
topic_id: topic_id,
post_number: post_number,
diff --git a/app/models/reviewable.rb b/app/models/reviewable.rb
index 1dbe09130e2..aaaaa4263a5 100644
--- a/app/models/reviewable.rb
+++ b/app/models/reviewable.rb
@@ -62,7 +62,7 @@ class Reviewable < ActiveRecord::Base
end
def self.valid_type?(type)
- return false unless Reviewable.types.include?(type)
+ return false if Reviewable.types.exclude?(type)
type.constantize <= Reviewable
rescue NameError
false
@@ -383,7 +383,7 @@ class Reviewable < ActiveRecord::Base
end
def self.viewable_by(user, order: nil, preload: true)
- return none unless user.present?
+ return none if user.blank?
result = self.order(order || "reviewables.score desc, reviewables.created_at desc")
@@ -732,7 +732,7 @@ class Reviewable < ActiveRecord::Base
private
def update_flag_stats(status:, user_ids:)
- return unless %i[agreed disagreed ignored].include?(status)
+ return if %i[agreed disagreed ignored].exclude?(status)
# Don't count self-flags
user_ids -= [post&.user_id]
diff --git a/app/models/screened_ip_address.rb b/app/models/screened_ip_address.rb
index 136164ecb0a..d1f2311a85d 100644
--- a/app/models/screened_ip_address.rb
+++ b/app/models/screened_ip_address.rb
@@ -29,7 +29,7 @@ class ScreenedIpAddress < ActiveRecord::Base
end
def check_for_match
- unless self.errors[:ip_address].present?
+ if self.errors[:ip_address].blank?
matched = self.class.match_for_ip_address(self.ip_address)
if matched && matched.action_type == self.action_type
self.errors.add(:ip_address, :ip_address_already_screened)
diff --git a/app/models/search_log.rb b/app/models/search_log.rb
index b87231d63fa..46606367b2a 100644
--- a/app/models/search_log.rb
+++ b/app/models/search_log.rb
@@ -36,7 +36,7 @@ class SearchLog < ActiveRecord::Base
return [:error] if term.blank?
search_type = search_types[search_type]
- return [:error] unless search_type.present? && ip_address.present?
+ return [:error] if search_type.blank? || ip_address.blank?
ip_address = nil if user_id
key = redis_key(user_id: user_id, ip_address: ip_address)
diff --git a/app/models/tag.rb b/app/models/tag.rb
index 0d0b3917ef1..493339d06ec 100644
--- a/app/models/tag.rb
+++ b/app/models/tag.rb
@@ -233,10 +233,10 @@ class Tag < ActiveRecord::Base
def update_synonym_associations
if target_tag_id && saved_change_to_target_tag_id?
target_tag.tag_groups.each do |tag_group|
- tag_group.tags << self unless tag_group.tags.include?(self)
+ tag_group.tags << self if tag_group.tags.exclude?(self)
end
target_tag.categories.each do |category|
- category.tags << self unless category.tags.include?(self)
+ category.tags << self if category.tags.exclude?(self)
end
end
end
diff --git a/app/models/theme_field.rb b/app/models/theme_field.rb
index 5387c9a79da..c0c3682a516 100644
--- a/app/models/theme_field.rb
+++ b/app/models/theme_field.rb
@@ -23,7 +23,7 @@ class ThemeField < ActiveRecord::Base
scope :find_by_theme_ids,
->(theme_ids) do
- return none unless theme_ids.present?
+ return none if theme_ids.blank?
where(theme_id: theme_ids).joins(
"JOIN (
@@ -34,7 +34,7 @@ class ThemeField < ActiveRecord::Base
scope :filter_locale_fields,
->(locale_codes) do
- return none unless locale_codes.present?
+ return none if locale_codes.blank?
where(target_id: Theme.targets[:translations], name: locale_codes).joins(
DB.sql_fragment(
@@ -420,7 +420,7 @@ class ThemeField < ActiveRecord::Base
if basic_html_field? || translation_field?
self.value_baked, self.error =
translation_field? ? process_translation : process_html(self.value)
- self.error = nil unless self.error.present?
+ self.error = nil if self.error.blank?
self.compiler_version = Theme.compiler_version
CSP::Extension.clear_theme_extensions_cache!
elsif extra_js_field? || js_tests_field?
diff --git a/app/models/topic.rb b/app/models/topic.rb
index 4568d0c05c7..b5a13133f8c 100644
--- a/app/models/topic.rb
+++ b/app/models/topic.rb
@@ -1372,7 +1372,7 @@ class Topic < ActiveRecord::Base
self.slug_computed_callbacks = []
def slug_for_topic(title)
- return "" unless title.present?
+ return "" if title.blank?
slug = Slug.for(title)
# this is a hook for plugins that need to modify the generated slug
@@ -1384,7 +1384,7 @@ class Topic < ActiveRecord::Base
# Even if the slug column in the database is null, topic.slug will return something:
def slug
unless slug = read_attribute(:slug)
- return "" unless title.present?
+ return "" if title.blank?
slug = slug_for_topic(title)
if new_record?
write_attribute(:slug, slug)
@@ -1445,12 +1445,12 @@ class Topic < ActiveRecord::Base
end
def clear_pin_for(user)
- return unless user.present?
+ return if user.blank?
TopicUser.change(user.id, id, cleared_pinned_at: Time.now)
end
def re_pin_for(user)
- return unless user.present?
+ return if user.blank?
TopicUser.change(user.id, id, cleared_pinned_at: nil)
end
@@ -2062,7 +2062,7 @@ class Topic < ActiveRecord::Base
def self.publish_stats_to_clients!(topic_id, type, opts = {})
topic = Topic.find_by(id: topic_id)
- return unless topic.present?
+ return if topic.blank?
case type
when :liked, :unliked
diff --git a/app/models/topic_embed.rb b/app/models/topic_embed.rb
index 8d5263f8d02..0e67c1593bc 100644
--- a/app/models/topic_embed.rb
+++ b/app/models/topic_embed.rb
@@ -315,7 +315,7 @@ class TopicEmbed < ActiveRecord::Base
return result if result.size >= 100
end
end
- return result unless result.blank?
+ return result if result.present?
# If there is no first paragraph, return the first div (onebox)
doc.css("div").first.to_s
diff --git a/app/models/topic_link_click.rb b/app/models/topic_link_click.rb
index 8dde67f47f0..f1236c8c28b 100644
--- a/app/models/topic_link_click.rb
+++ b/app/models/topic_link_click.rb
@@ -86,7 +86,7 @@ class TopicLinkClick < ActiveRecord::Base
).first
# If no link is found...
- unless link.present?
+ if link.blank?
# ... return the url for relative links or when using the same host
return url if url =~ %r{\A/[^/]} || uri.try(:host) == Discourse.current_hostname
diff --git a/app/models/translation_override.rb b/app/models/translation_override.rb
index 23a81a1fbc1..0e891f793ff 100644
--- a/app/models/translation_override.rb
+++ b/app/models/translation_override.rb
@@ -45,7 +45,7 @@ class TranslationOverride < ActiveRecord::Base
validate :check_interpolation_keys
- enum :status, %i[up_to_date outdated invalid_interpolation_keys deprecated]
+ enum status: { up_to_date: 0, outdated: 1, invalid_interpolation_keys: 2, deprecated: 3 }
def self.upsert!(locale, key, value)
params = { locale: locale, translation_key: key }
diff --git a/app/models/user.rb b/app/models/user.rb
index 4932fce708f..cf8324981cb 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -898,7 +898,7 @@ class User < ActiveRecord::Base
def password=(password)
# special case for passwordless accounts
- @raw_password = password unless password.blank?
+ @raw_password = password if password.present?
end
def password
diff --git a/app/models/user_profile.rb b/app/models/user_profile.rb
index 5ee6ce6e9d8..af9af96fff7 100644
--- a/app/models/user_profile.rb
+++ b/app/models/user_profile.rb
@@ -203,7 +203,7 @@ class UserProfile < ActiveRecord::Base
URI.parse(self.website).host
rescue URI::Error
end
- unless allowed_domains.split("|").include?(domain)
+ if allowed_domains.split("|").exclude?(domain)
self.errors.add :base,
(
I18n.t(
diff --git a/app/serializers/reviewable_serializer.rb b/app/serializers/reviewable_serializer.rb
index 8bd59b8eec4..a454cbd89e5 100644
--- a/app/serializers/reviewable_serializer.rb
+++ b/app/serializers/reviewable_serializer.rb
@@ -49,7 +49,7 @@ class ReviewableSerializer < ApplicationSerializer
end
def claimed_by
- return nil unless @options[:claimed_topics].present?
+ return nil if @options[:claimed_topics].blank?
@options[:claimed_topics][object.topic_id]
end
diff --git a/app/serializers/user_auth_token_serializer.rb b/app/serializers/user_auth_token_serializer.rb
index 2fac32872ac..ffb287b47d0 100644
--- a/app/serializers/user_auth_token_serializer.rb
+++ b/app/serializers/user_auth_token_serializer.rb
@@ -15,7 +15,7 @@ class UserAuthTokenSerializer < ApplicationSerializer
end
def seen_at
- return object.created_at unless object.seen_at.present?
+ return object.created_at if object.seen_at.blank?
object.seen_at
end
diff --git a/app/services/anonymous_shadow_creator.rb b/app/services/anonymous_shadow_creator.rb
index 20340d5b988..362de36dabe 100644
--- a/app/services/anonymous_shadow_creator.rb
+++ b/app/services/anonymous_shadow_creator.rb
@@ -79,7 +79,7 @@ class AnonymousShadowCreator
def resolve_username
username = I18n.t("anonymous").downcase
- username = "anonymous" unless UserNameSuggester.sanitize_username(username).present?
+ username = "anonymous" if UserNameSuggester.sanitize_username(username).blank?
UserNameSuggester.suggest(username)
end
diff --git a/app/services/badge_granter.rb b/app/services/badge_granter.rb
index 07b9dc3eaeb..ab2c76b6edf 100644
--- a/app/services/badge_granter.rb
+++ b/app/services/badge_granter.rb
@@ -244,7 +244,7 @@ class BadgeGranter
post_ids = list.flat_map { |i| i["post_ids"] }.compact.uniq
user_ids = list.flat_map { |i| i["user_ids"] }.compact.uniq
- next unless post_ids.present? || user_ids.present?
+ next if post_ids.blank? && user_ids.blank?
find_by_type(type).each { |badge| backfill(badge, post_ids: post_ids, user_ids: user_ids) }
end
@@ -368,7 +368,7 @@ class BadgeGranter
end
if opts[:target_posts]
raise "Query did not return a post ID" unless result.post_id
- unless Post.exists?(result.post_id).present?
+ if Post.exists?(result.post_id).blank?
raise "Query returned a non-existent post ID:\n#{result.post_id}"
end
end
@@ -383,7 +383,7 @@ class BadgeGranter
def self.backfill(badge, opts = nil)
return unless SiteSetting.enable_badges
return unless badge.enabled
- return unless badge.query.present?
+ return if badge.query.blank?
post_ids = user_ids = nil
post_ids = opts[:post_ids] if opts
diff --git a/app/services/notification_emailer.rb b/app/services/notification_emailer.rb
index 951896d3965..4e9274cc068 100644
--- a/app/services/notification_emailer.rb
+++ b/app/services/notification_emailer.rb
@@ -108,7 +108,7 @@ class NotificationEmailer
return
end
- return unless EMAILABLE_POST_TYPES.include?(post_type)
+ return if EMAILABLE_POST_TYPES.exclude?(post_type)
Jobs.enqueue_in(delay, :user_email, self.class.notification_params(notification, type))
end
diff --git a/app/services/staff_action_logger.rb b/app/services/staff_action_logger.rb
index bed4cec1e46..7eb767919d8 100644
--- a/app/services/staff_action_logger.rb
+++ b/app/services/staff_action_logger.rb
@@ -318,7 +318,7 @@ class StaffActionLogger
end
def log_site_text_change(subject, new_text = nil, old_text = nil, opts = {})
- raise Discourse::InvalidParameters.new(:subject) unless subject.present?
+ raise Discourse::InvalidParameters.new(:subject) if subject.blank?
UserHistory.create!(
params(opts).merge(
action: UserHistory.actions[:change_site_text],
@@ -856,9 +856,7 @@ class StaffActionLogger
if opts[:changes]
old_values, new_values = get_changes(opts[:changes])
- history_params[:previous_value] = old_values&.join(", ") unless opts[:changes].keys.include?(
- "id",
- )
+ history_params[:previous_value] = old_values&.join(", ") if opts[:changes].keys.exclude?("id")
history_params[:new_value] = new_values&.join(", ")
end
diff --git a/config/initializers/008-rack-cors.rb b/config/initializers/008-rack-cors.rb
index d16a6281079..f9d23ec771d 100644
--- a/config/initializers/008-rack-cors.rb
+++ b/config/initializers/008-rack-cors.rb
@@ -39,7 +39,7 @@ class Discourse::Cors
elsif cors_origins
origin = nil
if origin = env["HTTP_ORIGIN"]
- origin = nil unless cors_origins.include?(origin)
+ origin = nil if cors_origins.exclude?(origin)
end
headers["Access-Control-Allow-Origin"] = origin || cors_origins[0]
diff --git a/db/migrate/20131014203951_backfill_post_upload_reverse_index.rb b/db/migrate/20131014203951_backfill_post_upload_reverse_index.rb
index 1d3b1d47027..ed05ce25ac0 100644
--- a/db/migrate/20131014203951_backfill_post_upload_reverse_index.rb
+++ b/db/migrate/20131014203951_backfill_post_upload_reverse_index.rb
@@ -19,7 +19,7 @@ class BackfillPostUploadReverseIndex < ActiveRecord::Migration[4.2]
def add_to_reverse_index(url, post_id)
# make sure we have a url to insert
- return unless url.present?
+ return if url.blank?
# local uploads are relative
if index = url.index(local_base_url)
url = url[index..-1]
diff --git a/db/migrate/20180710172959_disallow_multi_levels_theme_components.rb b/db/migrate/20180710172959_disallow_multi_levels_theme_components.rb
index 99caa7e55e4..b9c040bd7bd 100644
--- a/db/migrate/20180710172959_disallow_multi_levels_theme_components.rb
+++ b/db/migrate/20180710172959_disallow_multi_levels_theme_components.rb
@@ -73,9 +73,9 @@ class DisallowMultiLevelsThemeComponents < ActiveRecord::Migration[5.2]
)
children.each do |child|
- unless @handled.include?(
- [top_parent.parent_theme_id, child.parent_theme_id, child.child_theme_id],
- )
+ if @handled.exclude?(
+ [top_parent.parent_theme_id, child.parent_theme_id, child.child_theme_id],
+ )
migrate_child(child, top_parent)
end
end
diff --git a/lib/archetype.rb b/lib/archetype.rb
index 6d8b3619018..e518bc76b27 100644
--- a/lib/archetype.rb
+++ b/lib/archetype.rb
@@ -27,7 +27,7 @@ class Archetype
end
def self.list
- return [] unless @archetypes.present?
+ return [] if @archetypes.blank?
@archetypes.values
end
diff --git a/lib/auth/managed_authenticator.rb b/lib/auth/managed_authenticator.rb
index bb163d1a715..90d2ae1b612 100644
--- a/lib/auth/managed_authenticator.rb
+++ b/lib/auth/managed_authenticator.rb
@@ -161,8 +161,8 @@ class Auth::ManagedAuthenticator < Auth::Authenticator
if bio || location
profile = user.user_profile
- profile.bio_raw = bio unless profile.bio_raw.present?
- profile.location = location unless profile.location.present?
+ profile.bio_raw = bio if profile.bio_raw.blank?
+ profile.location = location if profile.location.blank?
profile.save
end
end
diff --git a/lib/autospec/manager.rb b/lib/autospec/manager.rb
index 30e952c3509..adfb85c2830 100644
--- a/lib/autospec/manager.rb
+++ b/lib/autospec/manager.rb
@@ -317,7 +317,7 @@ class Autospec::Manager
if @queue.first && @queue.first[0] == "focus"
focus = @queue.shift
@queue.unshift([file, spec, runner])
- unless spec.include?(":") && focus[1].include?(spec.split(":")[0])
+ if spec.exclude?(":") || focus[1].exclude?(spec.split(":")[0])
@queue.unshift(focus) if focus[1].include?(spec) || file != spec
end
else
diff --git a/lib/backup_restore/backuper.rb b/lib/backup_restore/backuper.rb
index c4cc1f2c9ad..56923c363d6 100644
--- a/lib/backup_restore/backuper.rb
+++ b/lib/backup_restore/backuper.rb
@@ -153,7 +153,7 @@ module BackupRestore
RailsMultisite::ConnectionManagement.establish_connection(db: @current_db)
while pg_dump_running
message = logs.pop.strip
- log(message) unless message.blank?
+ log(message) if message.present?
end
end
diff --git a/lib/bookmarks_bulk_action.rb b/lib/bookmarks_bulk_action.rb
index c433c3bdf8d..3050ab1162d 100644
--- a/lib/bookmarks_bulk_action.rb
+++ b/lib/bookmarks_bulk_action.rb
@@ -14,7 +14,7 @@ class BookmarksBulkAction
end
def perform!
- unless BookmarksBulkAction.operations.include?(@operation[:type])
+ if BookmarksBulkAction.operations.exclude?(@operation[:type])
raise Discourse::InvalidParameters.new(:operation)
end
# careful these are private methods, we need send
diff --git a/lib/common_passwords.rb b/lib/common_passwords.rb
index 72aad6c3c47..a8ac6c33a87 100644
--- a/lib/common_passwords.rb
+++ b/lib/common_passwords.rb
@@ -18,7 +18,7 @@ class CommonPasswords
@mutex = Mutex.new
def self.common_password?(password)
- return false unless password.present?
+ return false if password.blank?
password_list.include?(password)
end
diff --git a/lib/composer_messages_finder.rb b/lib/composer_messages_finder.rb
index efc230108fe..738052a1d1b 100644
--- a/lib/composer_messages_finder.rb
+++ b/lib/composer_messages_finder.rb
@@ -183,7 +183,7 @@ class ComposerMessagesFinder
def check_get_a_room(min_users_posted: 5)
return unless @user.guardian.can_send_private_messages?
return unless educate_reply?(:notified_about_get_a_room)
- return unless @details[:post_id].present?
+ return if @details[:post_id].blank?
return if @topic.category&.read_restricted
reply_to_user_id = Post.where(id: @details[:post_id]).pluck(:user_id)[0]
diff --git a/lib/cooked_processor_mixin.rb b/lib/cooked_processor_mixin.rb
index 967695659a3..fcf9df667c9 100644
--- a/lib/cooked_processor_mixin.rb
+++ b/lib/cooked_processor_mixin.rb
@@ -155,7 +155,7 @@ module CookedProcessorMixin
end
def get_size_from_image_sizes(src, image_sizes)
- return unless image_sizes.present?
+ return if image_sizes.blank?
image_sizes.each do |image_size|
url, size = image_size[0], image_size[1]
if url && src && url.include?(src) && size && size["width"].to_i > 0 &&
diff --git a/lib/directory_helper.rb b/lib/directory_helper.rb
index 80b2865a85a..f8bcc9aa64e 100644
--- a/lib/directory_helper.rb
+++ b/lib/directory_helper.rb
@@ -4,7 +4,7 @@ module DirectoryHelper
def tmp_directory(prefix)
directory_cache[prefix] ||= begin
f = File.join(Rails.root, "tmp", Time.now.strftime("#{prefix}%Y%m%d%H%M%S"))
- FileUtils.mkdir_p(f) unless Dir[f].present?
+ FileUtils.mkdir_p(f) if Dir[f].blank?
f
end
end
diff --git a/lib/discourse.rb b/lib/discourse.rb
index db8aaa63c34..96946422511 100644
--- a/lib/discourse.rb
+++ b/lib/discourse.rb
@@ -1182,7 +1182,7 @@ module Discourse
CDN_REQUEST_METHODS ||= %w[GET HEAD OPTIONS]
def self.is_cdn_request?(env, request_method)
- return unless CDN_REQUEST_METHODS.include?(request_method)
+ return if CDN_REQUEST_METHODS.exclude?(request_method)
cdn_hostnames = GlobalSetting.cdn_hostnames
return if cdn_hostnames.blank?
diff --git a/lib/discourse_tagging.rb b/lib/discourse_tagging.rb
index c5ca6bad163..58d1ee605c5 100644
--- a/lib/discourse_tagging.rb
+++ b/lib/discourse_tagging.rb
@@ -159,7 +159,7 @@ module DiscourseTagging
parent_tag = tags.select { |t| t.id == parent_tag_ids.first }.first
original_child_tag = tags.select { |t| t.id == tag_id }.first
- next unless parent_tag.present? && original_child_tag.present?
+ next if parent_tag.blank? || original_child_tag.blank?
parent_child_names_map[parent_tag.name] = original_child_tag.name
end
diff --git a/lib/email/message_builder.rb b/lib/email/message_builder.rb
index 02ef75e8843..63160eb9835 100644
--- a/lib/email/message_builder.rb
+++ b/lib/email/message_builder.rb
@@ -300,7 +300,7 @@ module Email
def reply_by_email_address
return @reply_by_email_address if @reply_by_email_address
- return nil unless SiteSetting.reply_by_email_address.present?
+ return nil if SiteSetting.reply_by_email_address.blank?
@reply_by_email_address = SiteSetting.reply_by_email_address.dup
diff --git a/lib/email/receiver.rb b/lib/email/receiver.rb
index a7583541d98..c84b9ffcb50 100644
--- a/lib/email/receiver.rb
+++ b/lib/email/receiver.rb
@@ -445,7 +445,7 @@ module Email
text_content_type = @mail.content_type
end
- return unless text.present? || html.present?
+ return if text.blank? && html.blank?
if text.present?
text = trim_discourse_markers(text)
diff --git a/lib/email/styles.rb b/lib/email/styles.rb
index 03e78844656..48b051cd88a 100644
--- a/lib/email/styles.rb
+++ b/lib/email/styles.rb
@@ -423,7 +423,7 @@ module Email
.css("a")
.each do |link|
begin
- link["href"] = "#{site_uri}#{link["href"]}" unless URI(link["href"].to_s).host.present?
+ link["href"] = "#{site_uri}#{link["href"]}" if URI(link["href"].to_s).host.blank?
rescue URI::Error
# leave it
end
diff --git a/lib/email_controller_helper/digest_email_unsubscriber.rb b/lib/email_controller_helper/digest_email_unsubscriber.rb
index b96e77402c5..5555222ac9e 100644
--- a/lib/email_controller_helper/digest_email_unsubscriber.rb
+++ b/lib/email_controller_helper/digest_email_unsubscriber.rb
@@ -20,7 +20,7 @@ module EmailControllerHelper
take_next: false,
) do |memo, v|
memo[:current] = v[:name] if v[:value] == frequency_in_minutes && email_digests
- next(memo) unless allowed_frequencies.include?(v[:name])
+ next(memo) if allowed_frequencies.exclude?(v[:name])
memo.tap do |m|
m[:selected] = v[:value] if m[:take_next] && email_digests
diff --git a/lib/encodings.rb b/lib/encodings.rb
index b8e68f24e57..fcabaa89933 100644
--- a/lib/encodings.rb
+++ b/lib/encodings.rb
@@ -26,7 +26,7 @@ module Encodings
end
def self.delete_bom!(string)
- string.sub!(/\A\xEF\xBB\xBF/, "") unless string.blank?
+ string.sub!(/\A\xEF\xBB\xBF/, "") if string.present?
string
end
end
diff --git a/lib/final_destination.rb b/lib/final_destination.rb
index 7fffb608ce8..ee39aa266df 100644
--- a/lib/final_destination.rb
+++ b/lib/final_destination.rb
@@ -407,7 +407,7 @@ class FinalDestination
def validate_uri_format
return false unless @uri && @uri.host
- return false unless %w[https http].include?(@uri.scheme)
+ return false if %w[https http].exclude?(@uri.scheme)
# In some cases (like local/test environments) we may want to allow http URLs
# to be used for internal hosts, but only if it's the case that the host is
diff --git a/lib/final_destination/http.rb b/lib/final_destination/http.rb
index 111b1c80143..542f372a0ad 100644
--- a/lib/final_destination/http.rb
+++ b/lib/final_destination/http.rb
@@ -2,7 +2,7 @@
class FinalDestination::HTTP < Net::HTTP
def connect
- raise ArgumentError.new("address cannot be nil or empty") unless @address.present?
+ raise ArgumentError.new("address cannot be nil or empty") if @address.blank?
original_open_timeout = @open_timeout
return super if @ipaddr
diff --git a/lib/freedom_patches/translate_accelerator.rb b/lib/freedom_patches/translate_accelerator.rb
index 79c2b9e1615..623a5603117 100644
--- a/lib/freedom_patches/translate_accelerator.rb
+++ b/lib/freedom_patches/translate_accelerator.rb
@@ -73,7 +73,7 @@ module I18n
execute_reload if @requires_reload
locale = (opts[:locale] || config.locale).to_sym
- load_locale(locale) unless @loaded_locales.include?(locale)
+ load_locale(locale) if @loaded_locales.exclude?(locale)
results = {}
regexp = I18n::Backend::DiscourseI18n.create_search_regexp(query)
@@ -99,7 +99,7 @@ module I18n
def ensure_loaded!(locale)
locale = locale.to_sym
@loaded_locales ||= []
- load_locale(locale) unless @loaded_locales.include?(locale)
+ load_locale(locale) if @loaded_locales.exclude?(locale)
end
# In some environments such as migrations we don't want to use overrides.
@@ -198,7 +198,7 @@ module I18n
key = args.shift
locale = (options[:locale] || config.locale).to_sym
- load_locale(locale) unless @loaded_locales.include?(locale)
+ load_locale(locale) if @loaded_locales.exclude?(locale)
if @overrides_enabled
overrides = {}
@@ -234,7 +234,7 @@ module I18n
locale ||= config.locale
locale = locale.to_sym
- load_locale(locale) unless @loaded_locales.include?(locale)
+ load_locale(locale) if @loaded_locales.exclude?(locale)
exists_no_cache?(key, locale)
end
diff --git a/lib/has_errors.rb b/lib/has_errors.rb
index bd50e403f45..6b2f94d1341 100644
--- a/lib/has_errors.rb
+++ b/lib/has_errors.rb
@@ -26,7 +26,7 @@ module HasErrors
end
def add_error(msg)
- errors.add(:base, msg) unless errors[:base].include?(msg)
+ errors.add(:base, msg) if errors[:base].exclude?(msg)
end
def add_errors_from(obj)
diff --git a/lib/import_export/base_exporter.rb b/lib/import_export/base_exporter.rb
index 640278ceacd..c3171c17b2b 100644
--- a/lib/import_export/base_exporter.rb
+++ b/lib/import_export/base_exporter.rb
@@ -125,7 +125,7 @@ module ImportExport
@export_data[:categories].each do |c|
c[:permissions_params].each do |group_name, _|
- group_names << group_name unless auto_group_names.include?(group_name.to_s)
+ group_names << group_name if auto_group_names.exclude?(group_name.to_s)
end
end
diff --git a/lib/new_post_manager.rb b/lib/new_post_manager.rb
index 72118492533..0c97bb03f42 100644
--- a/lib/new_post_manager.rb
+++ b/lib/new_post_manager.rb
@@ -59,7 +59,7 @@ class NewPostManager
pattern = SiteSetting.auto_silence_first_post_regex
- return false unless pattern.present?
+ return false if pattern.blank?
return false unless is_first_post?(manager)
begin
diff --git a/lib/new_post_result.rb b/lib/new_post_result.rb
index 861fcc5ff94..0c04b4e309c 100644
--- a/lib/new_post_result.rb
+++ b/lib/new_post_result.rb
@@ -29,7 +29,7 @@ class NewPostResult
if arr.empty?
@success = true
else
- arr.each { |e| errors.add(:base, e) unless errors[:base].include?(e) }
+ arr.each { |e| errors.add(:base, e) if errors[:base].exclude?(e) }
end
end
diff --git a/lib/onebox/engine/google_maps_onebox.rb b/lib/onebox/engine/google_maps_onebox.rb
index cd3072a93ae..87a0acae0cc 100644
--- a/lib/onebox/engine/google_maps_onebox.rb
+++ b/lib/onebox/engine/google_maps_onebox.rb
@@ -182,7 +182,7 @@ module Onebox
)
response = http.head(uri.path)
- unless %w[200 301 302].include?(response.code)
+ if %w[200 301 302].exclude?(response.code)
raise "unexpected response code #{response.code}"
end
diff --git a/lib/onebox/engine/hackernews_onebox.rb b/lib/onebox/engine/hackernews_onebox.rb
index b4507f26e0c..10591d2019b 100644
--- a/lib/onebox/engine/hackernews_onebox.rb
+++ b/lib/onebox/engine/hackernews_onebox.rb
@@ -23,7 +23,7 @@ module Onebox
end
def data
- return nil unless %w[story comment].include?(raw["type"])
+ return nil if %w[story comment].exclude?(raw["type"])
html_entities = HTMLEntities.new
data = {
diff --git a/lib/onebox/helpers.rb b/lib/onebox/helpers.rb
index f6f71eb705a..c4bb7809525 100644
--- a/lib/onebox/helpers.rb
+++ b/lib/onebox/helpers.rb
@@ -124,7 +124,7 @@ module Onebox
code = response.code.to_i
unless code === 200
- response.error! unless [301, 302, 303, 307, 308].include?(code)
+ response.error! if [301, 302, 303, 307, 308].exclude?(code)
return(
fetch_response(
diff --git a/lib/plugin/instance.rb b/lib/plugin/instance.rb
index 78588ee9975..0a0a495189c 100644
--- a/lib/plugin/instance.rb
+++ b/lib/plugin/instance.rb
@@ -753,7 +753,7 @@ class Plugin::Instance
assets.concat(auto_assets)
end
- register_assets! unless assets.blank?
+ register_assets! if assets.present?
register_locales!
register_service_workers!
diff --git a/lib/plugin_gem.rb b/lib/plugin_gem.rb
index 8bbbd726737..4814bb095c9 100644
--- a/lib/plugin_gem.rb
+++ b/lib/plugin_gem.rb
@@ -10,7 +10,7 @@ module PluginGem
spec_file = spec_path + "/#{name}-#{version}"
- unless platform_variants(spec_file).find(&File.method(:exist?)).present?
+ if platform_variants(spec_file).find(&File.method(:exist?)).blank?
command =
"gem install #{name} -v #{version} -i #{gems_path} --no-document --ignore-dependencies --no-user-install"
command += " --source #{opts[:source]}" if opts[:source]
diff --git a/lib/post_creator.rb b/lib/post_creator.rb
index 51eb1d6d168..5af9c148661 100644
--- a/lib/post_creator.rb
+++ b/lib/post_creator.rb
@@ -299,7 +299,7 @@ class PostCreator
end
def self.set_reply_info(post)
- return unless post.reply_to_post_number.present?
+ return if post.reply_to_post_number.blank?
# Before the locking here was added, replying to a post and liking a post
# at roughly the same time could cause a deadlock.
@@ -396,7 +396,7 @@ class PostCreator
end
def create_embedded_topic
- return unless @opts[:embed_url].present?
+ return if @opts[:embed_url].blank?
original_uri = URI.parse(@opts[:embed_url])
raise Discourse::InvalidParameters.new(:embed_url) unless original_uri.is_a?(URI::HTTP)
diff --git a/lib/post_revisor.rb b/lib/post_revisor.rb
index cc8932c7860..ad52a24f7cd 100644
--- a/lib/post_revisor.rb
+++ b/lib/post_revisor.rb
@@ -61,7 +61,7 @@ class PostRevisor
tracked_topic_fields[field] = block
# Define it in the serializer unless it already has been defined
- unless PostRevisionSerializer.instance_methods(false).include?("#{field}_changes".to_sym)
+ if PostRevisionSerializer.instance_methods(false).exclude?("#{field}_changes".to_sym)
PostRevisionSerializer.add_compared_field(field)
end
end
diff --git a/lib/pretty_text/helpers.rb b/lib/pretty_text/helpers.rb
index 5f200bc04ac..0b60e66f447 100644
--- a/lib/pretty_text/helpers.rb
+++ b/lib/pretty_text/helpers.rb
@@ -18,7 +18,7 @@ module PrettyText
def avatar_template(username)
return "" unless username
user = User.find_by(username_lower: username.downcase)
- return "" unless user.present?
+ return "" if user.blank?
# TODO: Add support for ES6 and call `avatar-template` directly
UrlHelper.schemaless(UrlHelper.absolute(user.avatar_template))
@@ -27,7 +27,7 @@ module PrettyText
def lookup_primary_user_group(username)
return "" unless username
user = User.find_by(username_lower: username.downcase)
- return "" unless user.present?
+ return "" if user.blank?
user.primary_group.try(:name) || ""
end
diff --git a/lib/search.rb b/lib/search.rb
index e38466b01b2..7f756b85ec4 100644
--- a/lib/search.rb
+++ b/lib/search.rb
@@ -919,7 +919,7 @@ class Search
def find_grouped_results
if @results.type_filter.present?
- unless Search.facets.include?(@results.type_filter)
+ if Search.facets.exclude?(@results.type_filter)
raise Discourse::InvalidAccess.new("invalid type filter")
end
# calling protected methods
diff --git a/lib/site_settings/type_supervisor.rb b/lib/site_settings/type_supervisor.rb
index f1fc1a493f5..1b6f6c125ee 100644
--- a/lib/site_settings/type_supervisor.rb
+++ b/lib/site_settings/type_supervisor.rb
@@ -259,7 +259,7 @@ class SiteSettings::TypeSupervisor
raise Discourse::InvalidParameters.new(name)
end
- raise Discourse::InvalidParameters.new(:value) unless choice.include?(val)
+ raise Discourse::InvalidParameters.new(:value) if choice.exclude?(val)
end
end
diff --git a/lib/tasks/assets.rake b/lib/tasks/assets.rake
index 422896fbcec..8b360032771 100644
--- a/lib/tasks/assets.rake
+++ b/lib/tasks/assets.rake
@@ -1,7 +1,7 @@
# frozen_string_literal: true
task "assets:precompile:prereqs" do
- unless %w[profile production].include? Rails.env
+ if %w[profile production].exclude? Rails.env
raise "rake assets:precompile should only be run in RAILS_ENV=production, you are risking unminified assets"
end
end
@@ -214,7 +214,7 @@ end
def max_compress?(path, locales)
return false if Rails.configuration.assets.skip_minification.include? path
return false if EmberCli.is_ember_cli_asset?(path)
- return true unless path.include? "locales/"
+ return true if path.exclude? "locales/"
path_locale = path.delete_prefix("locales/").delete_suffix(".js")
return true if locales.include? path_locale
diff --git a/lib/tasks/avatars.rake b/lib/tasks/avatars.rake
index 78e53a1541f..55409b5b10a 100644
--- a/lib/tasks/avatars.rake
+++ b/lib/tasks/avatars.rake
@@ -37,7 +37,7 @@ task "avatars:clean" => :environment do
optimized_image_ids.each do |id|
begin
optimized_image = OptimizedImage.find_by(id: id)
- next unless optimized_image.present?
+ next if optimized_image.blank?
optimized_image.destroy!
rescue => e
puts "", "Failed to cleanup avatar (optimized_image id: #{id})", e, e.backtrace.join("\n")
diff --git a/lib/tasks/emails.rake b/lib/tasks/emails.rake
index 87942951151..e533fd632de 100644
--- a/lib/tasks/emails.rake
+++ b/lib/tasks/emails.rake
@@ -238,7 +238,7 @@ task "emails:fix_mailman_users" => :environment do
.includes(:user, :post)
.where("raw LIKE '%X-Mailman-Version: %'")
.find_each do |ie|
- next unless ie.post.present?
+ next if ie.post.blank?
mail = Mail.new(ie.raw)
email, name = Email::Receiver.extract_email_address_and_name_from_mailman(mail)
diff --git a/lib/tasks/javascript.rake b/lib/tasks/javascript.rake
index 5b077fb661e..3587384ca33 100644
--- a/lib/tasks/javascript.rake
+++ b/lib/tasks/javascript.rake
@@ -279,7 +279,7 @@ task "javascript:clean_up" do
next if processed.include?(package_dir_name)
versions = Dir["#{File.join(public_js, package_dir_name)}/*"].collect { |p| p.split("/").last }
- next unless versions.present?
+ next if versions.blank?
versions = versions.sort { |a, b| Gem::Version.new(a) <=> Gem::Version.new(b) }
puts "Keeping #{package_dir_name} version: #{versions[-1]}"
diff --git a/lib/tasks/version_bump.rake b/lib/tasks/version_bump.rake
index 9107e7c8b4a..51a48a6d6f3 100644
--- a/lib/tasks/version_bump.rake
+++ b/lib/tasks/version_bump.rake
@@ -338,7 +338,7 @@ desc <<~DESC
DESC
task "version_bump:major_stable_merge", [:version_bump_ref] do |t, args|
merge_ref = args[:version_bump_ref]
- raise "Must pass version_bump_ref" unless merge_ref.present?
+ raise "Must pass version_bump_ref" if merge_ref.blank?
git "fetch", "origin", merge_ref
raise "Unknown version_bump_ref: #{merge_ref.inspect}" unless ref_exists?(merge_ref)
@@ -395,7 +395,7 @@ desc <<~DESC
DESC
task "version_bump:stage_security_fixes", [:base] do |t, args|
base = args[:base]
- raise "Unknown base: #{base.inspect}" unless %w[stable main].include?(base)
+ raise "Unknown base: #{base.inspect}" if %w[stable main].exclude?(base)
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?
diff --git a/lib/theme_settings_parser.rb b/lib/theme_settings_parser.rb
index 2a95e9aad05..823c611890a 100644
--- a/lib/theme_settings_parser.rb
+++ b/lib/theme_settings_parser.rb
@@ -28,7 +28,7 @@ class ThemeSettingsParser
if type == @types[:enum]
choices = raw_opts[:choices]
choices = [] unless choices.is_a?(Array)
- choices << default unless choices.include?(default)
+ choices << default if choices.exclude?(default)
opts[:choices] = choices
end
diff --git a/lib/theme_settings_validator.rb b/lib/theme_settings_validator.rb
index ecee0c99fe7..4d62f84bda9 100644
--- a/lib/theme_settings_validator.rb
+++ b/lib/theme_settings_validator.rb
@@ -29,7 +29,7 @@ class ThemeSettingsValidator
case type
when types[:enum]
- unless opts[:choices].include?(value) || opts[:choices].map(&:to_s).include?(value)
+ if opts[:choices].exclude?(value) && opts[:choices].map(&:to_s).exclude?(value)
errors << I18n.t(
"themes.settings_errors.enum_value_not_valid",
choices: opts[:choices].join(", "),
diff --git a/lib/theme_store/git_importer.rb b/lib/theme_store/git_importer.rb
index 9958d580acd..ee7e6901594 100644
--- a/lib/theme_store/git_importer.rb
+++ b/lib/theme_store/git_importer.rb
@@ -111,7 +111,7 @@ class ThemeStore::GitImporter < ThemeStore::BaseImporter
def clone_http!
uri = redirected_uri
- raise_import_error! unless %w[http https].include?(@uri.scheme)
+ raise_import_error! if %w[http https].exclude?(@uri.scheme)
addresses = FinalDestination::SSRFDetector.lookup_and_filter_ips(uri.host)
@@ -133,7 +133,7 @@ class ThemeStore::GitImporter < ThemeStore::BaseImporter
end
def clone_ssh!
- raise_import_error! unless @private_key.present?
+ raise_import_error! if @private_key.blank?
with_ssh_private_key do |ssh_folder|
# Use only the specified SSH key
diff --git a/lib/topic_creator.rb b/lib/topic_creator.rb
index 559d3a45c76..1557dd46e3b 100644
--- a/lib/topic_creator.rb
+++ b/lib/topic_creator.rb
@@ -206,7 +206,7 @@ class TopicCreator
end
def setup_auto_close_time(topic)
- return unless @opts[:auto_close_time].present?
+ return if @opts[:auto_close_time].blank?
return unless @guardian.can_moderate?(topic)
topic.set_auto_close(@opts[:auto_close_time], by_user: @user)
end
@@ -215,8 +215,8 @@ class TopicCreator
return unless @opts[:archetype] == Archetype.private_message
topic.subtype = TopicSubtype.user_to_user unless topic.subtype
- unless @opts[:target_usernames].present? || @opts[:target_emails].present? ||
- @opts[:target_group_names].present?
+ if @opts[:target_usernames].blank? && @opts[:target_emails].blank? &&
+ @opts[:target_group_names].blank?
rollback_with!(topic, :no_user_selected)
end
diff --git a/lib/topic_query.rb b/lib/topic_query.rb
index 76d40ad0e8a..e69eb6eec4d 100644
--- a/lib/topic_query.rb
+++ b/lib/topic_query.rb
@@ -721,7 +721,7 @@ class TopicQuery
end
def get_category_id(category_id_or_slug)
- return nil unless category_id_or_slug.present?
+ return nil if category_id_or_slug.blank?
category_id = category_id_or_slug.to_i
if category_id == 0
diff --git a/lib/topic_subtype.rb b/lib/topic_subtype.rb
index e4c4621c81e..e0752da0070 100644
--- a/lib/topic_subtype.rb
+++ b/lib/topic_subtype.rb
@@ -15,7 +15,7 @@ class TopicSubtype
end
def self.list
- return [] unless @archetypes.present?
+ return [] if @archetypes.blank?
@archetypes.values
end
diff --git a/lib/topic_view.rb b/lib/topic_view.rb
index ce221e50d24..916bb8d2e29 100644
--- a/lib/topic_view.rb
+++ b/lib/topic_view.rb
@@ -758,8 +758,8 @@ class TopicView
@read_posts_set ||=
begin
result = Set.new
- return result unless @user.present?
- return result unless topic_user.present?
+ return result if @user.blank?
+ return result if topic_user.blank?
post_numbers =
PostTiming
diff --git a/lib/topics_bulk_action.rb b/lib/topics_bulk_action.rb
index 20174c0d200..daa28c2bb64 100644
--- a/lib/topics_bulk_action.rb
+++ b/lib/topics_bulk_action.rb
@@ -37,7 +37,7 @@ class TopicsBulkAction
end
def perform!
- unless TopicsBulkAction.operations.include?(@operation[:type])
+ if TopicsBulkAction.operations.exclude?(@operation[:type])
raise Discourse::InvalidParameters.new(:operation)
end
# careful these are private methods, we need send
diff --git a/lib/validators/form_template_yaml_validator.rb b/lib/validators/form_template_yaml_validator.rb
index 5931bbaa8fd..6d8e769a30f 100644
--- a/lib/validators/form_template_yaml_validator.rb
+++ b/lib/validators/form_template_yaml_validator.rb
@@ -69,6 +69,6 @@ class FormTemplateYamlValidator < ActiveModel::Validator
record.errors.add(:template, I18n.t("form_templates.errors.duplicate_ids"))
end
- existing_ids << field["id"] unless field["id"].blank?
+ existing_ids << field["id"] if field["id"].present?
end
end
diff --git a/lib/validators/post_validator.rb b/lib/validators/post_validator.rb
index 2977ae5764a..f0539e72d64 100644
--- a/lib/validators/post_validator.rb
+++ b/lib/validators/post_validator.rb
@@ -39,7 +39,7 @@ class PostValidator < ActiveModel::Validator
if private_message?(post)
SiteSetting.private_message_post_length
elsif post.is_first_post? || (post.topic.present? && post.topic.posts_count == 0)
- if post.topic&.featured_link&.present?
+ if post.topic&.featured_link.present?
(0..SiteSetting.max_post_length)
else
SiteSetting.first_post_length
diff --git a/lib/validators/upload_validator.rb b/lib/validators/upload_validator.rb
index 0e79784ac9c..3ff057ce0ae 100644
--- a/lib/validators/upload_validator.rb
+++ b/lib/validators/upload_validator.rb
@@ -78,7 +78,7 @@ class UploadValidator < ActiveModel::Validator
.gsub(/[\s\.]+/, "")
.downcase
.split("|")
- .each { |extension| extensions << extension unless extension.include?("*") }
+ .each { |extension| extensions << extension if extension.exclude?("*") }
extensions
end
diff --git a/lib/version.rb b/lib/version.rb
index ed5ca152936..95177629e56 100644
--- a/lib/version.rb
+++ b/lib/version.rb
@@ -37,7 +37,7 @@ module Discourse
# 2.4.4.beta6: some-other-branch-ref
# 2.4.2.beta1: v1-tag
def self.find_compatible_resource(version_list, target_version = ::Discourse::VERSION::STRING)
- return unless version_list.present?
+ return if version_list.blank?
begin
version_list = YAML.safe_load(version_list)
diff --git a/lib/wizard.rb b/lib/wizard.rb
index 7624fbc4d4d..2b327602cdb 100644
--- a/lib/wizard.rb
+++ b/lib/wizard.rb
@@ -89,7 +89,7 @@ class Wizard
.pluck(:context)
# First uncompleted step
- steps_with_fields.each { |s| return s unless completed.include?(s.id) }
+ steps_with_fields.each { |s| return s if completed.exclude?(s.id) }
@first_step
end
diff --git a/migrations/config/gemfiles/common/Gemfile b/migrations/config/gemfiles/common/Gemfile
index 6cec3b77d15..1f1de5e271d 100644
--- a/migrations/config/gemfiles/common/Gemfile
+++ b/migrations/config/gemfiles/common/Gemfile
@@ -6,13 +6,17 @@ source "https://rubygems.org"
ruby ">= 3.2.2"
# `activesupport` gem needs to be in sync with the Rails version of Discourse, see `/Gemfile`
-gem "activesupport", "< 7.1", require: "active_support"
+lock_file = %w[Gemfile.lock ../Gemfile.lock].detect { File.exist?(_1) }
+activesupport_version =
+ Bundler::LockfileParser
+ .new(Bundler.read_file(lock_file))
+ .specs
+ .detect { _1.name == "activesupport" }
+ .version
+gem "activesupport", "= #{activesupport_version}", require: "active_support"
# for SQLite
-gem "extralite-bundle",
- "~> 2.8",
- require: "extralite",
- github: "digital-fabric/extralite"
+gem "extralite-bundle", "~> 2.8", require: "extralite", github: "digital-fabric/extralite"
gem "lru_redux", "~> 1.1", require: false
# for communication between process forks
diff --git a/migrations/lib/common/intermediate_database_migrator.rb b/migrations/lib/common/intermediate_database_migrator.rb
index 72a2031a721..860a6ceecaa 100644
--- a/migrations/lib/common/intermediate_database_migrator.rb
+++ b/migrations/lib/common/intermediate_database_migrator.rb
@@ -41,7 +41,7 @@ module Migrations
Dir[file_pattern].sort.each do |path|
relative_path = Pathname(path).relative_path_from(Migrations.root_path).to_s
- unless performed_migrations.include?(relative_path)
+ if performed_migrations.exclude?(relative_path)
sql = File.read(path)
sql_hash = Digest::SHA1.hexdigest(sql)
connection.execute(sql)
diff --git a/plugins/automation/lib/discourse_automation/event_handlers.rb b/plugins/automation/lib/discourse_automation/event_handlers.rb
index ba7f13cc4cf..8ed26d28691 100644
--- a/plugins/automation/lib/discourse_automation/event_handlers.rb
+++ b/plugins/automation/lib/discourse_automation/event_handlers.rb
@@ -25,7 +25,7 @@ module DiscourseAutomation
valid_trust_levels = automation.trigger_field("valid_trust_levels")
if valid_trust_levels["value"]
- next unless valid_trust_levels["value"].include?(post.user.trust_level)
+ next if valid_trust_levels["value"].exclude?(post.user.trust_level)
end
restricted_category = automation.trigger_field("restricted_category")
@@ -205,7 +205,7 @@ module DiscourseAutomation
.find_each do |automation|
valid_trust_levels = automation.trigger_field("valid_trust_levels")
if valid_trust_levels["value"]
- next unless valid_trust_levels["value"].include?(post.user.trust_level)
+ next if valid_trust_levels["value"].exclude?(post.user.trust_level)
end
restricted_category = automation.trigger_field("restricted_category")
diff --git a/plugins/chat/app/controllers/chat/chat_controller.rb b/plugins/chat/app/controllers/chat/chat_controller.rb
index 83ab410338d..b3824bd9e32 100644
--- a/plugins/chat/app/controllers/chat/chat_controller.rb
+++ b/plugins/chat/app/controllers/chat/chat_controller.rb
@@ -42,7 +42,7 @@ module Chat
def dismiss_retention_reminder
params.require(:chatable_type)
guardian.ensure_can_chat!
- unless Chat::Channel.chatable_types.include?(params[:chatable_type])
+ if Chat::Channel.chatable_types.exclude?(params[:chatable_type])
raise Discourse::InvalidParameters
end
diff --git a/plugins/chat/app/jobs/regular/chat/send_message_notifications.rb b/plugins/chat/app/jobs/regular/chat/send_message_notifications.rb
index 4724f5a6f94..32c59a6c6b5 100644
--- a/plugins/chat/app/jobs/regular/chat/send_message_notifications.rb
+++ b/plugins/chat/app/jobs/regular/chat/send_message_notifications.rb
@@ -6,7 +6,7 @@ module Jobs
def execute(args)
reason = args[:reason]
valid_reasons = %w[new edit]
- return unless valid_reasons.include?(reason)
+ return if valid_reasons.exclude?(reason)
return if (timestamp = args[:timestamp]).blank?
diff --git a/plugins/chat/db/migrate/20240118120825_add_threads_enabled_site_setting.rb b/plugins/chat/db/migrate/20240118120825_add_threads_enabled_site_setting.rb
index e0d502dd9d0..ab1a828c446 100644
--- a/plugins/chat/db/migrate/20240118120825_add_threads_enabled_site_setting.rb
+++ b/plugins/chat/db/migrate/20240118120825_add_threads_enabled_site_setting.rb
@@ -7,7 +7,7 @@ class AddThreadsEnabledSiteSetting < ActiveRecord::Migration[7.0]
threading_enabled_channels =
DB.query_single("SELECT name FROM chat_channels WHERE threading_enabled = 't'")
- return unless threading_enabled_channels.present?
+ return if threading_enabled_channels.blank?
DB.exec("UPDATE site_settings SET value = 't' WHERE name = 'chat_threads_enabled'")
end
diff --git a/plugins/discourse-narrative-bot/app/controllers/discourse_narrative_bot/certificates_controller.rb b/plugins/discourse-narrative-bot/app/controllers/discourse_narrative_bot/certificates_controller.rb
index 21fb902bc9d..fc2043c49bb 100644
--- a/plugins/discourse-narrative-bot/app/controllers/discourse_narrative_bot/certificates_controller.rb
+++ b/plugins/discourse-narrative-bot/app/controllers/discourse_narrative_bot/certificates_controller.rb
@@ -11,9 +11,7 @@ module DiscourseNarrativeBot
immutable_for(24.hours)
%i[date user_id].each do |key|
- unless params[key]&.present?
- raise Discourse::InvalidParameters.new("#{key} must be present")
- end
+ raise Discourse::InvalidParameters.new("#{key} must be present") if params[key].blank?
end
if params[:user_id].to_i != current_user.id
diff --git a/plugins/discourse-narrative-bot/lib/discourse_narrative_bot/certificate_generator.rb b/plugins/discourse-narrative-bot/lib/discourse_narrative_bot/certificate_generator.rb
index c052dfaf59a..0d485417e48 100644
--- a/plugins/discourse-narrative-bot/lib/discourse_narrative_bot/certificate_generator.rb
+++ b/plugins/discourse-narrative-bot/lib/discourse_narrative_bot/certificate_generator.rb
@@ -63,7 +63,7 @@ module DiscourseNarrativeBot
end
def logo_group(size, width, height)
- return unless SiteSetting.site_logo_small_url.present?
+ return if SiteSetting.site_logo_small_url.blank?
uri = URI(SiteSetting.site_logo_small_url)
diff --git a/plugins/poll/db/migrate/20180820080623_migrate_polls_data.rb b/plugins/poll/db/migrate/20180820080623_migrate_polls_data.rb
index 37b34c4e7f7..3eaa55300fa 100644
--- a/plugins/poll/db/migrate/20180820080623_migrate_polls_data.rb
+++ b/plugins/poll/db/migrate/20180820080623_migrate_polls_data.rb
@@ -74,7 +74,7 @@ class MigratePollsData < ActiveRecord::Migration[5.2]
votes = {}
r.votes.each do |user_id, user_votes|
# don't migrate votes from deleted/non-existing users
- next unless existing_user_ids.include?(user_id.to_i)
+ next if existing_user_ids.exclude?(user_id.to_i)
user_votes.each do |poll_name, options|
votes[poll_name] ||= {}
diff --git a/plugins/poll/lib/poll.rb b/plugins/poll/lib/poll.rb
index f51f43cf9c1..d4fc025f5e8 100644
--- a/plugins/poll/lib/poll.rb
+++ b/plugins/poll/lib/poll.rb
@@ -211,7 +211,7 @@ class DiscoursePoll::Poll
raise DiscoursePoll::Error.new I18n.t("poll.user_cant_post_in_topic")
end
- unless SiteSetting.poll_groupable_user_fields.split("|").include?(user_field_name)
+ if SiteSetting.poll_groupable_user_fields.split("|").exclude?(user_field_name)
raise Discourse::InvalidParameters.new(:user_field_name)
end
diff --git a/script/bulk_import/base.rb b/script/bulk_import/base.rb
index 16658fe5ed4..e0812a1f29a 100644
--- a/script/bulk_import/base.rb
+++ b/script/bulk_import/base.rb
@@ -1853,7 +1853,7 @@ class BulkImport::Base
end
def normalize_text(text)
- return nil unless text.present?
+ return nil if text.blank?
@html_entities.decode(normalize_charset(text.presence || "").scrub)
end
diff --git a/script/bulk_import/discourse_merger.rb b/script/bulk_import/discourse_merger.rb
index 8f9a0c83340..30b3a7bc832 100644
--- a/script/bulk_import/discourse_merger.rb
+++ b/script/bulk_import/discourse_merger.rb
@@ -910,7 +910,7 @@ class BulkImport::DiscourseMerger < BulkImport::Base
end
def process_post_action(post_action)
- return nil unless post_action["post_id"].present?
+ return nil if post_action["post_id"].blank?
post_action["related_post_id"] = post_id_from_imported_id(post_action["related_post_id"])
post_action["deferred_by_id"] = user_id_from_imported_id(post_action["deferred_by_id"])
post_action["agreed_by_id"] = user_id_from_imported_id(post_action["agreed_by_id"])
@@ -969,7 +969,7 @@ class BulkImport::DiscourseMerger < BulkImport::Base
end
def process_group_archived_message(gam)
- return nil unless gam["topic_id"].present? && gam["group_id"].present?
+ return nil if gam["topic_id"].blank? || gam["group_id"].blank?
gam
end
@@ -990,14 +990,12 @@ class BulkImport::DiscourseMerger < BulkImport::Base
user_avatar["gravatar_upload_id"] = upload_id_from_imported_id(
user_avatar["gravatar_upload_id"],
) if user_avatar["gravatar_upload_id"]
- unless user_avatar["custom_upload_id"].present? || user_avatar["gravatar_upload_id"].present?
- return nil
- end
+ return nil if user_avatar["custom_upload_id"].blank? && user_avatar["gravatar_upload_id"].blank?
user_avatar
end
def process_user_history(user_history)
- return nil unless user_history["group_id"].present?
+ return nil if user_history["group_id"].blank?
user_history["acting_user_id"] = user_id_from_imported_id(
user_history["acting_user_id"],
) if user_history["acting_user_id"]
@@ -1011,7 +1009,7 @@ class BulkImport::DiscourseMerger < BulkImport::Base
user_warning["created_by_id"] = user_id_from_imported_id(
user_warning["created_by_id"],
) if user_warning["created_by_id"]
- return nil unless user_warning["created_by_id"].present?
+ return nil if user_warning["created_by_id"].blank?
user_warning
end
diff --git a/script/bulk_import/generic_bulk.rb b/script/bulk_import/generic_bulk.rb
index 83fa6d365a5..b977dabe384 100644
--- a/script/bulk_import/generic_bulk.rb
+++ b/script/bulk_import/generic_bulk.rb
@@ -165,7 +165,7 @@ class BulkImport::Generic < BulkImport::Base
when "append"
raise "Cannot append to #{name} setting" if setting[:type] != "list"
items = (SiteSetting.get(name) || "").split("|")
- items << row["value"] unless items.include?(row["value"])
+ items << row["value"] if items.exclude?(row["value"])
SiteSetting.set_and_log(name, items.join("|"))
end
end
@@ -2287,7 +2287,7 @@ class BulkImport::Generic < BulkImport::Base
rows.each do |row|
normalization = row["normalization"]
- normalizations << normalization unless normalizations.include?(normalization)
+ normalizations << normalization if normalizations.exclude?(normalization)
end
SiteSetting.permalink_normalizations = normalizations.join("|")
diff --git a/script/bulk_import/uploads_importer.rb b/script/bulk_import/uploads_importer.rb
index da03c690b0f..e47d00306e6 100644
--- a/script/bulk_import/uploads_importer.rb
+++ b/script/bulk_import/uploads_importer.rb
@@ -114,7 +114,7 @@ module BulkImport
producer_thread =
Thread.new do
query("SELECT * FROM uploads ORDER BY id", @source_db).tap do |result_set|
- result_set.each { |row| queue << row unless output_existing_ids.include?(row["id"]) }
+ result_set.each { |row| queue << row if output_existing_ids.exclude?(row["id"]) }
result_set.close
end
end
@@ -612,7 +612,7 @@ module BulkImport
begin
if optimized_images.present?
optimized_images.map! do |optimized_image|
- next unless optimized_image.present?
+ next if optimized_image.blank?
optimized_image_path =
add_multisite_prefix(store.get_path_for_optimized_image(optimized_image))
diff --git a/script/bulk_import/vanilla.rb b/script/bulk_import/vanilla.rb
index 827f57c3fd9..c6e57efcb89 100644
--- a/script/bulk_import/vanilla.rb
+++ b/script/bulk_import/vanilla.rb
@@ -227,7 +227,7 @@ class BulkImport::Vanilla < BulkImport::Base
).first
next if r.nil?
photo = r["photo"]
- next unless photo.present?
+ next if photo.blank?
# Possible encoded values:
# 1. cf://uploads/userpics/820/Y0AFUQYYM6QN.jpg
@@ -305,7 +305,7 @@ class BulkImport::Vanilla < BulkImport::Base
next if r.nil?
path = r["Path"]
name = r["Name"]
- next unless path.present?
+ next if path.blank?
path.gsub!("s3://content/", "")
path.gsub!("s3://uploads/", "")
diff --git a/script/bulk_import/vbulletin.rb b/script/bulk_import/vbulletin.rb
index 6428b79cb1f..e78be02f1d3 100644
--- a/script/bulk_import/vbulletin.rb
+++ b/script/bulk_import/vbulletin.rb
@@ -640,9 +640,9 @@ class BulkImport::VBulletin < BulkImport::Base
next if item == (".") || item == ("..") || item == (".DS_Store")
next unless item =~ /avatar(\d+)_(\d).gif/
scan = item.scan(/avatar(\d+)_(\d).gif/)
- next unless scan[0][0].present?
+ next if scan[0][0].blank?
u = UserCustomField.find_by(name: "import_id", value: scan[0][0]).try(:user)
- next unless u.present?
+ next if u.blank?
# raise "User not found for id #{user_id}" if user.blank?
photo_real_filename = File.join(AVATAR_DIR, item)
@@ -686,10 +686,10 @@ class BulkImport::VBulletin < BulkImport::Base
print_status current_count, total_count
user_id = sig[0]
user_sig = sig[1]
- next unless user_id.present? && user_sig.present?
+ next if user_id.blank? || user_sig.blank?
u = UserCustomField.find_by(name: "import_id", value: user_id).try(:user)
- next unless u.present?
+ next if u.blank?
# can not hold dupes
UserCustomField.where(
diff --git a/script/diff_heaps.rb b/script/diff_heaps.rb
index 8c390e3c31f..6cbc1f83a1b 100644
--- a/script/diff_heaps.rb
+++ b/script/diff_heaps.rb
@@ -29,7 +29,7 @@ File
.each_line do |line|
parsed = JSON.parse(line)
if parsed && parsed["address"]
- diff << parsed unless origs.include? parsed["address"]
+ diff << parsed if origs.exclude? parsed["address"]
end
end
diff --git a/script/import_scripts/answerbase.rb b/script/import_scripts/answerbase.rb
index 63de1d4a937..184f33800a0 100644
--- a/script/import_scripts/answerbase.rb
+++ b/script/import_scripts/answerbase.rb
@@ -318,7 +318,7 @@ class ImportScripts::Answerbase < ImportScripts::Base
end
def add_normalization(normalizations, normalization)
- normalizations << normalization unless normalizations.include?(normalization)
+ normalizations << normalization if normalizations.exclude?(normalization)
end
def permalink_exists?(url)
diff --git a/script/import_scripts/askbot.rb b/script/import_scripts/askbot.rb
index 537c5ba71fe..a8ff40bcddd 100644
--- a/script/import_scripts/askbot.rb
+++ b/script/import_scripts/askbot.rb
@@ -155,7 +155,7 @@ class ImportScripts::MyAskBot < ImportScripts::Base
cat = nil
if tags
CATEGORIES.each do |cname|
- next unless tags.include?(cname.downcase)
+ next if tags.exclude?(cname.downcase)
cat = cname
break
end
diff --git a/script/import_scripts/discuz_x.rb b/script/import_scripts/discuz_x.rb
index 17a6698adaa..274431f9f13 100644
--- a/script/import_scripts/discuz_x.rb
+++ b/script/import_scripts/discuz_x.rb
@@ -994,7 +994,7 @@ class ImportScripts::DiscuzX < ImportScripts::Base
next
end
html = html_for_upload(upload, filename)
- unless new_raw.include? html
+ if new_raw.exclude? html
new_raw << "\n"
new_raw << html
end
diff --git a/script/import_scripts/disqus.rb b/script/import_scripts/disqus.rb
index f865420bfdd..7edc2cc153e 100644
--- a/script/import_scripts/disqus.rb
+++ b/script/import_scripts/disqus.rb
@@ -73,7 +73,7 @@ class ImportScripts::Disqus < ImportScripts::Base
if post.present? && post.topic.posts_count <= 1
(t[:posts] || []).each do |p|
post_user = find_existing_user(p[:author_email] || "", p[:author_username])
- next unless post_user.present?
+ next if post_user.blank?
attrs = {
user_id: post_user.id,
diff --git a/script/import_scripts/drupal.rb b/script/import_scripts/drupal.rb
index 15bc3d8b008..b1ec58d3953 100644
--- a/script/import_scripts/drupal.rb
+++ b/script/import_scripts/drupal.rb
@@ -383,7 +383,7 @@ class ImportScripts::Drupal < ImportScripts::Base
end
upload_html = html_for_upload(upload, filename)
- new_raw = "#{new_raw}\n\n#{upload_html}" unless new_raw.include?(upload_html)
+ new_raw = "#{new_raw}\n\n#{upload_html}" if new_raw.exclude?(upload_html)
if new_raw != post.raw
PostRevisor.new(post).revise!(
diff --git a/script/import_scripts/jive.rb b/script/import_scripts/jive.rb
index 3d5d2a5d82e..bd44a27af6d 100644
--- a/script/import_scripts/jive.rb
+++ b/script/import_scripts/jive.rb
@@ -188,7 +188,7 @@ class ImportScripts::Jive < ImportScripts::Base
rows = []
csv_parse("communities") do |row|
- next unless CATEGORY_IDS.include?(row.communityid.to_i)
+ next if CATEGORY_IDS.exclude?(row.communityid.to_i)
rows << { id: row.communityid, name: "#{row.name} (#{row.communityid})" }
end
@@ -261,7 +261,7 @@ class ImportScripts::Jive < ImportScripts::Base
thread_map = {}
csv_parse("messages") do |thread|
- next unless CATEGORY_IDS.include?(thread.containerid.to_i)
+ next if CATEGORY_IDS.exclude?(thread.containerid.to_i)
if !thread.parentmessageid
# topic
@@ -329,7 +329,7 @@ class ImportScripts::Jive < ImportScripts::Base
csv_parse("messages") do |thread|
# post
- next unless CATEGORY_IDS.include?(thread.containerid.to_i)
+ next if CATEGORY_IDS.exclude?(thread.containerid.to_i)
if thread.parentmessageid
#IMAGE UPLOADER
diff --git a/script/import_scripts/kunena.rb b/script/import_scripts/kunena.rb
index 37371f2716e..b6ec7582fbb 100644
--- a/script/import_scripts/kunena.rb
+++ b/script/import_scripts/kunena.rb
@@ -75,7 +75,7 @@ class ImportScripts::Kunena < ImportScripts::Base
results =
@client.query("SELECT id, username, email, registerDate FROM jos_users;", cache_rows: false)
results.each do |u|
- next unless u["id"].to_i > (0) && u["username"].present? && u["email"].present?
+ next if u["id"].to_i <= (0) || u["username"].blank? || u["email"].blank?
username = u["username"].gsub(" ", "_").gsub(/[^A-Za-z0-9_]/, "")[0, User.username_length.end]
if username.length < User.username_length.first
username = username * User.username_length.first
diff --git a/script/import_scripts/kunena3.rb b/script/import_scripts/kunena3.rb
index e20864da4d5..3d2d52a462a 100644
--- a/script/import_scripts/kunena3.rb
+++ b/script/import_scripts/kunena3.rb
@@ -94,7 +94,7 @@ class ImportScripts::Kunena < ImportScripts::Base
cache_rows: false,
)
results.each do |u|
- next unless u["id"].to_i > (0) && u["username"].present? && u["email"].present?
+ next if u["id"].to_i <= (0) || u["username"].blank? || u["email"].blank?
username = u["username"].gsub(" ", "_").gsub(/[^A-Za-z0-9_]/, "")[0, User.username_length.end]
if username.length < User.username_length.first
username = username * User.username_length.first
diff --git a/script/import_scripts/mbox/support/indexer.rb b/script/import_scripts/mbox/support/indexer.rb
index b19f83f5ff1..84e9e6f1f57 100644
--- a/script/import_scripts/mbox/support/indexer.rb
+++ b/script/import_scripts/mbox/support/indexer.rb
@@ -218,7 +218,7 @@ module ImportScripts::Mbox
end
def read_mail_from_string(raw_message)
- unless raw_message.blank?
+ if raw_message.present?
Email::Receiver.new(raw_message, convert_plaintext: true, skip_trimming: false)
end
end
diff --git a/script/import_scripts/mylittleforum.rb b/script/import_scripts/mylittleforum.rb
index 4509f37c8c5..e9bf8188e05 100644
--- a/script/import_scripts/mylittleforum.rb
+++ b/script/import_scripts/mylittleforum.rb
@@ -224,7 +224,7 @@ class ImportScripts::MylittleforumSQL < ImportScripts::Base
raw = clean_up(discussion["Body"])
youtube = nil
- unless discussion["youtube"].blank?
+ if discussion["youtube"].present?
youtube = clean_youtube(discussion["youtube"])
raw += "\n#{youtube}\n"
print_warning(raw)
@@ -286,7 +286,7 @@ class ImportScripts::MylittleforumSQL < ImportScripts::Base
next if comment["Body"].blank?
raw = clean_up(comment["Body"])
youtube = nil
- unless comment["youtube"].blank?
+ if comment["youtube"].present?
youtube = clean_youtube(comment["youtube"])
raw += "\n#{youtube}\n"
end
diff --git a/script/import_scripts/phpbb3/importers/message_importer.rb b/script/import_scripts/phpbb3/importers/message_importer.rb
index c71795b3280..2e9a9e9a5a1 100644
--- a/script/import_scripts/phpbb3/importers/message_importer.rb
+++ b/script/import_scripts/phpbb3/importers/message_importer.rb
@@ -136,7 +136,7 @@ module ImportScripts::PhpBB3
# This appears to be a reply. Let's try to find the Discourse topic_id for this message.
parent_msg_id = get_import_id(row[:root_msg_id])
parent = @lookup.topic_lookup_from_imported_post_id(parent_msg_id)
- parent[:topic_id] unless parent.blank?
+ parent[:topic_id] if parent.present?
end
end
diff --git a/script/import_scripts/phpbb3/importers/permalink_importer.rb b/script/import_scripts/phpbb3/importers/permalink_importer.rb
index 5dcd9ffe60f..2594bd9c4ac 100644
--- a/script/import_scripts/phpbb3/importers/permalink_importer.rb
+++ b/script/import_scripts/phpbb3/importers/permalink_importer.rb
@@ -56,7 +56,7 @@ module ImportScripts::PhpBB3
normalization = "/#{prefix.gsub("/", '\/')}\\#{normalization}"
end
- normalizations << normalization unless normalizations.include?(normalization)
+ normalizations << normalization if normalizations.exclude?(normalization)
end
def permalink_exists(url)
diff --git a/script/import_scripts/sfn.rb b/script/import_scripts/sfn.rb
index 9f371110e36..dae0f4dff7c 100644
--- a/script/import_scripts/sfn.rb
+++ b/script/import_scripts/sfn.rb
@@ -38,7 +38,7 @@ class ImportScripts::Sfn < ImportScripts::Base
@external_users = {}
CSV.foreach("/Users/zogstrip/Desktop/sfn.csv", col_sep: ";") do |row|
- next unless @personify_id_to_contact_key.include?(row[0])
+ next if @personify_id_to_contact_key.exclude?(row[0])
id = @personify_id_to_contact_key[row[0]]
full_name = [row[1].strip, row[2].strip, row[3].strip].join(" ").strip
diff --git a/script/import_scripts/smf2.rb b/script/import_scripts/smf2.rb
index b8d697b2b3a..c10c976d05d 100644
--- a/script/import_scripts/smf2.rb
+++ b/script/import_scripts/smf2.rb
@@ -278,7 +278,7 @@ class ImportScripts::Smf2 < ImportScripts::Base
attachment[:file_hash],
attachment[:filename],
)
- raise "Attachment for post #{post[:id]} failed: #{attachment[:filename]}" unless path.present?
+ raise "Attachment for post #{post[:id]} failed: #{attachment[:filename]}" if path.blank?
upload = create_upload(post[:user_id], path, attachment[:filename])
unless upload.persisted?
raise "Attachment for post #{post[:id]} failed: #{upload.errors.full_messages.join(", ")}"
@@ -378,7 +378,7 @@ class ImportScripts::Smf2 < ImportScripts::Base
pattern, emitter = *p
body.gsub!(pattern) do |s|
next s if (num = $~[:num].to_i - 1) < 0
- next s unless (upload = attachments[num]).present?
+ next s if (upload = attachments[num]).blank?
use_count[num] += 1
instance_exec(upload, &emitter)
end
diff --git a/script/import_scripts/telligent.rb b/script/import_scripts/telligent.rb
index c46be23facb..5a5b188e636 100644
--- a/script/import_scripts/telligent.rb
+++ b/script/import_scripts/telligent.rb
@@ -888,7 +888,7 @@ class ImportScripts::Telligent < ImportScripts::Base
end
def add_normalization(normalizations, normalization)
- normalizations << normalization unless normalizations.include?(normalization)
+ normalizations << normalization if normalizations.exclude?(normalization)
end
def batches
diff --git a/script/import_scripts/vanilla_mysql.rb b/script/import_scripts/vanilla_mysql.rb
index 72f294337ae..5d337ea198e 100644
--- a/script/import_scripts/vanilla_mysql.rb
+++ b/script/import_scripts/vanilla_mysql.rb
@@ -166,7 +166,7 @@ class ImportScripts::VanillaSQL < ImportScripts::Base
).first
next if r.nil?
photo = r["photo"]
- next unless photo.present?
+ next if photo.blank?
# Possible encoded values:
# 1. cf://uploads/userpics/820/Y0AFUQYYM6QN.jpg
@@ -642,7 +642,7 @@ class ImportScripts::VanillaSQL < ImportScripts::Base
next if r.nil?
path = r["Path"]
name = r["Name"]
- next unless path.present?
+ next if path.blank?
path.gsub!("s3://content/", "")
path.gsub!("s3://uploads/", "")
diff --git a/script/import_scripts/yammer.rb b/script/import_scripts/yammer.rb
index f367a73cbfd..e7aa3f447b4 100644
--- a/script/import_scripts/yammer.rb
+++ b/script/import_scripts/yammer.rb
@@ -107,7 +107,7 @@ class ImportScripts::Yammer < ImportScripts::Base
csv_parse("Messages") do |row|
next unless row[:thread_id] == row[:id]
next if row[:in_private_conversation] == "true"
- next unless row[:deleted_at].blank?
+ next if row[:deleted_at].present?
# next if row[:message_type] == 'system'
title = ""
url = ""
@@ -119,7 +119,7 @@ class ImportScripts::Yammer < ImportScripts::Base
url = Regexp.last_match(2)
title = Regexp.last_match(3) if Regexp.last_match(3)
description = Regexp.last_match(4)
- raw += "\n***\n#{description}\n#{url}\n" unless raw.include?(url)
+ raw += "\n***\n#{description}\n#{url}\n" if raw.exclude?(url)
end
row[:attachments].match(/uploadedfile:(\d*)$/) do
file_id = Regexp.last_match(1).to_i
@@ -148,7 +148,7 @@ class ImportScripts::Yammer < ImportScripts::Base
csv_parse("Messages") do |row|
next unless row[:thread_id] == row[:id]
next unless row[:in_private_conversation] == "true"
- next unless row[:deleted_at].blank?
+ next if row[:deleted_at].present?
# next if row[:message_type] == 'system'
title = ""
url = ""
@@ -160,7 +160,7 @@ class ImportScripts::Yammer < ImportScripts::Base
url = Regexp.last_match(2)
title = Regexp.last_match(3) if Regexp.last_match(3)
description = Regexp.last_match(4)
- raw += "\n***\n#{description}\n#{url}\n" unless raw.include?(url)
+ raw += "\n***\n#{description}\n#{url}\n" if raw.exclude?(url)
end
row[:attachments].match(/uploadedfile:(\d*)$/) do
file_id = Regexp.last_match(1).to_i
@@ -189,7 +189,7 @@ class ImportScripts::Yammer < ImportScripts::Base
# get posts from messages
csv_parse("Messages") do |row|
next if row[:thread_id] == row[:id]
- next unless row[:deleted_at].blank?
+ next if row[:deleted_at].present?
next if row[:in_private_conversation] == "true"
@db.insert_post(
id: row[:id],
@@ -204,7 +204,7 @@ class ImportScripts::Yammer < ImportScripts::Base
# get pm posts from messages
csv_parse("Messages") do |row|
next if row[:thread_id] == row[:id]
- next unless row[:deleted_at].blank?
+ next if row[:deleted_at].present?
next unless row[:in_private_conversation] == "false"
@db.insert_pm_post(
id: row[:id],
diff --git a/script/import_scripts/zoho.rb b/script/import_scripts/zoho.rb
index b05debeb7e2..fecd28221c3 100644
--- a/script/import_scripts/zoho.rb
+++ b/script/import_scripts/zoho.rb
@@ -79,7 +79,7 @@ class ImportScripts::Zoho < ImportScripts::Base
@all_posts << row.dup
@categories[row.forum_name] = [] if @categories[row.forum_name].nil?
- unless @categories[row.forum_name].include?(row.category_name)
+ if @categories[row.forum_name].exclude?(row.category_name)
@categories[row.forum_name] << row.category_name
end
end
diff --git a/script/user_simulator.rb b/script/user_simulator.rb
index 562c559ed1c..0688d4fd214 100644
--- a/script/user_simulator.rb
+++ b/script/user_simulator.rb
@@ -38,7 +38,7 @@ end
require File.expand_path(File.dirname(__FILE__) + "/../config/environment")
-unless %w[profile development].include? Rails.env
+if %w[profile development].exclude? Rails.env
puts "Bad idea to run a script that inserts random posts in any non development environment"
exit
end
diff --git a/spec/lib/s3_inventory_spec.rb b/spec/lib/s3_inventory_spec.rb
index 7fca5bd2ede..3070fb99538 100644
--- a/spec/lib/s3_inventory_spec.rb
+++ b/spec/lib/s3_inventory_spec.rb
@@ -29,7 +29,7 @@ RSpec.describe S3Inventory do
freeze_time
CSV.foreach(csv_filename, headers: false) do |row|
- next unless row[S3Inventory::CSV_KEY_INDEX].include?("default")
+ next if row[S3Inventory::CSV_KEY_INDEX].exclude?("default")
Fabricate(
:upload,
etag: row[S3Inventory::CSV_ETAG_INDEX],
@@ -182,7 +182,7 @@ RSpec.describe S3Inventory do
freeze_time
CSV.foreach(csv_filename, headers: false) do |row|
- next unless row[S3Inventory::CSV_KEY_INDEX].include?("default")
+ next if row[S3Inventory::CSV_KEY_INDEX].exclude?("default")
Fabricate(:upload, etag: row[S3Inventory::CSV_ETAG_INDEX], updated_at: 2.days.ago)
end
diff --git a/spec/support/helpers.rb b/spec/support/helpers.rb
index 31d49528322..da79720a601 100644
--- a/spec/support/helpers.rb
+++ b/spec/support/helpers.rb
@@ -206,7 +206,7 @@ module Helpers
def track_sql_queries
queries = []
callback = ->(*, payload) do
- queries << payload.fetch(:sql) unless %w[CACHE SCHEMA].include?(payload.fetch(:name))
+ queries << payload.fetch(:sql) if %w[CACHE SCHEMA].exclude?(payload.fetch(:name))
end
ActiveSupport::Notifications.subscribed(callback, "sql.active_record") { yield }