Skip to content

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

DEV: Update rubocop-discourse to 3.13 and autofix issues (#35073)

Jarek Radosz71834c898f2f
diff --git a/Gemfile.lock b/Gemfile.lock
index 2985ea2886e..0a77cf914f5 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -562,7 +562,7 @@ GEM
rubocop-capybara (2.22.1)
lint_roller (~> 1.1)
rubocop (~> 1.72, >= 1.72.1)
- rubocop-discourse (3.12.1)
+ rubocop-discourse (3.13.3)
activesupport (>= 6.1)
lint_roller (>= 1.1.0)
rubocop (>= 1.73.2)
@@ -1156,7 +1156,7 @@ CHECKSUMS
rubocop (1.81.1) sha256=352a9a6f314a4312f6c305f1f72bc466254d221c95445cd49e1b65d1f9411635
rubocop-ast (1.47.1) sha256=592682017855408b046a8190689490763aecea175238232b1b526826349d01ae
rubocop-capybara (2.22.1) sha256=ced88caef23efea53f46e098ff352f8fc1068c649606ca75cb74650970f51c0c
- rubocop-discourse (3.12.1) sha256=ebf7e2224f053047372071419052828c3e3a01bccb14ea1f282ac143547df9bc
+ rubocop-discourse (3.13.3) sha256=637395e37ac45f0c5ba4376d7648b5f1e3a8406697c38befb66a9729738a059f
rubocop-factory_bot (2.27.1) sha256=9d744b5916778c1848e5fe6777cc69855bd96548853554ec239ba9961b8573fe
rubocop-rails (2.33.4) sha256=34ec8f6637706dc224483d949ccc88b3e41596a81a11a1ec0c7d74ecbea356b5
rubocop-rspec (3.7.0) sha256=b7b214da112034db9c6d00f2d811a354847e870f7b6ed2482b29649c3d42058f
diff --git a/app/controllers/admin/admin_notices_controller.rb b/app/controllers/admin/admin_notices_controller.rb
index 44c787abb87..5f22a7ddf25 100644
--- a/app/controllers/admin/admin_notices_controller.rb
+++ b/app/controllers/admin/admin_notices_controller.rb
@@ -4,7 +4,7 @@ class Admin::AdminNoticesController < Admin::StaffController
def destroy
AdminNotices::Dismiss.call(service_params) do
on_success { render(json: success_json) }
- on_failure { render(json: failed_json, status: 422) }
+ on_failure { render(json: failed_json, status: :unprocessable_entity) }
end
end
end
diff --git a/app/controllers/admin/api_controller.rb b/app/controllers/admin/api_controller.rb
index 4bc15407627..acb48730665 100644
--- a/app/controllers/admin/api_controller.rb
+++ b/app/controllers/admin/api_controller.rb
@@ -27,7 +27,7 @@ class Admin::ApiController < Admin::AdminController
end
def show
- api_key = ApiKey.includes(:api_key_scopes).find_by!(id: params[:id])
+ api_key = ApiKey.includes(:api_key_scopes).find(params[:id])
render_serialized(api_key, ApiKeySerializer, root: "key")
end
@@ -53,7 +53,7 @@ class Admin::ApiController < Admin::AdminController
end
def update
- api_key = ApiKey.find_by!(id: params[:id])
+ api_key = ApiKey.find(params[:id])
ApiKey.transaction do
api_key.update!(update_params)
log_api_key(api_key, UserHistory.actions[:api_key_update], changes: api_key.saved_changes)
@@ -62,7 +62,7 @@ class Admin::ApiController < Admin::AdminController
end
def destroy
- api_key = ApiKey.find_by!(id: params[:id])
+ api_key = ApiKey.find(params[:id])
ApiKey.transaction do
api_key.destroy
log_api_key(api_key, UserHistory.actions[:api_key_destroy])
diff --git a/app/controllers/admin/backups_controller.rb b/app/controllers/admin/backups_controller.rb
index e19d2a55614..c81e3bf308a 100644
--- a/app/controllers/admin/backups_controller.rb
+++ b/app/controllers/admin/backups_controller.rb
@@ -89,14 +89,14 @@ class Admin::BackupsController < Admin::AdminController
render body: nil
else
- render body: nil, status: 404
+ render body: nil, status: :not_found
end
end
def show
if !EmailBackupToken.compare(current_user.id, params.fetch(:token))
@error = I18n.t("download_backup_mailer.no_token")
- return render layout: "no_ember", status: 422, formats: [:html]
+ return render layout: "no_ember", status: :unprocessable_entity, formats: [:html]
end
store = BackupRestore::BackupStore.create
@@ -112,7 +112,7 @@ class Admin::BackupsController < Admin::AdminController
send_file backup.source
end
else
- render body: nil, status: 404
+ render body: nil, status: :not_found
end
end
@@ -124,7 +124,7 @@ class Admin::BackupsController < Admin::AdminController
store.delete_file(backup.filename)
render body: nil
else
- render body: nil, status: 404
+ render body: nil, status: :not_found
end
end
@@ -193,13 +193,17 @@ class Admin::BackupsController < Admin::AdminController
raise Discourse::InvalidParameters.new(:resumableIdentifier) unless valid_filename?(identifier)
unless valid_extension?(filename)
- return render status: 415, plain: I18n.t("backup.backup_file_should_be_tar_gz")
+ return(
+ render status: :unsupported_media_type, plain: I18n.t("backup.backup_file_should_be_tar_gz")
+ )
end
unless has_enough_space_on_disk?(total_size)
- return render status: 415, plain: I18n.t("backup.not_enough_space_on_disk")
+ return(
+ render status: :unsupported_media_type, plain: I18n.t("backup.not_enough_space_on_disk")
+ )
end
unless valid_filename?(filename)
- return render status: 415, plain: I18n.t("backup.invalid_filename")
+ return render status: :unsupported_media_type, plain: I18n.t("backup.invalid_filename")
end
file = params.fetch(:file)
diff --git a/app/controllers/admin/badges_controller.rb b/app/controllers/admin/badges_controller.rb
index 198cd967b1d..901fee1b2b3 100644
--- a/app/controllers/admin/badges_controller.rb
+++ b/app/controllers/admin/badges_controller.rb
@@ -24,7 +24,9 @@ class Admin::BadgesController < Admin::AdminController
end
def preview
- return render json: "preview not allowed", status: 403 unless SiteSetting.enable_badge_sql
+ unless SiteSetting.enable_badge_sql
+ return render json: "preview not allowed", status: :forbidden
+ end
render json:
BadgeGranter.preview(
diff --git a/app/controllers/admin/config/flags_controller.rb b/app/controllers/admin/config/flags_controller.rb
index c0f3f888ebc..815535dfd2c 100644
--- a/app/controllers/admin/config/flags_controller.rb
+++ b/app/controllers/admin/config/flags_controller.rb
@@ -7,11 +7,11 @@ class Admin::Config::FlagsController < Admin::AdminController
Discourse.request_refresh!
render(json: success_json)
end
- on_failure { render(json: failed_json, status: 422) }
+ on_failure { render(json: failed_json, status: :unprocessable_entity) }
on_model_not_found(:message) { raise Discourse::NotFound }
on_failed_policy(:invalid_access) { raise Discourse::InvalidAccess }
on_failed_contract do |contract|
- render(json: failed_json.merge(errors: contract.errors.full_messages), status: 400)
+ render(json: failed_json.merge(errors: contract.errors.full_messages), status: :bad_request)
end
end
end
@@ -31,11 +31,11 @@ class Admin::Config::FlagsController < Admin::AdminController
Discourse.request_refresh!
render json: flag, serializer: FlagSerializer
end
- on_failure { render(json: failed_json, status: 422) }
+ on_failure { render(json: failed_json, status: :unprocessable_entity) }
on_failed_policy(:invalid_access) { raise Discourse::InvalidAccess }
on_failed_policy(:unique_name) { render_json_error(I18n.t("flags.errors.unique_name")) }
on_failed_contract do |contract|
- render(json: failed_json.merge(errors: contract.errors.full_messages), status: 400)
+ render(json: failed_json.merge(errors: contract.errors.full_messages), status: :bad_request)
end
end
end
@@ -46,14 +46,14 @@ class Admin::Config::FlagsController < Admin::AdminController
Discourse.request_refresh!
render json: flag, serializer: FlagSerializer
end
- on_failure { render(json: failed_json, status: 422) }
+ on_failure { render(json: failed_json, status: :unprocessable_entity) }
on_model_not_found(:message) { raise Discourse::NotFound }
on_failed_policy(:not_system) { render_json_error(I18n.t("flags.errors.system")) }
on_failed_policy(:not_used) { render_json_error(I18n.t("flags.errors.used")) }
on_failed_policy(:invalid_access) { raise Discourse::InvalidAccess }
on_failed_policy(:unique_name) { render_json_error(I18n.t("flags.errors.unique_name")) }
on_failed_contract do |contract|
- render(json: failed_json.merge(errors: contract.errors.full_messages), status: 400)
+ render(json: failed_json.merge(errors: contract.errors.full_messages), status: :bad_request)
end
end
end
@@ -64,12 +64,12 @@ class Admin::Config::FlagsController < Admin::AdminController
Discourse.request_refresh!
render(json: success_json)
end
- on_failure { render(json: failed_json, status: 422) }
+ on_failure { render(json: failed_json, status: :unprocessable_entity) }
on_model_not_found(:message) { raise Discourse::NotFound }
on_failed_policy(:invalid_access) { raise Discourse::InvalidAccess }
on_failed_policy(:invalid_move) { render_json_error(I18n.t("flags.errors.wrong_move")) }
on_failed_contract do |contract|
- render(json: failed_json.merge(errors: contract.errors.full_messages), status: 400)
+ render(json: failed_json.merge(errors: contract.errors.full_messages), status: :bad_request)
end
end
end
@@ -80,12 +80,12 @@ class Admin::Config::FlagsController < Admin::AdminController
Discourse.request_refresh!
render(json: success_json)
end
- on_failure { render(json: failed_json, status: 422) }
+ on_failure { render(json: failed_json, status: :unprocessable_entity) }
on_failed_policy(:not_system) { render_json_error(I18n.t("flags.errors.system")) }
on_failed_policy(:not_used) { render_json_error(I18n.t("flags.errors.used")) }
on_failed_policy(:invalid_access) { raise Discourse::InvalidAccess }
on_failed_contract do |contract|
- render(json: failed_json.merge(errors: contract.errors.full_messages), status: 400)
+ render(json: failed_json.merge(errors: contract.errors.full_messages), status: :bad_request)
end
end
end
diff --git a/app/controllers/admin/dashboard_controller.rb b/app/controllers/admin/dashboard_controller.rb
index 2253b89abb7..5df42c0a9ce 100644
--- a/app/controllers/admin/dashboard_controller.rb
+++ b/app/controllers/admin/dashboard_controller.rb
@@ -63,11 +63,11 @@ class Admin::DashboardController < Admin::StaffController
def toggle_feature
Experiments::Toggle.call(service_params) do
on_success { render(json: success_json) }
- on_failure { render(json: failed_json, status: 422) }
+ on_failure { render(json: failed_json, status: :unprocessable_entity) }
on_failed_policy(:current_user_is_admin) { raise Discourse::InvalidAccess }
on_failed_policy(:setting_is_available) { raise Discourse::InvalidAccess }
on_failed_contract do |contract|
- render(json: failed_json.merge(errors: contract.errors.full_messages), status: 400)
+ render(json: failed_json.merge(errors: contract.errors.full_messages), status: :bad_request)
end
end
end
diff --git a/app/controllers/admin/email_controller.rb b/app/controllers/admin/email_controller.rb
index 0d00cc2c9e6..b8a5fd290af 100644
--- a/app/controllers/admin/email_controller.rb
+++ b/app/controllers/admin/email_controller.rb
@@ -17,7 +17,7 @@ class Admin::EmailController < Admin::AdminController
render json: { sent_test_email_message: I18n.t("admin.email.sent_test") }
rescue => e
- render json: { errors: [e.message] }, status: 422
+ render json: { errors: [e.message] }, status: :unprocessable_entity
end
end
@@ -55,7 +55,7 @@ class Admin::EmailController < Admin::AdminController
Email::Sender.new(message, :digest).send
render json: success_json
rescue => e
- render json: { errors: [e.message] }, status: 422
+ render json: { errors: [e.message] }, status: :unprocessable_entity
end
else
render json: { errors: skip_reason }
diff --git a/app/controllers/admin/email_logs_controller.rb b/app/controllers/admin/email_logs_controller.rb
index 65a6d0b069c..2e2b9e1c549 100644
--- a/app/controllers/admin/email_logs_controller.rb
+++ b/app/controllers/admin/email_logs_controller.rb
@@ -96,7 +96,7 @@ class Admin::EmailLogsController < Admin::AdminController
serializer = IncomingEmailDetailsSerializer.new(incoming_email, root: false)
render_json_dump(serializer)
rescue => e
- render json: { errors: [e.message] }, status: 404
+ render json: { errors: [e.message] }, status: :not_found
end
end
diff --git a/app/controllers/admin/reports_controller.rb b/app/controllers/admin/reports_controller.rb
index dcd100c2499..5266a552194 100644
--- a/app/controllers/admin/reports_controller.rb
+++ b/app/controllers/admin/reports_controller.rb
@@ -87,7 +87,7 @@ class Admin::ReportsController < Admin::StaffController
if report_params[:start_date].present?
Time.parse(report_params[:start_date]).to_date
else
- 1.days.ago
+ 1.day.ago
end
).beginning_of_day
end_date =
diff --git a/app/controllers/admin/site_texts_controller.rb b/app/controllers/admin/site_texts_controller.rb
index b79352dd1c7..9d3118de664 100644
--- a/app/controllers/admin/site_texts_controller.rb
+++ b/app/controllers/admin/site_texts_controller.rb
@@ -106,7 +106,7 @@ class Admin::SiteTextsController < Admin::AdminController
else
render json:
failed_json.merge(message: translation_override.errors.full_messages.join("\n\n")),
- status: 422
+ status: :unprocessable_entity
end
end
@@ -140,7 +140,8 @@ class Admin::SiteTextsController < Admin::AdminController
if override.make_up_to_date!
render json: success_json
else
- render json: failed_json.merge(message: "Can only dismiss outdated translations"), status: 422
+ render json: failed_json.merge(message: "Can only dismiss outdated translations"),
+ status: :unprocessable_entity
end
end
diff --git a/app/controllers/admin/themes_controller.rb b/app/controllers/admin/themes_controller.rb
index c20b3df47cb..2fef9399a9d 100644
--- a/app/controllers/admin/themes_controller.rb
+++ b/app/controllers/admin/themes_controller.rb
@@ -205,13 +205,13 @@ class Admin::ThemesController < Admin::AdminController
) do
on_success { |theme:| render json: serialize_data(theme, ThemeSerializer), status: :created }
on_failed_contract do |contract|
- render json: failed_json.merge(errors: contract.errors.full_messages), status: 400
+ render json: failed_json.merge(errors: contract.errors.full_messages), status: :bad_request
end
on_failed_policy(:ensure_remote_themes_are_not_allowlisted) { raise Discourse::InvalidAccess }
on_model_errors { |theme:| render json: theme.errors, status: :unprocessable_entity }
on_model_not_found(:theme) do |result|
raise Discourse::NotFound if !result.exception
- render json: failed_json.merge(errors: result.exception.message), status: 400
+ render json: failed_json.merge(errors: result.exception.message), status: :bad_request
end
end
end
@@ -291,7 +291,7 @@ class Admin::ThemesController < Admin::AdminController
Themes::Destroy.call(service_params) do
on_success { head :no_content }
on_failed_contract do |contract|
- render json: failed_json.merge(errors: contract.errors.full_messages), status: 400
+ render json: failed_json.merge(errors: contract.errors.full_messages), status: :bad_request
end
on_model_not_found(:theme) { raise Discourse::NotFound }
end
@@ -301,7 +301,7 @@ class Admin::ThemesController < Admin::AdminController
Themes::BulkDestroy.call(service_params) do
on_success { head :no_content }
on_failed_contract do |contract|
- render json: failed_json.merge(errors: contract.errors.full_messages), status: 400
+ render json: failed_json.merge(errors: contract.errors.full_messages), status: :bad_request
end
on_model_not_found(:themes) { raise Discourse::NotFound }
end
@@ -333,7 +333,7 @@ class Admin::ThemesController < Admin::AdminController
Themes::GetTranslations.call(service_params) do
on_success { |translations:| render(json: success_json.merge(translations:)) }
on_failed_contract do |contract|
- render json: failed_json.merge(errors: contract.errors.full_messages), status: 400
+ render json: failed_json.merge(errors: contract.errors.full_messages), status: :bad_request
end
on_failed_policy(:validate_locale) { raise Discourse::InvalidParameters.new(:locale) }
on_model_not_found(:theme) { raise Discourse::NotFound }
diff --git a/app/controllers/admin/users_controller.rb b/app/controllers/admin/users_controller.rb
index 315a1648239..8d94fac4f4b 100644
--- a/app/controllers/admin/users_controller.rb
+++ b/app/controllers/admin/users_controller.rb
@@ -135,11 +135,11 @@ class Admin::UsersController < Admin::StaffController
)
end
on_failed_contract do |contract|
- render json: failed_json.merge(errors: contract.errors.full_messages), status: 400
+ render json: failed_json.merge(errors: contract.errors.full_messages), status: :bad_request
end
on_model_not_found(:user) { raise Discourse::NotFound }
on_failed_policy(:not_suspended_already) do |policy|
- render json: failed_json.merge(message: policy.reason), status: 409
+ render json: failed_json.merge(message: policy.reason), status: :conflict
end
on_failed_policy(:can_suspend_all_users) { raise Discourse::InvalidAccess.new }
end
@@ -163,7 +163,7 @@ class Admin::UsersController < Admin::StaffController
@user.logged_out
render json: success_json
else
- render json: { error: I18n.t("admin_js.admin.users.id_not_found") }, status: 404
+ render json: { error: I18n.t("admin_js.admin.users.id_not_found") }, status: :not_found
end
end
@@ -335,11 +335,11 @@ class Admin::UsersController < Admin::StaffController
)
end
on_failed_contract do |contract|
- render json: failed_json.merge(errors: contract.errors.full_messages), status: 400
+ render json: failed_json.merge(errors: contract.errors.full_messages), status: :bad_request
end
on_model_not_found(:user) { raise Discourse::NotFound }
on_failed_policy(:not_silenced_already) do |policy|
- render json: failed_json.merge(message: policy.reason), status: 409
+ render json: failed_json.merge(message: policy.reason), status: :conflict
end
on_failed_policy(:can_silence_all_users) { raise Discourse::InvalidAccess.new }
end
@@ -404,7 +404,7 @@ class Admin::UsersController < Admin::StaffController
count: user.posts.joins(:topic).count,
),
},
- status: 403
+ status: :forbidden
end
end
end
@@ -419,14 +419,16 @@ class Admin::UsersController < Admin::StaffController
on_success { render json: { deleted: true } }
on_failed_contract do |contract|
- render json: failed_json.merge(errors: contract.errors.full_messages), status: 400
+ render json: failed_json.merge(errors: contract.errors.full_messages),
+ status: :bad_request
end
on_failed_policy(:can_delete_users) do
- render json: failed_json.merge(errors: [I18n.t("user.cannot_bulk_delete")]), status: 403
+ render json: failed_json.merge(errors: [I18n.t("user.cannot_bulk_delete")]),
+ status: :forbidden
end
- on_model_not_found(:users) { render json: failed_json, status: 404 }
+ on_model_not_found(:users) { render json: failed_json, status: :not_found }
end
end
end
@@ -445,14 +447,14 @@ class Admin::UsersController < Admin::StaffController
end
def sync_sso
- return render body: nil, status: 404 unless SiteSetting.enable_discourse_connect
+ return render body: nil, status: :not_found unless SiteSetting.enable_discourse_connect
begin
sso = DiscourseConnect.parse("sso=#{params[:sso]}&sig=#{params[:sig]}", server_session:)
rescue DiscourseConnect::ParseError
return(
render json: failed_json.merge(message: I18n.t("discourse_connect.login_error")),
- status: 422
+ status: :unprocessable_entity
)
end
@@ -461,10 +463,10 @@ class Admin::UsersController < Admin::StaffController
DiscourseEvent.trigger(:sync_sso, user)
render_serialized(user, AdminDetailedUserSerializer, root: false)
rescue ActiveRecord::RecordInvalid => ex
- render json: failed_json.merge(message: ex.message), status: 403
+ render json: failed_json.merge(message: ex.message), status: :forbidden
rescue DiscourseConnect::BlankExternalId => ex
render json: failed_json.merge(message: I18n.t("discourse_connect.blank_id_error")),
- status: 422
+ status: :unprocessable_entity
end
end
diff --git a/app/controllers/admin/web_hooks_controller.rb b/app/controllers/admin/web_hooks_controller.rb
index 208da2048ae..91232c0ccac 100644
--- a/app/controllers/admin/web_hooks_controller.rb
+++ b/app/controllers/admin/web_hooks_controller.rb
@@ -39,20 +39,20 @@ class Admin::WebHooksController < Admin::AdminController
admin_web_hooks_path(limit: limit, offset: offset + limit, format: :json),
}
- render json: MultiJson.dump(json), status: 200
+ render json: MultiJson.dump(json), status: :ok
end
def show
data = serialize_data(@web_hook, AdminWebHookSerializer, root: "web_hook")
web_hook = data.delete("web_hook")
data = { "extras" => data, "web_hook" => web_hook }
- render json: MultiJson.dump(data), status: 200
+ render json: MultiJson.dump(data), status: :ok
end
def edit
data = serialize_data(@web_hook, AdminWebHookSerializer, root: "web_hook")
data["extras"] = { "categories" => data.delete(:categories) }
- render json: MultiJson.dump(data), status: 200
+ render json: MultiJson.dump(data), status: :ok
end
def create
@@ -120,7 +120,7 @@ class Admin::WebHooksController < Admin::AdminController
},
}
- render json: MultiJson.dump(json), status: 200
+ render json: MultiJson.dump(json), status: :ok
end
def bulk_events
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb
index 1eef09ab3ab..5b43bc5038e 100644
--- a/app/controllers/application_controller.rb
+++ b/app/controllers/application_controller.rb
@@ -29,7 +29,7 @@ class ApplicationController < ActionController::Base
unless is_api? || is_user_api?
super
clear_current_user
- render plain: "[\"BAD CSRF\"]", status: 403
+ render plain: "[\"BAD CSRF\"]", status: :forbidden
end
end
@@ -255,14 +255,16 @@ class ApplicationController < ActionController::Base
format.json do
render_json_error I18n.t("read_only_mode_enabled"), type: :read_only, status: 503
end
- format.html { render status: 503, layout: "no_ember", template: "exceptions/read_only" }
+ format.html do
+ render status: :service_unavailable, layout: "no_ember", template: "exceptions/read_only"
+ end
end
end
end
rescue_from SecondFactor::AuthManager::SecondFactorRequired do |e|
if request.xhr?
- render json: { second_factor_challenge_nonce: e.nonce }, status: 403
+ render json: { second_factor_challenge_nonce: e.nonce }, status: :forbidden
else
redirect_to session_2fa_path(nonce: e.nonce)
end
diff --git a/app/controllers/bookmarks_controller.rb b/app/controllers/bookmarks_controller.rb
index d5414fec6f8..2912b929d74 100644
--- a/app/controllers/bookmarks_controller.rb
+++ b/app/controllers/bookmarks_controller.rb
@@ -35,7 +35,8 @@ class BookmarksController < ApplicationController
return render json: success_json.merge(id: bookmark.id) if bookmark_manager.errors.empty?
- render json: failed_json.merge(errors: bookmark_manager.errors.full_messages), status: 400
+ render json: failed_json.merge(errors: bookmark_manager.errors.full_messages),
+ status: :bad_request
end
def destroy
@@ -61,7 +62,8 @@ class BookmarksController < ApplicationController
return render json: success_json if bookmark_manager.errors.empty?
- render json: failed_json.merge(errors: bookmark_manager.errors.full_messages), status: 400
+ render json: failed_json.merge(errors: bookmark_manager.errors.full_messages),
+ status: :bad_request
end
def toggle_pin
@@ -72,7 +74,8 @@ class BookmarksController < ApplicationController
return render json: success_json if bookmark_manager.errors.empty?
- render json: failed_json.merge(errors: bookmark_manager.errors.full_messages), status: 400
+ render json: failed_json.merge(errors: bookmark_manager.errors.full_messages),
+ status: :bad_request
end
def bulk
diff --git a/app/controllers/categories_controller.rb b/app/controllers/categories_controller.rb
index 7dc95e25e26..1ad26c90551 100644
--- a/app/controllers/categories_controller.rb
+++ b/app/controllers/categories_controller.rb
@@ -100,7 +100,7 @@ class CategoriesController < ApplicationController
category.move_to(params["position"].to_i)
render json: success_json
else
- render status: 500, json: failed_json
+ render status: :internal_server_error, json: failed_json
end
end
@@ -143,7 +143,7 @@ class CategoriesController < ApplicationController
begin
Category.new(required_create_params.merge(user: current_user))
rescue ArgumentError => e
- return render json: { errors: [e.message] }, status: 422
+ return render json: { errors: [e.message] }, status: :unprocessable_entity
end
if @category.save
diff --git a/app/controllers/drafts_controller.rb b/app/controllers/drafts_controller.rb
index da11cec64d1..a40c57a9520 100644
--- a/app/controllers/drafts_controller.rb
+++ b/app/controllers/drafts_controller.rb
@@ -148,7 +148,7 @@ class DraftsController < ApplicationController
# nothing really we can do here, if try clearing a draft that is not ours, just skip it.
# rendering an error causes issues in the composer
rescue StandardError => e
- return render json: failed_json.merge(errors: e), status: 401
+ return render json: failed_json.merge(errors: e), status: :unauthorized
end
render json: success_json
@@ -191,7 +191,7 @@ class DraftsController < ApplicationController
failed_json.merge(
errors: "Draft sequence conflict for keys: #{sequence_errors.join(", ")}",
),
- status: 409
+ status: :conflict
return
end
@@ -205,7 +205,7 @@ class DraftsController < ApplicationController
UserStat.update_draft_count(user.id)
end
rescue StandardError => e
- return render json: failed_json.merge(errors: e.message), status: 500
+ return render json: failed_json.merge(errors: e.message), status: :internal_server_error
end
render json: success_json.merge(deleted_count: deleted_count)
diff --git a/app/controllers/embed_controller.rb b/app/controllers/embed_controller.rb
index b0bd5893997..558ca261478 100644
--- a/app/controllers/embed_controller.rb
+++ b/app/controllers/embed_controller.rb
@@ -16,14 +16,14 @@ class EmbedController < ApplicationController
@show_reason = true
@hosts = EmbeddableHost.all
end
- render "embed_error", status: 400
+ render "embed_error", status: :bad_request
end
def topics
discourse_expires_in 1.minute
unless SiteSetting.embed_topics_list?
- render "embed_topics_error", status: 400
+ render "embed_topics_error", status: :bad_request
return
end
diff --git a/app/controllers/export_csv_controller.rb b/app/controllers/export_csv_controller.rb
index 6ce173b1bce..30889fd5267 100644
--- a/app/controllers/export_csv_controller.rb
+++ b/app/controllers/export_csv_controller.rb
@@ -22,7 +22,7 @@ class ExportCsvController < ApplicationController
unless current_user.admin ||
UserExport.where(
user_id: entity_id || current_user.id,
- created_at: (Time.zone.now.beginning_of_day..Time.zone.now.end_of_day),
+ created_at: (Time.zone.now.all_day),
).count == 0
render_json_error I18n.t("csv_export.rate_limit_error")
return
diff --git a/app/controllers/forums_controller.rb b/app/controllers/forums_controller.rb
index 61987c111b2..2d1c950e713 100644
--- a/app/controllers/forums_controller.rb
+++ b/app/controllers/forums_controller.rb
@@ -11,9 +11,9 @@ class ForumsController < ActionController::Base
def status
if params[:cluster]
if GlobalSetting.cluster_name.nil?
- return render plain: "cluster name not configured", status: 500
+ return render plain: "cluster name not configured", status: :internal_server_error
elsif GlobalSetting.cluster_name != params[:cluster]
- return render plain: "cluster name does not match", status: 500
+ return render plain: "cluster name does not match", status: :internal_server_error
end
end
diff --git a/app/controllers/groups_controller.rb b/app/controllers/groups_controller.rb
index bb34a8e810e..9e0e42e5593 100644
--- a/app/controllers/groups_controller.rb
+++ b/app/controllers/groups_controller.rb
@@ -162,7 +162,7 @@ class GroupsController < ApplicationController
user_count = count_existing_users(group.group_users, notification_level, categories, tags)
if user_count > 0
return(
- render status: 422,
+ render status: :unprocessable_entity,
json: {
user_count: user_count,
errors: [I18n.t("invalid_params", message: :update_existing_users)],
@@ -612,7 +612,7 @@ class GroupsController < ApplicationController
rescue ActiveRecord::RecordNotUnique
return(
render json: failed_json.merge(error: I18n.t("groups.errors.already_requested_membership")),
- status: 409
+ status: :conflict
)
end
diff --git a/app/controllers/inline_onebox_controller.rb b/app/controllers/inline_onebox_controller.rb
index b8e4240a5c4..babd723a80c 100644
--- a/app/controllers/inline_onebox_controller.rb
+++ b/app/controllers/inline_onebox_controller.rb
@@ -9,7 +9,8 @@ class InlineOneboxController < ApplicationController
urls = params[:urls] || []
if urls.size > MAX_URLS_LIMIT
- render json: failed_json.merge(errors: [I18n.t("inline_oneboxer.too_many_urls")]), status: 413
+ render json: failed_json.merge(errors: [I18n.t("inline_oneboxer.too_many_urls")]),
+ status: :payload_too_large
return
end
@@ -18,7 +19,7 @@ class InlineOneboxController < ApplicationController
if InlineOneboxer.is_previewing?(current_user_id)
response.headers["Retry-After"] = "60"
render json: failed_json.merge(errors: [I18n.t("inline_oneboxer.concurrency_not_allowed")]),
- status: 429
+ status: :too_many_requests
return
end
diff --git a/app/controllers/invites_controller.rb b/app/controllers/invites_controller.rb
index 19220197694..68f816965c0 100644
--- a/app/controllers/invites_controller.rb
+++ b/app/controllers/invites_controller.rb
@@ -169,7 +169,7 @@ class InvitesController < ApplicationController
show_warnings: true,
)
else
- render json: failed_json, status: 422
+ render json: failed_json, status: :unprocessable_entity
end
rescue Invite::UserExists => e
render_json_error(e.message)
@@ -378,11 +378,14 @@ class InvitesController < ApplicationController
ActiveRecord::RecordNotSaved,
ActiveRecord::LockWaitTimeout,
Invite::UserExists => e
- return render json: failed_json.merge(message: e.message), status: 412
+ return render json: failed_json.merge(message: e.message), status: :precondition_failed
end
if user.blank?
- return render json: failed_json.merge(message: I18n.t("invite.not_found_json")), status: 404
+ return(
+ render json: failed_json.merge(message: I18n.t("invite.not_found_json")),
+ status: :not_found
+ )
end
log_on_user(user) if !redeeming_user && user.active? && user.guardian.can_access_forum?
@@ -416,7 +419,7 @@ class InvitesController < ApplicationController
render json: success_json.merge(response)
else
- render json: failed_json.merge(message: I18n.t("invite.not_found_json")), status: 404
+ render json: failed_json.merge(message: I18n.t("invite.not_found_json")), status: :not_found
end
end
@@ -495,7 +498,9 @@ class InvitesController < ApplicationController
DiscoursePluginRegistry.apply_modifier(:invite_bulk_csv_custom_error, nil, invites)
if custom_error.present?
- return render json: failed_json.merge(errors: [custom_error]), status: 422
+ return(
+ render json: failed_json.merge(errors: [custom_error]), status: :unprocessable_entity
+ )
end
Jobs.enqueue(:bulk_invite, invites: invites, current_user_id: current_user.id)
@@ -510,12 +515,13 @@ class InvitesController < ApplicationController
),
],
),
- status: 422
+ status: :unprocessable_entity
else
render json: success_json
end
else
- render json: failed_json.merge(errors: [I18n.t("bulk_invite.error")]), status: 422
+ render json: failed_json.merge(errors: [I18n.t("bulk_invite.error")]),
+ status: :unprocessable_entity
end
end
end
diff --git a/app/controllers/list_controller.rb b/app/controllers/list_controller.rb
index 0de3afb3094..08706302a08 100644
--- a/app/controllers/list_controller.rb
+++ b/app/controllers/list_controller.rb
@@ -430,7 +430,7 @@ class ListController < ApplicationController
url = url.sub(ActionController::Base.config.relative_url_root, "")
end
- return redirect_to path(url), status: 301
+ return redirect_to path(url), status: :moved_permanently
end
@description_meta =
diff --git a/app/controllers/metadata_controller.rb b/app/controllers/metadata_controller.rb
index b9b2a2978bc..77a71ff8090 100644
--- a/app/controllers/metadata_controller.rb
+++ b/app/controllers/metadata_controller.rb
@@ -8,24 +8,24 @@ class MetadataController < ApplicationController
:redirect_to_profile_if_required
def manifest
- expires_in 1.minutes
+ expires_in 1.minute
render json: default_manifest.to_json, content_type: "application/manifest+json"
end
def opensearch
- expires_in 1.minutes
+ expires_in 1.minute
render template: "metadata/opensearch", formats: [:xml]
end
def app_association_android
raise Discourse::NotFound if SiteSetting.app_association_android.blank?
- expires_in 1.minutes
+ expires_in 1.minute
render plain: SiteSetting.app_association_android, content_type: "application/json"
end
def app_association_ios
raise Discourse::NotFound if SiteSetting.app_association_ios.blank?
- expires_in 1.minutes
+ expires_in 1.minute
render plain: SiteSetting.app_association_ios, content_type: "application/json"
end
diff --git a/app/controllers/onebox_controller.rb b/app/controllers/onebox_controller.rb
index 5ccdcd0b9e0..c691876e003 100644
--- a/app/controllers/onebox_controller.rb
+++ b/app/controllers/onebox_controller.rb
@@ -11,7 +11,7 @@ class OneboxController < ApplicationController
end
# only 1 outgoing preview per user
- return render(body: nil, status: 429) if Oneboxer.is_previewing?(current_user.id)
+ return render(body: nil, status: :too_many_requests) if Oneboxer.is_previewing?(current_user.id)
user_id = current_user.id
category_id = params[:category_id].to_i
@@ -19,7 +19,7 @@ class OneboxController < ApplicationController
invalidate = params[:refresh] == "true"
url = params[:url]
- return render(body: nil, status: 404) if Oneboxer.recently_failed?(url)
+ return render(body: nil, status: :not_found) if Oneboxer.recently_failed?(url)
hijack(info: "#{url} topic_id: #{topic_id} user_id: #{user_id}") do
Oneboxer.preview_onebox!(user_id)
@@ -39,7 +39,7 @@ class OneboxController < ApplicationController
if preview.blank?
Oneboxer.cache_failed!(url)
- render body: nil, status: 404
+ render body: nil, status: :not_found
else
render plain: preview
end
diff --git a/app/controllers/reviewable_notes_controller.rb b/app/controllers/reviewable_notes_controller.rb
index 9c7a199b394..c2a9cf4168c 100644
--- a/app/controllers/reviewable_notes_controller.rb
+++ b/app/controllers/reviewable_notes_controller.rb
@@ -13,7 +13,7 @@ class ReviewableNotesController < ApplicationController
note.reload
render json: ReviewableNoteSerializer.new(note, scope: guardian, root: false)
else
- render json: { errors: note.errors.full_messages }, status: 422
+ render json: { errors: note.errors.full_messages }, status: :unprocessable_entity
end
end
diff --git a/app/controllers/session_controller.rb b/app/controllers/session_controller.rb
index 1841f269f1b..bd0192dcca0 100644
--- a/app/controllers/session_controller.rb
+++ b/app/controllers/session_controller.rb
@@ -91,14 +91,15 @@ class SessionController < ApplicationController
render json: success_json.merge(redirect_url: redirect_url)
end
rescue DiscourseConnectProvider::BlankSecret
- render plain: I18n.t("discourse_connect.missing_secret"), status: 400
+ render plain: I18n.t("discourse_connect.missing_secret"), status: :bad_request
rescue DiscourseConnectProvider::ParseError
# Do NOT pass the error text to the client, it would give them the correct signature
- render plain: I18n.t("discourse_connect.login_error"), status: 422
+ render plain: I18n.t("discourse_connect.login_error"), status: :unprocessable_entity
rescue DiscourseConnectProvider::BlankReturnUrl
- render plain: "return_sso_url is blank, it must be provided", status: 400
+ render plain: "return_sso_url is blank, it must be provided", status: :bad_request
rescue DiscourseConnectProvider::InvalidParameterValueError => e
- render plain: I18n.t("discourse_connect.invalid_parameter_value", param: e.param), status: 400
+ render plain: I18n.t("discourse_connect.invalid_parameter_value", param: e.param),
+ status: :bad_request
end
# For use in development mode only when login options could be limited or disabled.
@@ -110,7 +111,7 @@ class SessionController < ApplicationController
raise Discourse::InvalidAccess if Rails.env.production?
if ENV["DISCOURSE_DEV_ALLOW_ANON_TO_IMPERSONATE"] != "1"
- return render plain: <<~TEXT, status: 403
+ return render plain: <<~TEXT, status: :forbidden
To enable impersonating any user without typing passwords set the following ENV var
export DISCOURSE_DEV_ALLOW_ANON_TO_IMPERSONATE=1
@@ -122,9 +123,9 @@ class SessionController < ApplicationController
user = User.find_by_username(params[:session_id])
if user.blank?
- return render plain: "User #{params[:session_id]} not found", status: 403
+ return render plain: "User #{params[:session_id]} not found", status: :forbidden
elsif !user.active?
- return render plain: "User #{params[:session_id]} is not active", status: 403
+ return render plain: "User #{params[:session_id]} is not active", status: :forbidden
end
log_on_user(user)
@@ -157,7 +158,7 @@ class SessionController < ApplicationController
# but since this is a test route, we allow passing a bad value into the API, catch the error
# and return a JSON response to assert against.
if e.message == "running 2fa against another user is not allowed"
- render json: { result: "wrong user" }, status: 400
+ render json: { result: "wrong user" }, status: :bad_request
else
raise e
end
@@ -605,7 +606,7 @@ class SessionController < ApplicationController
.deep_symbolize_keys
.slice(:ok, :error, :reason)
.merge(failed_json)
- render json: error_json, status: 400
+ render json: error_json, status: :bad_request
return
end
end
@@ -615,7 +616,7 @@ class SessionController < ApplicationController
callback_path: challenge[:callback_path],
redirect_url: challenge[:redirect_url],
},
- status: 200
+ status: :ok
end
def forgot_password
@@ -661,7 +662,7 @@ class SessionController < ApplicationController
if current_user.present?
render_serialized(current_user, CurrentUserSerializer, { login_method: login_method })
else
- render body: nil, status: 404
+ render body: nil, status: :not_found
end
end
@@ -716,7 +717,7 @@ class SessionController < ApplicationController
api_key = ApiKey.active.with_key(key).first
render_serialized(api_key.api_key_scopes, ApiKeyScopeSerializer, root: "scopes")
else
- render body: nil, status: 404
+ render body: nil, status: :not_found
end
end
diff --git a/app/controllers/sidebar_sections_controller.rb b/app/controllers/sidebar_sections_controller.rb
index 96e823be114..2cffa13589f 100644
--- a/app/controllers/sidebar_sections_controller.rb
+++ b/app/controllers/sidebar_sections_controller.rb
@@ -74,7 +74,7 @@ class SidebarSectionsController < ApplicationController
rescue ActiveRecord::NestedAttributes::TooManyRecords => e
render_json_error(e.message)
rescue Discourse::InvalidAccess
- render json: failed_json, status: 403
+ render json: failed_json, status: :forbidden
end
def reset
@@ -102,7 +102,7 @@ class SidebarSectionsController < ApplicationController
render json: success_json
rescue Discourse::InvalidAccess
- render json: failed_json, status: 403
+ render json: failed_json, status: :forbidden
end
def section_params
diff --git a/app/controllers/static_controller.rb b/app/controllers/static_controller.rb
index b4f3c6bf724..6c735ccf62a 100644
--- a/app/controllers/static_controller.rb
+++ b/app/controllers/static_controller.rb
@@ -108,7 +108,7 @@ class StaticController < ApplicationController
end
@title = "#{title_prefix} - #{SiteSetting.title}"
@body = @topic.posts.first.cooked
- @faq_overridden = !SiteSetting.faq_url.blank?
+ @faq_overridden = SiteSetting.faq_url.present?
@experimental_rename_faq_to_guidelines = rename_faq
render :show, layout: !request.xhr?, formats: [:html]
@@ -203,7 +203,7 @@ class StaticController < ApplicationController
file&.unlink
end
else
- File.read(Rails.root.join("public", favicon.url[1..-1]))
+ File.read(Rails.public_path.join(favicon.url[1..-1]))
end
end
@@ -265,7 +265,7 @@ class StaticController < ApplicationController
rescue Errno::ENOENT
expires_in 1.second, public: true, must_revalidate: false
- render plain: "can not find #{params[:path]}", status: 404
+ render plain: "can not find #{params[:path]}", status: :not_found
return
end
end
diff --git a/app/controllers/steps_controller.rb b/app/controllers/steps_controller.rb
index 153a2cccfd3..aeed15ca36a 100644
--- a/app/controllers/steps_controller.rb
+++ b/app/controllers/steps_controller.rb
@@ -20,7 +20,7 @@ class StepsController < ApplicationController
updater.errors.messages.each do |field, msg|
errors << { field: field, description: msg.join }
end
- render json: { errors: errors }, status: 422
+ render json: { errors: errors }, status: :unprocessable_entity
end
end
end
diff --git a/app/controllers/stylesheets_controller.rb b/app/controllers/stylesheets_controller.rb
index 7ffd2902c0c..a1a077eec0d 100644
--- a/app/controllers/stylesheets_controller.rb
+++ b/app/controllers/stylesheets_controller.rb
@@ -78,7 +78,7 @@ class StylesheetsController < ApplicationController
end
end
- if Rails.env == "development"
+ if Rails.env.development?
response.headers["Last-Modified"] = Time.zone.now.httpdate
immutable_for(1.second)
else
diff --git a/app/controllers/svg_sprite_controller.rb b/app/controllers/svg_sprite_controller.rb
index 48e985be162..1db07800ef0 100644
--- a/app/controllers/svg_sprite_controller.rb
+++ b/app/controllers/svg_sprite_controller.rb
@@ -37,7 +37,7 @@ class SvgSpriteController < ApplicationController
data = SvgSprite.search(keyword)
if data.blank?
- render body: nil, status: 404
+ render body: nil, status: :not_found
else
render plain: data.inspect, disposition: nil, content_type: "text/plain"
end
@@ -62,14 +62,14 @@ class SvgSpriteController < ApplicationController
icon = SvgSprite.search(name)
if icon.blank?
- render body: nil, status: 404
+ render body: nil, status: :not_found
else
doc = Nokogiri.XML(icon)
doc.at_xpath("symbol").name = "svg"
doc.at_xpath("svg")["xmlns"] = "http://www.w3.org/2000/svg"
doc.at_xpath("svg")["fill"] = adjust_hex(params[:color]) if params[:color]
- response.headers["Last-Modified"] = 1.years.ago.httpdate
+ response.headers["Last-Modified"] = 1.year.ago.httpdate
response.headers["Content-Length"] = doc.to_s.bytesize.to_s
immutable_for 1.day
diff --git a/app/controllers/tags_controller.rb b/app/controllers/tags_controller.rb
index 14dce215d1f..60fd0ce12fb 100644
--- a/app/controllers/tags_controller.rb
+++ b/app/controllers/tags_controller.rb
@@ -267,7 +267,7 @@ class TagsController < ::ApplicationController
end
render json: success_json
rescue Discourse::InvalidParameters => e
- render json: failed_json.merge(errors: [e.message]), status: 422
+ render json: failed_json.merge(errors: [e.message]), status: :unprocessable_entity
end
end
end
@@ -328,7 +328,7 @@ class TagsController < ::ApplicationController
filter_params[:category] = Category.find_by_id(params[:categoryId]) if params[:categoryId]
- if !params[:q].blank?
+ if params[:q].present?
clean_name = DiscourseTagging.clean_tag(params[:q])
filter_params[:term] = clean_name
filter_params[:order_search_results] = true
@@ -444,7 +444,7 @@ class TagsController < ::ApplicationController
synonym.update!(target_tag: nil)
render json: success_json
else
- render json: failed_json, status: 400
+ render json: failed_json, status: :bad_request
end
end
diff --git a/app/controllers/topics_controller.rb b/app/controllers/topics_controller.rb
index d61873c1c06..c2340c23898 100644
--- a/app/controllers/topics_controller.rb
+++ b/app/controllers/topics_controller.rb
@@ -571,7 +571,7 @@ class TopicsController < ApplicationController
options = { by_user: current_user, based_on_last_post: based_on_last_post }
- options.merge!(category_id: params[:category_id]) if !params[:category_id].blank?
+ options.merge!(category_id: params[:category_id]) if params[:category_id].present?
if params[:duration_minutes].present?
options.merge!(duration_minutes: params[:duration_minutes].to_i)
end
@@ -729,7 +729,7 @@ class TopicsController < ApplicationController
if topic.remove_allowed_user(current_user, user)
render json: success_json
else
- render json: failed_json, status: 422
+ render json: failed_json, status: :unprocessable_entity
end
end
@@ -741,7 +741,7 @@ class TopicsController < ApplicationController
if topic.remove_allowed_group(current_user, params[:name])
render json: success_json
else
- render json: failed_json, status: 422
+ render json: failed_json, status: :unprocessable_entity
end
end
@@ -774,7 +774,7 @@ class TopicsController < ApplicationController
topic.invite_group(current_user, group, should_notify: should_notify)
render_json_dump BasicGroupSerializer.new(group, scope: guardian, root: "group")
else
- render json: failed_json, status: 422
+ render json: failed_json, status: :unprocessable_entity
end
end
@@ -827,10 +827,10 @@ class TopicsController < ApplicationController
end
end
- render json: json, status: 422
+ render json: json, status: :unprocessable_entity
end
rescue Topic::UserExists, Topic::NotAllowed => e
- render json: { errors: [e.message] }, status: 422
+ render json: { errors: [e.message] }, status: :unprocessable_entity
end
end
@@ -935,7 +935,7 @@ class TopicsController < ApplicationController
).change_owner!
render json: success_json
rescue ArgumentError
- render json: failed_json, status: 422
+ render json: failed_json, status: :unprocessable_entity
end
end
@@ -959,7 +959,7 @@ class TopicsController < ApplicationController
render json: success_json
rescue ActiveRecord::RecordInvalid, TopicTimestampChanger::InvalidTimestampError
- render json: failed_json, status: 422
+ render json: failed_json, status: :unprocessable_entity
end
end
@@ -1293,7 +1293,7 @@ class TopicsController < ApplicationController
url << "#{s}#{k}=#{v}"
end
- redirect_to url, status: 301
+ redirect_to url, status: :moved_permanently
end
def track_visit_to_topic
@@ -1377,8 +1377,7 @@ class TopicsController < ApplicationController
helpers.localize_topic_view_content(@topic_view) if SiteSetting.content_localization_enabled
@breadcrumbs = helpers.categories_breadcrumb(@topic_view.topic) || []
- @description_meta =
- @topic_view.topic.excerpt.present? ? @topic_view.topic.excerpt : @topic_view.summary
+ @description_meta = (@topic_view.topic.excerpt.presence || @topic_view.summary)
store_preloaded("topic_#{@topic_view.topic.id}", MultiJson.dump(topic_view_serializer))
render :show
end
diff --git a/app/controllers/uploads_controller.rb b/app/controllers/uploads_controller.rb
index 058f7ecfbf1..092e09a6a83 100644
--- a/app/controllers/uploads_controller.rb
+++ b/app/controllers/uploads_controller.rb
@@ -53,7 +53,7 @@ class UploadsController < ApplicationController
SiteSetting.discourse_connect_overrides_avatar || SiteSetting.auth_overrides_avatar ||
!me.in_any_groups?(SiteSetting.uploaded_avatars_allowed_groups_map)
)
- return render json: failed_json, status: 422
+ return render json: failed_json, status: :unprocessable_entity
end
url = params[:url]
@@ -81,7 +81,8 @@ class UploadsController < ApplicationController
retain_hours: retain_hours,
)
rescue => e
- render json: failed_json.merge(message: e.message&.split("\n")&.first), status: 422
+ render json: failed_json.merge(message: e.message&.split("\n")&.first),
+ status: :unprocessable_entity
else
render json: UploadsController.serialize_upload(info), status: Upload === info ? 200 : 422
end
diff --git a/app/controllers/user_api_keys_controller.rb b/app/controllers/user_api_keys_controller.rb
index 940235baeed..10e77fb662a 100644
--- a/app/controllers/user_api_keys_controller.rb
+++ b/app/controllers/user_api_keys_controller.rb
@@ -87,7 +87,7 @@ class UserApiKeysController < ApplicationController
api: AUTH_API_VERSION,
}.to_json
- public_key_str = @client.public_key.present? ? @client.public_key : params[:public_key]
+ public_key_str = (@client.public_key.presence || params[:public_key])
public_key = OpenSSL::PKey::RSA.new(public_key_str)
# by default, Ruby uses `PKCS1_PADDING` here
diff --git a/app/controllers/user_badges_controller.rb b/app/controllers/user_badges_controller.rb
index 84c62d10451..4e83ce5c23e 100644
--- a/app/controllers/user_badges_controller.rb
+++ b/app/controllers/user_badges_controller.rb
@@ -81,7 +81,7 @@ class UserBadgesController < ApplicationController
params.require(:username)
user = fetch_user_from_params
- return render json: failed_json, status: 403 unless can_assign_badge_to_user?(user)
+ return render json: failed_json, status: :forbidden unless can_assign_badge_to_user?(user)
badge = fetch_badge_from_params
post_id = nil
@@ -90,7 +90,7 @@ class UserBadgesController < ApplicationController
unless is_badge_reason_valid? params[:reason]
return(
render json: failed_json.merge(message: I18n.t("invalid_grant_badge_reason_link")),
- status: 400
+ status: :bad_request
)
end
@@ -120,7 +120,7 @@ class UserBadgesController < ApplicationController
user_badge = UserBadge.find(params[:id])
unless can_assign_badge_to_user?(user_badge.user)
- render json: failed_json, status: 403
+ render json: failed_json, status: :forbidden
return
end
@@ -133,14 +133,14 @@ class UserBadgesController < ApplicationController
user_badge = UserBadge.find(params[:user_badge_id])
user_badges = user_badge.user.user_badges
- return render json: failed_json, status: 403 unless can_favorite_badge?(user_badge)
+ return render json: failed_json, status: :forbidden unless can_favorite_badge?(user_badge)
is_favorite = user_badges.where(badge: user_badge.badge, is_favorite: true).exists?
if !is_favorite &&
user_badges.select(:badge_id).distinct.where(is_favorite: true).count >=
SiteSetting.max_favorite_badges
- return render json: failed_json, status: 400
+ return render json: failed_json, status: :bad_request
end
UserBadge.where(user_id: user_badge.user_id, badge_id: user_badge.badge_id).update_all(
diff --git a/app/controllers/users/discourse_id_controller.rb b/app/controllers/users/discourse_id_controller.rb
index 3909866fb0b..3ea21a660e9 100644
--- a/app/controllers/users/discourse_id_controller.rb
+++ b/app/controllers/users/discourse_id_controller.rb
@@ -10,11 +10,11 @@ class Users::DiscourseIdController < ApplicationController
on_success { render json: { success: true } }
on_failed_contract do |contract|
logger.warn(result.inspect_steps) if SiteSetting.discourse_id_verbose_logging
- render json: { error: contract.errors.full_messages.join(", ") }, status: 400
+ render json: { error: contract.errors.full_messages.join(", ") }, status: :bad_request
end
on_failure do
logger.warn(result.inspect_steps) if SiteSetting.discourse_id_verbose_logging
- render json: { error: "Invalid request" }, status: 400
+ render json: { error: "Invalid request" }, status: :bad_request
end
end
end
diff --git a/app/controllers/users/omniauth_callbacks_controller.rb b/app/controllers/users/omniauth_callbacks_controller.rb
index f144a1be424..5088cd0e212 100644
--- a/app/controllers/users/omniauth_callbacks_controller.rb
+++ b/app/controllers/users/omniauth_callbacks_controller.rb
@@ -104,7 +104,7 @@ class Users::OmniauthCallbacksController < ApplicationController
true
end
- ALLOWED_FAILURE_ERRORS = %w[csrf_detected request_error invalid_iat].to_h { [_1, _1] }
+ ALLOWED_FAILURE_ERRORS = %w[csrf_detected request_error invalid_iat].index_by { _1 }
def failure
error_name = params[:message].to_s.gsub(/[^\w-]/, "").presence
diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb
index a52fcd60093..35f4859d636 100644
--- a/app/controllers/users_controller.rb
+++ b/app/controllers/users_controller.rb
@@ -288,7 +288,7 @@ class UsersController < ApplicationController
if current_user&.staff?
render_json_error(I18n.t("errors.messages.auth_overrides_username"))
else
- render json: failed_json, status: 403
+ render json: failed_json, status: :forbidden
end
end
@@ -310,7 +310,7 @@ class UsersController < ApplicationController
associated_accounts: user.associated_accounts,
}
rescue Discourse::InvalidAccess
- render json: failed_json, status: 403
+ render json: failed_json, status: :forbidden
end
def check_sso_email
@@ -326,7 +326,7 @@ class UsersController < ApplicationController
render json: { email: email }
rescue Discourse::InvalidAccess
- render json: failed_json, status: 403
+ render json: failed_json, status: :forbidden
end
def check_sso_payload
@@ -342,11 +342,11 @@ class UsersController < ApplicationController
render json: { payload: payload }
rescue Discourse::InvalidAccess
- render json: failed_json, status: 403
+ render json: failed_json, status: :forbidden
end
def update_primary_email
- return render json: failed_json, status: 410 if !SiteSetting.enable_secondary_emails
+ return render json: failed_json, status: :gone if !SiteSetting.enable_secondary_emails
params.require(:email)
@@ -359,7 +359,8 @@ class UsersController < ApplicationController
new_primary = user.user_emails.find_by(email: params[:email])
if new_primary.blank?
return(
- render json: failed_json.merge(errors: [I18n.t("change_email.doesnt_exist")]), status: 428
+ render json: failed_json.merge(errors: [I18n.t("change_email.doesnt_exist")]),
+ status: :precondition_required
)
end
@@ -379,7 +380,7 @@ class UsersController < ApplicationController
end
def destroy_email
- return render json: failed_json, status: 410 if !SiteSetting.enable_secondary_emails
+ return render json: failed_json, status: :gone if !SiteSetting.enable_secondary_emails
params.require(:email)
@@ -392,7 +393,7 @@ class UsersController < ApplicationController
elsif user.user_emails.where(email: params[:email], primary: false).destroy_all.present?
DiscourseEvent.trigger(:user_updated, user)
else
- return render json: failed_json, status: 428
+ return render json: failed_json, status: :precondition_required
end
if current_user.staff? && current_user != user
@@ -1075,7 +1076,7 @@ class UsersController < ApplicationController
log_on_user(user)
render json: success_json
else
- render json: failed_json, status: 403
+ render json: failed_json, status: :forbidden
end
end
@@ -1324,23 +1325,23 @@ class UsersController < ApplicationController
guardian.ensure_can_edit!(user)
if SiteSetting.discourse_connect_overrides_avatar || SiteSetting.auth_overrides_avatar
- return render json: failed_json, status: 422
+ return render json: failed_json, status: :unprocessable_entity
end
type = params[:type]
if type == "gravatar" && !SiteSetting.gravatar_enabled?
- return render json: failed_json, status: 422
+ return render json: failed_json, status: :unprocessable_entity
end
invalid_type = type.present? && !AVATAR_TYPES_WITH_UPLOAD.include?(type) && type != "system"
- return render json: failed_json, status: 422 if invalid_type
+ return render json: failed_json, status: :unprocessable_entity if invalid_type
if type.blank? || type == "system"
upload_id = nil
elsif !user.in_any_groups?(SiteSetting.uploaded_avatars_allowed_groups_map) &&
!user.is_system_user?
- return render json: failed_json, status: 422
+ return render json: failed_json, status: :unprocessable_entity
else
upload_id = params[:upload_id]
upload = Upload.find_by(id: upload_id)
@@ -1374,19 +1375,23 @@ class UsersController < ApplicationController
url = params[:url]
- return render json: failed_json, status: 422 if url.blank?
+ return render json: failed_json, status: :unprocessable_entity if url.blank?
if SiteSetting.selectable_avatars_mode == "disabled"
- return render json: failed_json, status: 422
+ return render json: failed_json, status: :unprocessable_entity
end
- return render json: failed_json, status: 422 if SiteSetting.selectable_avatars.blank?
+ if SiteSetting.selectable_avatars.blank?
+ return render json: failed_json, status: :unprocessable_entity
+ end
unless upload = Upload.get_from_url(url)
- return render json: failed_json, status: 422
+ return render json: failed_json, status: :unprocessable_entity
end
- return render json: failed_json, status: 422 if SiteSetting.selectable_avatars.exclude?(upload)
+ if SiteSetting.selectable_avatars.exclude?(upload)
+ return render json: failed_json, status: :unprocessable_entity
+ end
user.uploaded_avatar_id = upload.id
@@ -1494,7 +1499,7 @@ class UsersController < ApplicationController
if !SiteSetting.log_search_queries
return(
render json: failed_json.merge(error: I18n.t("user_activity.no_log_search_queries")),
- status: 403
+ status: :forbidden
)
end
@@ -1722,7 +1727,7 @@ class UsersController < ApplicationController
user_security_key = current_user.security_keys.find_by(id: params[:id].to_i)
raise Discourse::InvalidParameters unless user_security_key
- user_security_key.update!(name: params[:name]) if params[:name] && !params[:name].blank?
+ user_security_key.update!(name: params[:name]) if params[:name] && params[:name].present?
user_security_key.update!(enabled: false) if params[:disable] == "true"
render json: success_json
@@ -1743,7 +1748,7 @@ class UsersController < ApplicationController
rate_limit_second_factor!(current_user)
authenticated =
- !auth_token.blank? &&
+ auth_token.present? &&
totp_object.verify(
auth_token,
drift_ahead: SecondFactorManager::TOTP_ALLOWED_DRIFT_SECONDS,
@@ -1784,7 +1789,7 @@ class UsersController < ApplicationController
raise Discourse::InvalidParameters unless user_second_factor
- user_second_factor.update!(name: params[:name]) if params[:name] && !params[:name].blank?
+ user_second_factor.update!(name: params[:name]) if params[:name] && params[:name].present?
if params[:disable] == "true"
# Disabling backup codes deletes *all* backup codes
if update_second_factor_method == UserSecondFactor.methods[:backup_codes]
diff --git a/app/controllers/users_email_controller.rb b/app/controllers/users_email_controller.rb
index 7a7dd97144c..f9126bfca2a 100644
--- a/app/controllers/users_email_controller.rb
+++ b/app/controllers/users_email_controller.rb
@@ -18,7 +18,7 @@ class UsersEmailController < ApplicationController
end
def create
- return render json: failed_json, status: 410 if !SiteSetting.enable_secondary_emails
+ return render json: failed_json, status: :gone if !SiteSetting.enable_secondary_emails
params.require(:email)
user = fetch_user_from_params
@@ -65,7 +65,7 @@ class UsersEmailController < ApplicationController
updater.user.user_stat.reset_bounce_score!
render json: success_json
else
- render json: { error: I18n.t("change_email.already_done") }, status: 400
+ render json: { error: I18n.t("change_email.already_done") }, status: :bad_request
end
end
end
@@ -89,7 +89,7 @@ class UsersEmailController < ApplicationController
if updater.confirm(params[:token]) == :authorizing_new
render json: success_json
else
- render json: { error: I18n.t("change_email.already_done") }, status: 400
+ render json: { error: I18n.t("change_email.already_done") }, status: :bad_request
end
end
diff --git a/app/controllers/webhooks_controller.rb b/app/controllers/webhooks_controller.rb
index 85568a01d1d..6495cc13640 100644
--- a/app/controllers/webhooks_controller.rb
+++ b/app/controllers/webhooks_controller.rb
@@ -202,11 +202,11 @@ class WebhooksController < ActionController::Base
private
def signature_failure
- render body: nil, status: 406
+ render body: nil, status: :not_acceptable
end
def success
- render body: nil, status: 200
+ render body: nil, status: :ok
end
def valid_mailgun_signature?(token, timestamp, signature)
diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb
index d05d9f076dd..44aff8e52f3 100644
--- a/app/helpers/application_helper.rb
+++ b/app/helpers/application_helper.rb
@@ -360,14 +360,7 @@ module ApplicationHelper
end
private def generate_twitter_card_metadata(result, opts)
- img_url =
- (
- if opts[:x_summary_large_image].present?
- opts[:x_summary_large_image]
- else
- opts[:image]
- end
- )
+ img_url = (opts[:x_summary_large_image].presence || opts[:image])
# Twitter does not allow SVGs, see https://developer.twitter.com/en/docs/twitter-for-websites/cards/overview/markup
if img_url.ends_with?(".svg")
diff --git a/app/helpers/embed_helper.rb b/app/helpers/embed_helper.rb
index 42db197c115..3af784f89aa 100644
--- a/app/helpers/embed_helper.rb
+++ b/app/helpers/embed_helper.rb
@@ -17,7 +17,7 @@ module EmbedHelper
def get_html(post)
key = "js.action_codes.#{post.action_code}"
- cooked = post.cooked.blank? ? I18n.t(key, when: nil).humanize : post.cooked
+ cooked = (post.cooked.presence || I18n.t(key, when: nil).humanize)
raw PrettyText.format_for_email(cooked, post)
end
diff --git a/app/jobs/base.rb b/app/jobs/base.rb
index 1dd7138f040..16fa6f1ccfc 100644
--- a/app/jobs/base.rb
+++ b/app/jobs/base.rb
@@ -423,7 +423,7 @@ module Jobs
DB.after_commit { klass.client_push(hash) }
else
- if Rails.env == "development"
+ if Rails.env.development?
Scheduler::Defer.later("job") { klass.new.perform(opts) }
else
# Run the job synchronously
diff --git a/app/jobs/concerns/skippable.rb b/app/jobs/concerns/skippable.rb
index dfc6adf2231..bb2e0bd2c24 100644
--- a/app/jobs/concerns/skippable.rb
+++ b/app/jobs/concerns/skippable.rb
@@ -15,9 +15,7 @@ module Skippable
if reason_type == SkippedEmailLog.reason_types[:exceeded_emails_limit]
exists =
SkippedEmailLog.exists?(
- { created_at: (Time.zone.now.beginning_of_day..Time.zone.now.end_of_day) }.merge!(
- attributes.except(:post_id),
- ),
+ { created_at: (Time.zone.now.all_day) }.merge!(attributes.except(:post_id)),
)
return if exists
diff --git a/app/jobs/regular/export_csv_file.rb b/app/jobs/regular/export_csv_file.rb
index d532f4f2c51..20bca4d3e23 100644
--- a/app/jobs/regular/export_csv_file.rb
+++ b/app/jobs/regular/export_csv_file.rb
@@ -11,7 +11,7 @@ module Jobs
attr_accessor :entity
HEADER_ATTRS_FOR =
- HashWithIndifferentAccess.new(
+ ActiveSupport::HashWithIndifferentAccess.new(
user_list: %w[
id
name
@@ -60,7 +60,7 @@ module Jobs
def execute(args)
@entity = args[:entity]
- @extra = HashWithIndifferentAccess.new(args[:args]) if args[:args]
+ @extra = ActiveSupport::HashWithIndifferentAccess.new(args[:args]) if args[:args]
@current_user = User.find_by(id: args[:user_id])
entity = { name: @entity }
diff --git a/app/jobs/regular/export_user_archive.rb b/app/jobs/regular/export_user_archive.rb
index b1697c8dd9a..f5480010dcf 100644
--- a/app/jobs/regular/export_user_archive.rb
+++ b/app/jobs/regular/export_user_archive.rb
@@ -26,7 +26,7 @@ module Jobs
]
HEADER_ATTRS_FOR =
- HashWithIndifferentAccess.new(
+ ActiveSupport::HashWithIndifferentAccess.new(
user_archive: %w[
topic_title
categories
@@ -130,7 +130,7 @@ module Jobs
@requesting_user = @archive_for_user
end
- @extra = HashWithIndifferentAccess.new(args[:args]) if args[:args]
+ @extra = ActiveSupport::HashWithIndifferentAccess.new(args[:args]) if args[:args]
@timestamp ||= Time.now.strftime("%y%m%d-%H%M%S")
components = []
diff --git a/app/jobs/regular/notify_mailing_list_subscribers.rb b/app/jobs/regular/notify_mailing_list_subscribers.rb
index 467af7cff79..ef81bf9ce28 100644
--- a/app/jobs/regular/notify_mailing_list_subscribers.rb
+++ b/app/jobs/regular/notify_mailing_list_subscribers.rb
@@ -4,7 +4,15 @@ module Jobs
class NotifyMailingListSubscribers < ::Jobs::Base
include Skippable
- RETRY_TIMES = [5.minute, 15.minute, 30.minute, 45.minute, 90.minute, 180.minute, 300.minute]
+ RETRY_TIMES = [
+ 5.minutes,
+ 15.minutes,
+ 30.minutes,
+ 45.minutes,
+ 90.minutes,
+ 180.minutes,
+ 300.minutes,
+ ]
sidekiq_options queue: "low"
diff --git a/app/jobs/regular/pull_hotlinked_images.rb b/app/jobs/regular/pull_hotlinked_images.rb
index 233c1144aad..d27f4180a50 100644
--- a/app/jobs/regular/pull_hotlinked_images.rb
+++ b/app/jobs/regular/pull_hotlinked_images.rb
@@ -24,7 +24,7 @@ module Jobs
post = Post.find_by(id: @post_id)
return if post.nil? || post.topic.nil?
- hotlinked_map = post.post_hotlinked_media.map { |r| [r.url, r] }.to_h
+ hotlinked_map = post.post_hotlinked_media.index_by { |r| r.url }
changed_hotlink_records = false
diff --git a/app/jobs/regular/update_hotlinked_raw.rb b/app/jobs/regular/update_hotlinked_raw.rb
index 3763ab96a61..b9432b6cbbc 100644
--- a/app/jobs/regular/update_hotlinked_raw.rb
+++ b/app/jobs/regular/update_hotlinked_raw.rb
@@ -13,7 +13,7 @@ module Jobs
return if post.cook_method == Post.cook_methods[:raw_html]
return if post.topic.nil?
- hotlinked_map = post.post_hotlinked_media.preload(:upload).map { |r| [r.url, r] }.to_h
+ hotlinked_map = post.post_hotlinked_media.preload(:upload).index_by { |r| r.url }
raw =
InlineUploads.replace_hotlinked_image_urls(raw: post.raw) do |match_src|
diff --git a/app/jobs/scheduled/aggregate_web_hooks_events.rb b/app/jobs/scheduled/aggregate_web_hooks_events.rb
index 856cbde059f..825dca90b59 100644
--- a/app/jobs/scheduled/aggregate_web_hooks_events.rb
+++ b/app/jobs/scheduled/aggregate_web_hooks_events.rb
@@ -5,7 +5,7 @@ module Jobs
every 1.day
def execute(args = {})
- date = args[:date].present? ? args[:date] : Time.zone.now.to_date
+ date = (args[:date].presence || Time.zone.now.to_date)
WebHook
.joins(
"LEFT JOIN web_hook_events_daily_aggregates ON web_hooks.id = web_hook_events_daily_aggregates.web_hook_id AND web_hook_events_daily_aggregates.date = '#{date}'",
diff --git a/app/jobs/scheduled/cleanup_redelivering_web_hook_events.rb b/app/jobs/scheduled/cleanup_redelivering_web_hook_events.rb
index 9e290e1f40b..27e04aacba3 100644
--- a/app/jobs/scheduled/cleanup_redelivering_web_hook_events.rb
+++ b/app/jobs/scheduled/cleanup_redelivering_web_hook_events.rb
@@ -9,7 +9,7 @@ module Jobs
def execute(args)
RedeliveringWebhookEvent
.includes(web_hook_event: :web_hook)
- .where("created_at < ?", 8.hour.ago)
+ .where("created_at < ?", 8.hours.ago)
.delete_all
end
end
diff --git a/app/jobs/scheduled/old_keys_reminder.rb b/app/jobs/scheduled/old_keys_reminder.rb
index cec2108b542..1adef8c59bb 100644
--- a/app/jobs/scheduled/old_keys_reminder.rb
+++ b/app/jobs/scheduled/old_keys_reminder.rb
@@ -67,9 +67,11 @@ module Jobs
def keys_list
messages =
- old_site_settings_keys.map { |key| "#{key.name} - #{key.updated_at.to_date.to_fs(:db)}" }
+ old_site_settings_keys.map do |key|
+ "#{key.name} - #{key.updated_at.to_date.to_formatted_s(:db)}"
+ end
old_api_keys.each_with_object(messages) do |key, array|
- array << "#{[key.description, key.user&.username, key.created_at.to_date.to_fs(:db)].compact.join(" - ")}"
+ array << "#{[key.description, key.user&.username, key.created_at.to_date.to_formatted_s(:db)].compact.join(" - ")}"
end
messages.join("\n")
end
diff --git a/app/jobs/scheduled/update_topic_hot_scores.rb b/app/jobs/scheduled/update_topic_hot_scores.rb
index c9eecedc1a5..d03f3a1d1ff 100644
--- a/app/jobs/scheduled/update_topic_hot_scores.rb
+++ b/app/jobs/scheduled/update_topic_hot_scores.rb
@@ -8,7 +8,7 @@ module Jobs
def execute(args)
if SiteSetting.top_menu_map.include?("hot") ||
- Discourse.redis.set(HOT_SCORE_UPDATE_REDIS_KEY, 1, ex: 6.hour, nx: true)
+ Discourse.redis.set(HOT_SCORE_UPDATE_REDIS_KEY, 1, ex: 6.hours, nx: true)
TopicHotScore.update_scores
end
end
diff --git a/app/mailers/user_notifications.rb b/app/mailers/user_notifications.rb
index d057c5c3420..52f862f4f97 100644
--- a/app/mailers/user_notifications.rb
+++ b/app/mailers/user_notifications.rb
@@ -75,7 +75,7 @@ class UserNotifications < ActionMailer::Base
template: "user_notifications.suspicious_login",
locale: user_locale(user),
client_ip: opts[:client_ip],
- location: location.present? ? location : I18n.t("staff_action_logs.unknown"),
+ location: (location.presence || I18n.t("staff_action_logs.unknown")),
browser: I18n.t("user_auth_tokens.browser.#{browser}"),
device: I18n.t("user_auth_tokens.device.#{device}"),
os: I18n.t("user_auth_tokens.os.#{os}"),
diff --git a/app/models/api_key_scope.rb b/app/models/api_key_scope.rb
index 77bf88606e9..52e98a0924f 100644
--- a/app/models/api_key_scope.rb
+++ b/app/models/api_key_scope.rb
@@ -1,8 +1,8 @@
# frozen_string_literal: true
class ApiKeyScope < ActiveRecord::Base
- validates_presence_of :resource
- validates_presence_of :action
+ validates :resource, presence: true
+ validates :action, presence: true
class << self
def list_actions
diff --git a/app/models/application_request.rb b/app/models/application_request.rb
index 9b605493423..ba93f5a1913 100644
--- a/app/models/application_request.rb
+++ b/app/models/application_request.rb
@@ -48,7 +48,7 @@ class ApplicationRequest < ActiveRecord::Base
end
def self.stats
- s = HashWithIndifferentAccess.new({})
+ s = ActiveSupport::HashWithIndifferentAccess.new({})
self.req_types.each do |key, i|
query = self.where(req_type: i)
diff --git a/app/models/badge.rb b/app/models/badge.rb
index 3ee34bd60df..03a595cd4dd 100644
--- a/app/models/badge.rb
+++ b/app/models/badge.rb
@@ -121,8 +121,8 @@ class Badge < ActiveRecord::Base
scope :enabled, -> { where(enabled: true) }
- before_create :ensure_not_system
before_save :sanitize_description
+ before_create :ensure_not_system
after_save do
if saved_change_to_image_upload_id?
diff --git a/app/models/category.rb b/app/models/category.rb
index 7c48540a669..12fb6340ea0 100644
--- a/app/models/category.rb
+++ b/app/models/category.rb
@@ -107,15 +107,22 @@ class Category < ActiveRecord::Base
validates :color, format: { with: /\A(\h{6}|\h{3})\z/ }
validates :text_color, format: { with: /\A(\h{6}|\h{3})\z/ }
- after_create :create_category_definition
- after_destroy :trash_category_definition
- after_destroy :clear_related_site_settings
-
before_save :apply_permissions
before_save :downcase_email
before_save :downcase_name
before_save :ensure_category_setting
+ after_create :create_category_definition
+ after_create :delete_category_permalink
+ after_update :rename_category_definition, if: :saved_change_to_name?
+ after_update :create_category_permalink, if: :saved_change_to_slug?
+ after_update :run_plugin_category_update_param_callbacks
+ after_destroy :trash_category_definition
+ after_destroy :clear_related_site_settings
+ after_destroy :reset_topic_ids_cache
+ after_destroy :clear_subcategory_ids
+ after_destroy :publish_category_deletion
+ after_destroy :remove_site_settings
after_save :reset_topic_ids_cache
after_save :clear_subcategory_ids
after_save :clear_url_cache
@@ -135,17 +142,6 @@ class Category < ActiveRecord::Base
end
end
- after_destroy :reset_topic_ids_cache
- after_destroy :clear_subcategory_ids
- after_destroy :publish_category_deletion
- after_destroy :remove_site_settings
-
- after_create :delete_category_permalink
-
- after_update :rename_category_definition, if: :saved_change_to_name?
- after_update :create_category_permalink, if: :saved_change_to_slug?
- after_update :run_plugin_category_update_param_callbacks
-
after_commit :trigger_category_created_event, on: :create
after_commit :trigger_category_updated_event, on: :update
after_commit :trigger_category_destroyed_event, on: :destroy
@@ -638,7 +634,7 @@ class Category < ActiveRecord::Base
def topic_url
if has_attribute?("topic_slug")
- Topic.relative_url(topic_id, read_attribute(:topic_slug))
+ Topic.relative_url(topic_id, self[:topic_slug])
else
topic_only_relative_url.try(:relative_url)
end
diff --git a/app/models/category_user.rb b/app/models/category_user.rb
index d7cee509c71..22232a7fb3c 100644
--- a/app/models/category_user.rb
+++ b/app/models/category_user.rb
@@ -228,9 +228,7 @@ class CategoryUser < ActiveRecord::Base
end
def self.create_lookup(category_users)
- category_users.each_with_object({}) do |category_user, acc|
- acc[category_user.category_id] = category_user
- end
+ category_users.index_by(&:category_id)
end
def self.muted_category_ids_query(user, include_direct: false)
diff --git a/app/models/concerns/has_custom_fields.rb b/app/models/concerns/has_custom_fields.rb
index f763b7278c1..b3b3121ad53 100644
--- a/app/models/concerns/has_custom_fields.rb
+++ b/app/models/concerns/has_custom_fields.rb
@@ -346,7 +346,7 @@ module HasCustomFields
protected
def refresh_custom_fields_from_db
- target = HashWithIndifferentAccess.new
+ target = ActiveSupport::HashWithIndifferentAccess.new
_custom_fields
.order(:id)
.pluck(:name, :value)
diff --git a/app/models/concerns/has_search_data.rb b/app/models/concerns/has_search_data.rb
index 1ff9a16358d..f96b4106022 100644
--- a/app/models/concerns/has_search_data.rb
+++ b/app/models/concerns/has_search_data.rb
@@ -7,6 +7,6 @@ module HasSearchData
_associated_record_name = self.name.sub("SearchData", "").underscore
self.primary_key = "#{_associated_record_name}_id"
belongs_to _associated_record_name.to_sym
- validates_presence_of :search_data
+ validates :search_data, presence: true
end
end
diff --git a/app/models/concerns/second_factor_manager.rb b/app/models/concerns/second_factor_manager.rb
index f0a1018d88a..438b9e66eb9 100644
--- a/app/models/concerns/second_factor_manager.rb
+++ b/app/models/concerns/second_factor_manager.rb
@@ -46,7 +46,7 @@ module SecondFactorManager
last_used = totp.last_used.to_i if totp.last_used
authenticated =
- !token.blank? &&
+ token.present? &&
totp.totp_object.verify(
token,
drift_ahead: TOTP_ALLOWED_DRIFT_SECONDS,
@@ -243,7 +243,7 @@ module SecondFactorManager
end
def authenticate_backup_code(backup_code)
- if !backup_code.blank?
+ if backup_code.present?
codes = self.user_second_factors&.backup_codes
codes.each do |code|
diff --git a/app/models/developer.rb b/app/models/developer.rb
index 458602c1341..0460ca4a57d 100644
--- a/app/models/developer.rb
+++ b/app/models/developer.rb
@@ -3,8 +3,8 @@
class Developer < ActiveRecord::Base
belongs_to :user
- after_save :rebuild_cache
after_destroy :rebuild_cache
+ after_save :rebuild_cache
def self.id_cache
@id_cache ||= DistributedCache.new("developer_ids")
diff --git a/app/models/discourse_connect.rb b/app/models/discourse_connect.rb
index ae50103d677..06ff49d6e3b 100644
--- a/app/models/discourse_connect.rb
+++ b/app/models/discourse_connect.rb
@@ -349,7 +349,7 @@ class DiscourseConnect < DiscourseConnectBase
end
if SiteSetting.auth_overrides_name && user.name != name && name.present?
- user.name = name || User.suggest_name(username.blank? ? email : username)
+ user.name = name || User.suggest_name(username.presence || email)
end
if locale_force_update && SiteSetting.allow_user_locale && locale.present? &&
diff --git a/app/models/global_setting.rb b/app/models/global_setting.rb
index c8cd6845c15..490c5b9e38e 100644
--- a/app/models/global_setting.rb
+++ b/app/models/global_setting.rb
@@ -45,7 +45,7 @@ class GlobalSetting
end
end
end
- if !secret_key_base.blank? && token != secret_key_base
+ if secret_key_base.present? && token != secret_key_base
STDERR.puts "WARNING: DISCOURSE_SECRET_KEY_BASE is invalid, it was re-generated"
end
token
@@ -219,7 +219,7 @@ class GlobalSetting
c[:username] = redis_username if redis_username.present?
c[:password] = redis_password if redis_password.present?
c[:db] = redis_db if redis_db != 0
- c[:db] = 1 if Rails.env == "test"
+ c[:db] = 1 if Rails.env.test?
c[:id] = nil if redis_skip_client_commands
c[:ssl] = true if redis_use_ssl
@@ -246,7 +246,7 @@ class GlobalSetting
c[:username] = message_bus_redis_username if message_bus_redis_username.present?
c[:password] = message_bus_redis_password if message_bus_redis_password.present?
c[:db] = message_bus_redis_db if message_bus_redis_db != 0
- c[:db] = 1 if Rails.env == "test"
+ c[:db] = 1 if Rails.env.test?
c[:id] = nil if message_bus_redis_skip_client_commands
c[:ssl] = true if redis_use_ssl
@@ -293,13 +293,7 @@ class GlobalSetting
end
def resolve(current, default)
- BaseProvider.coerce(
- if current.present?
- current
- else
- default.present? ? default : nil
- end,
- )
+ BaseProvider.coerce(current.presence || default.presence)
end
end
@@ -373,7 +367,7 @@ class GlobalSetting
end
def self.configure!
- if Rails.env == "test"
+ if Rails.env.test?
@provider = BlankProvider.new
else
@provider =
diff --git a/app/models/group.rb b/app/models/group.rb
index af656178b8a..f40ee8120b1 100644
--- a/app/models/group.rb
+++ b/app/models/group.rb
@@ -50,6 +50,8 @@ class Group < ActiveRecord::Base
before_save :downcase_incoming_email
before_save :cook_bio
+ before_destroy :cache_group_users_for_destroyed_event, prepend: true
+ after_destroy :expire_cache
after_save :destroy_deletions
after_save :update_primary_group
after_save :update_title
@@ -64,12 +66,10 @@ class Group < ActiveRecord::Base
end
after_save :expire_cache
- after_destroy :expire_cache
after_commit :automatic_group_membership, on: %i[create update]
after_commit :trigger_group_created_event, on: :create
after_commit :trigger_group_updated_event, on: :update
- before_destroy :cache_group_users_for_destroyed_event, prepend: true
after_commit :trigger_group_destroyed_event, on: :destroy
after_commit :set_default_notifications, on: %i[create update]
@@ -348,7 +348,7 @@ class Group < ActiveRecord::Base
end
def smtp_from_address
- self.email_from_alias.present? ? self.email_from_alias : self.email_username
+ email_from_alias.presence || email_username
end
def downcase_incoming_email
diff --git a/app/models/group_associated_group.rb b/app/models/group_associated_group.rb
index 4e9f963fbd1..893af1a1331 100644
--- a/app/models/group_associated_group.rb
+++ b/app/models/group_associated_group.rb
@@ -3,8 +3,8 @@ class GroupAssociatedGroup < ActiveRecord::Base
belongs_to :group
belongs_to :associated_group
- after_commit :add_associated_users, on: %i[create update]
before_destroy :remove_associated_users
+ after_commit :add_associated_users, on: %i[create update]
def add_associated_users
with_mutex do
diff --git a/app/models/group_history.rb b/app/models/group_history.rb
index 016306738dd..7d0de240759 100644
--- a/app/models/group_history.rb
+++ b/app/models/group_history.rb
@@ -31,7 +31,7 @@ class GroupHistory < ActiveRecord::Base
.where(group_id: group.id)
.order("group_histories.created_at DESC")
- if !params.blank?
+ if params.present?
params = params.slice(*filters)
records = records.where(action: self.actions[params[:action].to_sym]) if params[
:action
diff --git a/app/models/group_user.rb b/app/models/group_user.rb
index 2030f291b97..86ef4f65601 100644
--- a/app/models/group_user.rb
+++ b/app/models/group_user.rb
@@ -4,13 +4,13 @@ class GroupUser < ActiveRecord::Base
belongs_to :group
belongs_to :user
- after_save :update_title
+ before_create :set_notification_level
after_destroy :grant_other_available_title
+ after_destroy :remove_primary_and_flair_group, :recalculate_trust_level
+ after_save :update_title
after_save :set_primary_group
- after_destroy :remove_primary_and_flair_group, :recalculate_trust_level
- before_create :set_notification_level
after_save :grant_trust_level
after_save :set_category_notifications
after_save :set_tag_notifications
diff --git a/app/models/invite.rb b/app/models/invite.rb
index f76b0512cd0..83d3c4b42be 100644
--- a/app/models/invite.rb
+++ b/app/models/invite.rb
@@ -31,7 +31,7 @@ class Invite < ActiveRecord::Base
has_many :topic_invites
has_many :topics, through: :topic_invites, source: :topic
- validates_presence_of :invited_by_id
+ validates :invited_by_id, presence: true
validates :email, email: true, allow_blank: true
validates :custom_message, length: { maximum: 1000 }
validates :domain, length: { maximum: 500 }
diff --git a/app/models/invited_user.rb b/app/models/invited_user.rb
index efb994372f5..1f0cff1b757 100644
--- a/app/models/invited_user.rb
+++ b/app/models/invited_user.rb
@@ -4,8 +4,8 @@ class InvitedUser < ActiveRecord::Base
belongs_to :user
belongs_to :invite, -> { unscope(where: :deleted_at) }
- validates_presence_of :invite_id
- validates_uniqueness_of :invite_id, scope: :user_id, conditions: -> { where.not(user_id: nil) }
+ validates :invite_id, presence: true
+ validates :invite_id, uniqueness: { scope: :user_id, conditions: -> { where.not(user_id: nil) } }
end
# == Schema Information
diff --git a/app/models/notification.rb b/app/models/notification.rb
index 1d5cc9e08c1..8857ad7e731 100644
--- a/app/models/notification.rb
+++ b/app/models/notification.rb
@@ -11,8 +11,8 @@ class Notification < ActiveRecord::Base
MEMBERSHIP_REQUEST_CONSOLIDATION_WINDOW_HOURS = 24
- validates_presence_of :data
- validates_presence_of :notification_type
+ validates :data, presence: true
+ validates :notification_type, presence: true
scope :unread, lambda { where(read: false) }
scope :recent,
diff --git a/app/models/optimized_image.rb b/app/models/optimized_image.rb
index 84722c8c2b0..08a8c65ac30 100644
--- a/app/models/optimized_image.rb
+++ b/app/models/optimized_image.rb
@@ -178,7 +178,7 @@ class OptimizedImage < ActiveRecord::Base
else
size = calculate_filesize
- write_attribute(:filesize, size)
+ self[:filesize] = size
update_columns(filesize: size) if !new_record?
size
end
diff --git a/app/models/post.rb b/app/models/post.rb
index 2c3148b7385..8cbed1e6eec 100644
--- a/app/models/post.rb
+++ b/app/models/post.rb
@@ -1051,7 +1051,7 @@ class Post < ActiveRecord::Base
post_revision = PostRevision.find_by(post_id: id, number: (number + 1))
post_revision.modifications.each do |attribute, change|
attribute = "version" if attribute == "cached_version"
- write_attribute(attribute, change[0])
+ self[attribute] = change[0]
end
end
@@ -1342,7 +1342,7 @@ class Post < ActiveRecord::Base
def parse_quote_into_arguments(quote)
return {} if quote.blank?
- args = HashWithIndifferentAccess.new
+ args = ActiveSupport::HashWithIndifferentAccess.new
quote.first.scan(/([a-z]+)\:(\d+)/).each { |arg| args[arg[0]] = arg[1].to_i }
args
end
diff --git a/app/models/post_detail.rb b/app/models/post_detail.rb
index c28d501d8ec..d23b74bdd5f 100644
--- a/app/models/post_detail.rb
+++ b/app/models/post_detail.rb
@@ -3,8 +3,8 @@
class PostDetail < ActiveRecord::Base
belongs_to :post
- validates_presence_of :key, :value
- validates_uniqueness_of :key, scope: :post_id
+ validates :key, :value, presence: true
+ validates :key, uniqueness: { scope: :post_id }
end
# == Schema Information
diff --git a/app/models/post_reply.rb b/app/models/post_reply.rb
index d2cce1de360..e856501b063 100644
--- a/app/models/post_reply.rb
+++ b/app/models/post_reply.rb
@@ -4,7 +4,7 @@ class PostReply < ActiveRecord::Base
belongs_to :post
belongs_to :reply, foreign_key: :reply_post_id, class_name: "Post"
- validates_uniqueness_of :reply_post_id, scope: :post_id
+ validates :reply_post_id, uniqueness: { scope: :post_id }
validate :ensure_same_topic
private
diff --git a/app/models/post_timing.rb b/app/models/post_timing.rb
index 69d74dacc76..5d9d09b6753 100644
--- a/app/models/post_timing.rb
+++ b/app/models/post_timing.rb
@@ -4,8 +4,8 @@ class PostTiming < ActiveRecord::Base
belongs_to :topic
belongs_to :user
- validates_presence_of :post_number
- validates_presence_of :msecs
+ validates :post_number, presence: true
+ validates :msecs, presence: true
def self.pretend_read(topic_id, actual_read_post_number, pretend_read_post_number, user_ids = nil)
# This is done in SQL cause the logic is quite tricky and we want to do this in one db hit
diff --git a/app/models/published_page.rb b/app/models/published_page.rb
index 5fd47bb9236..49fc1df7417 100644
--- a/app/models/published_page.rb
+++ b/app/models/published_page.rb
@@ -3,8 +3,8 @@
class PublishedPage < ActiveRecord::Base
belongs_to :topic
- validates_presence_of :slug
- validates_uniqueness_of :slug, :topic_id
+ validates :slug, presence: true
+ validates :slug, :topic_id, uniqueness: true
validate :slug_format
def slug_format
diff --git a/app/models/remote_theme.rb b/app/models/remote_theme.rb
index bdd9e1b53d7..bdfe9661bf5 100644
--- a/app/models/remote_theme.rb
+++ b/app/models/remote_theme.rb
@@ -40,10 +40,12 @@ class RemoteTheme < ActiveRecord::Base
)
end
- validates_format_of :minimum_discourse_version,
- :maximum_discourse_version,
- with: Discourse::VERSION_REGEXP,
- allow_nil: true
+ validates :minimum_discourse_version,
+ :maximum_discourse_version,
+ format: {
+ with: Discourse::VERSION_REGEXP,
+ allow_nil: true,
+ }
def self.extract_theme_info(importer)
if importer.file_size("about.json") > MAX_METADATA_FILE_SIZE
diff --git a/app/models/reviewable.rb b/app/models/reviewable.rb
index d9241cfeada..fd16527b53c 100644
--- a/app/models/reviewable.rb
+++ b/app/models/reviewable.rb
@@ -22,7 +22,7 @@ class Reviewable < ActiveRecord::Base
end
attr_accessor :created_new
- validates_presence_of :type, :status, :created_by_id
+ validates :type, :status, :created_by_id, presence: true
belongs_to :target, polymorphic: true
belongs_to :created_by, class_name: "User"
belongs_to :target_created_by, class_name: "User"
diff --git a/app/models/reviewable_claimed_topic.rb b/app/models/reviewable_claimed_topic.rb
index e9e9d941ef0..56512813846 100644
--- a/app/models/reviewable_claimed_topic.rb
+++ b/app/models/reviewable_claimed_topic.rb
@@ -3,7 +3,7 @@
class ReviewableClaimedTopic < ActiveRecord::Base
belongs_to :topic
belongs_to :user
- validates_uniqueness_of :topic
+ validates :topic, uniqueness: true
def self.claimed_hash(topic_ids)
result = {}
diff --git a/app/models/search_log.rb b/app/models/search_log.rb
index 86cc0761e70..cedd937d686 100644
--- a/app/models/search_log.rb
+++ b/app/models/search_log.rb
@@ -3,7 +3,7 @@
class SearchLog < ActiveRecord::Base
MAXIMUM_USER_AGENT_LENGTH = 2000
- validates_presence_of :term
+ validates :term, presence: true
validates :user_agent, length: { maximum: MAXIMUM_USER_AGENT_LENGTH }
belongs_to :user
diff --git a/app/models/site_setting.rb b/app/models/site_setting.rb
index 7fecb3a03bd..4b4a3c24285 100644
--- a/app/models/site_setting.rb
+++ b/app/models/site_setting.rb
@@ -75,8 +75,8 @@ class SiteSetting < ActiveRecord::Base
has_many :upload_references, as: :target, dependent: :destroy
- validates_presence_of :name
- validates_presence_of :data_type
+ validates :name, presence: true
+ validates :data_type, presence: true
after_save do
if saved_change_to_value?
diff --git a/app/models/tag_group.rb b/app/models/tag_group.rb
index b8c61724ef2..d79d5270efb 100644
--- a/app/models/tag_group.rb
+++ b/app/models/tag_group.rb
@@ -2,7 +2,7 @@
class TagGroup < ActiveRecord::Base
validates :name, length: { maximum: 100 }
- validates_uniqueness_of :name, case_sensitive: false
+ validates :name, uniqueness: { case_sensitive: false }
has_many :tag_group_memberships, dependent: :destroy
has_many :tags, through: :tag_group_memberships
@@ -17,9 +17,9 @@ class TagGroup < ActiveRecord::Base
belongs_to :parent_tag, class_name: "Tag"
- before_create :init_permissions
before_save :apply_permissions
before_save :remove_parent_from_group
+ before_create :init_permissions
after_commit { DiscourseTagging.clear_cache! }
diff --git a/app/models/theme_modifier_set.rb b/app/models/theme_modifier_set.rb
index bff4604deb7..35afc214bdc 100644
--- a/app/models/theme_modifier_set.rb
+++ b/app/models/theme_modifier_set.rb
@@ -13,7 +13,7 @@ class ThemeModifierSet < ActiveRecord::Base
def type_validator
ThemeModifierSet.modifiers.each do |k, config|
- value = read_attribute(k)
+ value = self[k]
next if value.nil?
case config[:type]
@@ -92,8 +92,8 @@ class ThemeModifierSet < ActiveRecord::Base
value =
target_setting_name.present? ? target_setting_value : theme.settings[setting_name]&.value
value = coerce_setting_value(modifier_name, value)
- if read_attribute(modifier_name) != value
- write_attribute(modifier_name, value)
+ if self[modifier_name] != value
+ self[modifier_name] = value
changed = true
end
end
diff --git a/app/models/theme_setting.rb b/app/models/theme_setting.rb
index cabfbc54f89..3c61fcb280c 100644
--- a/app/models/theme_setting.rb
+++ b/app/models/theme_setting.rb
@@ -10,13 +10,13 @@ class ThemeSetting < ActiveRecord::Base
MAXIMUM_JSON_VALUE_SIZE_BYTES = 0.5 * 1024 * 1024 # 0.5 MB
- validates_presence_of :name, :theme
+ validates :name, :theme, presence: true
validates :data_type, inclusion: { in: TYPES_ENUM.values }
validate :json_value_size, if: -> { self.data_type == TYPES_ENUM[:objects] }
validates :name, length: { maximum: 255 }
- after_save :clear_settings_cache
after_destroy :clear_settings_cache
+ after_save :clear_settings_cache
after_save do
if self.data_type == ThemeSetting.types[:upload] && saved_change_to_value?
diff --git a/app/models/topic.rb b/app/models/topic.rb
index f0239cb295f..4fcc1e68542 100644
--- a/app/models/topic.rb
+++ b/app/models/topic.rb
@@ -408,7 +408,7 @@ class Topic < ActiveRecord::Base
before_save do
ensure_topic_has_a_category unless skip_callbacks
- write_attribute(:fancy_title, Topic.fancy_title(title)) if title_changed?
+ self[:fancy_title] = Topic.fancy_title(title) if title_changed?
if category_id_changed? || new_record?
inherit_auto_close_from_category
@@ -537,7 +537,7 @@ class Topic < ActiveRecord::Base
unless fancy_title = read_attribute(:fancy_title)
fancy_title = Topic.fancy_title(title)
- write_attribute(:fancy_title, fancy_title)
+ self[:fancy_title] = fancy_title
if !new_record? && !Discourse.readonly_mode?
# make sure data is set in table, this also allows us to change algorithm
@@ -1461,7 +1461,7 @@ class Topic < ActiveRecord::Base
return "" if title.blank?
slug = slug_for_topic(title)
if new_record?
- write_attribute(:slug, slug)
+ self[:slug] = slug
else
update_column(:slug, slug)
end
@@ -1481,8 +1481,8 @@ class Topic < ActiveRecord::Base
def title=(t)
slug = slug_for_topic(t.to_s)
- write_attribute(:slug, slug)
- write_attribute(:fancy_title, nil)
+ self[:slug] = slug
+ self[:fancy_title] = nil
write_attribute(:title, t)
end
@@ -1664,7 +1664,7 @@ class Topic < ActiveRecord::Base
topic_timer.status_type = status_type
time_now = Time.zone.now
- topic_timer.based_on_last_post = !based_on_last_post.blank?
+ topic_timer.based_on_last_post = based_on_last_post.present?
if status_type == TopicTimer.types[:publish_to_category]
topic_timer.category = Category.find_by(id: category_id)
diff --git a/app/models/topic_allowed_group.rb b/app/models/topic_allowed_group.rb
index d5ee5e5d63d..531ab354380 100644
--- a/app/models/topic_allowed_group.rb
+++ b/app/models/topic_allowed_group.rb
@@ -4,7 +4,7 @@ class TopicAllowedGroup < ActiveRecord::Base
belongs_to :topic
belongs_to :group
- validates_uniqueness_of :topic_id, scope: :group_id
+ validates :topic_id, uniqueness: { scope: :group_id }
end
# == Schema Information
diff --git a/app/models/topic_allowed_user.rb b/app/models/topic_allowed_user.rb
index cc497d1a842..e1aeb740f11 100644
--- a/app/models/topic_allowed_user.rb
+++ b/app/models/topic_allowed_user.rb
@@ -4,7 +4,7 @@ class TopicAllowedUser < ActiveRecord::Base
belongs_to :topic
belongs_to :user
- validates_uniqueness_of :topic_id, scope: :user_id
+ validates :topic_id, uniqueness: { scope: :user_id }
end
# == Schema Information
diff --git a/app/models/topic_embed.rb b/app/models/topic_embed.rb
index 2959a76e933..7d1aa6bcde8 100644
--- a/app/models/topic_embed.rb
+++ b/app/models/topic_embed.rb
@@ -7,8 +7,8 @@ class TopicEmbed < ActiveRecord::Base
belongs_to :topic
belongs_to :post
- validates_presence_of :embed_url
- validates_uniqueness_of :embed_url
+ validates :embed_url, presence: true
+ validates :embed_url, uniqueness: true
validates :embed_content_cache, length: { maximum: EMBED_CONTENT_CACHE_MAX_LENGTH }
before_validation(on: :create) do
diff --git a/app/models/topic_invite.rb b/app/models/topic_invite.rb
index 52f63070c7a..c9b6c1295a7 100644
--- a/app/models/topic_invite.rb
+++ b/app/models/topic_invite.rb
@@ -4,10 +4,10 @@ class TopicInvite < ActiveRecord::Base
belongs_to :topic
belongs_to :invite
- validates_presence_of :topic_id
- validates_presence_of :invite_id
+ validates :topic_id, presence: true
+ validates :invite_id, presence: true
- validates_uniqueness_of :topic_id, scope: :invite_id
+ validates :topic_id, uniqueness: { scope: :invite_id }
end
# == Schema Information
diff --git a/app/models/topic_link.rb b/app/models/topic_link.rb
index 6b6b6dda8fc..702ce7f5342 100644
--- a/app/models/topic_link.rb
+++ b/app/models/topic_link.rb
@@ -17,11 +17,11 @@ class TopicLink < ActiveRecord::Base
belongs_to :link_topic, class_name: "Topic"
belongs_to :link_post, class_name: "Post"
- validates_presence_of :url
+ validates :url, presence: true
- validates_length_of :url, maximum: 500
+ validates :url, length: { maximum: 500 }
- validates_uniqueness_of :url, scope: %i[topic_id post_id]
+ validates :url, uniqueness: { scope: %i[topic_id post_id] }
has_many :topic_link_clicks, dependent: :destroy
diff --git a/app/models/topic_link_click.rb b/app/models/topic_link_click.rb
index f1236c8c28b..aa3c833fd2f 100644
--- a/app/models/topic_link_click.rb
+++ b/app/models/topic_link_click.rb
@@ -7,7 +7,7 @@ class TopicLinkClick < ActiveRecord::Base
belongs_to :topic_link, counter_cache: :clicks
belongs_to :user
- validates_presence_of :topic_link_id
+ validates :topic_link_id, presence: true
ALLOWED_REDIRECT_HOSTNAMES = Set.new(%W[www.youtube.com youtu.be])
diff --git a/app/models/topic_view_item.rb b/app/models/topic_view_item.rb
index 143d22a0056..7801a708c93 100644
--- a/app/models/topic_view_item.rb
+++ b/app/models/topic_view_item.rb
@@ -7,7 +7,7 @@ class TopicViewItem < ActiveRecord::Base
self.table_name = "topic_views"
belongs_to :user
belongs_to :topic
- validates_presence_of :topic_id, :ip_address, :viewed_at
+ validates :topic_id, :ip_address, :viewed_at, presence: true
def self.add(topic_id, ip, user_id = nil, at = nil, skip_redis = false)
# Only store a view once per day per thing per (user || ip)
diff --git a/app/models/translation_override.rb b/app/models/translation_override.rb
index 5604d6f0f97..69d15530c3e 100644
--- a/app/models/translation_override.rb
+++ b/app/models/translation_override.rb
@@ -45,8 +45,8 @@ class TranslationOverride < ActiveRecord::Base
include HasSanitizableFields
- validates_uniqueness_of :translation_key, scope: :locale
- validates_presence_of :locale, :translation_key, :value
+ validates :translation_key, uniqueness: { scope: :locale }
+ validates :locale, :translation_key, :value, presence: true
validate :check_interpolation_keys
validate :check_MF_string, if: :message_format?
diff --git a/app/models/upload.rb b/app/models/upload.rb
index 4cff40ec82c..5f3db6ef5d8 100644
--- a/app/models/upload.rb
+++ b/app/models/upload.rb
@@ -41,9 +41,9 @@ class Upload < ActiveRecord::Base
attr_accessor :validate_file_size
attr_accessor :skip_video_conversion
- validates_presence_of :filesize
- validates_presence_of :original_filename
- validates :dominant_color, length: { is: 6 }, allow_blank: true, allow_nil: true
+ validates :filesize, presence: true
+ validates :original_filename, presence: true
+ validates :dominant_color, length: { is: 6 }, allow_blank: true
validates_with UploadValidator
@@ -339,11 +339,11 @@ class Upload < ActiveRecord::Base
# on demand image size calculation, this allows us to null out image sizes
# and still handle as needed
def get_dimension(key)
- if v = read_attribute(key)
+ if v = self[key]
return v
end
fix_dimensions!
- read_attribute(key)
+ self[key]
end
def width
diff --git a/app/models/user.rb b/app/models/user.rb
index d2997f3c9ed..c0b65436a5a 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -146,7 +146,7 @@ class User < ActiveRecord::Base
delegate :last_sent_email_address, to: :email_logs
- validates_presence_of :username
+ validates :username, presence: true
validate :username_validator, if: :will_save_change_to_username?
validate :password_validator
validate :name_validator, if: :will_save_change_to_name?
@@ -166,6 +166,12 @@ class User < ActiveRecord::Base
before_validation :set_skip_validate_email
+ before_save :update_usernames
+ before_save :match_primary_group_changes
+ before_save :check_if_title_is_badged_granted
+ before_save :apply_watched_words, unless: :should_skip_user_fields_validation?
+ before_save :check_qualification_for_users_directory,
+ if: Proc.new { SiteSetting.bootstrap_mode_enabled }
after_create :create_email_token
after_create :create_user_stat
after_create :create_user_option
@@ -183,13 +189,6 @@ class User < ActiveRecord::Base
after_update :trigger_user_automatic_group_refresh, if: :saved_change_to_staged?
after_update :change_display_name, if: :saved_change_to_name?
- before_save :update_usernames
- before_save :match_primary_group_changes
- before_save :check_if_title_is_badged_granted
- before_save :apply_watched_words, unless: :should_skip_user_fields_validation?
- before_save :check_qualification_for_users_directory,
- if: Proc.new { SiteSetting.bootstrap_mode_enabled }
-
after_save :expire_tokens_if_password_changed
after_save :clear_global_notice_if_needed
after_save :refresh_avatar
diff --git a/app/models/user_action.rb b/app/models/user_action.rb
index b17740e80a2..6387ad767b3 100644
--- a/app/models/user_action.rb
+++ b/app/models/user_action.rb
@@ -7,8 +7,8 @@ class UserAction < ActiveRecord::Base
belongs_to :target_post, class_name: "Post"
belongs_to :target_topic, class_name: "Topic"
- validates_presence_of :action_type
- validates_presence_of :user_id
+ validates :action_type, presence: true
+ validates :user_id, presence: true
LIKE = 1
WAS_LIKED = 2
diff --git a/app/models/user_associated_group.rb b/app/models/user_associated_group.rb
index 815309d1aaa..59406ff1108 100644
--- a/app/models/user_associated_group.rb
+++ b/app/models/user_associated_group.rb
@@ -4,8 +4,8 @@ class UserAssociatedGroup < ActiveRecord::Base
belongs_to :user
belongs_to :associated_group
- after_commit :add_to_associated_groups, on: %i[create update]
before_destroy :remove_from_associated_groups
+ after_commit :add_to_associated_groups, on: %i[create update]
def add_to_associated_groups
associated_group.groups.each do |group|
diff --git a/app/models/user_field.rb b/app/models/user_field.rb
index fd3bb1ab9c3..1f7c4cad6dd 100644
--- a/app/models/user_field.rb
+++ b/app/models/user_field.rb
@@ -10,8 +10,8 @@ class UserField < ActiveRecord::Base
deprecate_column :required, drop_from: "3.3"
self.ignored_columns += %i[field_type]
- validates_presence_of :description
- validates_presence_of :name, unless: -> { field_type == "confirm" }
+ validates :description, presence: true
+ validates :name, presence: { unless: -> { field_type == "confirm" } }
has_many :user_field_options, dependent: :destroy
has_one :directory_column, dependent: :destroy
accepts_nested_attributes_for :user_field_options
diff --git a/app/models/user_history.rb b/app/models/user_history.rb
index 80a510e3de6..16bae1986d9 100644
--- a/app/models/user_history.rb
+++ b/app/models/user_history.rb
@@ -28,7 +28,7 @@ class UserHistory < ActiveRecord::Base
validates :previous_value, length: { maximum: MAX_JSON_LENGTH }
validates :new_value, length: { maximum: MAX_JSON_LENGTH }
- validates_presence_of :action
+ validates :action, presence: true
scope :only_staff_actions, -> { where("action IN (?)", UserHistory.staff_action_ids) }
diff --git a/app/models/user_open_id.rb b/app/models/user_open_id.rb
index 3c5b1d457f6..e87fad86b1c 100644
--- a/app/models/user_open_id.rb
+++ b/app/models/user_open_id.rb
@@ -6,8 +6,8 @@ class UserOpenId < ActiveRecord::Base
belongs_to :user
- validates_presence_of :email
- validates_presence_of :url
+ validates :email, presence: true
+ validates :url, presence: true
private
diff --git a/app/models/user_option.rb b/app/models/user_option.rb
index 3c84be668a4..9e1c57f5540 100644
--- a/app/models/user_option.rb
+++ b/app/models/user_option.rb
@@ -23,9 +23,9 @@ class UserOption < ActiveRecord::Base
self.primary_key = :user_id
belongs_to :user
+ before_save :update_hide_profile_and_presence
before_create :set_defaults
- before_save :update_hide_profile_and_presence
after_save :update_tracked_topics
scope :human_users, -> { where("user_id > 0") }
diff --git a/app/models/user_profile_view.rb b/app/models/user_profile_view.rb
index 0648b75eb0b..c0406f2f559 100644
--- a/app/models/user_profile_view.rb
+++ b/app/models/user_profile_view.rb
@@ -1,7 +1,7 @@
# frozen_string_literal: true
class UserProfileView < ActiveRecord::Base
- validates_presence_of :user_profile_id, :viewed_at
+ validates :user_profile_id, :viewed_at, presence: true
belongs_to :user_profile
diff --git a/app/models/watched_word.rb b/app/models/watched_word.rb
index f91a4e0ac3f..b7b16c515d3 100644
--- a/app/models/watched_word.rb
+++ b/app/models/watched_word.rb
@@ -28,8 +28,8 @@ class WatchedWord < ActiveRecord::Base
end
end
- after_save -> { WordWatcher.clear_cache! }
after_destroy -> { WordWatcher.clear_cache! }
+ after_save -> { WordWatcher.clear_cache! }
scope :for,
->(word:) do
diff --git a/app/models/web_hook.rb b/app/models/web_hook.rb
index b1492d96f47..d9b9c27181e 100644
--- a/app/models/web_hook.rb
+++ b/app/models/web_hook.rb
@@ -14,9 +14,9 @@ class WebHook < ActiveRecord::Base
validates :payload_url, presence: true, format: URI.regexp(%w[http https])
validates :secret, length: { minimum: 12 }, allow_blank: true
- validates_presence_of :content_type
- validates_presence_of :last_delivery_status
- validates_presence_of :web_hook_event_types, unless: :wildcard_web_hook?
+ validates :content_type, presence: true
+ validates :last_delivery_status, presence: true
+ validates :web_hook_event_types, presence: { unless: :wildcard_web_hook? }
validate :ensure_payload_url_allowed, if: :payload_url_changed?
before_save :strip_url
diff --git a/app/serializers/post_revision_serializer.rb b/app/serializers/post_revision_serializer.rb
index fa4f92bec0f..7a18518f36f 100644
--- a/app/serializers/post_revision_serializer.rb
+++ b/app/serializers/post_revision_serializer.rb
@@ -257,7 +257,7 @@ class PostRevisionSerializer < ApplicationSerializer
# backtrack
post_revisions.each do |pr|
- revision = HashWithIndifferentAccess.new
+ revision = ActiveSupport::HashWithIndifferentAccess.new
revision[:revision] = pr.number
revision[:hidden] = pr.hidden
diff --git a/app/services/user_updater.rb b/app/services/user_updater.rb
index 87fc1f7ef05..dcb62f65808 100644
--- a/app/services/user_updater.rb
+++ b/app/services/user_updater.rb
@@ -113,7 +113,7 @@ class UserUpdater
user_notification_schedule.assign_attributes(attributes[:user_notification_schedule])
end
- old_user_name = user.name.present? ? user.name : ""
+ old_user_name = user.name.presence || ""
user.name = attributes.fetch(:name) { user.name } if guardian.can_edit_name?(user)
diff --git a/config/application.rb b/config/application.rb
index 6724d376ab4..5a3cbfc067d 100644
--- a/config/application.rb
+++ b/config/application.rb
@@ -84,7 +84,7 @@ module Discourse
config.active_record.belongs_to_required_by_default = false
config.active_record.yaml_column_permitted_classes = [
Hash,
- HashWithIndifferentAccess,
+ ActiveSupport::HashWithIndifferentAccess,
Time,
Symbol,
]
diff --git a/config/initializers/004-message_bus.rb b/config/initializers/004-message_bus.rb
index 077f27b43bd..0f0c61b4f94 100644
--- a/config/initializers/004-message_bus.rb
+++ b/config/initializers/004-message_bus.rb
@@ -123,7 +123,7 @@ MessageBus.on_disconnect do |site_id|
ActiveRecord::Base.connection_handler.clear_active_connections!
end
-if Rails.env == "test"
+if Rails.env.test?
MessageBus.configure(backend: :memory)
else
MessageBus.redis_config = GlobalSetting.message_bus_redis_config
@@ -135,7 +135,7 @@ MessageBus.long_polling_enabled =
GlobalSetting.enable_long_polling.nil? ? true : GlobalSetting.enable_long_polling
MessageBus.long_polling_interval = GlobalSetting.long_polling_interval || 25_000
-if Rails.env == "test" || $0 =~ /rake$/
+if Rails.env.test? || $0 =~ /rake$/
# disable keepalive in testing
MessageBus.keepalive_interval = -1
end
diff --git a/config/initializers/200-first_middlewares.rb b/config/initializers/200-first_middlewares.rb
index 329704e69c0..6d970ac4463 100644
--- a/config/initializers/200-first_middlewares.rb
+++ b/config/initializers/200-first_middlewares.rb
@@ -13,7 +13,7 @@ Rails.configuration.middleware.unshift(MessageBus::Rack::Middleware)
# no reason to track this in development, that is 300+ redis calls saved per
# page view (we serve all assets out of thin in development)
-if Rails.env != "development" || ENV["TRACK_REQUESTS"]
+if !Rails.env.development? || ENV["TRACK_REQUESTS"]
require "middleware/request_tracker"
Rails.configuration.middleware.unshift(Middleware::RequestTracker)
Rails.configuration.middleware.move_before(Middleware::RequestTracker, ActionDispatch::RemoteIp)
diff --git a/config/initializers/300-perf.rb b/config/initializers/300-perf.rb
index 86822bff8a0..8ce7a012ab5 100644
--- a/config/initializers/300-perf.rb
+++ b/config/initializers/300-perf.rb
@@ -1,6 +1,6 @@
# frozen_string_literal: true
-if Rails.env == "production"
+if Rails.env.production?
# This event happens quite a lot and fans out to ExplainSubscriber
# and Logger, this cuts out 2 method calls that every time we run SQL
#
diff --git a/config/routes.rb b/config/routes.rb
index fcf65f8c711..9c5a75e02be 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -27,7 +27,7 @@ Discourse::Application.routes.draw do
match "/404", to: "exceptions#not_found", via: %i[get post]
get "/404-body" => "exceptions#not_found_body"
- if Rails.env.test? || Rails.env.development?
+ if Rails.env.local?
get "/bootstrap/plugin-css-for-tests.css" => "bootstrap#plugin_css_for_tests"
get "/bootstrap/core-css-for-tests.css" => "bootstrap#core_css_for_tests"
end
diff --git a/db/migrate/20220825054405_fill_personal_message_enabled_groups_based_on_deprecated_settings.rb b/db/migrate/20220825054405_fill_personal_message_enabled_groups_based_on_deprecated_settings.rb
index 28241e035d5..d41bb1093e0 100644
--- a/db/migrate/20220825054405_fill_personal_message_enabled_groups_based_on_deprecated_settings.rb
+++ b/db/migrate/20220825054405_fill_personal_message_enabled_groups_based_on_deprecated_settings.rb
@@ -13,8 +13,7 @@ class FillPersonalMessageEnabledGroupsBasedOnDeprecatedSettings < ActiveRecord::
DB.query_single(
"SELECT value FROM site_settings WHERE name = 'min_trust_to_send_messages'",
).first
- min_trust_to_send_messages =
- (min_trust_to_send_messages_raw.blank? ? 1 : min_trust_to_send_messages_raw).to_i
+ min_trust_to_send_messages = (min_trust_to_send_messages_raw.presence || 1).to_i
# default to TL1, Group::AUTO_GROUPS[:trust_level_1] is 11
personal_message_enabled_groups = "11"
diff --git a/db/migrate/20221110175456_populate_default_composer_category.rb b/db/migrate/20221110175456_populate_default_composer_category.rb
index 22692d3ea11..3e1a25c7a76 100644
--- a/db/migrate/20221110175456_populate_default_composer_category.rb
+++ b/db/migrate/20221110175456_populate_default_composer_category.rb
@@ -10,7 +10,7 @@ class PopulateDefaultComposerCategory < ActiveRecord::Migration[7.0]
return if general_category_id.blank? || general_category_id[0].to_i < 0
default_composer_category =
DB.query_single("SELECT value FROM site_settings where name = 'default_composer_category'")
- return if !default_composer_category.blank?
+ return if default_composer_category.present?
DB.exec(
"INSERT INTO site_settings(name, value, data_type, created_at, updated_at)
VALUES('default_composer_category', :setting, '16', NOW(), NOW())",
diff --git a/lib/auth/default_current_user_provider.rb b/lib/auth/default_current_user_provider.rb
index 2b37c1252d7..8bfb71f4436 100644
--- a/lib/auth/default_current_user_provider.rb
+++ b/lib/auth/default_current_user_provider.rb
@@ -113,11 +113,11 @@ class Auth::DefaultCurrentUserProvider
user_api_key = @env[USER_API_KEY]
api_key = @env[HEADER_API_KEY]
- if [email protected]? && request[PARAMETER_USER_API_KEY] && api_parameter_allowed?
+ if @env.present? && request[PARAMETER_USER_API_KEY] && api_parameter_allowed?
user_api_key ||= request[PARAMETER_USER_API_KEY]
end
- api_key ||= request[API_KEY] if [email protected]? && request[API_KEY] && api_parameter_allowed?
+ api_key ||= request[API_KEY] if @env.present? && request[API_KEY] && api_parameter_allowed?
auth_token = find_auth_token
current_user = nil
diff --git a/lib/bookmark_manager.rb b/lib/bookmark_manager.rb
index ce3866f374e..5f2c4244741 100644
--- a/lib/bookmark_manager.rb
+++ b/lib/bookmark_manager.rb
@@ -149,11 +149,8 @@ class BookmarkManager
model_options = { pinned: options[:pinned] }
if options[:auto_delete_preference].blank?
- model_options[:auto_delete_preference] = if user_auto_delete_preference.present?
- user_auto_delete_preference
- else
+ model_options[:auto_delete_preference] = user_auto_delete_preference.presence ||
Bookmark.auto_delete_preferences[:clear_reminder]
- end
else
model_options[:auto_delete_preference] = options[:auto_delete_preference]
end
diff --git a/lib/configurable_urls.rb b/lib/configurable_urls.rb
index feb256ab162..cd09575c26f 100644
--- a/lib/configurable_urls.rb
+++ b/lib/configurable_urls.rb
@@ -2,7 +2,7 @@
module ConfigurableUrls
def faq_path
- SiteSetting.faq_url.blank? ? "#{Discourse.base_path}/faq" : SiteSetting.faq_url
+ SiteSetting.faq_url.presence || "#{Discourse.base_path}/faq"
end
def tos_url
diff --git a/lib/cooked_post_processor.rb b/lib/cooked_post_processor.rb
index cb9c48f169f..a0f357933ef 100644
--- a/lib/cooked_post_processor.rb
+++ b/lib/cooked_post_processor.rb
@@ -439,7 +439,7 @@ class CookedPostProcessor
def process_hotlinked_image(img)
onebox = img.ancestors(".onebox, .onebox-body").first
- @hotlinked_map ||= @post.post_hotlinked_media.preload(:upload).map { |r| [r.url, r] }.to_h
+ @hotlinked_map ||= @post.post_hotlinked_media.preload(:upload).index_by(&:url)
normalized_src =
PostHotlinkedMedia.normalize_src(img["src"] || img[PrettyText::BLOCKED_HOTLINKED_SRC_ATTR])
info = @hotlinked_map[normalized_src]
diff --git a/lib/crawler_detection.rb b/lib/crawler_detection.rb
index f926d3455df..6efd1c872d2 100644
--- a/lib/crawler_detection.rb
+++ b/lib/crawler_detection.rb
@@ -6,7 +6,7 @@ module CrawlerDetection
def self.to_matcher(string, type: nil)
escaped = string.split("|").map { |agent| Regexp.escape(agent) }.join("|")
- if type == :real && Rails.env == "test"
+ if type == :real && Rails.env.test?
# we need this bypass so we properly render views
escaped << "|Rails Testing"
end
diff --git a/lib/demon/email_sync.rb b/lib/demon/email_sync.rb
index 9f25c4f06b0..8d07145f3c5 100644
--- a/lib/demon/email_sync.rb
+++ b/lib/demon/email_sync.rb
@@ -178,7 +178,7 @@ class Demon::EmailSync < ::Demon::Base
RailsMultisite::ConnectionManagement.each_connection do |db|
next if !SiteSetting.enable_imap
- groups = Group.with_imap_configured.map { |group| [group.id, group] }.to_h
+ groups = Group.with_imap_configured.index_by(&:id)
@sync_lock.synchronize do
@sync_data[db] ||= {}
diff --git a/lib/discourse_plugin_registry.rb b/lib/discourse_plugin_registry.rb
index af80f8b0631..34708f7780d 100644
--- a/lib/discourse_plugin_registry.rb
+++ b/lib/discourse_plugin_registry.rb
@@ -60,8 +60,8 @@ class DiscoursePluginRegistry
define_register :desktop_stylesheets, Hash
define_register :color_definition_stylesheets, Hash
define_register :serialized_current_user_fields, Set
- define_register :seed_data, HashWithIndifferentAccess
- define_register :locales, HashWithIndifferentAccess
+ define_register :seed_data, ActiveSupport::HashWithIndifferentAccess
+ define_register :locales, ActiveSupport::HashWithIndifferentAccess
define_register :svg_icons, Set
define_register :custom_html, Hash
define_register :html_builders, Hash
diff --git a/lib/discourse_tagging.rb b/lib/discourse_tagging.rb
index a0d7773dc0b..4ba1f6f50e9 100644
--- a/lib/discourse_tagging.rb
+++ b/lib/discourse_tagging.rb
@@ -174,11 +174,7 @@ module DiscourseTagging
.map do |tag|
tag_name = tag.name
- if parent_child_names_map[tag_name].present?
- parent_child_names_map[tag_name]
- else
- tag_name
- end
+ parent_child_names_map[tag_name].presence || tag_name
end
.uniq
.sort
@@ -600,7 +596,7 @@ module DiscourseTagging
if opts[:order_popularity]
builder.order_by("#{topic_count_column} DESC, name")
- elsif opts[:order_search_results] && !term.blank?
+ elsif opts[:order_search_results] && term.present?
builder.order_by("lower(name) = lower(:cleaned_term) DESC, #{topic_count_column} DESC, name")
end
diff --git a/lib/email/styles.rb b/lib/email/styles.rb
index 16216604e50..dadd25c7d70 100644
--- a/lib/email/styles.rb
+++ b/lib/email/styles.rb
@@ -45,7 +45,7 @@ module Email
css = EmailStyle.new.compiled_css
@custom_styles = {}
- if !css.blank?
+ if css.present?
# there is a minor race condition here, CssParser could be
# loaded by ::CssParser::Parser not loaded
require "css_parser" unless defined?(::CssParser::Parser)
diff --git a/lib/excerpt_parser.rb b/lib/excerpt_parser.rb
index 2cb1a62a4a3..85a1b0da0f6 100644
--- a/lib/excerpt_parser.rb
+++ b/lib/excerpt_parser.rb
@@ -81,9 +81,9 @@ class ExcerptParser < Nokogiri::XML::SAX::Document
# If include_images is set, include the image in markdown
characters("!") if @markdown_images
- if !attributes["alt"].blank?
+ if attributes["alt"].present?
characters("[#{attributes["alt"]}]")
- elsif !attributes["title"].blank?
+ elsif attributes["title"].present?
characters("[#{attributes["title"]}]")
else
characters("[#{I18n.t "excerpt_image"}]")
diff --git a/lib/external_upload_helpers.rb b/lib/external_upload_helpers.rb
index 92a20503b8f..9700df192c8 100644
--- a/lib/external_upload_helpers.rb
+++ b/lib/external_upload_helpers.rb
@@ -295,7 +295,7 @@ module ExternalUploadHelpers
if upload.errors.empty?
response_serialized = self.class.serialize_upload(upload)
external_upload_stub.destroy!
- render json: response_serialized, status: 200
+ render json: response_serialized, status: :ok
else
render_json_error(upload.errors.to_hash.values.flatten, status: 422)
end
diff --git a/lib/file_store/s3_store.rb b/lib/file_store/s3_store.rb
index d16bfbdc89d..2f0fb28571b 100644
--- a/lib/file_store/s3_store.rb
+++ b/lib/file_store/s3_store.rb
@@ -187,11 +187,7 @@ module FileStore
end
def s3_upload_host
- if SiteSetting.Upload.s3_cdn_url.present?
- SiteSetting.Upload.s3_cdn_url
- else
- "https:#{absolute_base_url}"
- end
+ SiteSetting.Upload.s3_cdn_url.presence || "https:#{absolute_base_url}"
end
def external?
diff --git a/lib/file_store/to_s3_migration.rb b/lib/file_store/to_s3_migration.rb
index 24564630f83..f07e5d3fc82 100644
--- a/lib/file_store/to_s3_migration.rb
+++ b/lib/file_store/to_s3_migration.rb
@@ -161,7 +161,7 @@ module FileStore
end
bucket_has_folder_path = true if @s3_bucket.include? "/"
- public_directory = Rails.root.join("public").to_s
+ public_directory = Rails.public_path.to_s
s3 = Aws::S3::Client.new(@s3_client_options)
diff --git a/lib/guardian.rb b/lib/guardian.rb
index 12beb9e6eae..11f87e8f9cf 100644
--- a/lib/guardian.rb
+++ b/lib/guardian.rb
@@ -545,7 +545,7 @@ class Guardian
return false if [email protected]?
allowed_repos = GlobalSetting.allowed_theme_repos
- if !allowed_repos.blank?
+ if allowed_repos.present?
urls = allowed_repos.split(",").map(&:strip)
return urls.include?(repo)
end
diff --git a/lib/hijack.rb b/lib/hijack.rb
index fd92488aa0d..0447fe359ca 100644
--- a/lib/hijack.rb
+++ b/lib/hijack.rb
@@ -37,7 +37,7 @@ module Hijack
&scheduled.method(:resolve)
)
rescue WorkQueue::WorkQueueFull
- return render plain: "", status: 503
+ return render plain: "", status: :service_unavailable
end
# duplicate headers so other middleware does not mess with it
diff --git a/lib/import_export/importer.rb b/lib/import_export/importer.rb
index 1498831e46e..087832163b2 100644
--- a/lib/import_export/importer.rb
+++ b/lib/import_export/importer.rb
@@ -238,7 +238,7 @@ module ImportExport
end
def fix_permissions
- categories_by_id = @categories.to_h { |category| [category[:id], category] }
+ categories_by_id = @categories.index_by { _1[:id] }
@categories.each do |category|
if category[:permissions_params].blank?
diff --git a/lib/js_locale_helper.rb b/lib/js_locale_helper.rb
index 776460c1198..e176619b957 100644
--- a/lib/js_locale_helper.rb
+++ b/lib/js_locale_helper.rb
@@ -14,7 +14,7 @@ module JsLocaleHelper
end
def self.plugin_translations(locale_str)
- @plugin_translations ||= HashWithIndifferentAccess.new
+ @plugin_translations ||= ActiveSupport::HashWithIndifferentAccess.new
@plugin_translations[locale_str] ||= begin
translations = {}
@@ -30,7 +30,7 @@ module JsLocaleHelper
end
def self.load_translations(locale)
- @loaded_translations ||= HashWithIndifferentAccess.new
+ @loaded_translations ||= ActiveSupport::HashWithIndifferentAccess.new
@loaded_translations[locale] ||= begin
locale_str = locale.to_s
@@ -139,7 +139,7 @@ module JsLocaleHelper
message_formats =
I18n.fallbacks[locale]
- .each_with_object(HashWithIndifferentAccess.new) do |l, hash|
+ .each_with_object(ActiveSupport::HashWithIndifferentAccess.new) do |l, hash|
translations = translations_for(l, no_fallback: true)
hash[l] = remove_message_formats!(translations, l).merge(
TranslationOverride
diff --git a/lib/plain_text_to_markdown.rb b/lib/plain_text_to_markdown.rb
index 249b5194526..29697bad213 100644
--- a/lib/plain_text_to_markdown.rb
+++ b/lib/plain_text_to_markdown.rb
@@ -186,7 +186,7 @@ class PlainTextToMarkdown
urls = Set.new
text.scan(URL_REGEX) { urls << $& }
- hoisted = urls.map { |url| [SecureRandom.hex, url] }.to_h
+ hoisted = urls.index_by { |url| SecureRandom.hex }
hoisted.each { |h, url| text.gsub!(url, h) }
diff --git a/lib/plugin/instance.rb b/lib/plugin/instance.rb
index b575244f5da..aefcfe3f7b2 100644
--- a/lib/plugin/instance.rb
+++ b/lib/plugin/instance.rb
@@ -72,7 +72,7 @@ class Plugin::Instance
end
def seed_data
- @seed_data ||= HashWithIndifferentAccess.new({})
+ @seed_data ||= ActiveSupport::HashWithIndifferentAccess.new({})
end
def seed_fu_filter(filter = nil)
diff --git a/lib/post_creator.rb b/lib/post_creator.rb
index 2150322ccce..1eec0e12ec9 100644
--- a/lib/post_creator.rb
+++ b/lib/post_creator.rb
@@ -259,7 +259,7 @@ class PostCreator
end
def self.track_post_stats
- Rails.env != "test" || @track_post_stats
+ !Rails.env.test? || @track_post_stats
end
def self.track_post_stats=(val)
diff --git a/lib/pretty_text.rb b/lib/pretty_text.rb
index 44cc28e66c2..183cde9ca07 100644
--- a/lib/pretty_text.rb
+++ b/lib/pretty_text.rb
@@ -272,7 +272,7 @@ module PrettyText
__performEmojiUnescape(#{title.inspect}, {
getURL: __getURL,
emojiSet: #{set},
- emojiCDNUrl: "#{SiteSetting.external_emoji_url.blank? ? "" : SiteSetting.external_emoji_url}",
+ emojiCDNUrl: "#{SiteSetting.external_emoji_url.presence || ""}",
customEmoji: #{custom},
enableEmojiShortcuts: #{SiteSetting.enable_emoji_shortcuts},
inlineEmoji: #{SiteSetting.enable_inline_emoji_translation}
diff --git a/lib/reviewable/collection.rb b/lib/reviewable/collection.rb
index f05e898f483..584c3ebbd7d 100644
--- a/lib/reviewable/collection.rb
+++ b/lib/reviewable/collection.rb
@@ -11,6 +11,8 @@ class Reviewable < ActiveRecord::Base
end
end
+ delegate :present?, :blank?, to: :@content
+
def initialize(reviewable, guardian, args = nil)
args ||= {}
@@ -22,14 +24,6 @@ class Reviewable < ActiveRecord::Base
@content.any? { |a| a.server_action.to_s == action_id.to_s }
end
- def blank?
- @content.blank?
- end
-
- def present?
- !blank?
- end
-
def each
@content.each { |i| yield i }
end
diff --git a/lib/second_factor/actions/base.rb b/lib/second_factor/actions/base.rb
index 24ad12d8554..7b9455eb1cf 100644
--- a/lib/second_factor/actions/base.rb
+++ b/lib/second_factor/actions/base.rb
@@ -10,7 +10,7 @@ module SecondFactor::Actions
@current_user = guardian.user
@target_user = target_user
@request = request
- @opts = HashWithIndifferentAccess.new(opts)
+ @opts = ActiveSupport::HashWithIndifferentAccess.new(opts)
end
def skip_second_factor_auth?(params)
diff --git a/lib/site_setting_extension.rb b/lib/site_setting_extension.rb
index 1c9787f83fa..e09070e1706 100644
--- a/lib/site_setting_extension.rb
+++ b/lib/site_setting_extension.rb
@@ -39,7 +39,7 @@ module SiteSettingExtension
# note optimised cause this is called a lot so avoiding .presence which
# adds 2 method calls
locale = current[:default_locale]
- if locale && !locale.blank?
+ if locale && locale.present?
locale
else
SiteSettings::DefaultsProvider::DEFAULT_LOCALE
diff --git a/lib/tasks/docker.rake b/lib/tasks/docker.rake
index 215bfb52f1c..2d7835eb87f 100644
--- a/lib/tasks/docker.rake
+++ b/lib/tasks/docker.rake
@@ -51,7 +51,7 @@ def setup_test_env(
success &&= run_or_fail("bundle exec rake plugin:install_all_official") if install_all_official
success &&= run_or_fail("bundle exec rake plugin:update_all") if update_all_plugins
- if !plugins_to_remove.blank?
+ if plugins_to_remove.present?
plugins_to_remove
.split(",")
.map(&:strip)
diff --git a/lib/tasks/rspec.rake b/lib/tasks/rspec.rake
index 7e0ffa2a3b6..a088d6cfcbb 100644
--- a/lib/tasks/rspec.rake
+++ b/lib/tasks/rspec.rake
@@ -1,6 +1,6 @@
# frozen_string_literal: true
-if Rails.env.development? || Rails.env.test?
+if Rails.env.local?
require "rspec/core/rake_task"
RSpec::Core::RakeTask.new(:spec)
diff --git a/lib/tasks/uploads.rake b/lib/tasks/uploads.rake
index 04341ca6a06..dd4de562194 100644
--- a/lib/tasks/uploads.rake
+++ b/lib/tasks/uploads.rake
@@ -181,7 +181,7 @@ def clean_up_uploads
exit 1 unless backuper.success
end
- public_directory = Rails.root.join("public").to_s
+ public_directory = Rails.public_path.to_s
##
## DATABASE vs FILE SYSTEM
@@ -404,7 +404,7 @@ task "uploads:analyze", %i[cache_path limit] => :environment do |_, args|
cache_path = args[:cache_path]
current_db = RailsMultisite::ConnectionManagement.current_db
- uploads_path = Rails.root.join("public", "uploads", current_db)
+ uploads_path = Rails.public_path.join("uploads", current_db)
path =
if cache_path
@@ -1137,7 +1137,7 @@ def fix_missing_s3
tempfile =
FileHelper.download(
upload.url,
- max_file_size: 30.megabyte,
+ max_file_size: 30.megabytes,
tmp_file_name: "#{SecureRandom.hex}.#{upload.extension}",
)
downloaded_from = upload.url
@@ -1147,7 +1147,7 @@ def fix_missing_s3
tempfile =
FileHelper.download(
upload.origin,
- max_file_size: 30.megabyte,
+ max_file_size: 30.megabytes,
tmp_file_name: "#{SecureRandom.hex}.#{upload.extension}",
)
downloaded_from = upload.origin
diff --git a/lib/topic_creator.rb b/lib/topic_creator.rb
index f9c008071d2..a5bb692c3ae 100644
--- a/lib/topic_creator.rb
+++ b/lib/topic_creator.rb
@@ -82,8 +82,7 @@ class TopicCreator
def create_shared_draft(topic)
return if @opts[:shared_draft].blank? || @opts[:shared_draft] == "false"
- category_id =
- @opts[:category].blank? ? SiteSetting.shared_drafts_category.to_i : @opts[:category]
+ category_id = @opts[:category].presence || SiteSetting.shared_drafts_category.to_i
SharedDraft.create(topic_id: topic.id, category_id: category_id)
end
diff --git a/lib/topic_query.rb b/lib/topic_query.rb
index a62e6f63ad9..ccb1efbc7e1 100644
--- a/lib/topic_query.rb
+++ b/lib/topic_query.rb
@@ -244,7 +244,7 @@ class TopicQuery
if DiscoursePluginRegistry.list_suggested_for_providers.any?
DiscoursePluginRegistry.list_suggested_for_providers.each do |provider|
suggested = provider.call(topic, pm_params, self)
- builder.add_results(suggested[:result]) if suggested && !suggested[:result].blank?
+ builder.add_results(suggested[:result]) if suggested && suggested[:result].present?
end
end
diff --git a/lib/user_comm_screener.rb b/lib/user_comm_screener.rb
index c1a451bf27a..fee8c29ff62 100644
--- a/lib/user_comm_screener.rb
+++ b/lib/user_comm_screener.rb
@@ -103,7 +103,7 @@ class UserCommScreener
def initialize(acting_user: nil, acting_user_id: nil, target_user_ids:)
raise ArgumentError if acting_user.blank? && acting_user_id.blank?
- @acting_user = acting_user.present? ? acting_user : User.find(acting_user_id)
+ @acting_user = acting_user.presence || User.find(acting_user_id)
target_user_ids = Array.wrap(target_user_ids) - [@acting_user.id]
@target_users = User.where(id: target_user_ids).pluck(:id, :username).to_h
@preferences = load_preference_map
diff --git a/migrations/lib/database/schema/loader.rb b/migrations/lib/database/schema/loader.rb
index 3d1fc22cbcc..54872c23726 100644
--- a/migrations/lib/database/schema/loader.rb
+++ b/migrations/lib/database/schema/loader.rb
@@ -17,7 +17,7 @@ module Migrations::Database::Schema
def load_enums
enums = EnumResolver.new(@schema_config[:enums]).resolve
- @enums_by_name = enums.map { |enum| [enum.name, enum] }.to_h
+ @enums_by_name = enums.index_by(&:name)
enums
end
diff --git a/plugins/automation/app/jobs/regular/discourse_automation/trigger.rb b/plugins/automation/app/jobs/regular/discourse_automation/trigger.rb
index bf19e90312b..09adc6c47d1 100644
--- a/plugins/automation/app/jobs/regular/discourse_automation/trigger.rb
+++ b/plugins/automation/app/jobs/regular/discourse_automation/trigger.rb
@@ -3,7 +3,7 @@
module Jobs
module DiscourseAutomation
class Trigger < ::Jobs::Base
- RETRY_TIMES = [5.minute, 15.minute, 120.minute]
+ RETRY_TIMES = [5.minutes, 15.minutes, 120.minutes]
sidekiq_options retry: RETRY_TIMES.size
diff --git a/plugins/automation/spec/requests/admin_discourse_automation_automations_spec.rb b/plugins/automation/spec/requests/admin_discourse_automation_automations_spec.rb
index ef66d2da095..4aad3e88785 100644
--- a/plugins/automation/spec/requests/admin_discourse_automation_automations_spec.rb
+++ b/plugins/automation/spec/requests/admin_discourse_automation_automations_spec.rb
@@ -257,7 +257,7 @@ describe DiscourseAutomation::AdminAutomationsController do
automation.upsert_field!(
"execute_at",
"date_time",
- { value: 1.hours.from_now },
+ { value: 1.hour.from_now },
target: "trigger",
)
end
@@ -265,7 +265,7 @@ describe DiscourseAutomation::AdminAutomationsController do
it "updates the associated pending automation execute_at" do
expect(automation.pending_automations.count).to eq(1)
expect(automation.pending_automations.last.execute_at).to be_within_one_minute_of(
- 1.hours.from_now,
+ 1.hour.from_now,
)
expect {
diff --git a/plugins/automation/spec/triggers/recurring_spec.rb b/plugins/automation/spec/triggers/recurring_spec.rb
index 27126fd50d2..ff603163cee 100644
--- a/plugins/automation/spec/triggers/recurring_spec.rb
+++ b/plugins/automation/spec/triggers/recurring_spec.rb
@@ -243,7 +243,7 @@ describe "Recurring" do
expect(automation.pending_automations.count).to eq(1)
expect(automation.pending_automations.last.execute_at).to be_within_one_second_of(
- Time.zone.now + 2.days,
+ 2.days.from_now,
)
end
end
@@ -287,7 +287,7 @@ describe "Recurring" do
expect(automation.pending_automations.count).to eq(1)
expect(automation.pending_automations.last.execute_at).to be_within_one_second_of(
- Time.zone.now + 2.hour,
+ 2.hours.from_now,
)
end
end
@@ -390,7 +390,7 @@ describe "Recurring" do
pending_automation = automation.pending_automations.last
start_date = Time.parse(automation.trigger_field("start_date")["value"])
- expect(pending_automation.execute_at).to be_within_one_minute_of(start_date + 3.day)
+ expect(pending_automation.execute_at).to be_within_one_minute_of(start_date + 3.days)
end
it "creates the next iteration three days after without Saturday/Sunday" do
@@ -422,7 +422,7 @@ describe "Recurring" do
pending_automation = automation.pending_automations.last
expect(pending_automation.execute_at).to be_within_one_minute_of(
- (Time.zone.now + 1.hour).beginning_of_hour,
+ 1.hour.from_now.beginning_of_hour,
)
end
end
@@ -435,7 +435,7 @@ describe "Recurring" do
pending_automation = automation.pending_automations.last
expect(pending_automation.execute_at).to be_within_one_minute_of(
- (Time.zone.now + 1.minute).beginning_of_minute,
+ 1.minute.from_now.beginning_of_minute,
)
end
end
diff --git a/plugins/chat/app/controllers/chat/api/channel_messages_controller.rb b/plugins/chat/app/controllers/chat/api/channel_messages_controller.rb
index da3b450c834..1ff8586b39c 100644
--- a/plugins/chat/app/controllers/chat/api/channel_messages_controller.rb
+++ b/plugins/chat/app/controllers/chat/api/channel_messages_controller.rb
@@ -11,12 +11,12 @@ class Chat::Api::ChannelMessagesController < Chat::ApiController
**service_params,
) do |result|
on_success { render_serialized(result, ::Chat::MessagesSerializer, root: false) }
- on_failure { render(json: failed_json, status: 422) }
+ on_failure { render(json: failed_json, status: :unprocessable_entity) }
on_failed_policy(:can_view_channel) { raise Discourse::InvalidAccess }
on_failed_policy(:target_message_exists) { raise Discourse::NotFound }
on_model_not_found(:channel) { raise Discourse::NotFound }
on_failed_contract do |contract|
- render(json: failed_json.merge(errors: contract.errors.full_messages), status: 400)
+ render(json: failed_json.merge(errors: contract.errors.full_messages), status: :bad_request)
end
end
end
@@ -24,11 +24,11 @@ class Chat::Api::ChannelMessagesController < Chat::ApiController
def destroy
Chat::TrashMessage.call(service_params) do
on_success { render(json: success_json) }
- on_failure { render(json: failed_json, status: 422) }
+ on_failure { render(json: failed_json, status: :unprocessable_entity) }
on_model_not_found(:message) { raise Discourse::NotFound }
on_failed_policy(:invalid_access) { raise Discourse::InvalidAccess }
on_failed_contract do |contract|
- render(json: failed_json.merge(errors: contract.errors.full_messages), status: 400)
+ render(json: failed_json.merge(errors: contract.errors.full_messages), status: :bad_request)
end
end
end
@@ -36,11 +36,11 @@ class Chat::Api::ChannelMessagesController < Chat::ApiController
def bulk_destroy
Chat::TrashMessages.call(service_params) do
on_success { render(json: success_json) }
- on_failure { render(json: failed_json, status: 422) }
+ on_failure { render(json: failed_json, status: :unprocessable_entity) }
on_model_not_found(:messages) { raise Discourse::NotFound }
on_failed_policy(:invalid_access) { raise Discourse::InvalidAccess }
on_failed_contract do |contract|
- render(json: failed_json.merge(errors: contract.errors.full_messages), status: 400)
+ render(json: failed_json.merge(errors: contract.errors.full_messages), status: :bad_request)
end
end
end
@@ -48,11 +48,11 @@ class Chat::Api::ChannelMessagesController < Chat::ApiController
def restore
Chat::RestoreMessage.call(service_params) do
on_success { render(json: success_json) }
- on_failure { render(json: failed_json, status: 422) }
+ on_failure { render(json: failed_json, status: :unprocessable_entity) }
on_failed_policy(:invalid_access) { raise Discourse::InvalidAccess }
on_model_not_found(:message) { raise Discourse::NotFound }
on_failed_contract do |contract|
- render(json: failed_json.merge(errors: contract.errors.full_messages), status: 400)
+ render(json: failed_json.merge(errors: contract.errors.full_messages), status: :bad_request)
end
end
end
@@ -60,13 +60,13 @@ class Chat::Api::ChannelMessagesController < Chat::ApiController
def update
Chat::UpdateMessage.call(service_params) do
on_success { |message:| render json: success_json.merge(message_id: message.id) }
- on_failure { render(json: failed_json, status: 422) }
+ on_failure { render(json: failed_json, status: :unprocessable_entity) }
on_model_not_found(:message) { raise Discourse::NotFound }
on_model_errors(:message) do |model|
render_json_error(model.errors.map(&:full_message).join(", "))
end
on_failed_contract do |contract|
- render(json: failed_json.merge(errors: contract.errors.full_messages), status: 400)
+ render(json: failed_json.merge(errors: contract.errors.full_messages), status: :bad_request)
end
end
end
@@ -78,7 +78,7 @@ class Chat::Api::ChannelMessagesController < Chat::ApiController
on_success do |message_instance:|
render json: success_json.merge(message_id: message_instance.id)
end
- on_failure { render(json: failed_json, status: 422) }
+ on_failure { render(json: failed_json, status: :unprocessable_entity) }
on_failed_policy(:no_silenced_user) { raise Discourse::InvalidAccess }
on_model_not_found(:channel) { raise Discourse::NotFound }
on_failed_policy(:allowed_to_join_channel) { raise Discourse::InvalidAccess }
@@ -98,7 +98,7 @@ class Chat::Api::ChannelMessagesController < Chat::ApiController
render_json_error(model.errors.map(&:full_message).join(", "))
end
on_failed_contract do |contract|
- render(json: failed_json.merge(errors: contract.errors.full_messages), status: 400)
+ render(json: failed_json.merge(errors: contract.errors.full_messages), status: :bad_request)
end
end
end
diff --git a/plugins/chat/app/controllers/chat/api/channel_thread_messages_controller.rb b/plugins/chat/app/controllers/chat/api/channel_thread_messages_controller.rb
index 74e0dba5415..8c1cd17b179 100644
--- a/plugins/chat/app/controllers/chat/api/channel_thread_messages_controller.rb
+++ b/plugins/chat/app/controllers/chat/api/channel_thread_messages_controller.rb
@@ -19,12 +19,12 @@ class Chat::Api::ChannelThreadMessagesController < Chat::ApiController
include_thread_original_message: false,
)
end
- on_failure { render(json: failed_json, status: 422) }
+ on_failure { render(json: failed_json, status: :unprocessable_entity) }
on_failed_policy(:target_message_exists) { raise Discourse::NotFound }
on_failed_policy(:can_view_thread) { raise Discourse::InvalidAccess }
on_model_not_found(:thread) { raise Discourse::NotFound }
on_failed_contract do |contract|
- render(json: failed_json.merge(errors: contract.errors.full_messages), status: 400)
+ render(json: failed_json.merge(errors: contract.errors.full_messages), status: :bad_request)
end
end
end
diff --git a/plugins/chat/app/controllers/chat/api/channel_threads_controller.rb b/plugins/chat/app/controllers/chat/api/channel_threads_controller.rb
index 9e313851f57..a90fec4c545 100644
--- a/plugins/chat/app/controllers/chat/api/channel_threads_controller.rb
+++ b/plugins/chat/app/controllers/chat/api/channel_threads_controller.rb
@@ -22,9 +22,9 @@ class Chat::Api::ChannelThreadsController < Chat::ApiController
on_failed_policy(:can_view_channel) { raise Discourse::InvalidAccess }
on_model_not_found(:channel) { raise Discourse::NotFound }
on_model_not_found(:threads) { render json: success_json.merge(threads: []) }
- on_failure { render(json: failed_json, status: 422) }
+ on_failure { render(json: failed_json, status: :unprocessable_entity) }
on_failed_contract do |contract|
- render(json: failed_json.merge(errors: contract.errors.full_messages), status: 400)
+ render(json: failed_json.merge(errors: contract.errors.full_messages), status: :bad_request)
end
end
end
@@ -45,9 +45,9 @@ class Chat::Api::ChannelThreadsController < Chat::ApiController
on_failed_policy(:invalid_access) { raise Discourse::InvalidAccess }
on_failed_policy(:threading_enabled_for_channel) { raise Discourse::NotFound }
on_model_not_found(:thread) { raise Discourse::NotFound }
- on_failure { render(json: failed_json, status: 422) }
+ on_failure { render(json: failed_json, status: :unprocessable_entity) }
on_failed_contract do |contract|
- render(json: failed_json.merge(errors: contract.errors.full_messages), status: 400)
+ render(json: failed_json.merge(errors: contract.errors.full_messages), status: :bad_request)
end
end
end
@@ -59,12 +59,12 @@ class Chat::Api::ChannelThreadsController < Chat::ApiController
on_failed_policy(:can_edit_thread) { raise Discourse::InvalidAccess }
on_model_not_found(:thread) { raise Discourse::NotFound }
on_failed_step(:update) do |step|
- render json: failed_json.merge(errors: [step.error]), status: 422
+ render json: failed_json.merge(errors: [step.error]), status: :unprocessable_entity
end
on_success { render(json: success_json) }
- on_failure { render(json: failed_json, status: 422) }
+ on_failure { render(json: failed_json, status: :unprocessable_entity) }
on_failed_contract do |contract|
- render(json: failed_json.merge(errors: contract.errors.full_messages), status: 400)
+ render(json: failed_json.merge(errors: contract.errors.full_messages), status: :bad_request)
end
end
end
@@ -80,15 +80,16 @@ class Chat::Api::ChannelThreadsController < Chat::ApiController
)
end
on_failed_contract do |contract|
- render(json: failed_json.merge(errors: contract.errors.full_messages), status: 400)
+ render(json: failed_json.merge(errors: contract.errors.full_messages), status: :bad_request)
end
on_model_not_found(:channel) { raise Discourse::NotFound }
on_failed_policy(:can_view_channel) { raise Discourse::InvalidAccess }
on_failed_policy(:threading_enabled_for_channel) { raise Discourse::NotFound }
on_model_errors(:thread) do |model|
- render json: failed_json.merge(errors: [model.errors.full_messages.join(", ")]), status: 422
+ render json: failed_json.merge(errors: [model.errors.full_messages.join(", ")]),
+ status: :unprocessable_entity
end
- on_failure { render(json: failed_json, status: 422) }
+ on_failure { render(json: failed_json, status: :unprocessable_entity) }
end
end
end
diff --git a/plugins/chat/app/controllers/chat/api/channel_threads_current_user_notifications_settings_controller.rb b/plugins/chat/app/controllers/chat/api/channel_threads_current_user_notifications_settings_controller.rb
index abce511e4e4..5776d80da5a 100644
--- a/plugins/chat/app/controllers/chat/api/channel_threads_current_user_notifications_settings_controller.rb
+++ b/plugins/chat/app/controllers/chat/api/channel_threads_current_user_notifications_settings_controller.rb
@@ -6,12 +6,12 @@ class Chat::Api::ChannelThreadsCurrentUserNotificationsSettingsController < Chat
on_success do |membership:|
render_serialized(membership, Chat::BaseThreadMembershipSerializer, root: "membership")
end
- on_failure { render(json: failed_json, status: 422) }
+ on_failure { render(json: failed_json, status: :unprocessable_entity) }
on_failed_policy(:threading_enabled_for_channel) { raise Discourse::NotFound }
on_failed_policy(:can_view_channel) { raise Discourse::InvalidAccess }
on_model_not_found(:thread) { raise Discourse::NotFound }
on_failed_contract do |contract|
- render(json: failed_json.merge(errors: contract.errors.full_messages), status: 400)
+ render(json: failed_json.merge(errors: contract.errors.full_messages), status: :bad_request)
end
end
end
diff --git a/plugins/chat/app/controllers/chat/api/channel_threads_current_user_title_prompt_seen_controller.rb b/plugins/chat/app/controllers/chat/api/channel_threads_current_user_title_prompt_seen_controller.rb
index 6a740e9a5b5..4e068a5428a 100644
--- a/plugins/chat/app/controllers/chat/api/channel_threads_current_user_title_prompt_seen_controller.rb
+++ b/plugins/chat/app/controllers/chat/api/channel_threads_current_user_title_prompt_seen_controller.rb
@@ -6,12 +6,12 @@ class Chat::Api::ChannelThreadsCurrentUserTitlePromptSeenController < Chat::ApiC
on_success do |membership:|
render_serialized(membership, Chat::BaseThreadMembershipSerializer, root: "membership")
end
- on_failure { render(json: failed_json, status: 422) }
+ on_failure { render(json: failed_json, status: :unprocessable_entity) }
on_failed_policy(:threading_enabled_for_channel) { raise Discourse::NotFound }
on_failed_policy(:can_view_channel) { raise Discourse::InvalidAccess }
on_model_not_found(:thread) { raise Discourse::NotFound }
on_failed_contract do |contract|
- render(json: failed_json.merge(errors: contract.errors.full_messages), status: 400)
+ render(json: failed_json.merge(errors: contract.errors.full_messages), status: :bad_request)
end
end
end
diff --git a/plugins/chat/app/controllers/chat/api/channels_archives_controller.rb b/plugins/chat/app/controllers/chat/api/channels_archives_controller.rb
index 51ac0be0fdb..aaebe7536f5 100644
--- a/plugins/chat/app/controllers/chat/api/channels_archives_controller.rb
+++ b/plugins/chat/app/controllers/chat/api/channels_archives_controller.rb
@@ -26,7 +26,7 @@ class Chat::Api::ChannelsArchivesController < Chat::Api::ChannelsController
topic_params: topic_params,
)
rescue Chat::ChannelArchiveService::ArchiveValidationError => err
- return render json: failed_json.merge(errors: err.errors), status: 400
+ return render json: failed_json.merge(errors: err.errors), status: :bad_request
end
render json: success_json
diff --git a/plugins/chat/app/controllers/chat/api/channels_controller.rb b/plugins/chat/app/controllers/chat/api/channels_controller.rb
index df88bb3b51b..0c47fa72d87 100644
--- a/plugins/chat/app/controllers/chat/api/channels_controller.rb
+++ b/plugins/chat/app/controllers/chat/api/channels_controller.rb
@@ -33,9 +33,9 @@ class Chat::Api::ChannelsController < Chat::ApiController
on_failed_policy(:invalid_access) { raise Discourse::InvalidAccess }
on_model_not_found(:channel) { raise ActiveRecord::RecordNotFound }
on_success { render(json: success_json) }
- on_failure { render(json: failed_json, status: 422) }
+ on_failure { render(json: failed_json, status: :unprocessable_entity) }
on_failed_contract do |contract|
- render(json: failed_json.merge(errors: contract.errors.full_messages), status: 400)
+ render(json: failed_json.merge(errors: contract.errors.full_messages), status: :bad_request)
end
end
end
@@ -71,9 +71,9 @@ class Chat::Api::ChannelsController < Chat::ApiController
on_model_errors(:membership) do |model|
render_json_error(model, type: :record_invalid, status: 422)
end
- on_failure { render(json: failed_json, status: 422) }
+ on_failure { render(json: failed_json, status: :unprocessable_entity) }
on_failed_contract do |contract|
- render(json: failed_json.merge(errors: contract.errors.full_messages), status: 400)
+ render(json: failed_json.merge(errors: contract.errors.full_messages), status: :bad_request)
end
end
end
diff --git a/plugins/chat/app/controllers/chat/api/channels_current_user_membership_controller.rb b/plugins/chat/app/controllers/chat/api/channels_current_user_membership_controller.rb
index b7bf7e51249..5f80112a537 100644
--- a/plugins/chat/app/controllers/chat/api/channels_current_user_membership_controller.rb
+++ b/plugins/chat/app/controllers/chat/api/channels_current_user_membership_controller.rb
@@ -14,10 +14,10 @@ class Chat::Api::ChannelsCurrentUserMembershipController < Chat::Api::ChannelsCo
def destroy
Chat::LeaveChannel.call(service_params) do
on_success { render(json: success_json) }
- on_failure { render(json: failed_json, status: 422) }
+ on_failure { render(json: failed_json, status: :unprocessable_entity) }
on_model_not_found(:channel) { raise Discourse::NotFound }
on_failed_contract do |contract|
- render(json: failed_json.merge(errors: contract.errors.full_messages), status: 400)
+ render(json: failed_json.merge(errors: contract.errors.full_messages), status: :bad_request)
end
end
end
diff --git a/plugins/chat/app/controllers/chat/api/channels_current_user_membership_follows_controller.rb b/plugins/chat/app/controllers/chat/api/channels_current_user_membership_follows_controller.rb
index bc17163fd73..2eb273dac51 100644
--- a/plugins/chat/app/controllers/chat/api/channels_current_user_membership_follows_controller.rb
+++ b/plugins/chat/app/controllers/chat/api/channels_current_user_membership_follows_controller.rb
@@ -7,10 +7,10 @@ class Chat::Api::ChannelsCurrentUserMembershipFollowsController < Chat::Api::Cha
render_serialized(membership, Chat::UserChannelMembershipSerializer, root: "membership")
end
on_failed_contract do |contract|
- render(json: failed_json.merge(errors: contract.errors.full_messages), status: 400)
+ render(json: failed_json.merge(errors: contract.errors.full_messages), status: :bad_request)
end
on_model_not_found(:channel) { raise Discourse::NotFound }
- on_failure { render(json: failed_json, status: 422) }
+ on_failure { render(json: failed_json, status: :unprocessable_entity) }
end
end
end
diff --git a/plugins/chat/app/controllers/chat/api/channels_drafts_controller.rb b/plugins/chat/app/controllers/chat/api/channels_drafts_controller.rb
index b221aa74744..ae62470d086 100644
--- a/plugins/chat/app/controllers/chat/api/channels_drafts_controller.rb
+++ b/plugins/chat/app/controllers/chat/api/channels_drafts_controller.rb
@@ -4,10 +4,10 @@ class Chat::Api::ChannelsDraftsController < Chat::ApiController
def create
Chat::UpsertDraft.call(service_params) do
on_success { render(json: success_json) }
- on_failure { render(json: failed_json, status: 422) }
+ on_failure { render(json: failed_json, status: :unprocessable_entity) }
on_model_not_found(:channel) { raise Discourse::NotFound }
on_failed_contract do |contract|
- render(json: failed_json.merge(errors: contract.errors.full_messages), status: 400)
+ render(json: failed_json.merge(errors: contract.errors.full_messages), status: :bad_request)
end
end
end
diff --git a/plugins/chat/app/controllers/chat/api/channels_invites_controller.rb b/plugins/chat/app/controllers/chat/api/channels_invites_controller.rb
index ca992049184..9c295d1727b 100644
--- a/plugins/chat/app/controllers/chat/api/channels_invites_controller.rb
+++ b/plugins/chat/app/controllers/chat/api/channels_invites_controller.rb
@@ -4,11 +4,11 @@ class Chat::Api::ChannelsInvitesController < Chat::ApiController
def create
Chat::InviteUsersToChannel.call(service_params) do
on_success { render(json: success_json) }
- on_failure { render(json: failed_json, status: 422) }
+ on_failure { render(json: failed_json, status: :unprocessable_entity) }
on_failed_policy(:can_view_channel) { raise Discourse::InvalidAccess }
on_model_not_found(:channel) { raise Discourse::NotFound }
on_failed_contract do |contract|
- render(json: failed_json.merge(errors: contract.errors.full_messages), status: 400)
+ render(json: failed_json.merge(errors: contract.errors.full_messages), status: :bad_request)
end
end
end
diff --git a/plugins/chat/app/controllers/chat/api/channels_memberships_controller.rb b/plugins/chat/app/controllers/chat/api/channels_memberships_controller.rb
index e33a0cc42b4..fa9d90c5285 100644
--- a/plugins/chat/app/controllers/chat/api/channels_memberships_controller.rb
+++ b/plugins/chat/app/controllers/chat/api/channels_memberships_controller.rb
@@ -32,7 +32,7 @@ class Chat::Api::ChannelsMembershipsController < Chat::Api::ChannelsController
def create
Chat::AddUsersToChannel.call(service_params) do
on_success { render(json: success_json) }
- on_failure { render(json: failed_json, status: 422) }
+ on_failure { render(json: failed_json, status: :unprocessable_entity) }
on_failed_policy(:can_add_users_to_channel) do
render_json_error(I18n.t("chat.errors.users_cant_be_added_to_channel"))
end
@@ -40,7 +40,7 @@ class Chat::Api::ChannelsMembershipsController < Chat::Api::ChannelsController
render_json_dump({ error: policy.reason }, status: 400)
end
on_failed_contract do |contract|
- render(json: failed_json.merge(errors: contract.errors.full_messages), status: 400)
+ render(json: failed_json.merge(errors: contract.errors.full_messages), status: :bad_request)
end
end
end
@@ -48,14 +48,14 @@ class Chat::Api::ChannelsMembershipsController < Chat::Api::ChannelsController
def destroy
Chat::RemoveUserFromChannel.call(service_params) do
on_success { render(json: success_json) }
- on_failure { render(json: failed_json, status: 422) }
+ on_failure { render(json: failed_json, status: :unprocessable_entity) }
on_model_not_found(:channel) { raise Discourse::NotFound }
on_model_not_found(:target_user) { raise Discourse::NotFound }
on_failed_policy(:can_remove_users_from_channel) do
render_json_error(I18n.t("chat.errors.user_cant_be_removed_from_channel"), status: 403)
end
on_failed_contract do |contract|
- render(json: failed_json.merge(errors: contract.errors.full_messages), status: 400)
+ render(json: failed_json.merge(errors: contract.errors.full_messages), status: :bad_request)
end
end
end
diff --git a/plugins/chat/app/controllers/chat/api/channels_messages_flags_controller.rb b/plugins/chat/app/controllers/chat/api/channels_messages_flags_controller.rb
index a3fd12eba5e..5b6b2280224 100644
--- a/plugins/chat/app/controllers/chat/api/channels_messages_flags_controller.rb
+++ b/plugins/chat/app/controllers/chat/api/channels_messages_flags_controller.rb
@@ -2,15 +2,15 @@
class Chat::Api::ChannelsMessagesFlagsController < Chat::ApiController
def create
- RateLimiter.new(current_user, "flag_chat_message", 4, 1.minutes).performed!
+ RateLimiter.new(current_user, "flag_chat_message", 4, 1.minute).performed!
Chat::FlagMessage.call(service_params) do
on_success { render(json: success_json) }
- on_failure { render(json: failed_json, status: 422) }
+ on_failure { render(json: failed_json, status: :unprocessable_entity) }
on_model_not_found(:message) { raise Discourse::NotFound }
on_failed_policy(:can_flag_message_in_channel) { raise Discourse::InvalidAccess }
on_failed_contract do |contract|
- render(json: failed_json.merge(errors: contract.errors.full_messages), status: 400)
+ render(json: failed_json.merge(errors: contract.errors.full_messages), status: :bad_request)
end
end
end
diff --git a/plugins/chat/app/controllers/chat/api/channels_messages_interactions_controller.rb b/plugins/chat/app/controllers/chat/api/channels_messages_interactions_controller.rb
index af802b8d49d..db6123c1c98 100644
--- a/plugins/chat/app/controllers/chat/api/channels_messages_interactions_controller.rb
+++ b/plugins/chat/app/controllers/chat/api/channels_messages_interactions_controller.rb
@@ -6,11 +6,11 @@ class Chat::Api::ChannelsMessagesInteractionsController < Chat::ApiController
on_success do |interaction:|
render_serialized(interaction, Chat::MessageInteractionSerializer, root: "interaction")
end
- on_failure { render(json: failed_json, status: 422) }
+ on_failure { render(json: failed_json, status: :unprocessable_entity) }
on_model_not_found(:message) { raise Discourse::NotFound }
on_model_not_found(:action) { raise Discourse::NotFound }
on_failed_contract do |contract|
- render(json: failed_json.merge(errors: contract.errors.full_messages), status: 400)
+ render(json: failed_json.merge(errors: contract.errors.full_messages), status: :bad_request)
end
end
end
diff --git a/plugins/chat/app/controllers/chat/api/channels_messages_streaming_controller.rb b/plugins/chat/app/controllers/chat/api/channels_messages_streaming_controller.rb
index 5094f9dd39d..9f591fb85fa 100644
--- a/plugins/chat/app/controllers/chat/api/channels_messages_streaming_controller.rb
+++ b/plugins/chat/app/controllers/chat/api/channels_messages_streaming_controller.rb
@@ -4,12 +4,12 @@ class Chat::Api::ChannelsMessagesStreamingController < Chat::Api::ChannelsContro
def destroy
Chat::StopMessageStreaming.call(service_params) do
on_success { render(json: success_json) }
- on_failure { render(json: failed_json, status: 422) }
+ on_failure { render(json: failed_json, status: :unprocessable_entity) }
on_model_not_found(:message) { raise Discourse::NotFound }
on_model_not_found(:membership) { raise Discourse::NotFound }
on_failed_policy(:can_stop_streaming) { raise Discourse::InvalidAccess }
on_failed_contract do |contract|
- render(json: failed_json.merge(errors: contract.errors.full_messages), status: 400)
+ render(json: failed_json.merge(errors: contract.errors.full_messages), status: :bad_request)
end
end
end
diff --git a/plugins/chat/app/controllers/chat/api/channels_read_controller.rb b/plugins/chat/app/controllers/chat/api/channels_read_controller.rb
index a02a21a77dc..8af7b040290 100644
--- a/plugins/chat/app/controllers/chat/api/channels_read_controller.rb
+++ b/plugins/chat/app/controllers/chat/api/channels_read_controller.rb
@@ -4,7 +4,7 @@ class Chat::Api::ChannelsReadController < Chat::ApiController
def update
Chat::UpdateUserChannelLastRead.call(service_params) do
on_success { render(json: success_json) }
- on_failure { render(json: failed_json, status: 422) }
+ on_failure { render(json: failed_json, status: :unprocessable_entity) }
on_failed_policy(:ensure_message_id_recency) do
raise Discourse::InvalidParameters.new(:message_id)
end
@@ -13,7 +13,7 @@ class Chat::Api::ChannelsReadController < Chat::ApiController
on_model_not_found(:channel) { raise Discourse::NotFound }
on_failed_policy(:invalid_access) { raise Discourse::InvalidAccess }
on_failed_contract do |contract|
- render(json: failed_json.merge(errors: contract.errors.full_messages), status: 400)
+ render(json: failed_json.merge(errors: contract.errors.full_messages), status: :bad_request)
end
end
end
@@ -21,7 +21,7 @@ class Chat::Api::ChannelsReadController < Chat::ApiController
def update_all
Chat::MarkAllUserChannelsRead.call(service_params) do
on_success { |updated_memberships:| render(json: success_json.merge(updated_memberships:)) }
- on_failure { render(json: failed_json, status: 422) }
+ on_failure { render(json: failed_json, status: :unprocessable_entity) }
end
end
end
diff --git a/plugins/chat/app/controllers/chat/api/channels_status_controller.rb b/plugins/chat/app/controllers/chat/api/channels_status_controller.rb
index cd97271c6d0..ec4c8cc0240 100644
--- a/plugins/chat/app/controllers/chat/api/channels_status_controller.rb
+++ b/plugins/chat/app/controllers/chat/api/channels_status_controller.rb
@@ -6,9 +6,9 @@ class Chat::Api::ChannelsStatusController < Chat::Api::ChannelsController
on_success { |channel:| render_serialized(channel, Chat::ChannelSerializer, root: "channel") }
on_model_not_found(:channel) { raise ActiveRecord::RecordNotFound }
on_failed_policy(:check_channel_permission) { raise Discourse::InvalidAccess }
- on_failure { render(json: failed_json, status: 422) }
+ on_failure { render(json: failed_json, status: :unprocessable_entity) }
on_failed_contract do |contract|
- render(json: failed_json.merge(errors: contract.errors.full_messages), status: 400)
+ render(json: failed_json.merge(errors: contract.errors.full_messages), status: :bad_request)
end
end
end
diff --git a/plugins/chat/app/controllers/chat/api/channels_threads_drafts_controller.rb b/plugins/chat/app/controllers/chat/api/channels_threads_drafts_controller.rb
index 292fbbbfd22..b017e1cbe35 100644
--- a/plugins/chat/app/controllers/chat/api/channels_threads_drafts_controller.rb
+++ b/plugins/chat/app/controllers/chat/api/channels_threads_drafts_controller.rb
@@ -4,11 +4,11 @@ class Chat::Api::ChannelsThreadsDraftsController < Chat::ApiController
def create
Chat::UpsertDraft.call(service_params) do
on_success { render(json: success_json) }
- on_failure { render(json: failed_json, status: 422) }
+ on_failure { render(json: failed_json, status: :unprocessable_entity) }
on_model_not_found(:channel) { raise Discourse::NotFound }
on_failed_step(:check_thread_exists) { raise Discourse::NotFound }
on_failed_contract do |contract|
- render(json: failed_json.merge(errors: contract.errors.full_messages), status: 400)
+ render(json: failed_json.merge(errors: contract.errors.full_messages), status: :bad_request)
end
end
end
diff --git a/plugins/chat/app/controllers/chat/api/channels_threads_read_controller.rb b/plugins/chat/app/controllers/chat/api/channels_threads_read_controller.rb
index cc147436003..eab649228a1 100644
--- a/plugins/chat/app/controllers/chat/api/channels_threads_read_controller.rb
+++ b/plugins/chat/app/controllers/chat/api/channels_threads_read_controller.rb
@@ -4,12 +4,12 @@ class Chat::Api::ChannelsThreadsReadController < Chat::ApiController
def update
Chat::UpdateUserThreadLastRead.call(service_params) do
on_success { render(json: success_json) }
- on_failure { render(json: failed_json, status: 422) }
+ on_failure { render(json: failed_json, status: :unprocessable_entity) }
on_model_not_found(:thread) { raise Discourse::NotFound }
on_model_not_found(:message) { raise Discourse::NotFound }
on_failed_policy(:invalid_access) { raise Discourse::InvalidAccess }
on_failed_contract do |contract|
- render(json: failed_json.merge(errors: contract.errors.full_messages), status: 400)
+ render(json: failed_json.merge(errors: contract.errors.full_messages), status: :bad_request)
end
end
end
diff --git a/plugins/chat/app/controllers/chat/api/chatables_controller.rb b/plugins/chat/app/controllers/chat/api/chatables_controller.rb
index 166f6b660b9..17f133cfa4c 100644
--- a/plugins/chat/app/controllers/chat/api/chatables_controller.rb
+++ b/plugins/chat/app/controllers/chat/api/chatables_controller.rb
@@ -6,9 +6,9 @@ class Chat::Api::ChatablesController < Chat::ApiController
def index
::Chat::SearchChatable.call(service_params) do |result|
on_success { render_serialized(result, ::Chat::ChatablesSerializer, root: false) }
- on_failure { render(json: failed_json, status: 422) }
+ on_failure { render(json: failed_json, status: :unprocessable_entity) }
on_failed_contract do |contract|
- render(json: failed_json.merge(errors: contract.errors.full_messages), status: 400)
+ render(json: failed_json.merge(errors: contract.errors.full_messages), status: :bad_request)
end
end
end
diff --git a/plugins/chat/app/controllers/chat/api/current_user_channels_controller.rb b/plugins/chat/app/controllers/chat/api/current_user_channels_controller.rb
index d87955a5c24..a1e0853bfa0 100644
--- a/plugins/chat/app/controllers/chat/api/current_user_channels_controller.rb
+++ b/plugins/chat/app/controllers/chat/api/current_user_channels_controller.rb
@@ -11,7 +11,7 @@ class Chat::Api::CurrentUserChannelsController < Chat::ApiController
post_allowed_category_ids: post_allowed_category_ids,
)
end
- on_failure { render(json: failed_json, status: 422) }
+ on_failure { render(json: failed_json, status: :unprocessable_entity) }
end
end
end
diff --git a/plugins/chat/app/controllers/chat/api/current_user_threads_controller.rb b/plugins/chat/app/controllers/chat/api/current_user_threads_controller.rb
index 5fdaf983455..d7bcde2493d 100644
--- a/plugins/chat/app/controllers/chat/api/current_user_threads_controller.rb
+++ b/plugins/chat/app/controllers/chat/api/current_user_threads_controller.rb
@@ -19,10 +19,10 @@ class Chat::Api::CurrentUserThreadsController < Chat::ApiController
)
end
on_failed_contract do |contract|
- render(json: failed_json.merge(errors: contract.errors.full_messages), status: 400)
+ render(json: failed_json.merge(errors: contract.errors.full_messages), status: :bad_request)
end
on_model_not_found(:threads) { render json: success_json.merge(threads: []) }
- on_failure { render(json: failed_json, status: 422) }
+ on_failure { render(json: failed_json, status: :unprocessable_entity) }
end
end
end
diff --git a/plugins/chat/app/controllers/chat/api/direct_messages_controller.rb b/plugins/chat/app/controllers/chat/api/direct_messages_controller.rb
index 66b756f1be8..dfd4f412ab3 100644
--- a/plugins/chat/app/controllers/chat/api/direct_messages_controller.rb
+++ b/plugins/chat/app/controllers/chat/api/direct_messages_controller.rb
@@ -21,9 +21,9 @@ class Chat::Api::DirectMessagesController < Chat::ApiController
on_model_errors(:channel) do |model|
render_json_error(model, type: :record_invalid, status: 422)
end
- on_failure { render(json: failed_json, status: 422) }
+ on_failure { render(json: failed_json, status: :unprocessable_entity) }
on_failed_contract do |contract|
- render(json: failed_json.merge(errors: contract.errors.full_messages), status: 400)
+ render(json: failed_json.merge(errors: contract.errors.full_messages), status: :bad_request)
end
end
end
diff --git a/plugins/chat/app/controllers/chat/direct_messages_controller.rb b/plugins/chat/app/controllers/chat/direct_messages_controller.rb
index f20c647cfc5..2ab75d8b95b 100644
--- a/plugins/chat/app/controllers/chat/direct_messages_controller.rb
+++ b/plugins/chat/app/controllers/chat/direct_messages_controller.rb
@@ -16,7 +16,7 @@ module Chat
membership: chat_channel.membership_for(current_user),
)
else
- render body: nil, status: 404
+ render body: nil, status: :not_found
end
end
diff --git a/plugins/chat/app/controllers/chat/incoming_webhooks_controller.rb b/plugins/chat/app/controllers/chat/incoming_webhooks_controller.rb
index 105525ad6af..0f807e1a346 100644
--- a/plugins/chat/app/controllers/chat/incoming_webhooks_controller.rb
+++ b/plugins/chat/app/controllers/chat/incoming_webhooks_controller.rb
@@ -64,7 +64,7 @@ module Chat
incoming_chat_webhook: webhook,
) do
on_success { render json: success_json }
- on_failure { render(json: failed_json, status: 422) }
+ on_failure { render(json: failed_json, status: :unprocessable_entity) }
on_failed_contract do |contract|
raise Discourse::InvalidParameters.new(contract.errors.full_messages)
end
diff --git a/plugins/chat/lib/chat/statistics.rb b/plugins/chat/lib/chat/statistics.rb
index c5a57ffa966..793fd57ed9e 100644
--- a/plugins/chat/lib/chat/statistics.rb
+++ b/plugins/chat/lib/chat/statistics.rb
@@ -4,7 +4,7 @@ module Chat
class Statistics
def self.about_messages
{
- last_day: Chat::Message.where("created_at > ?", 1.days.ago).count,
+ last_day: Chat::Message.where("created_at > ?", 1.day.ago).count,
"7_days": Chat::Message.where("created_at > ?", 7.days.ago).count,
"30_days": Chat::Message.where("created_at > ?", 30.days.ago).count,
previous_30_days:
@@ -15,7 +15,7 @@ module Chat
def self.about_channels
{
- last_day: Chat::Channel.where(status: :open).where("created_at > ?", 1.days.ago).count,
+ last_day: Chat::Channel.where(status: :open).where("created_at > ?", 1.day.ago).count,
"7_days": Chat::Channel.where(status: :open).where("created_at > ?", 7.days.ago).count,
"30_days": Chat::Channel.where(status: :open).where("created_at > ?", 30.days.ago).count,
previous_30_days:
@@ -29,7 +29,7 @@ module Chat
def self.about_users
{
- last_day: Chat::Message.where("created_at > ?", 1.days.ago).distinct.count(:user_id),
+ last_day: Chat::Message.where("created_at > ?", 1.day.ago).distinct.count(:user_id),
"7_days": Chat::Message.where("created_at > ?", 7.days.ago).distinct.count(:user_id),
"30_days": Chat::Message.where("created_at > ?", 30.days.ago).distinct.count(:user_id),
previous_30_days:
@@ -46,7 +46,7 @@ module Chat
Chat::Message.joins(:chat_channel).where.not(chat_channel: { type: "DirectMessageChannel" })
{
- last_day: query.where("chat_messages.created_at > ?", 1.days.ago).count,
+ last_day: query.where("chat_messages.created_at > ?", 1.day.ago).count,
"7_days": query.where("chat_messages.created_at > ?", 7.days.ago).count,
"28_days": query.where("chat_messages.created_at > ?", 28.days.ago).count,
"30_days": query.where("chat_messages.created_at > ?", 30.days.ago).count,
@@ -59,7 +59,7 @@ module Chat
Chat::Message.joins(:chat_channel).where(chat_channel: { type: "DirectMessageChannel" })
{
- last_day: query.where("chat_messages.created_at > ?", 1.days.ago).count,
+ last_day: query.where("chat_messages.created_at > ?", 1.day.ago).count,
"7_days": query.where("chat_messages.created_at > ?", 7.days.ago).count,
"28_days": query.where("chat_messages.created_at > ?", 28.days.ago).count,
"30_days": query.where("chat_messages.created_at > ?", 30.days.ago).count,
@@ -77,7 +77,7 @@ module Chat
query = Chat::Message.where.not(thread: nil)
{
- last_day: query.where("chat_messages.created_at > ?", 1.days.ago).count,
+ last_day: query.where("chat_messages.created_at > ?", 1.day.ago).count,
"7_days": query.where("chat_messages.created_at > ?", 7.days.ago).count,
"28_days": query.where("chat_messages.created_at > ?", 28.days.ago).count,
"30_days": query.where("chat_messages.created_at > ?", 30.days.ago).count,
diff --git a/plugins/chat/lib/chat/transcript_service.rb b/plugins/chat/lib/chat/transcript_service.rb
index faaed8552df..fddc6388ad7 100644
--- a/plugins/chat/lib/chat/transcript_service.rb
+++ b/plugins/chat/lib/chat/transcript_service.rb
@@ -142,8 +142,7 @@ module Chat
def thread_title_attr(message, thread)
range = thread_ranges[message.id] if thread_ranges.has_key?(message.id)
- thread_title =
- thread.title.present? ? thread.title : I18n.t("chat.transcript.default_thread_title")
+ thread_title = thread.title.presence || I18n.t("chat.transcript.default_thread_title")
thread_title += " (#{range})" if range.present?
"threadTitle=\"#{thread_title}\""
end
diff --git a/plugins/chat/plugin.rb b/plugins/chat/plugin.rb
index 4f26c38d864..8697f666b23 100644
--- a/plugins/chat/plugin.rb
+++ b/plugins/chat/plugin.rb
@@ -216,7 +216,7 @@ after_initialize do
add_to_serializer(
:user_option,
:chat_sound,
- include_condition: -> { !object.chat_sound.blank? },
+ include_condition: -> { object.chat_sound.present? },
) { object.chat_sound }
add_to_serializer(:user_option, :only_chat_push_notifications) do
@@ -516,6 +516,4 @@ after_initialize do
end
end
-if Rails.env == "test"
- Dir[Rails.root.join("plugins/chat/spec/support/**/*.rb")].each { |f| require f }
-end
+Dir[Rails.root.join("plugins/chat/spec/support/**/*.rb")].each { |f| require f } if Rails.env.test?
diff --git a/plugins/chat/spec/jobs/scheduled/auto_join_users_spec.rb b/plugins/chat/spec/jobs/scheduled/auto_join_users_spec.rb
index cf50674b861..cba48ff6524 100644
--- a/plugins/chat/spec/jobs/scheduled/auto_join_users_spec.rb
+++ b/plugins/chat/spec/jobs/scheduled/auto_join_users_spec.rb
@@ -13,7 +13,7 @@ describe Jobs::Chat::AutoJoinUsers do
end
fab!(:staged_user) { Fabricate(:user, staged: true) }
fab!(:suspended_user) { Fabricate(:user, suspended_till: 1.day.from_now) }
- fab!(:silenced_user) { Fabricate(:user, silenced_till: 2.day.from_now) }
+ fab!(:silenced_user) { Fabricate(:user, silenced_till: 2.days.from_now) }
fab!(:inactive_user) { Fabricate(:user, active: false) }
fab!(:anonymous_user) do
# When using the `anonymous` fabricator, the `::Chat::AutoJoinChannels` is called in the
diff --git a/plugins/chat/spec/lib/chat/transcript_service_spec.rb b/plugins/chat/spec/lib/chat/transcript_service_spec.rb
index 6a5668d641b..8293db1411b 100644
--- a/plugins/chat/spec/lib/chat/transcript_service_spec.rb
+++ b/plugins/chat/spec/lib/chat/transcript_service_spec.rb
@@ -56,7 +56,7 @@ describe Chat::TranscriptService do
message1 =
Fabricate(
:chat_message,
- created_at: 10.minute.ago,
+ created_at: 10.minutes.ago,
user: user1,
chat_channel: channel,
message: "an extremely insightful response :)",
@@ -72,7 +72,7 @@ describe Chat::TranscriptService do
message3 =
Fabricate(
:chat_message,
- created_at: 1.minutes.ago,
+ created_at: 1.minute.ago,
user: user1,
chat_channel: channel,
message: "yay!",
diff --git a/plugins/chat/spec/requests/chat/api/channels_controller_spec.rb b/plugins/chat/spec/requests/chat/api/channels_controller_spec.rb
index 4358170d99f..15bbe9511ea 100644
--- a/plugins/chat/spec/requests/chat/api/channels_controller_spec.rb
+++ b/plugins/chat/spec/requests/chat/api/channels_controller_spec.rb
@@ -322,7 +322,7 @@ RSpec.describe Chat::Api::ChannelsController do
describe "triggers the auto-join process" do
fab!(:chatters_group, :group)
- fab!(:user) { Fabricate(:user, last_seen_at: 15.minute.ago) }
+ fab!(:user) { Fabricate(:user, last_seen_at: 15.minutes.ago) }
before do
Jobs.run_immediately!
@@ -555,7 +555,7 @@ RSpec.describe Chat::Api::ChannelsController do
describe "triggers the auto-join process" do
fab!(:chatters_group, :group)
- fab!(:another_user) { Fabricate(:user, last_seen_at: 15.minute.ago) }
+ fab!(:another_user) { Fabricate(:user, last_seen_at: 15.minutes.ago) }
before do
Jobs.run_immediately!
diff --git a/plugins/chat/spec/requests/core_ext/bookmarks_controller_spec.rb b/plugins/chat/spec/requests/core_ext/bookmarks_controller_spec.rb
index c5db4a072d5..ed8cc69a9a1 100644
--- a/plugins/chat/spec/requests/core_ext/bookmarks_controller_spec.rb
+++ b/plugins/chat/spec/requests/core_ext/bookmarks_controller_spec.rb
@@ -21,7 +21,7 @@ RSpec.describe BookmarksController do
params: {
bookmarkable_id: bookmark_message.id,
bookmarkable_type: "Chat::Message",
- reminder_at: (Time.zone.now + 1.day).iso8601,
+ reminder_at: 1.day.from_now.iso8601,
}
expect(response.status).to eq(200)
diff --git a/plugins/chat/spec/services/chat/list_channel_messages_spec.rb b/plugins/chat/spec/services/chat/list_channel_messages_spec.rb
index 61951ad5915..f2a9267954d 100644
--- a/plugins/chat/spec/services/chat/list_channel_messages_spec.rb
+++ b/plugins/chat/spec/services/chat/list_channel_messages_spec.rb
@@ -143,7 +143,7 @@ RSpec.describe Chat::ListChannelMessages do
Fabricate(:chat_message, chat_channel: channel, created_at: 3.days.ago)
end
fab!(:future_message) do
- Fabricate(:chat_message, chat_channel: channel, created_at: 1.days.ago)
+ Fabricate(:chat_message, chat_channel: channel, created_at: 1.day.ago)
end
let(:optional_params) { { target_date: 2.days.ago } }
diff --git a/plugins/chat/spec/services/chat/list_channel_thread_messages_spec.rb b/plugins/chat/spec/services/chat/list_channel_thread_messages_spec.rb
index 80c98db9674..aecbc6a2928 100644
--- a/plugins/chat/spec/services/chat/list_channel_thread_messages_spec.rb
+++ b/plugins/chat/spec/services/chat/list_channel_thread_messages_spec.rb
@@ -144,7 +144,7 @@ RSpec.describe Chat::ListChannelThreadMessages do
Fabricate(
:chat_message,
chat_channel: thread.channel,
- created_at: 1.days.from_now,
+ created_at: 1.day.from_now,
thread:,
)
end
diff --git a/plugins/chat/spec/services/chat/thread/policy/message_existence_spec.rb b/plugins/chat/spec/services/chat/thread/policy/message_existence_spec.rb
index c56b7e43995..6de29751b65 100644
--- a/plugins/chat/spec/services/chat/thread/policy/message_existence_spec.rb
+++ b/plugins/chat/spec/services/chat/thread/policy/message_existence_spec.rb
@@ -4,7 +4,7 @@ RSpec.describe Chat::Thread::Policy::MessageExistence do
subject(:policy) { described_class.new(context) }
fab!(:user) { Fabricate(:user, refresh_auto_groups: true) }
- fab!(:thread) { Fabricate(:chat_thread) }
+ fab!(:thread, :chat_thread)
let(:guardian) { user.guardian }
let(:context) { Service::Base::Context.build(thread:, guardian:, target_message_id:) }
diff --git a/plugins/chat/spec/system/admin/csv_exports_spec.rb b/plugins/chat/spec/system/admin/csv_exports_spec.rb
index 64784243546..5eec7d9bf00 100644
--- a/plugins/chat/spec/system/admin/csv_exports_spec.rb
+++ b/plugins/chat/spec/system/admin/csv_exports_spec.rb
@@ -18,7 +18,7 @@ RSpec.describe "Admin Chat CSV exports", type: :system do
Jobs.run_immediately!
message_1 = Fabricate(:chat_message, created_at: 12.months.ago)
message_2 = Fabricate(:chat_message, created_at: 6.months.ago)
- message_3 = Fabricate(:chat_message, created_at: 1.months.ago)
+ message_3 = Fabricate(:chat_message, created_at: 1.month.ago)
message_4 = Fabricate(:chat_message, created_at: Time.now)
visit "/admin/plugins/chat"
diff --git a/plugins/chat/spec/system/list_channels/drawer_spec.rb b/plugins/chat/spec/system/list_channels/drawer_spec.rb
index c2ffc27854c..3fa1ef3f7c7 100644
--- a/plugins/chat/spec/system/list_channels/drawer_spec.rb
+++ b/plugins/chat/spec/system/list_channels/drawer_spec.rb
@@ -143,7 +143,7 @@ RSpec.describe "List channels | Drawer", type: :system do
chat_channel: dm_channel_4,
user: user_3,
use_service: true,
- created_at: 1.days.ago,
+ created_at: 1.day.ago,
)
dm_channel_4.membership_for(current_user).mark_read!
diff --git a/plugins/chat/spec/system/message_user_info_spec.rb b/plugins/chat/spec/system/message_user_info_spec.rb
index 44345d4c5d4..76c48503b9a 100644
--- a/plugins/chat/spec/system/message_user_info_spec.rb
+++ b/plugins/chat/spec/system/message_user_info_spec.rb
@@ -74,7 +74,7 @@ RSpec.describe "Message user info", type: :system do
context "with large time difference between messages" do
fab!(:message_1) do
- Fabricate(:chat_message, chat_channel: channel_1, user: current_user, created_at: 1.days.ago)
+ Fabricate(:chat_message, chat_channel: channel_1, user: current_user, created_at: 1.day.ago)
end
fab!(:message_2) { Fabricate(:chat_message, chat_channel: channel_1, user: current_user) }
diff --git a/plugins/discourse-adplugin/app/models/ad_plugin/house_ad.rb b/plugins/discourse-adplugin/app/models/ad_plugin/house_ad.rb
index a1b5cb48317..a2d48eaf849 100644
--- a/plugins/discourse-adplugin/app/models/ad_plugin/house_ad.rb
+++ b/plugins/discourse-adplugin/app/models/ad_plugin/house_ad.rb
@@ -146,7 +146,7 @@ module AdPlugin
end
def self.publish_if_ads_enabled
- if AdPlugin::HouseAdSetting.all.any? { |_, adsToShow| !adsToShow.blank? }
+ if AdPlugin::HouseAdSetting.all.any? { |_, adsToShow| adsToShow.present? }
AdPlugin::HouseAdSetting.publish_settings
end
end
diff --git a/plugins/discourse-adplugin/spec/requests/site_controller_spec.rb b/plugins/discourse-adplugin/spec/requests/site_controller_spec.rb
index fb5b36a372d..0cca09beac2 100644
--- a/plugins/discourse-adplugin/spec/requests/site_controller_spec.rb
+++ b/plugins/discourse-adplugin/spec/requests/site_controller_spec.rb
@@ -4,7 +4,7 @@ RSpec.describe SiteController do
fab!(:group)
fab!(:private_category) { Fabricate(:private_category, group: group) }
fab!(:user)
- fab!(:group_2) { Fabricate(:group) }
+ fab!(:group_2, :group)
fab!(:user_with_group) { Fabricate(:user, group_ids: [group.id]) }
let!(:anon_ad) do
diff --git a/plugins/discourse-ai/app/controllers/discourse_ai/admin/ai_llm_quotas_controller.rb b/plugins/discourse-ai/app/controllers/discourse_ai/admin/ai_llm_quotas_controller.rb
index 9c15b0d9164..725d2fd5cb6 100644
--- a/plugins/discourse-ai/app/controllers/discourse_ai/admin/ai_llm_quotas_controller.rb
+++ b/plugins/discourse-ai/app/controllers/discourse_ai/admin/ai_llm_quotas_controller.rb
@@ -40,7 +40,7 @@ module DiscourseAi
head :no_content
rescue ActiveRecord::RecordNotFound
- render json: { error: I18n.t("not_found") }, status: 404
+ render json: { error: I18n.t("not_found") }, status: :not_found
end
private
diff --git a/plugins/discourse-ai/app/controllers/discourse_ai/admin/rag_document_fragments_controller.rb b/plugins/discourse-ai/app/controllers/discourse_ai/admin/rag_document_fragments_controller.rb
index 014a3ee4aef..cf5b744ba3b 100644
--- a/plugins/discourse-ai/app/controllers/discourse_ai/admin/rag_document_fragments_controller.rb
+++ b/plugins/discourse-ai/app/controllers/discourse_ai/admin/rag_document_fragments_controller.rb
@@ -39,7 +39,8 @@ module DiscourseAi
if upload.persisted?
render json: UploadSerializer.new(upload)
else
- render json: failed_json.merge(errors: upload.errors.full_messages), status: 422
+ render json: failed_json.merge(errors: upload.errors.full_messages),
+ status: :unprocessable_entity
end
end
end
diff --git a/plugins/discourse-ai/app/controllers/discourse_ai/ai_bot/bot_controller.rb b/plugins/discourse-ai/app/controllers/discourse_ai/ai_bot/bot_controller.rb
index c3a8e137487..844bf118235 100644
--- a/plugins/discourse-ai/app/controllers/discourse_ai/ai_bot/bot_controller.rb
+++ b/plugins/discourse-ai/app/controllers/discourse_ai/ai_bot/bot_controller.rb
@@ -11,7 +11,7 @@ module DiscourseAi
raise Discourse::NotFound if !log.topic
guardian.ensure_can_debug_ai_bot_conversation!(log.topic)
- render json: AiApiAuditLogSerializer.new(log, root: false), status: 200
+ render json: AiApiAuditLogSerializer.new(log, root: false), status: :ok
end
def show_debug_info
@@ -26,7 +26,7 @@ module DiscourseAi
debug_info = AiApiAuditLog.where(post: posts).order(created_at: :desc).first
- render json: AiApiAuditLogSerializer.new(debug_info, root: false), status: 200
+ render json: AiApiAuditLogSerializer.new(debug_info, root: false), status: :ok
end
def stop_streaming_response
@@ -35,14 +35,14 @@ module DiscourseAi
Discourse.redis.del("gpt_cancel:#{post.id}")
- render json: {}, status: 200
+ render json: {}, status: :ok
end
def show_bot_username
bot_user = DiscourseAi::AiBot::EntryPoint.find_user_from_model(params[:username])
raise Discourse::InvalidParameters.new(:username) if !bot_user
- render json: { bot_username: bot_user.username_lower }, status: 200
+ render json: { bot_username: bot_user.username_lower }, status: :ok
end
end
end
diff --git a/plugins/discourse-ai/app/controllers/discourse_ai/ai_helper/assistant_controller.rb b/plugins/discourse-ai/app/controllers/discourse_ai/ai_helper/assistant_controller.rb
index 92117f81488..d8d5d18015b 100644
--- a/plugins/discourse-ai/app/controllers/discourse_ai/ai_helper/assistant_controller.rb
+++ b/plugins/discourse-ai/app/controllers/discourse_ai/ai_helper/assistant_controller.rb
@@ -44,7 +44,7 @@ module DiscourseAi
force_default_locale: force_default_locale,
custom_prompt: params[:custom_prompt],
),
- status: 200
+ status: :ok
end
rescue DiscourseAi::Completions::Endpoints::Base::CompletionFailed
render_json_error I18n.t("discourse_ai.ai_helper.errors.completion_request_failed"),
@@ -67,7 +67,7 @@ module DiscourseAi
input,
current_user,
),
- status: 200
+ status: :ok
end
rescue DiscourseAi::Completions::Endpoints::Base::CompletionFailed
render_json_error I18n.t("discourse_ai.ai_helper.errors.completion_request_failed"),
@@ -85,7 +85,7 @@ module DiscourseAi
end
render json: DiscourseAi::AiHelper::SemanticCategorizer.new(current_user, opts).categories,
- status: 200
+ status: :ok
end
def suggest_tags
@@ -99,14 +99,14 @@ module DiscourseAi
end
render json: DiscourseAi::AiHelper::SemanticCategorizer.new(current_user, opts).tags,
- status: 200
+ status: :ok
end
def suggest_thumbnails(input)
hijack do
thumbnails = DiscourseAi::AiHelper::Painter.new.commission_thumbnails(input, current_user)
- render json: { thumbnails: thumbnails }, status: 200
+ render json: { thumbnails: thumbnails }, status: :ok
end
end
@@ -161,7 +161,7 @@ module DiscourseAi
)
end
- render json: { success: true, progress_channel: }, status: 200
+ render json: { success: true, progress_channel: }, status: :ok
rescue DiscourseAi::Completions::Endpoints::Base::CompletionFailed
render_json_error I18n.t("discourse_ai.ai_helper.errors.completion_request_failed"),
status: 502
@@ -193,7 +193,7 @@ module DiscourseAi
caption:
"#{caption} (#{I18n.t("discourse_ai.ai_helper.image_caption.attribution")})",
},
- status: 200
+ status: :ok
end
rescue DiscourseAi::Completions::Endpoints::Base::CompletionFailed, Net::HTTPBadResponse
render_json_error I18n.t("discourse_ai.ai_helper.errors.completion_request_failed"),
diff --git a/plugins/discourse-ai/app/controllers/discourse_ai/discover/discoveries_controller.rb b/plugins/discourse-ai/app/controllers/discourse_ai/discover/discoveries_controller.rb
index cb5cd242938..6ac186c4cbd 100644
--- a/plugins/discourse-ai/app/controllers/discourse_ai/discover/discoveries_controller.rb
+++ b/plugins/discourse-ai/app/controllers/discourse_ai/discover/discoveries_controller.rb
@@ -25,7 +25,7 @@ module DiscourseAi
Jobs.enqueue(:stream_discover_reply, user_id: current_user.id, query: query)
- render json: {}, status: 200
+ render json: {}, status: :ok
end
def continue_convo
@@ -59,7 +59,7 @@ module DiscourseAi
render json: success_json.merge(topic_id: post.topic_id)
rescue StandardError => e
- render json: failed_json.merge(errors: [e.message]), status: 422
+ render json: failed_json.merge(errors: [e.message]), status: :unprocessable_entity
end
end
end
diff --git a/plugins/discourse-ai/app/controllers/discourse_ai/embeddings/embeddings_controller.rb b/plugins/discourse-ai/app/controllers/discourse_ai/embeddings/embeddings_controller.rb
index d3f7cfd25cc..f8fb469cb34 100644
--- a/plugins/discourse-ai/app/controllers/discourse_ai/embeddings/embeddings_controller.rb
+++ b/plugins/discourse-ai/app/controllers/discourse_ai/embeddings/embeddings_controller.rb
@@ -39,14 +39,14 @@ module DiscourseAi
current_user,
"semantic-search",
MAX_HYDE_SEARCHES_PER_MINUTE,
- 1.minutes,
+ 1.minute,
).performed!
else
RateLimiter.new(
current_user,
"semantic-search-non-hyde",
MAX_SEARCHES_PER_MINUTE,
- 1.minutes,
+ 1.minute,
).performed!
end
@@ -88,7 +88,7 @@ module DiscourseAi
semantic_search = DiscourseAi::Embeddings::SemanticSearch.new(guardian)
if !semantic_search.cached_query?(query)
- RateLimiter.new(current_user, "semantic-search", 60, 1.minutes).performed!
+ RateLimiter.new(current_user, "semantic-search", 60, 1.minute).performed!
end
hijack do
diff --git a/plugins/discourse-ai/app/controllers/discourse_ai/translation/translation_controller.rb b/plugins/discourse-ai/app/controllers/discourse_ai/translation/translation_controller.rb
index 3a1f8a96d5f..8ab836782fa 100644
--- a/plugins/discourse-ai/app/controllers/discourse_ai/translation/translation_controller.rb
+++ b/plugins/discourse-ai/app/controllers/discourse_ai/translation/translation_controller.rb
@@ -23,7 +23,7 @@ module DiscourseAi
return(
render json:
failed_json.merge(error: I18n.t("discourse_ai.translation.errors.disabled")),
- status: 400
+ status: :bad_request
)
end
diff --git a/plugins/discourse-ai/app/models/ai_persona.rb b/plugins/discourse-ai/app/models/ai_persona.rb
index f626d4d628a..db4c8b40c5c 100644
--- a/plugins/discourse-ai/app/models/ai_persona.rb
+++ b/plugins/discourse-ai/app/models/ai_persona.rb
@@ -37,8 +37,8 @@ class AiPersona < ActiveRecord::Base
has_many :upload_references, as: :target, dependent: :destroy
has_many :uploads, through: :upload_references
- before_destroy :ensure_not_system
before_update :regenerate_rag_fragments
+ before_destroy :ensure_not_system
def self.persona_cache
@persona_cache ||= DiscourseAi::MultisiteHash.new("persona_cache")
diff --git a/plugins/discourse-ai/app/models/embedding_definition.rb b/plugins/discourse-ai/app/models/embedding_definition.rb
index f2118e8766c..854846b3b85 100644
--- a/plugins/discourse-ai/app/models/embedding_definition.rb
+++ b/plugins/discourse-ai/app/models/embedding_definition.rb
@@ -127,7 +127,7 @@ class EmbeddingDefinition < ActiveRecord::Base
validates :provider, presence: true, inclusion: provider_names
validates :display_name, presence: true, length: { maximum: 100 }
validates :tokenizer_class, presence: true, inclusion: tokenizer_names
- validates_presence_of :url, :api_key, :dimensions, :max_sequence_length, :pg_function
+ validates :url, :api_key, :dimensions, :max_sequence_length, :pg_function, presence: true
after_create :create_indexes
diff --git a/plugins/discourse-ai/app/models/llm_model.rb b/plugins/discourse-ai/app/models/llm_model.rb
index 3be95d82dd1..abd45767d45 100644
--- a/plugins/discourse-ai/app/models/llm_model.rb
+++ b/plugins/discourse-ai/app/models/llm_model.rb
@@ -11,7 +11,7 @@ class LlmModel < ActiveRecord::Base
validates :tokenizer, presence: true, inclusion: DiscourseAi::Completions::Llm.tokenizer_names
validates :provider, presence: true, inclusion: DiscourseAi::Completions::Llm.provider_names
validates :url, presence: true, unless: -> { provider == BEDROCK_PROVIDER_NAME }
- validates_presence_of :name, :api_key
+ validates :name, :api_key, presence: true
validates :max_prompt_tokens, numericality: { greater_than: 0 }
validates :input_cost,
:cached_input_cost,
diff --git a/plugins/discourse-ai/app/models/shared_ai_conversation.rb b/plugins/discourse-ai/app/models/shared_ai_conversation.rb
index a4485e06cfc..9ebe4a5ca9f 100644
--- a/plugins/discourse-ai/app/models/shared_ai_conversation.rb
+++ b/plugins/discourse-ai/app/models/shared_ai_conversation.rb
@@ -199,7 +199,7 @@ class SharedAiConversation < ActiveRecord::Base
private
def populate_user_info!(posts)
- users = User.where(id: posts.map(&:user_id).uniq).map { |u| [u.id, u] }.to_h
+ users = User.where(id: posts.map(&:user_id).uniq).index_by(&:id)
posts.each { |post| post.user = users[post.user_id] }
end
diff --git a/plugins/discourse-ai/lib/ai_bot/response_http_streamer.rb b/plugins/discourse-ai/lib/ai_bot/response_http_streamer.rb
index cfb2fbebc45..565484bec5f 100644
--- a/plugins/discourse-ai/lib/ai_bot/response_http_streamer.rb
+++ b/plugins/discourse-ai/lib/ai_bot/response_http_streamer.rb
@@ -117,7 +117,7 @@ module DiscourseAi
rescue StandardError => e
# make it a tiny bit easier to debug in dev, this is tricky
# multi-threaded code that exhibits various limitations in rails
- p e if Rails.env.development? || Rails.env.test?
+ p e if Rails.env.local?
Discourse.warn_exception(e, message: "Discourse AI: Unable to stream reply")
ensure
io.close
diff --git a/plugins/discourse-ai/lib/automation/llm_tool_triage.rb b/plugins/discourse-ai/lib/automation/llm_tool_triage.rb
index 58b9210d5b2..e8206da401b 100644
--- a/plugins/discourse-ai/lib/automation/llm_tool_triage.rb
+++ b/plugins/discourse-ai/lib/automation/llm_tool_triage.rb
@@ -5,7 +5,7 @@ module DiscourseAi
def self.handle(post:, tool_id:, automation: nil)
tool = AiTool.find_by(id: tool_id)
return if !tool
- return if !tool.parameters.blank?
+ return if tool.parameters.present?
context = DiscourseAi::Personas::BotContext.new(post: post)
diff --git a/plugins/discourse-ai/lib/automation/report_runner.rb b/plugins/discourse-ai/lib/automation/report_runner.rb
index d4d06b143b4..ea35e8091fa 100644
--- a/plugins/discourse-ai/lib/automation/report_runner.rb
+++ b/plugins/discourse-ai/lib/automation/report_runner.rb
@@ -68,12 +68,7 @@ module DiscourseAi
@receivers = []
end
@email_receivers = receivers&.filter { |r| r.include? "@" }
- @title =
- if title.present?
- title
- else
- I18n.t("discourse_automation.scriptables.llm_report.title")
- end
+ @title = title.presence || I18n.t("discourse_automation.scriptables.llm_report.title")
@model = LlmModel.find_by(id: model)
@persona = AiPersona.find(persona_id).class_instance.new
@category_ids = category_ids
diff --git a/plugins/discourse-ai/lib/completions/dialects/dialect.rb b/plugins/discourse-ai/lib/completions/dialects/dialect.rb
index c0d5e38b864..193e0a59ee4 100644
--- a/plugins/discourse-ai/lib/completions/dialects/dialect.rb
+++ b/plugins/discourse-ai/lib/completions/dialects/dialect.rb
@@ -25,9 +25,7 @@ module DiscourseAi
def dialect_for(llm_model)
dialects = []
- if Rails.env.test? || Rails.env.development?
- dialects = [DiscourseAi::Completions::Dialects::Fake]
- end
+ dialects = [DiscourseAi::Completions::Dialects::Fake] if Rails.env.local?
dialects = dialects.concat(all_dialects)
diff --git a/plugins/discourse-ai/lib/completions/dialects/nova.rb b/plugins/discourse-ai/lib/completions/dialects/nova.rb
index 10098c2676f..5197d4c1c47 100644
--- a/plugins/discourse-ai/lib/completions/dialects/nova.rb
+++ b/plugins/discourse-ai/lib/completions/dialects/nova.rb
@@ -111,7 +111,7 @@ module DiscourseAi
config[:top_k] = ic[:top_k] if ic[:top_k]
config[:stopSequences] = ic[:stop_sequences] if ic[:stop_sequences]
- config.present? ? config : nil
+ config.presence
end
def detect_format(mime_type)
diff --git a/plugins/discourse-ai/lib/completions/endpoints/base.rb b/plugins/discourse-ai/lib/completions/endpoints/base.rb
index 0a304abbab3..f0f0bbc9702 100644
--- a/plugins/discourse-ai/lib/completions/endpoints/base.rb
+++ b/plugins/discourse-ai/lib/completions/endpoints/base.rb
@@ -30,9 +30,7 @@ module DiscourseAi
endpoints << DiscourseAi::Completions::Endpoints::Ollama if !Rails.env.production?
- if Rails.env.test? || Rails.env.development?
- endpoints << DiscourseAi::Completions::Endpoints::Fake
- end
+ endpoints << DiscourseAi::Completions::Endpoints::Fake if Rails.env.local?
endpoints.detect(-> { raise DiscourseAi::Completions::Llm::UNKNOWN_MODEL }) do |ek|
ek.can_contact?(provider_name)
@@ -453,11 +451,7 @@ module DiscourseAi
if xml_stripper
response_data.map! do |partial|
stripped = (xml_stripper << partial) if partial.is_a?(String)
- if stripped.present?
- stripped
- else
- partial
- end
+ stripped.presence || partial
end
response_data << xml_stripper.finish
end
diff --git a/plugins/discourse-ai/lib/embeddings/semantic_related.rb b/plugins/discourse-ai/lib/embeddings/semantic_related.rb
index 869e4b5bfe0..5ffcdbb59dc 100644
--- a/plugins/discourse-ai/lib/embeddings/semantic_related.rb
+++ b/plugins/discourse-ai/lib/embeddings/semantic_related.rb
@@ -50,11 +50,11 @@ module DiscourseAi
def results_ttl(topic)
case topic.created_at
- when 6.hour.ago..Time.now
+ when 6.hours.ago..Time.now
15.minutes
- when 3.day.ago..6.hour.ago
+ when 3.days.ago..6.hours.ago
1.hour
- when 15.days.ago..3.day.ago
+ when 15.days.ago..3.days.ago
12.hours
else
1.week
diff --git a/plugins/discourse-ai/lib/embeddings/semantic_search.rb b/plugins/discourse-ai/lib/embeddings/semantic_search.rb
index 3f6f5ba8f07..e33080c2d44 100644
--- a/plugins/discourse-ai/lib/embeddings/semantic_search.rb
+++ b/plugins/discourse-ai/lib/embeddings/semantic_search.rb
@@ -239,11 +239,7 @@ module DiscourseAi
id: SiteSetting.ai_embeddings_semantic_search_hyde_persona,
)&.default_llm_id
- if persona_llm_id.present?
- persona_llm_id
- else
- SiteSetting.ai_default_llm_model.to_i || LlmModel.last&.id
- end
+ persona_llm_id.presence || SiteSetting.ai_default_llm_model.to_i || LlmModel.last&.id
end
private
diff --git a/plugins/discourse-ai/lib/personas/tools/discourse_meta_search.rb b/plugins/discourse-ai/lib/personas/tools/discourse_meta_search.rb
index 5fdfb76ef1b..ddaaaaf1be7 100644
--- a/plugins/discourse-ai/lib/personas/tools/discourse_meta_search.rb
+++ b/plugins/discourse-ai/lib/personas/tools/discourse_meta_search.rb
@@ -112,12 +112,12 @@ module DiscourseAi
else
categories =
if categories_json = json.dig("grouped_search_result", "extra", "categories")
- categories_json.map { |c| [c["id"], c] }.to_h
+ categories_json.index_by { _1["id"] }
else
self.class.categories
end
- topics = (json["topics"]).map { |t| [t["id"], t] }.to_h
+ topics = (json["topics"]).index_by { _1["id"] }
format_results(posts, args: parameters) do |post|
topic = topics[post["topic_id"]]
diff --git a/plugins/discourse-ai/lib/personas/tools/setting_context.rb b/plugins/discourse-ai/lib/personas/tools/setting_context.rb
index e8b390c61fa..c37f2c5d4e6 100644
--- a/plugins/discourse-ai/lib/personas/tools/setting_context.rb
+++ b/plugins/discourse-ai/lib/personas/tools/setting_context.rb
@@ -130,7 +130,7 @@ module DiscourseAi
"--heading",
success_status_codes: [0, 1],
)
- if !result.blank?
+ if result.present?
path = search_path
break
end
@@ -145,7 +145,7 @@ module DiscourseAi
filtered = []
rows.each do |row|
- if !filtered.blank?
+ if filtered.present?
break if row.match(/^\s*/)[0].length <= leading_spaces
end
filtered << row
diff --git a/plugins/discourse-ai/lib/personas/tools/tool.rb b/plugins/discourse-ai/lib/personas/tools/tool.rb
index 858750fc15d..da535e54262 100644
--- a/plugins/discourse-ai/lib/personas/tools/tool.rb
+++ b/plugins/discourse-ai/lib/personas/tools/tool.rb
@@ -8,7 +8,7 @@ module DiscourseAi
# This general limit is mainly a security feature to avoid tools
# forcing infinite downloads or causing memory exhaustion.
# The limit is somewhat arbitrary and can be increased in future if needed.
- MAX_RESPONSE_BODY_LENGTH = 30.megabyte
+ MAX_RESPONSE_BODY_LENGTH = 30.megabytes
class << self
def signature
@@ -87,7 +87,7 @@ module DiscourseAi
end
def options
- result = HashWithIndifferentAccess.new
+ result = ActiveSupport::HashWithIndifferentAccess.new
self.class.accepted_options.each do |option|
val = @persona_options[option.name]
if val
diff --git a/plugins/discourse-ai/spec/configuration/feature_spec.rb b/plugins/discourse-ai/spec/configuration/feature_spec.rb
index ba402b78598..eeacd009c8d 100644
--- a/plugins/discourse-ai/spec/configuration/feature_spec.rb
+++ b/plugins/discourse-ai/spec/configuration/feature_spec.rb
@@ -61,7 +61,7 @@ RSpec.describe DiscourseAi::Configuration::Feature do
end
context "with translation module" do
- fab!(:translation_model) { Fabricate(:llm_model) }
+ fab!(:translation_model, :llm_model)
let(:ai_feature) do
described_class.new(
diff --git a/plugins/discourse-ai/spec/fabricators/llm_quota_usage_fabricator.rb b/plugins/discourse-ai/spec/fabricators/llm_quota_usage_fabricator.rb
index 439cf739496..cf6e14be8e4 100644
--- a/plugins/discourse-ai/spec/fabricators/llm_quota_usage_fabricator.rb
+++ b/plugins/discourse-ai/spec/fabricators/llm_quota_usage_fabricator.rb
@@ -7,5 +7,5 @@ Fabricator(:llm_quota_usage) do
output_tokens_used { 0 }
usages { 0 }
started_at { Time.current }
- reset_at { Time.current + 1.day }
+ reset_at { 1.day.from_now }
end
diff --git a/plugins/discourse-ai/spec/jobs/regular/detect_translate_post_spec.rb b/plugins/discourse-ai/spec/jobs/regular/detect_translate_post_spec.rb
index 3ea8b0c41ca..db6cbf54568 100644
--- a/plugins/discourse-ai/spec/jobs/regular/detect_translate_post_spec.rb
+++ b/plugins/discourse-ai/spec/jobs/regular/detect_translate_post_spec.rb
@@ -110,7 +110,7 @@ describe Jobs::DetectTranslatePost do
fab!(:private_topic) { Fabricate(:topic, category: private_category) }
fab!(:private_post) { Fabricate(:post, topic: private_topic) }
- fab!(:personal_pm_topic) { Fabricate(:private_message_topic) }
+ fab!(:personal_pm_topic, :private_message_topic)
fab!(:personal_pm_post) { Fabricate(:post, topic: personal_pm_topic) }
fab!(:group_pm_topic) do
diff --git a/plugins/discourse-ai/spec/jobs/regular/detect_translate_topic_spec.rb b/plugins/discourse-ai/spec/jobs/regular/detect_translate_topic_spec.rb
index 4a8bca9d368..33b7c60113f 100644
--- a/plugins/discourse-ai/spec/jobs/regular/detect_translate_topic_spec.rb
+++ b/plugins/discourse-ai/spec/jobs/regular/detect_translate_topic_spec.rb
@@ -100,7 +100,7 @@ describe Jobs::DetectTranslateTopic do
fab!(:private_category) { Fabricate(:private_category, group: Group[:staff]) }
fab!(:private_topic) { Fabricate(:topic, category: private_category) }
- fab!(:personal_pm_topic) { Fabricate(:private_message_topic) }
+ fab!(:personal_pm_topic, :private_message_topic)
fab!(:group_pm_topic) do
Fabricate(:group_private_message_topic, recipient_group: Fabricate(:group))
diff --git a/plugins/discourse-ai/spec/jobs/regular/digest_rag_upload_spec.rb b/plugins/discourse-ai/spec/jobs/regular/digest_rag_upload_spec.rb
index 3cd861ce7b4..9f08fde9b1d 100644
--- a/plugins/discourse-ai/spec/jobs/regular/digest_rag_upload_spec.rb
+++ b/plugins/discourse-ai/spec/jobs/regular/digest_rag_upload_spec.rb
@@ -3,7 +3,7 @@
RSpec.describe Jobs::DigestRagUpload do
subject(:job) { described_class.new }
- fab!(:persona) { Fabricate(:ai_persona) }
+ fab!(:persona, :ai_persona)
fab!(:upload) { Fabricate(:upload, extension: "txt") }
fab!(:image_upload) { Fabricate(:upload, extension: "png") }
let(:document_file) { StringIO.new("some text" * 200) }
diff --git a/plugins/discourse-ai/spec/jobs/regular/fast_track_topic_gist_spec.rb b/plugins/discourse-ai/spec/jobs/regular/fast_track_topic_gist_spec.rb
index a64ecd08269..fa4e6cd1246 100644
--- a/plugins/discourse-ai/spec/jobs/regular/fast_track_topic_gist_spec.rb
+++ b/plugins/discourse-ai/spec/jobs/regular/fast_track_topic_gist_spec.rb
@@ -4,7 +4,7 @@ RSpec.describe Jobs::FastTrackTopicGist do
subject(:job) { described_class.new }
describe "#execute" do
- fab!(:topic_1) { Fabricate(:topic) }
+ fab!(:topic_1, :topic)
fab!(:post_1) { Fabricate(:post, topic: topic_1, post_number: 1) }
fab!(:post_2) { Fabricate(:post, topic: topic_1, post_number: 2) }
diff --git a/plugins/discourse-ai/spec/jobs/regular/generate_rag_embeddings_spec.rb b/plugins/discourse-ai/spec/jobs/regular/generate_rag_embeddings_spec.rb
index 60c14169168..2c5fdd9fd2c 100644
--- a/plugins/discourse-ai/spec/jobs/regular/generate_rag_embeddings_spec.rb
+++ b/plugins/discourse-ai/spec/jobs/regular/generate_rag_embeddings_spec.rb
@@ -6,7 +6,7 @@ RSpec.describe Jobs::GenerateRagEmbeddings do
before { enable_current_plugin }
describe "#execute" do
- fab!(:vector_def) { Fabricate(:embedding_definition) }
+ fab!(:vector_def, :embedding_definition)
let(:expected_embedding) { [0.0038493] * vector_def.dimensions }
diff --git a/plugins/discourse-ai/spec/jobs/regular/localize_posts_spec.rb b/plugins/discourse-ai/spec/jobs/regular/localize_posts_spec.rb
index 1670369ab62..8c0a863a57a 100644
--- a/plugins/discourse-ai/spec/jobs/regular/localize_posts_spec.rb
+++ b/plugins/discourse-ai/spec/jobs/regular/localize_posts_spec.rb
@@ -145,7 +145,7 @@ describe Jobs::LocalizePosts do
fab!(:public_post) { Fabricate(:post, locale: "es") }
- fab!(:personal_pm_topic) { Fabricate(:private_message_topic) }
+ fab!(:personal_pm_topic, :private_message_topic)
fab!(:personal_pm_post) { Fabricate(:post, topic: personal_pm_topic, locale: "es") }
fab!(:group)
diff --git a/plugins/discourse-ai/spec/jobs/regular/stream_composer_helper_spec.rb b/plugins/discourse-ai/spec/jobs/regular/stream_composer_helper_spec.rb
index 9ee821fa412..2a63c2f0495 100644
--- a/plugins/discourse-ai/spec/jobs/regular/stream_composer_helper_spec.rb
+++ b/plugins/discourse-ai/spec/jobs/regular/stream_composer_helper_spec.rb
@@ -10,7 +10,7 @@ RSpec.describe Jobs::StreamComposerHelper do
describe "#execute" do
let!(:input) { "I liek to eet pie fur brakefast becuz it is delishus." }
- fab!(:user) { Fabricate(:leader) }
+ fab!(:user, :leader)
before do
Group.find(Group::AUTO_GROUPS[:trust_level_3]).add(user)
diff --git a/plugins/discourse-ai/spec/jobs/regular/stream_post_helper_spec.rb b/plugins/discourse-ai/spec/jobs/regular/stream_post_helper_spec.rb
index 7a7442660b4..952bac0019a 100644
--- a/plugins/discourse-ai/spec/jobs/regular/stream_post_helper_spec.rb
+++ b/plugins/discourse-ai/spec/jobs/regular/stream_post_helper_spec.rb
@@ -18,7 +18,7 @@ RSpec.describe Jobs::StreamPostHelper do
"I like to eat pie. It is a very good dessert. Some people are wasteful by throwing pie at others but I do not do that. I always eat the pie.",
)
end
- fab!(:user) { Fabricate(:leader) }
+ fab!(:user, :leader)
before do
Group.find(Group::AUTO_GROUPS[:trust_level_3]).add(user)
diff --git a/plugins/discourse-ai/spec/jobs/regular/stream_topic_ai_summary_spec.rb b/plugins/discourse-ai/spec/jobs/regular/stream_topic_ai_summary_spec.rb
index 20a829b67dc..cc2f56e0a87 100644
--- a/plugins/discourse-ai/spec/jobs/regular/stream_topic_ai_summary_spec.rb
+++ b/plugins/discourse-ai/spec/jobs/regular/stream_topic_ai_summary_spec.rb
@@ -9,7 +9,7 @@ RSpec.describe Jobs::StreamTopicAiSummary do
fab!(:topic) { Fabricate(:topic, highest_post_number: 2) }
fab!(:post_1) { Fabricate(:post, topic: topic, post_number: 1) }
fab!(:post_2) { Fabricate(:post, topic: topic, post_number: 2) }
- fab!(:user) { Fabricate(:leader) }
+ fab!(:user, :leader)
before do
Group.find(Group::AUTO_GROUPS[:trust_level_3]).add(user)
diff --git a/plugins/discourse-ai/spec/jobs/scheduled/embeddings_backfill_spec.rb b/plugins/discourse-ai/spec/jobs/scheduled/embeddings_backfill_spec.rb
index 822da388b8e..8db75fae192 100644
--- a/plugins/discourse-ai/spec/jobs/scheduled/embeddings_backfill_spec.rb
+++ b/plugins/discourse-ai/spec/jobs/scheduled/embeddings_backfill_spec.rb
@@ -2,7 +2,7 @@
RSpec.describe Jobs::EmbeddingsBackfill do
fab!(:second_topic) do
- topic = Fabricate(:topic, created_at: 1.year.ago, bumped_at: 2.day.ago)
+ topic = Fabricate(:topic, created_at: 1.year.ago, bumped_at: 2.days.ago)
Fabricate(:post, topic: topic)
topic
end
@@ -14,13 +14,13 @@ RSpec.describe Jobs::EmbeddingsBackfill do
end
fab!(:third_topic) do
- topic = Fabricate(:topic, created_at: 1.year.ago, bumped_at: 3.day.ago)
+ topic = Fabricate(:topic, created_at: 1.year.ago, bumped_at: 3.days.ago)
Fabricate(:post, topic: topic)
topic
end
- fab!(:vector_def) { Fabricate(:embedding_definition) }
- fab!(:vector_def2) { Fabricate(:embedding_definition) }
+ fab!(:vector_def, :embedding_definition)
+ fab!(:vector_def2, :embedding_definition)
fab!(:embedding_array) { Array.new(1024) { 1 } }
before do
diff --git a/plugins/discourse-ai/spec/jobs/scheduled/posts_locale_detection_backfill_spec.rb b/plugins/discourse-ai/spec/jobs/scheduled/posts_locale_detection_backfill_spec.rb
index d74ae6cd5f4..21bc0451e6b 100644
--- a/plugins/discourse-ai/spec/jobs/scheduled/posts_locale_detection_backfill_spec.rb
+++ b/plugins/discourse-ai/spec/jobs/scheduled/posts_locale_detection_backfill_spec.rb
@@ -44,8 +44,8 @@ describe Jobs::PostsLocaleDetectionBackfill do
post_3 = Fabricate(:post, locale: nil)
post.update!(updated_at: 3.days.ago)
- post_2.update!(updated_at: 2.day.ago)
- post_3.update!(updated_at: 4.day.ago)
+ post_2.update!(updated_at: 2.days.ago)
+ post_3.update!(updated_at: 4.days.ago)
SiteSetting.ai_translation_backfill_hourly_rate = 12
@@ -89,7 +89,7 @@ describe Jobs::PostsLocaleDetectionBackfill do
fab!(:group_pm_topic) { Fabricate(:private_message_topic, allowed_groups: [group]) }
fab!(:group_pm_post) { Fabricate(:post, topic: group_pm_topic, locale: nil) }
- fab!(:pm_topic) { Fabricate(:private_message_topic) }
+ fab!(:pm_topic, :private_message_topic)
fab!(:pm_post) { Fabricate(:post, topic: pm_topic, locale: nil) }
before { SiteSetting.ai_translation_backfill_limit_to_public_content = true }
diff --git a/plugins/discourse-ai/spec/jobs/scheduled/remove_orphaned_embeddings_spec.rb b/plugins/discourse-ai/spec/jobs/scheduled/remove_orphaned_embeddings_spec.rb
index de620701fa5..fba1695e0fd 100644
--- a/plugins/discourse-ai/spec/jobs/scheduled/remove_orphaned_embeddings_spec.rb
+++ b/plugins/discourse-ai/spec/jobs/scheduled/remove_orphaned_embeddings_spec.rb
@@ -7,7 +7,7 @@ RSpec.describe Jobs::RemoveOrphanedEmbeddings do
describe "#execute" do
fab!(:embedding_definition)
- fab!(:embedding_definition_2) { Fabricate(:embedding_definition) }
+ fab!(:embedding_definition_2, :embedding_definition)
fab!(:topic)
fab!(:post)
diff --git a/plugins/discourse-ai/spec/jobs/scheduled/topics_locale_detection_backfill_spec.rb b/plugins/discourse-ai/spec/jobs/scheduled/topics_locale_detection_backfill_spec.rb
index 518c00d96ae..0597dab0831 100644
--- a/plugins/discourse-ai/spec/jobs/scheduled/topics_locale_detection_backfill_spec.rb
+++ b/plugins/discourse-ai/spec/jobs/scheduled/topics_locale_detection_backfill_spec.rb
@@ -44,8 +44,8 @@ describe Jobs::TopicsLocaleDetectionBackfill do
topic_3 = Fabricate(:topic, locale: nil)
topic.update!(updated_at: 3.days.ago)
- topic_2.update!(updated_at: 2.day.ago)
- topic_3.update!(updated_at: 4.day.ago)
+ topic_2.update!(updated_at: 2.days.ago)
+ topic_3.update!(updated_at: 4.days.ago)
SiteSetting.ai_translation_backfill_hourly_rate = 12
@@ -87,7 +87,7 @@ describe Jobs::TopicsLocaleDetectionBackfill do
fab!(:group)
fab!(:group_pm_topic) { Fabricate(:private_message_topic, allowed_groups: [group]) }
- fab!(:pm_topic) { Fabricate(:private_message_topic) }
+ fab!(:pm_topic, :private_message_topic)
fab!(:public_topic) { Fabricate(:topic, locale: nil) }
diff --git a/plugins/discourse-ai/spec/lib/completions/dialects/gemini_spec.rb b/plugins/discourse-ai/spec/lib/completions/dialects/gemini_spec.rb
index e4d50ee72d2..6052d0c6a6e 100644
--- a/plugins/discourse-ai/spec/lib/completions/dialects/gemini_spec.rb
+++ b/plugins/discourse-ai/spec/lib/completions/dialects/gemini_spec.rb
@@ -3,7 +3,7 @@
require_relative "dialect_context"
RSpec.describe DiscourseAi::Completions::Dialects::Gemini do
- fab!(:model) { Fabricate(:gemini_model) }
+ fab!(:model, :gemini_model)
let(:context) { DialectContext.new(described_class, model) }
before { enable_current_plugin }
diff --git a/plugins/discourse-ai/spec/lib/completions/dialects/mistral_spec.rb b/plugins/discourse-ai/spec/lib/completions/dialects/mistral_spec.rb
index 0cce09d5efa..12013840d63 100644
--- a/plugins/discourse-ai/spec/lib/completions/dialects/mistral_spec.rb
+++ b/plugins/discourse-ai/spec/lib/completions/dialects/mistral_spec.rb
@@ -3,7 +3,7 @@
require_relative "dialect_context"
RSpec.describe DiscourseAi::Completions::Dialects::Mistral do
- fab!(:model) { Fabricate(:mistral_model) }
+ fab!(:model, :mistral_model)
let(:context) { DialectContext.new(described_class, model) }
let(:image100x100) { plugin_file_from_fixtures("100x100.jpg") }
let(:upload100x100) do
diff --git a/plugins/discourse-ai/spec/lib/completions/dialects/ollama_spec.rb b/plugins/discourse-ai/spec/lib/completions/dialects/ollama_spec.rb
index e0a2e8e1808..22db5028c9e 100644
--- a/plugins/discourse-ai/spec/lib/completions/dialects/ollama_spec.rb
+++ b/plugins/discourse-ai/spec/lib/completions/dialects/ollama_spec.rb
@@ -3,7 +3,7 @@
require_relative "dialect_context"
RSpec.describe DiscourseAi::Completions::Dialects::Ollama do
- fab!(:model) { Fabricate(:ollama_model) }
+ fab!(:model, :ollama_model)
let(:context) { DialectContext.new(described_class, model) }
let(:dialect_class) { DiscourseAi::Completions::Dialects::Dialect.dialect_for(model) }
diff --git a/plugins/discourse-ai/spec/lib/completions/endpoints/aws_bedrock_spec.rb b/plugins/discourse-ai/spec/lib/completions/endpoints/aws_bedrock_spec.rb
index 8d95be58183..a0eab17436d 100644
--- a/plugins/discourse-ai/spec/lib/completions/endpoints/aws_bedrock_spec.rb
+++ b/plugins/discourse-ai/spec/lib/completions/endpoints/aws_bedrock_spec.rb
@@ -11,7 +11,7 @@ RSpec.describe DiscourseAi::Completions::Endpoints::AwsBedrock do
subject(:endpoint) { described_class.new(model) }
fab!(:user)
- fab!(:model) { Fabricate(:bedrock_model) }
+ fab!(:model, :bedrock_model)
let(:bedrock_mock) { BedrockMock.new(endpoint) }
diff --git a/plugins/discourse-ai/spec/lib/completions/endpoints/ollama_spec.rb b/plugins/discourse-ai/spec/lib/completions/endpoints/ollama_spec.rb
index 3531a4a1914..4d2def80ace 100644
--- a/plugins/discourse-ai/spec/lib/completions/endpoints/ollama_spec.rb
+++ b/plugins/discourse-ai/spec/lib/completions/endpoints/ollama_spec.rb
@@ -127,7 +127,7 @@ RSpec.describe DiscourseAi::Completions::Endpoints::Ollama do
subject(:endpoint) { described_class.new(model) }
fab!(:user)
- fab!(:model) { Fabricate(:ollama_model) }
+ fab!(:model, :ollama_model)
let(:ollama_mock) { OllamaMock.new(endpoint) }
diff --git a/plugins/discourse-ai/spec/lib/completions/endpoints/open_ai_spec.rb b/plugins/discourse-ai/spec/lib/completions/endpoints/open_ai_spec.rb
index 7297e56a664..21902795ee3 100644
--- a/plugins/discourse-ai/spec/lib/completions/endpoints/open_ai_spec.rb
+++ b/plugins/discourse-ai/spec/lib/completions/endpoints/open_ai_spec.rb
@@ -151,7 +151,7 @@ RSpec.describe DiscourseAi::Completions::Endpoints::OpenAi do
subject(:endpoint) { described_class.new(model) }
fab!(:user)
- fab!(:model) { Fabricate(:llm_model) }
+ fab!(:model, :llm_model)
let(:echo_tool) do
{
diff --git a/plugins/discourse-ai/spec/lib/completions/endpoints/samba_nova_spec.rb b/plugins/discourse-ai/spec/lib/completions/endpoints/samba_nova_spec.rb
index bacff00d086..b983dca1809 100644
--- a/plugins/discourse-ai/spec/lib/completions/endpoints/samba_nova_spec.rb
+++ b/plugins/discourse-ai/spec/lib/completions/endpoints/samba_nova_spec.rb
@@ -1,7 +1,7 @@
# frozen_string_literal: true
RSpec.describe DiscourseAi::Completions::Endpoints::SambaNova do
- fab!(:llm_model) { Fabricate(:samba_nova_model) }
+ fab!(:llm_model, :samba_nova_model)
let(:llm) { llm_model.to_llm }
before { enable_current_plugin }
diff --git a/plugins/discourse-ai/spec/lib/completions/endpoints/vllm_spec.rb b/plugins/discourse-ai/spec/lib/completions/endpoints/vllm_spec.rb
index 27bdd4feb42..d586864463e 100644
--- a/plugins/discourse-ai/spec/lib/completions/endpoints/vllm_spec.rb
+++ b/plugins/discourse-ai/spec/lib/completions/endpoints/vllm_spec.rb
@@ -65,7 +65,7 @@ end
RSpec.describe DiscourseAi::Completions::Endpoints::Vllm do
subject(:endpoint) { described_class.new(llm_model) }
- fab!(:llm_model) { Fabricate(:vllm_model) }
+ fab!(:llm_model, :vllm_model)
fab!(:user)
let(:llm) { DiscourseAi::Completions::Llm.proxy(llm_model) }
diff --git a/plugins/discourse-ai/spec/lib/completions/llm_spec.rb b/plugins/discourse-ai/spec/lib/completions/llm_spec.rb
index 3759a627972..814a4053e1c 100644
--- a/plugins/discourse-ai/spec/lib/completions/llm_spec.rb
+++ b/plugins/discourse-ai/spec/lib/completions/llm_spec.rb
@@ -11,7 +11,7 @@ RSpec.describe DiscourseAi::Completions::Llm do
end
fab!(:user)
- fab!(:model) { Fabricate(:llm_model) }
+ fab!(:model, :llm_model)
before { enable_current_plugin }
diff --git a/plugins/discourse-ai/spec/lib/completions/prompt_messages_builder_spec.rb b/plugins/discourse-ai/spec/lib/completions/prompt_messages_builder_spec.rb
index 44e97cc97d1..7aa106fc238 100644
--- a/plugins/discourse-ai/spec/lib/completions/prompt_messages_builder_spec.rb
+++ b/plugins/discourse-ai/spec/lib/completions/prompt_messages_builder_spec.rb
@@ -4,8 +4,8 @@ describe DiscourseAi::Completions::PromptMessagesBuilder do
let(:builder) { DiscourseAi::Completions::PromptMessagesBuilder.new }
fab!(:user)
fab!(:admin)
- fab!(:bot_user) { Fabricate(:user) }
- fab!(:other_user) { Fabricate(:user) }
+ fab!(:bot_user, :user)
+ fab!(:other_user, :user)
fab!(:image_upload1) do
Fabricate(:upload, user: user, original_filename: "image.png", extension: "png")
@@ -175,7 +175,7 @@ describe DiscourseAi::Completions::PromptMessagesBuilder do
Fabricate(:chat_message, chat_channel: dm_channel, user: user, message: "How are you?")
end
- fab!(:public_channel) { Fabricate(:category_channel) }
+ fab!(:public_channel, :category_channel)
fab!(:public_message1) do
Fabricate(:chat_message, chat_channel: public_channel, user: user, message: "Hello everyone")
end
@@ -312,8 +312,8 @@ describe DiscourseAi::Completions::PromptMessagesBuilder do
end
describe "upload limits in messages_from_chat" do
- fab!(:test_channel) { Fabricate(:category_channel) }
- fab!(:test_user) { Fabricate(:user) }
+ fab!(:test_channel, :category_channel)
+ fab!(:test_user, :user)
# Create MAX_CHAT_UPLOADS + 1 uploads
fab!(:uploads) do
diff --git a/plugins/discourse-ai/spec/lib/discourse_automation/llm_persona_triage_spec.rb b/plugins/discourse-ai/spec/lib/discourse_automation/llm_persona_triage_spec.rb
index 57ca6d12698..b7f3ecddef4 100644
--- a/plugins/discourse-ai/spec/lib/discourse_automation/llm_persona_triage_spec.rb
+++ b/plugins/discourse-ai/spec/lib/discourse_automation/llm_persona_triage_spec.rb
@@ -4,7 +4,7 @@ return if !defined?(DiscourseAutomation)
describe DiscourseAi::Automation::LlmPersonaTriage do
fab!(:user)
- fab!(:bot_user) { Fabricate(:user) }
+ fab!(:bot_user, :user)
fab!(:llm_model) { Fabricate(:anthropic_model, name: "claude-3-opus", enabled_chat_bot: true) }
@@ -272,8 +272,8 @@ describe DiscourseAi::Automation::LlmPersonaTriage do
describe "LLM Persona Triage with Chat Message Creation" do
fab!(:user)
- fab!(:bot_user) { Fabricate(:user) }
- fab!(:chat_channel) { Fabricate(:category_channel) }
+ fab!(:bot_user, :user)
+ fab!(:chat_channel, :category_channel)
fab!(:custom_tool) do
AiTool.create!(
diff --git a/plugins/discourse-ai/spec/lib/discourse_automation/llm_tool_triage_spec.rb b/plugins/discourse-ai/spec/lib/discourse_automation/llm_tool_triage_spec.rb
index 0b3cdeef84a..f7981ab33b5 100644
--- a/plugins/discourse-ai/spec/lib/discourse_automation/llm_tool_triage_spec.rb
+++ b/plugins/discourse-ai/spec/lib/discourse_automation/llm_tool_triage_spec.rb
@@ -1,7 +1,7 @@
# frozen_string_literal: true
RSpec.describe DiscourseAi::Automation::LlmToolTriage do
- fab!(:solver) { Fabricate(:user) }
+ fab!(:solver, :user)
fab!(:new_user) { Fabricate(:user, trust_level: TrustLevel[0], created_at: 1.day.ago) }
fab!(:topic) { Fabricate(:topic, user: new_user) }
fab!(:post) { Fabricate(:post, topic: topic, user: new_user, raw: "How do I reset my password?") }
diff --git a/plugins/discourse-ai/spec/lib/discourse_automation/llm_triage_spec.rb b/plugins/discourse-ai/spec/lib/discourse_automation/llm_triage_spec.rb
index f31489da4b9..f6d8957da62 100644
--- a/plugins/discourse-ai/spec/lib/discourse_automation/llm_triage_spec.rb
+++ b/plugins/discourse-ai/spec/lib/discourse_automation/llm_triage_spec.rb
@@ -4,8 +4,8 @@ return if !defined?(DiscourseAutomation)
describe DiscourseAi::Automation::LlmTriage do
fab!(:category)
- fab!(:reply_user) { Fabricate(:user) }
- fab!(:personal_message) { Fabricate(:private_message_topic) }
+ fab!(:reply_user, :user)
+ fab!(:personal_message, :private_message_topic)
let(:canned_reply_text) { "Hello, this is a reply" }
let(:automation) { Fabricate(:automation, script: "llm_triage", enabled: true) }
diff --git a/plugins/discourse-ai/spec/lib/inferred_concepts/applier_spec.rb b/plugins/discourse-ai/spec/lib/inferred_concepts/applier_spec.rb
index b0eeb952225..ac549c40cce 100644
--- a/plugins/discourse-ai/spec/lib/inferred_concepts/applier_spec.rb
+++ b/plugins/discourse-ai/spec/lib/inferred_concepts/applier_spec.rb
@@ -8,7 +8,7 @@ RSpec.describe DiscourseAi::InferredConcepts::Applier do
fab!(:user) { Fabricate(:user, username: "dev_user") }
fab!(:concept1) { Fabricate(:inferred_concept, name: "programming") }
fab!(:concept2) { Fabricate(:inferred_concept, name: "testing") }
- fab!(:llm_model) { Fabricate(:fake_model) }
+ fab!(:llm_model, :fake_model)
before do
enable_current_plugin
diff --git a/plugins/discourse-ai/spec/lib/inferred_concepts/finder_spec.rb b/plugins/discourse-ai/spec/lib/inferred_concepts/finder_spec.rb
index 0db814c84e3..d9176b408ed 100644
--- a/plugins/discourse-ai/spec/lib/inferred_concepts/finder_spec.rb
+++ b/plugins/discourse-ai/spec/lib/inferred_concepts/finder_spec.rb
@@ -7,7 +7,7 @@ RSpec.describe DiscourseAi::InferredConcepts::Finder do
fab!(:post) { Fabricate(:post, like_count: 10) }
fab!(:concept1) { Fabricate(:inferred_concept, name: "programming") }
fab!(:concept2) { Fabricate(:inferred_concept, name: "testing") }
- fab!(:llm_model) { Fabricate(:fake_model) }
+ fab!(:llm_model, :fake_model)
before do
enable_current_plugin
diff --git a/plugins/discourse-ai/spec/lib/modules/ai_bot/entry_point_spec.rb b/plugins/discourse-ai/spec/lib/modules/ai_bot/entry_point_spec.rb
index 69f073fb95a..e64d8af5947 100644
--- a/plugins/discourse-ai/spec/lib/modules/ai_bot/entry_point_spec.rb
+++ b/plugins/discourse-ai/spec/lib/modules/ai_bot/entry_point_spec.rb
@@ -6,7 +6,7 @@ RSpec.describe DiscourseAi::AiBot::EntryPoint do
describe "#inject_into" do
describe "subscribes to the post_created event" do
fab!(:admin)
- fab!(:bot_allowed_group) { Fabricate(:group) }
+ fab!(:bot_allowed_group, :group)
fab!(:gpt_4) { Fabricate(:llm_model, name: "gpt-4") }
let(:gpt_bot) { gpt_4.reload.user }
diff --git a/plugins/discourse-ai/spec/lib/modules/ai_bot/playground_spec.rb b/plugins/discourse-ai/spec/lib/modules/ai_bot/playground_spec.rb
index fe9e0306fb6..1c57b5fd46d 100644
--- a/plugins/discourse-ai/spec/lib/modules/ai_bot/playground_spec.rb
+++ b/plugins/discourse-ai/spec/lib/modules/ai_bot/playground_spec.rb
@@ -11,7 +11,7 @@ RSpec.describe DiscourseAi::AiBot::Playground do
name: "claude-2",
)
end
- fab!(:opus_model) { Fabricate(:anthropic_model) }
+ fab!(:opus_model, :anthropic_model)
fab!(:bot_user) do
enable_current_plugin
@@ -310,7 +310,7 @@ RSpec.describe DiscourseAi::AiBot::Playground do
end
context "with chat channels" do
- fab!(:channel) { Fabricate(:chat_channel) }
+ fab!(:channel, :chat_channel)
fab!(:membership) do
Fabricate(:user_chat_channel_membership, user: user, chat_channel: channel)
diff --git a/plugins/discourse-ai/spec/lib/modules/ai_helper/chat_thread_titler_spec.rb b/plugins/discourse-ai/spec/lib/modules/ai_helper/chat_thread_titler_spec.rb
index 2b68497b0ae..4c39556f6de 100644
--- a/plugins/discourse-ai/spec/lib/modules/ai_helper/chat_thread_titler_spec.rb
+++ b/plugins/discourse-ai/spec/lib/modules/ai_helper/chat_thread_titler_spec.rb
@@ -3,7 +3,7 @@
RSpec.describe DiscourseAi::AiHelper::ChatThreadTitler do
subject(:titler) { described_class.new(thread) }
- fab!(:thread) { Fabricate(:chat_thread) }
+ fab!(:thread, :chat_thread)
fab!(:chat_message) { Fabricate(:chat_message, thread: thread) }
fab!(:user)
diff --git a/plugins/discourse-ai/spec/lib/modules/ai_helper/entry_point_spec.rb b/plugins/discourse-ai/spec/lib/modules/ai_helper/entry_point_spec.rb
index 9f14ca98c0e..6e665f12420 100644
--- a/plugins/discourse-ai/spec/lib/modules/ai_helper/entry_point_spec.rb
+++ b/plugins/discourse-ai/spec/lib/modules/ai_helper/entry_point_spec.rb
@@ -1,7 +1,7 @@
# frozen_string_literal: true
describe DiscourseAi::AiHelper::EntryPoint do
- fab!(:english_user) { Fabricate(:user) }
+ fab!(:english_user, :user)
fab!(:french_user) { Fabricate(:user, locale: "fr") }
before { enable_current_plugin }
diff --git a/plugins/discourse-ai/spec/lib/modules/ai_helper/semantic_categorizer_spec.rb b/plugins/discourse-ai/spec/lib/modules/ai_helper/semantic_categorizer_spec.rb
index effec0e9e9f..4c44b580ec9 100644
--- a/plugins/discourse-ai/spec/lib/modules/ai_helper/semantic_categorizer_spec.rb
+++ b/plugins/discourse-ai/spec/lib/modules/ai_helper/semantic_categorizer_spec.rb
@@ -1,9 +1,9 @@
# frozen_string_literal: true
RSpec.describe DiscourseAi::AiHelper::SemanticCategorizer do
- fab!(:vector_def) { Fabricate(:embedding_definition) }
+ fab!(:vector_def, :embedding_definition)
fab!(:user)
- fab!(:muted_category) { Fabricate(:category) }
+ fab!(:muted_category, :category)
fab!(:category_mute) do
CategoryUser.create!(
user: user,
diff --git a/plugins/discourse-ai/spec/lib/modules/automation/report_context_generator_spec.rb b/plugins/discourse-ai/spec/lib/modules/automation/report_context_generator_spec.rb
index 58d01d77faa..ee1094e9b7e 100644
--- a/plugins/discourse-ai/spec/lib/modules/automation/report_context_generator_spec.rb
+++ b/plugins/discourse-ai/spec/lib/modules/automation/report_context_generator_spec.rb
@@ -5,7 +5,7 @@ module DiscourseAi
describe ReportContextGenerator do
describe ".generate" do
fab!(:private_message_post)
- fab!(:post_in_other_category) { Fabricate(:post) }
+ fab!(:post_in_other_category, :post)
fab!(:category)
fab!(:topic) { Fabricate(:topic, category: category) }
@@ -23,7 +23,7 @@ module DiscourseAi
end
fab!(:tag)
- fab!(:tag2) { Fabricate(:tag) }
+ fab!(:tag2, :tag)
fab!(:topic_with_tag) { Fabricate(:topic, tags: [tag, tag2]) }
fab!(:post_with_tag) { Fabricate(:post, topic: topic_with_tag) }
@@ -49,7 +49,7 @@ module DiscourseAi
it "will correctly denote solved topics" do
Fabricate(:solved_topic, topic: topic_with_likes, answer_post: post_with_likes2)
- context = ReportContextGenerator.generate(start_date: 1.day.ago, duration: 2.day)
+ context = ReportContextGenerator.generate(start_date: 1.day.ago, duration: 2.days)
expect(context).to include("solved: true")
expect(context).to include("solution: true")
@@ -59,28 +59,28 @@ module DiscourseAi
it "will exclude non visible topics" do
post_with_likes3.topic.update(visible: false)
- context = ReportContextGenerator.generate(start_date: 1.day.ago, duration: 2.day)
+ context = ReportContextGenerator.generate(start_date: 1.day.ago, duration: 2.days)
expect(context).not_to include("topic_id: #{topic_with_likes.id}")
end
it "always includes info from last posts on topic" do
context =
- ReportContextGenerator.generate(start_date: 1.day.ago, duration: 2.day, max_posts: 1)
+ ReportContextGenerator.generate(start_date: 1.day.ago, duration: 2.days, max_posts: 1)
expect(context).to include("...")
expect(context).to include("post_number: 3")
end
it "includes a summary" do
- context = ReportContextGenerator.generate(start_date: 1.day.ago, duration: 2.day)
+ context = ReportContextGenerator.generate(start_date: 1.day.ago, duration: 2.days)
expect(context).to include("New posts: 8")
expect(context).to include("New topics: 5")
end
it "orders so most liked are first" do
- context = ReportContextGenerator.generate(start_date: 1.day.ago, duration: 2.day)
+ context = ReportContextGenerator.generate(start_date: 1.day.ago, duration: 2.days)
regex = "topic_id: #{topic_with_likes.id}.*topic_id: #{long_post.topic.id}"
expect(context).to match(Regexp.new(regex, Regexp::MULTILINE))
@@ -90,7 +90,7 @@ module DiscourseAi
context =
ReportContextGenerator.generate(
start_date: 1.day.ago,
- duration: 2.day,
+ duration: 2.days,
prioritized_group_ids: [group.id],
allow_secure_categories: true,
max_posts: 1,
@@ -102,7 +102,7 @@ module DiscourseAi
end
it "can generate context (excluding PMs)" do
- context = ReportContextGenerator.generate(start_date: 1.day.ago, duration: 2.day)
+ context = ReportContextGenerator.generate(start_date: 1.day.ago, duration: 2.days)
expect(context).to include(post_in_other_category.topic.title)
expect(context).to include(topic.title)
@@ -114,7 +114,7 @@ module DiscourseAi
context =
ReportContextGenerator.generate(
start_date: 1.day.ago,
- duration: 2.day,
+ duration: 2.days,
tags: [tag.name],
)
@@ -129,7 +129,7 @@ module DiscourseAi
context =
ReportContextGenerator.generate(
start_date: 1.day.ago,
- duration: 2.day,
+ duration: 2.days,
allow_secure_categories: true,
)
expect(context).to include(post_in_other_category.topic.title)
@@ -142,7 +142,7 @@ module DiscourseAi
context =
ReportContextGenerator.generate(
start_date: 1.day.ago,
- duration: 2.day,
+ duration: 2.days,
category_ids: [category.id],
)
diff --git a/plugins/discourse-ai/spec/lib/modules/automation/report_runner_spec.rb b/plugins/discourse-ai/spec/lib/modules/automation/report_runner_spec.rb
index d1b1b50221a..bd955618a02 100644
--- a/plugins/discourse-ai/spec/lib/modules/automation/report_runner_spec.rb
+++ b/plugins/discourse-ai/spec/lib/modules/automation/report_runner_spec.rb
@@ -4,7 +4,7 @@ module DiscourseAi
module Automation
describe ReportRunner do
fab!(:user)
- fab!(:receiver) { Fabricate(:user) }
+ fab!(:receiver, :user)
fab!(:post) { Fabricate(:post, user: user) }
fab!(:group)
fab!(:secure_category) { Fabricate(:private_category, group: group) }
diff --git a/plugins/discourse-ai/spec/lib/modules/embeddings/entry_point_spec.rb b/plugins/discourse-ai/spec/lib/modules/embeddings/entry_point_spec.rb
index ba36534554f..c748cb3cb5c 100644
--- a/plugins/discourse-ai/spec/lib/modules/embeddings/entry_point_spec.rb
+++ b/plugins/discourse-ai/spec/lib/modules/embeddings/entry_point_spec.rb
@@ -61,7 +61,7 @@ describe DiscourseAi::Embeddings::EntryPoint do
fab!(:category)
fab!(:normal_topic_1) { Fabricate(:topic, category: category) }
fab!(:normal_topic_2) { Fabricate(:topic, category: category) }
- fab!(:private_topic) { Fabricate(:private_message_topic) }
+ fab!(:private_topic, :private_message_topic)
let(:query) { "title\n\nraw" }
diff --git a/plugins/discourse-ai/spec/lib/modules/embeddings/jobs/generate_embeddings_spec.rb b/plugins/discourse-ai/spec/lib/modules/embeddings/jobs/generate_embeddings_spec.rb
index 6d7cec65b2b..c8da9a0d480 100644
--- a/plugins/discourse-ai/spec/lib/modules/embeddings/jobs/generate_embeddings_spec.rb
+++ b/plugins/discourse-ai/spec/lib/modules/embeddings/jobs/generate_embeddings_spec.rb
@@ -3,7 +3,7 @@
RSpec.describe Jobs::GenerateEmbeddings do
subject(:job) { described_class.new }
- fab!(:vector_def) { Fabricate(:embedding_definition) }
+ fab!(:vector_def, :embedding_definition)
before { enable_current_plugin }
diff --git a/plugins/discourse-ai/spec/lib/modules/embeddings/schema_spec.rb b/plugins/discourse-ai/spec/lib/modules/embeddings/schema_spec.rb
index 2a2956ee76c..0ce006bce0c 100644
--- a/plugins/discourse-ai/spec/lib/modules/embeddings/schema_spec.rb
+++ b/plugins/discourse-ai/spec/lib/modules/embeddings/schema_spec.rb
@@ -3,7 +3,7 @@
RSpec.describe DiscourseAi::Embeddings::Schema do
subject(:posts_schema) { described_class.for(Post) }
- fab!(:vector_def) { Fabricate(:cloudflare_embedding_def) }
+ fab!(:vector_def, :cloudflare_embedding_def)
let(:embeddings) { [0.0038490295] * vector_def.dimensions }
fab!(:post) { Fabricate(:post, post_number: 1) }
let(:digest) { OpenSSL::Digest.hexdigest("SHA1", "test") }
@@ -33,7 +33,7 @@ RSpec.describe DiscourseAi::Embeddings::Schema do
end
describe "similarity searches" do
- fab!(:post_2) { Fabricate(:post) }
+ fab!(:post_2, :post)
let(:similar_embeddings) { [0.0038490294] * vector_def.dimensions }
describe "#symmetric_similarity_search" do
diff --git a/plugins/discourse-ai/spec/lib/modules/embeddings/semantic_related_spec.rb b/plugins/discourse-ai/spec/lib/modules/embeddings/semantic_related_spec.rb
index b17f069bca3..06d84d8b118 100644
--- a/plugins/discourse-ai/spec/lib/modules/embeddings/semantic_related_spec.rb
+++ b/plugins/discourse-ai/spec/lib/modules/embeddings/semantic_related_spec.rb
@@ -3,17 +3,17 @@
describe DiscourseAi::Embeddings::SemanticRelated do
subject(:semantic_related) { described_class.new }
- fab!(:target) { Fabricate(:topic) }
- fab!(:normal_topic_1) { Fabricate(:topic) }
- fab!(:normal_topic_2) { Fabricate(:topic) }
- fab!(:normal_topic_3) { Fabricate(:topic) }
+ fab!(:target, :topic)
+ fab!(:normal_topic_1, :topic)
+ fab!(:normal_topic_2, :topic)
+ fab!(:normal_topic_3, :topic)
fab!(:unlisted_topic) { Fabricate(:topic, visible: false) }
- fab!(:private_topic) { Fabricate(:private_message_topic) }
+ fab!(:private_topic, :private_message_topic)
fab!(:secured_category) { Fabricate(:category, read_restricted: true) }
fab!(:secured_category_topic) { Fabricate(:topic, category: secured_category) }
fab!(:closed_topic) { Fabricate(:topic, closed: true) }
- fab!(:vector_def) { Fabricate(:embedding_definition) }
+ fab!(:vector_def, :embedding_definition)
before do
enable_current_plugin
diff --git a/plugins/discourse-ai/spec/lib/modules/embeddings/semantic_search_spec.rb b/plugins/discourse-ai/spec/lib/modules/embeddings/semantic_search_spec.rb
index 38bf9f357e7..9923c714884 100644
--- a/plugins/discourse-ai/spec/lib/modules/embeddings/semantic_search_spec.rb
+++ b/plugins/discourse-ai/spec/lib/modules/embeddings/semantic_search_spec.rb
@@ -5,7 +5,7 @@ RSpec.describe DiscourseAi::Embeddings::SemanticSearch do
fab!(:post)
fab!(:user)
- fab!(:vector_def) { Fabricate(:embedding_definition) }
+ fab!(:vector_def, :embedding_definition)
let(:query) { "test_query" }
diff --git a/plugins/discourse-ai/spec/lib/modules/embeddings/semantic_topic_query_spec.rb b/plugins/discourse-ai/spec/lib/modules/embeddings/semantic_topic_query_spec.rb
index d5ebe9d7b1c..afdc0d2402f 100644
--- a/plugins/discourse-ai/spec/lib/modules/embeddings/semantic_topic_query_spec.rb
+++ b/plugins/discourse-ai/spec/lib/modules/embeddings/semantic_topic_query_spec.rb
@@ -9,9 +9,9 @@ describe DiscourseAi::Embeddings::EntryPoint do
describe "#list_semantic_related_topics" do
subject(:topic_query) { DiscourseAi::Embeddings::SemanticTopicQuery.new(user) }
- fab!(:target) { Fabricate(:topic) }
+ fab!(:target, :topic)
- fab!(:vector_def) { Fabricate(:cloudflare_embedding_def) }
+ fab!(:vector_def, :cloudflare_embedding_def)
before do
SiteSetting.ai_embeddings_enabled = true
@@ -44,7 +44,7 @@ describe DiscourseAi::Embeddings::EntryPoint do
end
context "when the semantic search returns a private topic" do
- fab!(:private_topic) { Fabricate(:private_message_topic) }
+ fab!(:private_topic, :private_message_topic)
before { seed_embeddings([private_topic]) }
@@ -101,9 +101,9 @@ describe DiscourseAi::Embeddings::EntryPoint do
end
context "when the semantic search returns public topics" do
- fab!(:normal_topic_1) { Fabricate(:topic) }
- fab!(:normal_topic_2) { Fabricate(:topic) }
- fab!(:normal_topic_3) { Fabricate(:topic) }
+ fab!(:normal_topic_1, :topic)
+ fab!(:normal_topic_2, :topic)
+ fab!(:normal_topic_3, :topic)
fab!(:closed_topic) { Fabricate(:topic, closed: true) }
before { seed_embeddings([closed_topic, normal_topic_1, normal_topic_2, normal_topic_3]) }
@@ -125,8 +125,8 @@ describe DiscourseAi::Embeddings::EntryPoint do
end
context "with semantic_related_topics_query modifier registered" do
- fab!(:included_topic) { Fabricate(:topic) }
- fab!(:excluded_topic) { Fabricate(:topic) }
+ fab!(:included_topic, :topic)
+ fab!(:excluded_topic, :topic)
before { seed_embeddings([included_topic, excluded_topic]) }
diff --git a/plugins/discourse-ai/spec/lib/modules/embeddings/vector_spec.rb b/plugins/discourse-ai/spec/lib/modules/embeddings/vector_spec.rb
index 685c8fe9b9f..6a625a9f07e 100644
--- a/plugins/discourse-ai/spec/lib/modules/embeddings/vector_spec.rb
+++ b/plugins/discourse-ai/spec/lib/modules/embeddings/vector_spec.rb
@@ -83,7 +83,7 @@ RSpec.describe DiscourseAi::Embeddings::Vector do
end
describe "#gen_bulk_reprensentations" do
- fab!(:topic_2) { Fabricate(:topic) }
+ fab!(:topic_2, :topic)
fab!(:post_2_1) { Fabricate(:post, post_number: 1, topic: topic_2) }
fab!(:post_2_2) { Fabricate(:post, post_number: 2, topic: topic_2) }
@@ -140,7 +140,7 @@ RSpec.describe DiscourseAi::Embeddings::Vector do
end
context "with open_ai as the provider" do
- fab!(:vdef) { Fabricate(:open_ai_embedding_def) }
+ fab!(:vdef, :open_ai_embedding_def)
def stub_vector_mapping(text, expected_embedding, result_status: 200)
EmbeddingsGenerationStubs.openai_service(
@@ -175,7 +175,7 @@ RSpec.describe DiscourseAi::Embeddings::Vector do
end
context "with hugging_face as the provider" do
- fab!(:vdef) { Fabricate(:embedding_definition) }
+ fab!(:vdef, :embedding_definition)
def stub_vector_mapping(text, expected_embedding, result_status: 200)
EmbeddingsGenerationStubs.hugging_face_service(
@@ -189,7 +189,7 @@ RSpec.describe DiscourseAi::Embeddings::Vector do
end
context "with google as the provider" do
- fab!(:vdef) { Fabricate(:gemini_embedding_def) }
+ fab!(:vdef, :gemini_embedding_def)
def stub_vector_mapping(text, expected_embedding, result_status: 200)
EmbeddingsGenerationStubs.gemini_service(
@@ -204,7 +204,7 @@ RSpec.describe DiscourseAi::Embeddings::Vector do
end
context "with cloudflare as the provider" do
- fab!(:vdef) { Fabricate(:cloudflare_embedding_def) }
+ fab!(:vdef, :cloudflare_embedding_def)
def stub_vector_mapping(text, expected_embedding, result_status: 200)
EmbeddingsGenerationStubs.cloudflare_service(
diff --git a/plugins/discourse-ai/spec/lib/modules/sentiment/entry_point_spec.rb b/plugins/discourse-ai/spec/lib/modules/sentiment/entry_point_spec.rb
index 0ca1d7a3188..628e353911b 100644
--- a/plugins/discourse-ai/spec/lib/modules/sentiment/entry_point_spec.rb
+++ b/plugins/discourse-ai/spec/lib/modules/sentiment/entry_point_spec.rb
@@ -38,10 +38,10 @@ RSpec.describe DiscourseAi::Sentiment::EntryPoint do
"[{\"model_name\":\"SamLowe/roberta-base-go_emotions\",\"endpoint\":\"http://samlowe-emotion.com\",\"api_key\":\"123\"},{\"model_name\":\"j-hartmann/emotion-english-distilroberta-base\",\"endpoint\":\"http://jhartmann-emotion.com\",\"api_key\":\"123\"},{\"model_name\":\"cardiffnlp/twitter-roberta-base-sentiment-latest\",\"endpoint\":\"http://cardiffnlp-sentiment.com\",\"api_key\":\"123\"}]"
end
- fab!(:pm) { Fabricate(:private_message_post) }
+ fab!(:pm, :private_message_post)
- fab!(:post_1) { Fabricate(:post) }
- fab!(:post_2) { Fabricate(:post) }
+ fab!(:post_1, :post)
+ fab!(:post_2, :post)
describe "overall_sentiment report" do
let(:positive_classification) { { negative: 0.2, neutral: 0.3, positive: 0.7 } }
@@ -68,7 +68,7 @@ RSpec.describe DiscourseAi::Sentiment::EntryPoint do
exporter = Jobs::ExportCsvFile.new
exporter.entity = "report"
- exporter.extra = HashWithIndifferentAccess.new(name: "overall_sentiment")
+ exporter.extra = ActiveSupport::HashWithIndifferentAccess.new(name: "overall_sentiment")
exported_csv = []
exporter.report_export { |entry| exported_csv << entry }
expect(exported_csv[0]).to eq(["Day", "Overall sentiment (Positive - Negative)"])
diff --git a/plugins/discourse-ai/spec/lib/personas/artifact_update_strategies/diff_spec.rb b/plugins/discourse-ai/spec/lib/personas/artifact_update_strategies/diff_spec.rb
index 5f48f5bbf1b..49a4a197158 100644
--- a/plugins/discourse-ai/spec/lib/personas/artifact_update_strategies/diff_spec.rb
+++ b/plugins/discourse-ai/spec/lib/personas/artifact_update_strategies/diff_spec.rb
@@ -3,7 +3,7 @@
RSpec.describe DiscourseAi::Personas::ArtifactUpdateStrategies::Diff do
fab!(:user)
fab!(:post)
- fab!(:artifact) { Fabricate(:ai_artifact) }
+ fab!(:artifact, :ai_artifact)
fab!(:llm_model)
let(:llm) { llm_model.to_llm }
diff --git a/plugins/discourse-ai/spec/lib/personas/persona_spec.rb b/plugins/discourse-ai/spec/lib/personas/persona_spec.rb
index 82c55ebefc5..cde7d787e38 100644
--- a/plugins/discourse-ai/spec/lib/personas/persona_spec.rb
+++ b/plugins/discourse-ai/spec/lib/personas/persona_spec.rb
@@ -279,7 +279,7 @@ RSpec.describe DiscourseAi::Personas::Persona do
end
describe "#craft_prompt" do
- fab!(:vector_def) { Fabricate(:embedding_definition) }
+ fab!(:vector_def, :embedding_definition)
before do
Group.refresh_automatic_groups!
@@ -308,7 +308,7 @@ RSpec.describe DiscourseAi::Personas::Persona do
context "when RAG is running with a question consolidator" do
let(:consolidated_question) { "what is the time in france?" }
- fab!(:llm_model) { Fabricate(:fake_model) }
+ fab!(:llm_model, :fake_model)
fab!(:custom_ai_persona) do
Fabricate(
diff --git a/plugins/discourse-ai/spec/lib/personas/tools/researcher_spec.rb b/plugins/discourse-ai/spec/lib/personas/tools/researcher_spec.rb
index 7591eaa0c50..c57c6dc01db 100644
--- a/plugins/discourse-ai/spec/lib/personas/tools/researcher_spec.rb
+++ b/plugins/discourse-ai/spec/lib/personas/tools/researcher_spec.rb
@@ -17,7 +17,7 @@ RSpec.describe DiscourseAi::Personas::Tools::Researcher do
fab!(:topic_with_tags) { Fabricate(:topic, category: category, tags: [tag_research, tag_data]) }
fab!(:post) { Fabricate(:post, topic: topic_with_tags) }
- fab!(:another_post) { Fabricate(:post) }
+ fab!(:another_post, :post)
before do
enable_current_plugin
diff --git a/plugins/discourse-ai/spec/lib/translation/topic_candidates_spec.rb b/plugins/discourse-ai/spec/lib/translation/topic_candidates_spec.rb
index a0ecce1df51..9e5f0673dd4 100644
--- a/plugins/discourse-ai/spec/lib/translation/topic_candidates_spec.rb
+++ b/plugins/discourse-ai/spec/lib/translation/topic_candidates_spec.rb
@@ -25,7 +25,7 @@ describe DiscourseAi::Translation::TopicCandidates do
end
describe "SiteSetting.ai_translation_backfill_limit_to_public_content" do
- fab!(:pm) { Fabricate(:private_message_topic) }
+ fab!(:pm, :private_message_topic)
fab!(:group_pm) { Fabricate(:private_message_topic, allowed_groups: [Fabricate(:group)]) }
fab!(:public_topic) do
Fabricate(:topic, category: Fabricate(:category, read_restricted: false))
diff --git a/plugins/discourse-ai/spec/lib/utils/research/filter_spec.rb b/plugins/discourse-ai/spec/lib/utils/research/filter_spec.rb
index dd239cf6dbd..1acaea8db07 100644
--- a/plugins/discourse-ai/spec/lib/utils/research/filter_spec.rb
+++ b/plugins/discourse-ai/spec/lib/utils/research/filter_spec.rb
@@ -10,7 +10,7 @@ describe DiscourseAi::Utils::Research::Filter do
end
fab!(:user)
- fab!(:user2) { Fabricate(:user) }
+ fab!(:user2, :user)
fab!(:feature_tag) { Fabricate(:tag, name: "feature") }
fab!(:bug_tag) { Fabricate(:tag, name: "bug") }
@@ -89,7 +89,7 @@ describe DiscourseAi::Utils::Research::Filter do
end
describe "security filtering" do
- fab!(:secure_group) { Fabricate(:group) }
+ fab!(:secure_group, :group)
fab!(:secure_category) { Fabricate(:category, name: "Secure") }
fab!(:secure_topic) do
diff --git a/plugins/discourse-ai/spec/models/ai_tool_spec.rb b/plugins/discourse-ai/spec/models/ai_tool_spec.rb
index 9c970970ef3..92421011d11 100644
--- a/plugins/discourse-ai/spec/models/ai_tool_spec.rb
+++ b/plugins/discourse-ai/spec/models/ai_tool_spec.rb
@@ -483,7 +483,7 @@ RSpec.describe AiTool do
SiteSetting.chat_enabled = true
end
- fab!(:chat_user) { Fabricate(:user) }
+ fab!(:chat_user, :user)
fab!(:chat_channel) do
Fabricate(:chat_channel).tap do |channel|
Fabricate(
@@ -948,7 +948,7 @@ RSpec.describe AiTool do
context "when creating topics" do
fab!(:category)
- fab!(:user) { Fabricate(:admin) }
+ fab!(:user, :admin)
it "can create a topic" do
script = <<~JS
diff --git a/plugins/discourse-ai/spec/models/embedding_definition_spec.rb b/plugins/discourse-ai/spec/models/embedding_definition_spec.rb
index c9009f70a1d..ceec53eb75e 100644
--- a/plugins/discourse-ai/spec/models/embedding_definition_spec.rb
+++ b/plugins/discourse-ai/spec/models/embedding_definition_spec.rb
@@ -1,8 +1,8 @@
# frozen_string_literal: true
describe EmbeddingDefinition do
- fab!(:embedding_definition) { Fabricate(:open_ai_embedding_def) }
- fab!(:gemini_embedding_definition) { Fabricate(:gemini_embedding_def) }
+ fab!(:embedding_definition, :open_ai_embedding_def)
+ fab!(:gemini_embedding_definition, :gemini_embedding_def)
describe "#prepare_query_text" do
let(:text) { "test query" }
diff --git a/plugins/discourse-ai/spec/models/llm_model_spec.rb b/plugins/discourse-ai/spec/models/llm_model_spec.rb
index 9395bc50f3e..67058be1399 100644
--- a/plugins/discourse-ai/spec/models/llm_model_spec.rb
+++ b/plugins/discourse-ai/spec/models/llm_model_spec.rb
@@ -4,7 +4,7 @@ RSpec.describe LlmModel do
before { enable_current_plugin }
describe "api_key" do
- fab!(:llm_model) { Fabricate(:seeded_model) }
+ fab!(:llm_model, :seeded_model)
before { ENV["DISCOURSE_AI_SEEDED_LLM_API_KEY_2"] = "blabla" }
diff --git a/plugins/discourse-ai/spec/models/rag_document_fragment_spec.rb b/plugins/discourse-ai/spec/models/rag_document_fragment_spec.rb
index 52305e78262..1797f124b34 100644
--- a/plugins/discourse-ai/spec/models/rag_document_fragment_spec.rb
+++ b/plugins/discourse-ai/spec/models/rag_document_fragment_spec.rb
@@ -1,10 +1,10 @@
# frozen_string_literal: true
RSpec.describe RagDocumentFragment do
- fab!(:persona) { Fabricate(:ai_persona) }
- fab!(:upload_1) { Fabricate(:upload) }
- fab!(:upload_2) { Fabricate(:upload) }
- fab!(:vector_def) { Fabricate(:embedding_definition) }
+ fab!(:persona, :ai_persona)
+ fab!(:upload_1, :upload)
+ fab!(:upload_2, :upload)
+ fab!(:vector_def, :embedding_definition)
before do
enable_current_plugin
diff --git a/plugins/discourse-ai/spec/models/reviewable_ai_post_spec.rb b/plugins/discourse-ai/spec/models/reviewable_ai_post_spec.rb
index 5d13449dabe..7e914fc1e30 100644
--- a/plugins/discourse-ai/spec/models/reviewable_ai_post_spec.rb
+++ b/plugins/discourse-ai/spec/models/reviewable_ai_post_spec.rb
@@ -3,7 +3,7 @@
describe ReviewableAiPost do
subject(:reviewable_ai_post) { described_class.new }
- fab!(:target) { Fabricate(:post) }
+ fab!(:target, :post)
before { enable_current_plugin }
diff --git a/plugins/discourse-ai/spec/requests/admin/ai_artifacts_controller_spec.rb b/plugins/discourse-ai/spec/requests/admin/ai_artifacts_controller_spec.rb
index 83896f05d17..c2630352aab 100644
--- a/plugins/discourse-ai/spec/requests/admin/ai_artifacts_controller_spec.rb
+++ b/plugins/discourse-ai/spec/requests/admin/ai_artifacts_controller_spec.rb
@@ -3,7 +3,7 @@
RSpec.describe DiscourseAi::Admin::AiArtifactsController, type: :request do
fab!(:admin)
fab!(:user)
- fab!(:target_post) { Fabricate(:post) }
+ fab!(:target_post, :post)
before do
enable_current_plugin
@@ -36,7 +36,7 @@ RSpec.describe DiscourseAi::Admin::AiArtifactsController, type: :request do
end
describe "GET #show" do
- fab!(:artifact) { Fabricate(:ai_artifact) }
+ fab!(:artifact, :ai_artifact)
it "returns a single artifact" do
get "/admin/plugins/discourse-ai/ai-artifacts/#{artifact.id}.json"
@@ -78,7 +78,7 @@ RSpec.describe DiscourseAi::Admin::AiArtifactsController, type: :request do
end
describe "PUT #update" do
- fab!(:artifact) { Fabricate(:ai_artifact) }
+ fab!(:artifact, :ai_artifact)
it "updates fields" do
put "/admin/plugins/discourse-ai/ai-artifacts/#{artifact.id}.json",
@@ -95,7 +95,7 @@ RSpec.describe DiscourseAi::Admin::AiArtifactsController, type: :request do
end
describe "DELETE #destroy" do
- fab!(:artifact) { Fabricate(:ai_artifact) }
+ fab!(:artifact, :ai_artifact)
it "removes the artifact" do
expect { delete "/admin/plugins/discourse-ai/ai-artifacts/#{artifact.id}.json" }.to change(
diff --git a/plugins/discourse-ai/spec/requests/admin/ai_features_controller_spec.rb b/plugins/discourse-ai/spec/requests/admin/ai_features_controller_spec.rb
index 3326df4f770..4de5c1511a1 100644
--- a/plugins/discourse-ai/spec/requests/admin/ai_features_controller_spec.rb
+++ b/plugins/discourse-ai/spec/requests/admin/ai_features_controller_spec.rb
@@ -5,8 +5,8 @@ RSpec.describe DiscourseAi::Admin::AiFeaturesController do
fab!(:admin)
fab!(:group)
fab!(:llm_model)
- fab!(:summarizer_persona) { Fabricate(:ai_persona) }
- fab!(:alternate_summarizer_persona) { Fabricate(:ai_persona) }
+ fab!(:summarizer_persona, :ai_persona)
+ fab!(:alternate_summarizer_persona, :ai_persona)
before do
enable_current_plugin
diff --git a/plugins/discourse-ai/spec/requests/admin/ai_llms_controller_spec.rb b/plugins/discourse-ai/spec/requests/admin/ai_llms_controller_spec.rb
index 1fb2c526098..82bb861ce00 100644
--- a/plugins/discourse-ai/spec/requests/admin/ai_llms_controller_spec.rb
+++ b/plugins/discourse-ai/spec/requests/admin/ai_llms_controller_spec.rb
@@ -11,7 +11,7 @@ RSpec.describe DiscourseAi::Admin::AiLlmsController do
describe "GET #index" do
fab!(:llm_model) { Fabricate(:llm_model, enabled_chat_bot: true) }
- fab!(:llm_model2) { Fabricate(:llm_model) }
+ fab!(:llm_model2, :llm_model)
fab!(:ai_persona) do
Fabricate(
:ai_persona,
diff --git a/plugins/discourse-ai/spec/requests/admin/ai_spam_controller_spec.rb b/plugins/discourse-ai/spec/requests/admin/ai_spam_controller_spec.rb
index 246b35f15eb..2d84082d346 100644
--- a/plugins/discourse-ai/spec/requests/admin/ai_spam_controller_spec.rb
+++ b/plugins/discourse-ai/spec/requests/admin/ai_spam_controller_spec.rb
@@ -219,7 +219,7 @@ RSpec.describe DiscourseAi::Admin::AiSpamController do
end
describe "#test" do
- fab!(:spam_post) { Fabricate(:post) }
+ fab!(:spam_post, :post)
fab!(:spam_post2) { Fabricate(:post, topic: spam_post.topic, raw: "something special 123") }
fab!(:setting) do
AiModerationSetting.create(
diff --git a/plugins/discourse-ai/spec/requests/admin/rag_document_fragments_controller_spec.rb b/plugins/discourse-ai/spec/requests/admin/rag_document_fragments_controller_spec.rb
index 190f3488f5c..f911b36e947 100644
--- a/plugins/discourse-ai/spec/requests/admin/rag_document_fragments_controller_spec.rb
+++ b/plugins/discourse-ai/spec/requests/admin/rag_document_fragments_controller_spec.rb
@@ -4,7 +4,7 @@ RSpec.describe DiscourseAi::Admin::RagDocumentFragmentsController do
fab!(:admin)
fab!(:ai_persona)
- fab!(:vector_def) { Fabricate(:embedding_definition) }
+ fab!(:vector_def, :embedding_definition)
before do
enable_current_plugin
diff --git a/plugins/discourse-ai/spec/requests/admin/reviewable_controller_spec.rb b/plugins/discourse-ai/spec/requests/admin/reviewable_controller_spec.rb
index eee480db37a..d6385f50ea0 100644
--- a/plugins/discourse-ai/spec/requests/admin/reviewable_controller_spec.rb
+++ b/plugins/discourse-ai/spec/requests/admin/reviewable_controller_spec.rb
@@ -1,8 +1,8 @@
# frozen_string_literal: true
RSpec.describe ReviewablesController do
- fab!(:post1) { Fabricate(:post) }
- fab!(:post2) { Fabricate(:post) }
+ fab!(:post1, :post)
+ fab!(:post2, :post)
fab!(:admin)
fab!(:llm_model)
diff --git a/plugins/discourse-ai/spec/requests/ai_bot/artifact_key_values_controller_spec.rb b/plugins/discourse-ai/spec/requests/ai_bot/artifact_key_values_controller_spec.rb
index e55bf913f13..8e137384863 100644
--- a/plugins/discourse-ai/spec/requests/ai_bot/artifact_key_values_controller_spec.rb
+++ b/plugins/discourse-ai/spec/requests/ai_bot/artifact_key_values_controller_spec.rb
@@ -3,7 +3,7 @@
RSpec.describe DiscourseAi::AiBot::ArtifactKeyValuesController do
fab!(:user)
fab!(:admin)
- fab!(:other_user) { Fabricate(:user) }
+ fab!(:other_user, :user)
fab!(:private_message_topic) { Fabricate(:private_message_topic, user: user) }
fab!(:private_message_post) { Fabricate(:post, topic: private_message_topic, user: user) }
fab!(:artifact) do
diff --git a/plugins/discourse-ai/spec/requests/ai_bot/bot_controller_spec.rb b/plugins/discourse-ai/spec/requests/ai_bot/bot_controller_spec.rb
index 4616fd53c07..47d3d45aaa0 100644
--- a/plugins/discourse-ai/spec/requests/ai_bot/bot_controller_spec.rb
+++ b/plugins/discourse-ai/spec/requests/ai_bot/bot_controller_spec.rb
@@ -2,7 +2,7 @@
RSpec.describe DiscourseAi::AiBot::BotController do
fab!(:user)
- fab!(:pm_topic) { Fabricate(:private_message_topic) }
+ fab!(:pm_topic, :private_message_topic)
fab!(:pm_post) { Fabricate(:post, topic: pm_topic) }
fab!(:pm_post2) { Fabricate(:post, topic: pm_topic) }
fab!(:pm_post3) { Fabricate(:post, topic: pm_topic) }
diff --git a/plugins/discourse-ai/spec/requests/ai_bot/shared_ai_conversations_controller_spec.rb b/plugins/discourse-ai/spec/requests/ai_bot/shared_ai_conversations_controller_spec.rb
index 678a23658f8..953a2bcbd86 100644
--- a/plugins/discourse-ai/spec/requests/ai_bot/shared_ai_conversations_controller_spec.rb
+++ b/plugins/discourse-ai/spec/requests/ai_bot/shared_ai_conversations_controller_spec.rb
@@ -13,7 +13,7 @@ RSpec.describe DiscourseAi::AiBot::SharedAiConversationsController do
fab!(:user) { Fabricate(:user, refresh_auto_groups: true) }
fab!(:topic)
- fab!(:pm) { Fabricate(:private_message_topic) }
+ fab!(:pm, :private_message_topic)
fab!(:user_pm) { Fabricate(:private_message_topic, recipient: user) }
fab!(:bot_user) do
diff --git a/plugins/discourse-ai/spec/requests/ai_bot/topic_serialization_spec.rb b/plugins/discourse-ai/spec/requests/ai_bot/topic_serialization_spec.rb
index 8d111e5f9df..1da3fa29c6a 100644
--- a/plugins/discourse-ai/spec/requests/ai_bot/topic_serialization_spec.rb
+++ b/plugins/discourse-ai/spec/requests/ai_bot/topic_serialization_spec.rb
@@ -1,8 +1,8 @@
# frozen_string_literal: true
RSpec.describe "AI Bot Post Serializer" do
- fab!(:current_user) { Fabricate(:user) }
- fab!(:bot_user) { Fabricate(:user) }
+ fab!(:current_user, :user)
+ fab!(:bot_user, :user)
before do
enable_current_plugin
diff --git a/plugins/discourse-ai/spec/requests/embeddings/embeddings_controller_spec.rb b/plugins/discourse-ai/spec/requests/embeddings/embeddings_controller_spec.rb
index c256bfa6916..510dc10c0fc 100644
--- a/plugins/discourse-ai/spec/requests/embeddings/embeddings_controller_spec.rb
+++ b/plugins/discourse-ai/spec/requests/embeddings/embeddings_controller_spec.rb
@@ -2,7 +2,7 @@
describe DiscourseAi::Embeddings::EmbeddingsController do
context "when performing a topic search" do
- fab!(:vector_def) { Fabricate(:open_ai_embedding_def) }
+ fab!(:vector_def, :open_ai_embedding_def)
before do
enable_current_plugin
diff --git a/plugins/discourse-ai/spec/requests/summarization/chat_summary_controller_spec.rb b/plugins/discourse-ai/spec/requests/summarization/chat_summary_controller_spec.rb
index 607013f5725..826711bdc4c 100644
--- a/plugins/discourse-ai/spec/requests/summarization/chat_summary_controller_spec.rb
+++ b/plugins/discourse-ai/spec/requests/summarization/chat_summary_controller_spec.rb
@@ -1,7 +1,7 @@
# frozen_string_literal: true
RSpec.describe DiscourseAi::Summarization::ChatSummaryController do
- fab!(:current_user) { Fabricate(:user) }
+ fab!(:current_user, :user)
fab!(:group)
before do
@@ -20,7 +20,7 @@ RSpec.describe DiscourseAi::Summarization::ChatSummaryController do
describe "#show" do
context "when the user is not allowed to join the channel" do
- fab!(:channel) { Fabricate(:private_category_channel) }
+ fab!(:channel, :private_category_channel)
it "returns a 403" do
get "/discourse-ai/summarization/channels/#{channel.id}", params: { since: 6 }
diff --git a/plugins/discourse-ai/spec/requests/summarization/summary_controller_spec.rb b/plugins/discourse-ai/spec/requests/summarization/summary_controller_spec.rb
index 62a079eeb20..a6f27d4648c 100644
--- a/plugins/discourse-ai/spec/requests/summarization/summary_controller_spec.rb
+++ b/plugins/discourse-ai/spec/requests/summarization/summary_controller_spec.rb
@@ -50,7 +50,7 @@ RSpec.describe DiscourseAi::Summarization::SummaryController do
end
context "when the user is a member of an allowlisted group" do
- fab!(:user) { Fabricate(:leader) }
+ fab!(:user, :leader)
before do
sign_in(user)
@@ -140,7 +140,7 @@ RSpec.describe DiscourseAi::Summarization::SummaryController do
fab!(:post_1) { Fabricate(:post, topic: topic, post_number: 1) }
fab!(:post_2) { Fabricate(:post, topic: topic, post_number: 2) }
- fab!(:topic_1) { Fabricate(:topic) }
+ fab!(:topic_1, :topic)
fab!(:post_3) { Fabricate(:post, topic: topic_1, post_number: 1) }
fab!(:post_4) { Fabricate(:post, topic: topic_1, post_number: 2) }
diff --git a/plugins/discourse-ai/spec/requests/topic_spec.rb b/plugins/discourse-ai/spec/requests/topic_spec.rb
index 85acb3ba8bd..25672f01f92 100644
--- a/plugins/discourse-ai/spec/requests/topic_spec.rb
+++ b/plugins/discourse-ai/spec/requests/topic_spec.rb
@@ -2,10 +2,10 @@
describe ::TopicsController do
fab!(:topic)
- fab!(:topic1) { Fabricate(:topic) }
- fab!(:topic2) { Fabricate(:topic) }
- fab!(:topic3) { Fabricate(:topic) }
- fab!(:user) { Fabricate(:admin) }
+ fab!(:topic1, :topic)
+ fab!(:topic2, :topic)
+ fab!(:topic3, :topic)
+ fab!(:user, :admin)
before do
enable_current_plugin
diff --git a/plugins/discourse-ai/spec/requests/translation/translation_controller_spec.rb b/plugins/discourse-ai/spec/requests/translation/translation_controller_spec.rb
index 656b68a5e85..870ea370321 100644
--- a/plugins/discourse-ai/spec/requests/translation/translation_controller_spec.rb
+++ b/plugins/discourse-ai/spec/requests/translation/translation_controller_spec.rb
@@ -3,7 +3,7 @@
describe DiscourseAi::Translation::TranslationController do
fab!(:user)
fab!(:admin)
- fab!(:test_post) { Fabricate(:post) }
+ fab!(:test_post, :post)
fab!(:group)
before do
diff --git a/plugins/discourse-ai/spec/serializers/ai_chat_channel_serializer_spec.rb b/plugins/discourse-ai/spec/serializers/ai_chat_channel_serializer_spec.rb
index a7f010fd103..5751bafde93 100644
--- a/plugins/discourse-ai/spec/serializers/ai_chat_channel_serializer_spec.rb
+++ b/plugins/discourse-ai/spec/serializers/ai_chat_channel_serializer_spec.rb
@@ -7,7 +7,7 @@ RSpec.describe AiChatChannelSerializer do
describe "#title" do
context "when the channel is a DM" do
- fab!(:dm_channel) { Fabricate(:direct_message_channel) }
+ fab!(:dm_channel, :direct_message_channel)
it "display every participant" do
serialized = described_class.new(dm_channel, scope: Guardian.new(admin), root: nil)
@@ -17,7 +17,7 @@ RSpec.describe AiChatChannelSerializer do
end
context "when the channel is a regular one" do
- fab!(:channel) { Fabricate(:chat_channel) }
+ fab!(:channel, :chat_channel)
it "displays the category title" do
serialized = described_class.new(channel, scope: Guardian.new(admin), root: nil)
diff --git a/plugins/discourse-ai/spec/serializers/ai_features_persona_serializer_spec.rb b/plugins/discourse-ai/spec/serializers/ai_features_persona_serializer_spec.rb
index ea1438bee45..d9a5ac7f1d7 100644
--- a/plugins/discourse-ai/spec/serializers/ai_features_persona_serializer_spec.rb
+++ b/plugins/discourse-ai/spec/serializers/ai_features_persona_serializer_spec.rb
@@ -4,7 +4,7 @@ RSpec.describe AiFeaturesPersonaSerializer do
fab!(:admin)
fab!(:ai_persona)
fab!(:group)
- fab!(:group_2) { Fabricate(:group) }
+ fab!(:group_2, :group)
before { enable_current_plugin }
diff --git a/plugins/discourse-ai/spec/services/discourse_ai/topic_summarization_spec.rb b/plugins/discourse-ai/spec/services/discourse_ai/topic_summarization_spec.rb
index d0ee7712b77..74dc3341eb2 100644
--- a/plugins/discourse-ai/spec/services/discourse_ai/topic_summarization_spec.rb
+++ b/plugins/discourse-ai/spec/services/discourse_ai/topic_summarization_spec.rb
@@ -1,7 +1,7 @@
# frozen_string_literal: true
describe DiscourseAi::TopicSummarization do
- fab!(:user) { Fabricate(:admin) }
+ fab!(:user, :admin)
fab!(:topic) { Fabricate(:topic, highest_post_number: 2) }
fab!(:post_1) { Fabricate(:post, topic: topic, post_number: 1) }
fab!(:post_2) { Fabricate(:post, topic: topic, post_number: 2) }
diff --git a/plugins/discourse-ai/spec/system/admin_ai_features_spec.rb b/plugins/discourse-ai/spec/system/admin_ai_features_spec.rb
index e4e5458e917..923175bf05b 100644
--- a/plugins/discourse-ai/spec/system/admin_ai_features_spec.rb
+++ b/plugins/discourse-ai/spec/system/admin_ai_features_spec.rb
@@ -3,9 +3,9 @@
RSpec.describe "Admin AI features configuration", type: :system do
fab!(:admin)
fab!(:llm_model)
- fab!(:summarization_persona) { Fabricate(:ai_persona) }
- fab!(:group_1) { Fabricate(:group) }
- fab!(:group_2) { Fabricate(:group) }
+ fab!(:summarization_persona, :ai_persona)
+ fab!(:group_1, :group)
+ fab!(:group_2, :group)
let(:page_header) { PageObjects::Components::DPageHeader.new }
let(:form) { PageObjects::Components::FormKit.new("form") }
let(:ai_features_page) { PageObjects::Pages::AdminAiFeatures.new }
diff --git a/plugins/discourse-ai/spec/system/ai_bot/artifact_spec.rb b/plugins/discourse-ai/spec/system/ai_bot/artifact_spec.rb
index 24282ddf38d..5a0998c2b32 100644
--- a/plugins/discourse-ai/spec/system/ai_bot/artifact_spec.rb
+++ b/plugins/discourse-ai/spec/system/ai_bot/artifact_spec.rb
@@ -3,7 +3,7 @@
RSpec.describe "AI Artifact with Data Attributes", type: :system do
fab!(:admin)
fab!(:user)
- fab!(:author) { Fabricate(:user) }
+ fab!(:author, :user)
fab!(:category) { Fabricate(:category, user: admin, read_restricted: false) }
fab!(:topic) { Fabricate(:topic, category: category, user: author) }
fab!(:post) { Fabricate(:post, topic: topic, user: author) }
diff --git a/plugins/discourse-ai/spec/system/ai_bot/header_toggle_spec.rb b/plugins/discourse-ai/spec/system/ai_bot/header_toggle_spec.rb
index 2cf6e778844..9ea7586ccd6 100644
--- a/plugins/discourse-ai/spec/system/ai_bot/header_toggle_spec.rb
+++ b/plugins/discourse-ai/spec/system/ai_bot/header_toggle_spec.rb
@@ -7,7 +7,7 @@ RSpec.describe "AI Bot - Header Toggle", type: :system do
fab!(:user) { Fabricate(:user, refresh_auto_groups: true) }
fab!(:group)
- fab!(:regular_topic) { Fabricate(:topic) }
+ fab!(:regular_topic, :topic)
fab!(:gpt_4) { Fabricate(:llm_model, name: "gpt-4") }
fab!(:gpt_3_5_turbo) { Fabricate(:llm_model, name: "gpt-3.5-turbo") }
diff --git a/plugins/discourse-ai/spec/system/ai_bot/homepage_spec.rb b/plugins/discourse-ai/spec/system/ai_bot/homepage_spec.rb
index d284c57e394..dbb7157a060 100644
--- a/plugins/discourse-ai/spec/system/ai_bot/homepage_spec.rb
+++ b/plugins/discourse-ai/spec/system/ai_bot/homepage_spec.rb
@@ -294,7 +294,7 @@ RSpec.describe "AI Bot - Homepage", type: :system do
end
it "displays last_7_days label in the sidebar" do
- pm.update!(last_posted_at: Time.zone.now - 5.days)
+ pm.update!(last_posted_at: 5.days.ago)
visit "/"
header.click_bot_button
@@ -303,7 +303,7 @@ RSpec.describe "AI Bot - Homepage", type: :system do
end
it "displays last_30_days label in the sidebar" do
- pm.update!(last_posted_at: Time.zone.now - 28.days)
+ pm.update!(last_posted_at: 28.days.ago)
visit "/"
header.click_bot_button
diff --git a/plugins/discourse-ai/spec/system/ai_helper/ai_composer_helper_spec.rb b/plugins/discourse-ai/spec/system/ai_helper/ai_composer_helper_spec.rb
index 786944165eb..f70c2498eb6 100644
--- a/plugins/discourse-ai/spec/system/ai_helper/ai_composer_helper_spec.rb
+++ b/plugins/discourse-ai/spec/system/ai_helper/ai_composer_helper_spec.rb
@@ -2,7 +2,7 @@
RSpec.describe "AI Composer helper", type: :system do
fab!(:user) { Fabricate(:admin, refresh_auto_groups: true) }
- fab!(:non_member_group) { Fabricate(:group) }
+ fab!(:non_member_group, :group)
fab!(:embedding_definition)
fab!(:custom_prompts_persona) do
@@ -28,12 +28,12 @@ RSpec.describe "AI Composer helper", type: :system do
let(:topic_page) { PageObjects::Pages::Topic.new }
fab!(:category)
- fab!(:category_2) { Fabricate(:category) }
- fab!(:video) { Fabricate(:tag) }
- fab!(:music) { Fabricate(:tag) }
- fab!(:cloud) { Fabricate(:tag) }
- fab!(:feedback) { Fabricate(:tag) }
- fab!(:review) { Fabricate(:tag) }
+ fab!(:category_2, :category)
+ fab!(:video, :tag)
+ fab!(:music, :tag)
+ fab!(:cloud, :tag)
+ fab!(:feedback, :tag)
+ fab!(:review, :tag)
fab!(:topic) { Fabricate(:topic, category: category, tags: [video, music]) }
fab!(:post) do
Fabricate(
diff --git a/plugins/discourse-ai/spec/system/ai_helper/ai_image_caption_spec.rb b/plugins/discourse-ai/spec/system/ai_helper/ai_image_caption_spec.rb
index 4d23bf65a4b..878ed34198d 100644
--- a/plugins/discourse-ai/spec/system/ai_helper/ai_image_caption_spec.rb
+++ b/plugins/discourse-ai/spec/system/ai_helper/ai_image_caption_spec.rb
@@ -2,7 +2,7 @@
RSpec.describe "AI image caption", type: :system do
fab!(:user) { Fabricate(:admin, refresh_auto_groups: true) }
- fab!(:non_member_group) { Fabricate(:group) }
+ fab!(:non_member_group, :group)
let(:user_preferences_ai_page) { PageObjects::Pages::UserPreferencesAi.new }
let(:topic_page) { PageObjects::Pages::Topic.new }
fab!(:topic)
diff --git a/plugins/discourse-ai/spec/system/ai_helper/ai_post_helper_spec.rb b/plugins/discourse-ai/spec/system/ai_helper/ai_post_helper_spec.rb
index 1cbb930bd0c..c2e93b7dc89 100644
--- a/plugins/discourse-ai/spec/system/ai_helper/ai_post_helper_spec.rb
+++ b/plugins/discourse-ai/spec/system/ai_helper/ai_post_helper_spec.rb
@@ -1,8 +1,8 @@
# frozen_string_literal: true
RSpec.describe "AI Post helper", type: :system do
- fab!(:user) { Fabricate(:admin) }
- fab!(:non_member_group) { Fabricate(:group) }
+ fab!(:user, :admin)
+ fab!(:non_member_group, :group)
fab!(:topic)
fab!(:post) do
Fabricate(
diff --git a/plugins/discourse-ai/spec/system/ai_helper/ai_split_topic_suggestion_spec.rb b/plugins/discourse-ai/spec/system/ai_helper/ai_split_topic_suggestion_spec.rb
index a993f004bb2..7141b583895 100644
--- a/plugins/discourse-ai/spec/system/ai_helper/ai_split_topic_suggestion_spec.rb
+++ b/plugins/discourse-ai/spec/system/ai_helper/ai_split_topic_suggestion_spec.rb
@@ -1,11 +1,11 @@
# frozen_string_literal: true
RSpec.describe "AI Post helper", type: :system do
- fab!(:user) { Fabricate(:admin) }
- fab!(:non_member_group) { Fabricate(:group) }
+ fab!(:user, :admin)
+ fab!(:non_member_group, :group)
fab!(:topic)
fab!(:category)
- fab!(:category_2) { Fabricate(:category) }
+ fab!(:category_2, :category)
fab!(:post) do
Fabricate(
:post,
@@ -30,11 +30,11 @@ RSpec.describe "AI Post helper", type: :system do
end
let(:topic_page) { PageObjects::Pages::Topic.new }
let(:suggestion_menu) { PageObjects::Components::AiSplitTopicSuggester.new }
- fab!(:video) { Fabricate(:tag) }
- fab!(:music) { Fabricate(:tag) }
- fab!(:cloud) { Fabricate(:tag) }
- fab!(:feedback) { Fabricate(:tag) }
- fab!(:review) { Fabricate(:tag) }
+ fab!(:video, :tag)
+ fab!(:music, :tag)
+ fab!(:cloud, :tag)
+ fab!(:feedback, :tag)
+ fab!(:review, :tag)
fab!(:embedding_definition)
before do
diff --git a/plugins/discourse-ai/spec/system/embeddings/semantic_search_spec.rb b/plugins/discourse-ai/spec/system/embeddings/semantic_search_spec.rb
index 1da00957eb0..ed340b89cd1 100644
--- a/plugins/discourse-ai/spec/system/embeddings/semantic_search_spec.rb
+++ b/plugins/discourse-ai/spec/system/embeddings/semantic_search_spec.rb
@@ -5,7 +5,7 @@ RSpec.describe "AI Composer helper", type: :system do
let(:query) { "apple_pie" }
let(:hypothetical_post) { "This is an hypothetical post generated from the keyword apple_pie" }
- fab!(:user) { Fabricate(:admin) }
+ fab!(:user, :admin)
fab!(:topic)
fab!(:post) { Fabricate(:post, topic: topic, raw: "Apple pie is a delicious dessert to eat") }
diff --git a/plugins/discourse-ai/spec/system/llms/ai_llm_spec.rb b/plugins/discourse-ai/spec/system/llms/ai_llm_spec.rb
index 8614be50baa..314a44769dd 100644
--- a/plugins/discourse-ai/spec/system/llms/ai_llm_spec.rb
+++ b/plugins/discourse-ai/spec/system/llms/ai_llm_spec.rb
@@ -130,7 +130,7 @@ RSpec.describe "Managing LLM configurations", type: :system do
context "with quotas" do
fab!(:llm_model_1) { Fabricate(:llm_model, name: "claude-2") }
- fab!(:group_1) { Fabricate(:group) }
+ fab!(:group_1, :group)
before { Fabricate(:llm_quota, group: group_1, llm_model: llm_model_1, max_tokens: 1000) }
@@ -172,7 +172,7 @@ RSpec.describe "Managing LLM configurations", type: :system do
end
context "when seeded LLM is present" do
- fab!(:llm_model) { Fabricate(:seeded_model) }
+ fab!(:llm_model, :seeded_model)
it "shows the provider as CDCK in the UI" do
visit "/admin/plugins/discourse-ai/ai-llms"
diff --git a/plugins/discourse-ai/spec/system/summarization/chat_summarization_spec.rb b/plugins/discourse-ai/spec/system/summarization/chat_summarization_spec.rb
index 1d49a3667c0..dcbd71f01fd 100644
--- a/plugins/discourse-ai/spec/system/summarization/chat_summarization_spec.rb
+++ b/plugins/discourse-ai/spec/system/summarization/chat_summarization_spec.rb
@@ -1,9 +1,9 @@
# frozen_string_literal: true
RSpec.describe "Summarize a channel since your last visit", type: :system do
- fab!(:current_user) { Fabricate(:user) }
+ fab!(:current_user, :user)
fab!(:group)
- fab!(:channel) { Fabricate(:chat_channel) }
+ fab!(:channel, :chat_channel)
fab!(:message_1) { Fabricate(:chat_message, chat_channel: channel) }
let(:chat) { PageObjects::Pages::Chat.new }
let(:summarization_result) { "This is a summary" }
diff --git a/plugins/discourse-ai/spec/system/summarization/gists_toggle_spec.rb b/plugins/discourse-ai/spec/system/summarization/gists_toggle_spec.rb
index 94e8b59cdb0..7bfda00befc 100644
--- a/plugins/discourse-ai/spec/system/summarization/gists_toggle_spec.rb
+++ b/plugins/discourse-ai/spec/system/summarization/gists_toggle_spec.rb
@@ -3,7 +3,7 @@
describe "Gists Toggle Functionality", type: :system do
fab!(:admin)
fab!(:group)
- fab!(:topic_with_gist) { Fabricate(:topic) }
+ fab!(:topic_with_gist, :topic)
fab!(:topic_ai_gist) { Fabricate(:topic_ai_gist, target: topic_with_gist) }
before do
diff --git a/plugins/discourse-ai/spec/system/summarization/topic_summarization_spec.rb b/plugins/discourse-ai/spec/system/summarization/topic_summarization_spec.rb
index dd6fc677eaa..12658162b96 100644
--- a/plugins/discourse-ai/spec/system/summarization/topic_summarization_spec.rb
+++ b/plugins/discourse-ai/spec/system/summarization/topic_summarization_spec.rb
@@ -1,7 +1,7 @@
# frozen_string_literal: true
RSpec.describe "Summarize a topic ", type: :system do
- fab!(:current_user) { Fabricate(:user) }
+ fab!(:current_user, :user)
fab!(:group)
fab!(:topic)
fab!(:post) do
diff --git a/plugins/discourse-assign/app/controllers/discourse_assign/assign_controller.rb b/plugins/discourse-assign/app/controllers/discourse_assign/assign_controller.rb
index ddd50e49242..376cd42ab80 100644
--- a/plugins/discourse-assign/app/controllers/discourse_assign/assign_controller.rb
+++ b/plugins/discourse-assign/app/controllers/discourse_assign/assign_controller.rb
@@ -71,7 +71,7 @@ module DiscourseAssign
if assign[:success]
render json: success_json
else
- render json: translate_failure(assign[:reason], assign_to), status: 400
+ render json: translate_failure(assign[:reason], assign_to), status: :bad_request
end
end
diff --git a/plugins/discourse-assign/spec/components/search_spec.rb b/plugins/discourse-assign/spec/components/search_spec.rb
index 18e8582abcd..168ac6fc81a 100644
--- a/plugins/discourse-assign/spec/components/search_spec.rb
+++ b/plugins/discourse-assign/spec/components/search_spec.rb
@@ -3,8 +3,8 @@
require_relative "../support/assign_allowed_group"
describe Search do
- fab!(:user) { Fabricate(:active_user) }
- fab!(:user2) { Fabricate(:user) }
+ fab!(:user, :active_user)
+ fab!(:user2, :user)
before do
SearchIndexer.enable
diff --git a/plugins/discourse-assign/spec/components/topic_query_spec.rb b/plugins/discourse-assign/spec/components/topic_query_spec.rb
index 4f3e44e24ea..ff82c3c7355 100644
--- a/plugins/discourse-assign/spec/components/topic_query_spec.rb
+++ b/plugins/discourse-assign/spec/components/topic_query_spec.rb
@@ -6,9 +6,9 @@ describe TopicQuery do
before { SiteSetting.assign_enabled = true }
fab!(:user)
- fab!(:user2) { Fabricate(:user) }
- fab!(:user3) { Fabricate(:user) }
- fab!(:user4) { Fabricate(:user) }
+ fab!(:user2, :user)
+ fab!(:user3, :user)
+ fab!(:user4, :user)
include_context "with group that is allowed to assign"
diff --git a/plugins/discourse-assign/spec/components/topics_bulk_action_spec.rb b/plugins/discourse-assign/spec/components/topics_bulk_action_spec.rb
index 3e0fdfd2264..acc96d059bd 100644
--- a/plugins/discourse-assign/spec/components/topics_bulk_action_spec.rb
+++ b/plugins/discourse-assign/spec/components/topics_bulk_action_spec.rb
@@ -4,8 +4,8 @@ require_relative "../support/assign_allowed_group"
describe TopicsBulkAction do
fab!(:post)
- fab!(:post1) { Fabricate(:post) }
- fab!(:post2) { Fabricate(:post) }
+ fab!(:post1, :post)
+ fab!(:post2, :post)
before { SiteSetting.assign_enabled = true }
diff --git a/plugins/discourse-assign/spec/integration/assign_spec.rb b/plugins/discourse-assign/spec/integration/assign_spec.rb
index b4afa6d0827..a797baceec4 100644
--- a/plugins/discourse-assign/spec/integration/assign_spec.rb
+++ b/plugins/discourse-assign/spec/integration/assign_spec.rb
@@ -166,7 +166,7 @@ describe "integration tests" do
end
describe "move post" do
- fab!(:old_topic) { Fabricate(:topic) }
+ fab!(:old_topic, :topic)
fab!(:post) { Fabricate(:post, topic: old_topic) }
fab!(:user)
fab!(:assignment) do
diff --git a/plugins/discourse-assign/spec/jobs/regular/unassign_notification_spec.rb b/plugins/discourse-assign/spec/jobs/regular/unassign_notification_spec.rb
index b3fcceda8d7..c3a9afea8ec 100644
--- a/plugins/discourse-assign/spec/jobs/regular/unassign_notification_spec.rb
+++ b/plugins/discourse-assign/spec/jobs/regular/unassign_notification_spec.rb
@@ -2,11 +2,11 @@
RSpec.describe Jobs::UnassignNotification do
describe "#execute" do
- fab!(:user1) { Fabricate(:user) }
- fab!(:user2) { Fabricate(:user) }
+ fab!(:user1, :user)
+ fab!(:user2, :user)
fab!(:topic)
fab!(:post) { Fabricate(:post, topic: topic) }
- fab!(:pm_post) { Fabricate(:private_message_post) }
+ fab!(:pm_post, :private_message_post)
fab!(:pm) { pm_post.topic }
fab!(:assign_allowed_group) { Group.find_by(name: "staff") }
@@ -58,7 +58,7 @@ RSpec.describe Jobs::UnassignNotification do
describe "Group" do
fab!(:assign_allowed_group) { Group.find_by(name: "staff") }
- fab!(:user3) { Fabricate(:user) }
+ fab!(:user3, :user)
fab!(:group)
fab!(:assignment) do
Fabricate(:topic_assignment, topic: topic, assigned_to: group, assigned_by_user: user1)
diff --git a/plugins/discourse-assign/spec/jobs/scheduled/enqueue_reminders_spec.rb b/plugins/discourse-assign/spec/jobs/scheduled/enqueue_reminders_spec.rb
index cf2fa2bb382..b7e9e3696a1 100644
--- a/plugins/discourse-assign/spec/jobs/scheduled/enqueue_reminders_spec.rb
+++ b/plugins/discourse-assign/spec/jobs/scheduled/enqueue_reminders_spec.rb
@@ -1,7 +1,7 @@
# frozen_string_literal: true
RSpec.describe Jobs::EnqueueReminders do
- fab!(:assign_allowed_group) { Fabricate(:group) }
+ fab!(:assign_allowed_group, :group)
fab!(:user) { Fabricate(:user, groups: [assign_allowed_group]) }
before do
@@ -58,11 +58,11 @@ RSpec.describe Jobs::EnqueueReminders do
user.custom_fields[
PendingAssignsReminder::REMINDERS_FREQUENCY
] = RemindAssignsFrequencySiteSettings::DAILY_MINUTES
- user.custom_fields[PendingAssignsReminder::REMINDED_AT] = 1.days.ago +
+ user.custom_fields[PendingAssignsReminder::REMINDED_AT] = 1.day.ago +
(Jobs::EnqueueReminders::REMINDER_BUFFER_MINUTES - 1)
user.save
- assign_multiple_tasks_to(user, assigned_on: 2.day.ago)
+ assign_multiple_tasks_to(user, assigned_on: 2.days.ago)
assert_reminders_enqueued(1)
end
@@ -70,7 +70,7 @@ RSpec.describe Jobs::EnqueueReminders do
it "does not enqueue a reminder if it's too soon" do
user.upsert_custom_fields(
PendingAssignsReminder::REMINDED_AT =>
- 1.days.ago + Jobs::EnqueueReminders::REMINDER_BUFFER_MINUTES,
+ 1.day.ago + Jobs::EnqueueReminders::REMINDER_BUFFER_MINUTES,
)
assign_multiple_tasks_to(user)
diff --git a/plugins/discourse-assign/spec/lib/assigner_spec.rb b/plugins/discourse-assign/spec/lib/assigner_spec.rb
index 9c291f33a3f..98671dc1fd7 100644
--- a/plugins/discourse-assign/spec/lib/assigner_spec.rb
+++ b/plugins/discourse-assign/spec/lib/assigner_spec.rb
@@ -561,8 +561,8 @@ RSpec.describe Assigner do
end
describe "assign_self_regex" do
- fab!(:me) { Fabricate(:admin) }
- fab!(:op) { Fabricate(:post) }
+ fab!(:me, :admin)
+ fab!(:op, :post)
fab!(:reply) do
Fabricate(:post, topic: op.topic, user: me, raw: "Will fix. Added to my list ;)")
end
@@ -602,9 +602,9 @@ RSpec.describe Assigner do
end
describe "assign_other_regex" do
- fab!(:me) { Fabricate(:admin) }
- fab!(:other) { Fabricate(:admin) }
- fab!(:op) { Fabricate(:post) }
+ fab!(:me, :admin)
+ fab!(:other, :admin)
+ fab!(:op, :post)
fab!(:reply) do
Fabricate(
:post,
diff --git a/plugins/discourse-assign/spec/lib/random_assign_utils_spec.rb b/plugins/discourse-assign/spec/lib/random_assign_utils_spec.rb
index d6670eb9a9e..b45cb2e21a5 100644
--- a/plugins/discourse-assign/spec/lib/random_assign_utils_spec.rb
+++ b/plugins/discourse-assign/spec/lib/random_assign_utils_spec.rb
@@ -18,12 +18,12 @@ RSpec.describe RandomAssignUtils do
describe ".automation_script!" do
subject(:auto_assign) { described_class.automation_script!(ctx, fields, automation) }
- fab!(:post_1) { Fabricate(:post) }
+ fab!(:post_1, :post)
fab!(:topic_1) { post_1.topic }
- fab!(:group_1) { Fabricate(:group) }
- fab!(:user_1) { Fabricate(:user) }
- fab!(:user_2) { Fabricate(:user) }
- fab!(:user_3) { Fabricate(:user) }
+ fab!(:group_1, :group)
+ fab!(:user_1, :user)
+ fab!(:user_2, :user)
+ fab!(:user_3, :user)
let(:ctx) { {} }
let(:fields) { {} }
diff --git a/plugins/discourse-assign/spec/lib/topic_query_spec.rb b/plugins/discourse-assign/spec/lib/topic_query_spec.rb
index 4c152285d97..d77ad3d0d07 100644
--- a/plugins/discourse-assign/spec/lib/topic_query_spec.rb
+++ b/plugins/discourse-assign/spec/lib/topic_query_spec.rb
@@ -5,7 +5,7 @@ require "topic_view"
describe TopicQuery do
fab!(:user)
fab!(:admin)
- fab!(:other_admin) { Fabricate(:admin) }
+ fab!(:other_admin, :admin)
fab!(:user_pm) { Fabricate(:private_message_topic, user: user) }
fab!(:admin_pm) { Fabricate(:private_message_topic, user: admin) }
diff --git a/plugins/discourse-assign/spec/models/reviewable_spec.rb b/plugins/discourse-assign/spec/models/reviewable_spec.rb
index 59eed8b494c..7bf19dc6a9f 100644
--- a/plugins/discourse-assign/spec/models/reviewable_spec.rb
+++ b/plugins/discourse-assign/spec/models/reviewable_spec.rb
@@ -3,8 +3,8 @@
describe Reviewable do
fab!(:user)
fab!(:admin)
- fab!(:post1) { Fabricate(:post) }
- fab!(:post2) { Fabricate(:post) }
+ fab!(:post1, :post)
+ fab!(:post2, :post)
fab!(:reviewable1) { Fabricate(:reviewable_flagged_post, target: post1) }
fab!(:reviewable2) { Fabricate(:reviewable_flagged_post, target: post2) }
diff --git a/plugins/discourse-assign/spec/requests/assign_controller_spec.rb b/plugins/discourse-assign/spec/requests/assign_controller_spec.rb
index 6ff907d435f..85dd122b778 100644
--- a/plugins/discourse-assign/spec/requests/assign_controller_spec.rb
+++ b/plugins/discourse-assign/spec/requests/assign_controller_spec.rb
@@ -9,8 +9,8 @@ RSpec.describe DiscourseAssign::AssignController do
end
fab!(:staff_group) { Group.find_by(name: "staff") }
- fab!(:non_allowed_group) { Fabricate(:group) }
- fab!(:allowed_group) { Fabricate(:group) }
+ fab!(:non_allowed_group, :group)
+ fab!(:allowed_group, :group)
fab!(:admin)
fab!(:allowed_user) { Fabricate(:user, username: "mads", name: "Mads", groups: [allowed_group]) }
@@ -339,8 +339,8 @@ RSpec.describe DiscourseAssign::AssignController do
describe "#assigned" do
fab!(:topic1) { Fabricate(:topic, bumped_at: 1.hour.from_now) }
- fab!(:topic2) { Fabricate(:topic, bumped_at: 2.hour.from_now) }
- fab!(:topic3) { Fabricate(:topic, bumped_at: 3.hour.from_now) }
+ fab!(:topic2) { Fabricate(:topic, bumped_at: 2.hours.from_now) }
+ fab!(:topic3) { Fabricate(:topic, bumped_at: 3.hours.from_now) }
fab!(:assignments) do
Fabricate(
diff --git a/plugins/discourse-assign/spec/requests/list_controller_spec.rb b/plugins/discourse-assign/spec/requests/list_controller_spec.rb
index 98870df4286..ced922c1132 100644
--- a/plugins/discourse-assign/spec/requests/list_controller_spec.rb
+++ b/plugins/discourse-assign/spec/requests/list_controller_spec.rb
@@ -8,8 +8,8 @@ describe ListController do
SiteSetting.assign_enabled = true
end
- fab!(:user) { Fabricate(:active_user) }
- fab!(:user2) { Fabricate(:user) }
+ fab!(:user, :active_user)
+ fab!(:user2, :user)
let(:admin) { Fabricate(:admin) }
let(:post) { Fabricate(:post) }
@@ -48,9 +48,9 @@ describe ListController do
describe "#group_topics_assigned" do
include_context "with group that is allowed to assign"
- fab!(:post1) { Fabricate(:post) }
- fab!(:post2) { Fabricate(:post) }
- fab!(:post3) { Fabricate(:post) }
+ fab!(:post1, :post)
+ fab!(:post2, :post)
+ fab!(:post3, :post)
fab!(:topic) { post3.topic }
fab!(:topic1) { post1.topic }
fab!(:topic2) { post2.topic }
@@ -110,9 +110,9 @@ describe ListController do
describe "#sorting messages_assigned and group_topics_assigned" do
include_context "with group that is allowed to assign"
- fab!(:post1) { Fabricate(:post) }
- fab!(:post2) { Fabricate(:post) }
- fab!(:post3) { Fabricate(:post) }
+ fab!(:post1, :post)
+ fab!(:post2, :post)
+ fab!(:post3, :post)
fab!(:topic1) { post1.topic }
fab!(:topic2) { post2.topic }
fab!(:topic3) { post3.topic }
@@ -131,7 +131,7 @@ describe ListController do
it "group_topics_assigned returns sorted topicsList" do
topic1.bumped_at = Time.now
topic2.bumped_at = 1.day.ago
- topic3.bumped_at = 3.day.ago
+ topic3.bumped_at = 3.days.ago
topic1.views = 3
topic2.views = 5
@@ -178,7 +178,7 @@ describe ListController do
it "messages_assigned returns sorted topicsList" do
topic1.bumped_at = Time.now
- topic3.bumped_at = 3.day.ago
+ topic3.bumped_at = 3.days.ago
topic1.views = 3
topic3.views = 1
@@ -224,9 +224,9 @@ describe ListController do
describe "filtering of topics as per parameter" do
include_context "with group that is allowed to assign"
- fab!(:post1) { Fabricate(:post) }
- fab!(:post2) { Fabricate(:post) }
- fab!(:post3) { Fabricate(:post) }
+ fab!(:post1, :post)
+ fab!(:post2, :post)
+ fab!(:post3, :post)
fab!(:topic1) { post1.topic }
fab!(:topic2) { post2.topic }
fab!(:topic3) { post3.topic }
@@ -307,8 +307,8 @@ describe ListController do
describe "#messages_assigned" do
include_context "with group that is allowed to assign"
- fab!(:post1) { Fabricate(:post) }
- fab!(:post2) { Fabricate(:post) }
+ fab!(:post1, :post)
+ fab!(:post2, :post)
before do
add_to_assign_allowed_group(user)
@@ -360,9 +360,9 @@ describe ListController do
fab!(:group) { Fabricate(:group, assignable_level: Group::ALIAS_LEVELS[:mods_and_admins]) }
- fab!(:topic_1) { Fabricate(:topic) }
- fab!(:topic_2) { Fabricate(:topic) }
- fab!(:topic_3) { Fabricate(:topic) }
+ fab!(:topic_1, :topic)
+ fab!(:topic_2, :topic)
+ fab!(:topic_3, :topic)
fab!(:post_1) { Fabricate(:post, topic: topic_1) }
fab!(:post_2) { Fabricate(:post, topic: topic_2) }
diff --git a/plugins/discourse-assign/spec/serializers/group_show_serializer_spec.rb b/plugins/discourse-assign/spec/serializers/group_show_serializer_spec.rb
index 313df4d9d4a..a581a54f2dc 100644
--- a/plugins/discourse-assign/spec/serializers/group_show_serializer_spec.rb
+++ b/plugins/discourse-assign/spec/serializers/group_show_serializer_spec.rb
@@ -6,7 +6,7 @@ RSpec.describe GroupShowSerializer do
fab!(:group_user) { Fabricate(:group_user, group: group, user: user) }
fab!(:topic)
fab!(:post) { Fabricate(:post, topic: topic) }
- fab!(:topic2) { Fabricate(:topic) }
+ fab!(:topic2, :topic)
fab!(:post2) { Fabricate(:post, topic: topic2) }
let(:guardian) { Guardian.new(user) }
let(:serializer) { described_class.new(group, scope: guardian) }
diff --git a/plugins/discourse-assign/spec/serializers/suggested_topic_serializer_spec.rb b/plugins/discourse-assign/spec/serializers/suggested_topic_serializer_spec.rb
index 5509c7773e4..05f20584cfa 100644
--- a/plugins/discourse-assign/spec/serializers/suggested_topic_serializer_spec.rb
+++ b/plugins/discourse-assign/spec/serializers/suggested_topic_serializer_spec.rb
@@ -6,7 +6,7 @@ RSpec.describe SuggestedTopicSerializer do
fab!(:group_user) { Fabricate(:group_user, group: group, user: user) }
fab!(:topic)
fab!(:post) { Fabricate(:post, topic: topic) }
- fab!(:topic2) { Fabricate(:topic) }
+ fab!(:topic2, :topic)
fab!(:post2) { Fabricate(:post, topic: topic2) }
fab!(:guardian) { Guardian.new(user) }
fab!(:serializer) { described_class.new(topic, scope: guardian) }
diff --git a/plugins/discourse-assign/spec/system/assign_topic_spec.rb b/plugins/discourse-assign/spec/system/assign_topic_spec.rb
index df466c1f7e3..7a96b74fe2c 100644
--- a/plugins/discourse-assign/spec/system/assign_topic_spec.rb
+++ b/plugins/discourse-assign/spec/system/assign_topic_spec.rb
@@ -3,8 +3,8 @@
describe "Assign | Assigning topics", type: :system do
let(:topic_page) { PageObjects::Pages::Topic.new }
let(:assign_modal) { PageObjects::Modals::Assign.new }
- fab!(:admin1) { Fabricate(:admin) }
- fab!(:admin2) { Fabricate(:admin) }
+ fab!(:admin1, :admin)
+ fab!(:admin2, :admin)
fab!(:topic)
fab!(:post) { Fabricate(:post, topic: topic) }
diff --git a/plugins/discourse-cakeday/spec/integration/cakeday_spec.rb b/plugins/discourse-cakeday/spec/integration/cakeday_spec.rb
index 64961670767..a9bef3c86e7 100644
--- a/plugins/discourse-cakeday/spec/integration/cakeday_spec.rb
+++ b/plugins/discourse-cakeday/spec/integration/cakeday_spec.rb
@@ -35,11 +35,11 @@ describe "Anniversaries and Birthdays" do
freeze_time(time) do
created_at = time - 1.year
- user1 = Fabricate(:user, created_at: created_at - 2.year)
+ user1 = Fabricate(:user, created_at: created_at - 2.years)
user2 = Fabricate(:user, created_at: created_at - 1.day)
user3 = Fabricate(:user, created_at: created_at)
user4 = Fabricate(:user, created_at: created_at + 1.day)
- user5 = Fabricate(:user, created_at: created_at + 2.day)
+ user5 = Fabricate(:user, created_at: created_at + 2.days)
user6 = Fabricate(:user, created_at: created_at + 1.year)
hidden_user = Fabricate(:user, created_at: created_at - 1.year)
diff --git a/plugins/discourse-calendar/app/controllers/discourse_post_event/events_controller.rb b/plugins/discourse-calendar/app/controllers/discourse_post_event/events_controller.rb
index 145a51af11e..323a1074843 100644
--- a/plugins/discourse-calendar/app/controllers/discourse_post_event/events_controller.rb
+++ b/plugins/discourse-calendar/app/controllers/discourse_post_event/events_controller.rb
@@ -79,14 +79,14 @@ module DiscoursePostEvent
failed_json.merge(
errors: [I18n.t("discourse_post_event.errors.bulk_invite.error")],
),
- status: 422
+ status: :unprocessable_entity
end
rescue StandardError
render json:
failed_json.merge(
errors: [I18n.t("discourse_post_event.errors.bulk_invite.error")],
),
- status: 422
+ status: :unprocessable_entity
end
end
end
@@ -112,7 +112,7 @@ module DiscoursePostEvent
failed_json.merge(
errors: [I18n.t("discourse_post_event.errors.bulk_invite.error")],
),
- status: 422
+ status: :unprocessable_entity
end
end
diff --git a/plugins/discourse-calendar/app/models/discourse_post_event/event.rb b/plugins/discourse-calendar/app/models/discourse_post_event/event.rb
index 703b5219e05..c8ac02cf805 100644
--- a/plugins/discourse-calendar/app/models/discourse_post_event/event.rb
+++ b/plugins/discourse-calendar/app/models/discourse_post_event/event.rb
@@ -19,9 +19,9 @@ module DiscoursePostEvent
scope :visible, -> { where(deleted_at: nil) }
scope :open, -> { where(closed: false) }
+ before_save :chat_channel_sync
after_commit :destroy_topic_custom_field, on: %i[destroy]
after_commit :create_or_update_event_date, on: %i[create update]
- before_save :chat_channel_sync
validate :raw_invitees_are_groups
validates :original_starts_at, presence: true
diff --git a/plugins/discourse-calendar/db/migrate/20201111005205_move_data_to_event_dates.rb b/plugins/discourse-calendar/db/migrate/20201111005205_move_data_to_event_dates.rb
index a9fadab48ba..e61411fa8fd 100644
--- a/plugins/discourse-calendar/db/migrate/20201111005205_move_data_to_event_dates.rb
+++ b/plugins/discourse-calendar/db/migrate/20201111005205_move_data_to_event_dates.rb
@@ -86,7 +86,7 @@ class MoveDataToEventDates < ActiveRecord::Migration[6.0]
next if !extracted_event
finished_at = (event.original_ends_at < Time.current) && event.original_ends_at
- event_will_start_sent_at = event.original_starts_at - 1.hours
+ event_will_start_sent_at = event.original_starts_at - 1.hour
event_started_sent_at = event.original_starts_at
reminder_counter = due_reminders(event).length
diff --git a/plugins/discourse-calendar/lib/discourse_post_event/rrule_generator.rb b/plugins/discourse-calendar/lib/discourse_post_event/rrule_generator.rb
index d794b15c426..b9015a54e14 100644
--- a/plugins/discourse-calendar/lib/discourse_post_event/rrule_generator.rb
+++ b/plugins/discourse-calendar/lib/discourse_post_event/rrule_generator.rb
@@ -16,7 +16,7 @@ class RRuleGenerator
::RRule::Rule
.new(stringify(rrule), dtstart: starts_at, tzid: timezone)
- .between(Time.current, Time.current + 14.months)
+ .between(Time.current, 14.months.from_now)
.first(RRuleConfigurator.how_many_recurring_events(recurrence:, max_years:))
end
diff --git a/plugins/discourse-calendar/lib/holiday_status.rb b/plugins/discourse-calendar/lib/holiday_status.rb
index c9dc6300b99..7f9da028eeb 100644
--- a/plugins/discourse-calendar/lib/holiday_status.rb
+++ b/plugins/discourse-calendar/lib/holiday_status.rb
@@ -26,8 +26,7 @@ module DiscourseCalendar
end
def self.emoji_name
- emoji = SiteSetting.holiday_status_emoji
- emoji.blank? ? "date" : emoji
+ SiteSetting.holiday_status_emoji.presence || "date"
end
end
end
diff --git a/plugins/discourse-calendar/spec/integration/curently_away_report_spec.rb b/plugins/discourse-calendar/spec/integration/curently_away_report_spec.rb
index a5a7aa8d370..b7e5d14282a 100644
--- a/plugins/discourse-calendar/spec/integration/curently_away_report_spec.rb
+++ b/plugins/discourse-calendar/spec/integration/curently_away_report_spec.rb
@@ -1,9 +1,9 @@
# frozen_string_literal: true
describe "currently_away report" do
- fab!(:user_1) { Fabricate(:user) }
- fab!(:user_2) { Fabricate(:user) }
- fab!(:group_1) { Fabricate(:group) }
+ fab!(:user_1, :user)
+ fab!(:user_2, :user)
+ fab!(:group_1, :group)
before { group_1.add(user_1) }
diff --git a/plugins/discourse-calendar/spec/jobs/regular/discourse_post_event/send_reminder_spec.rb b/plugins/discourse-calendar/spec/jobs/regular/discourse_post_event/send_reminder_spec.rb
index 8d2e2fe46cb..e882488d49a 100644
--- a/plugins/discourse-calendar/spec/jobs/regular/discourse_post_event/send_reminder_spec.rb
+++ b/plugins/discourse-calendar/spec/jobs/regular/discourse_post_event/send_reminder_spec.rb
@@ -363,7 +363,7 @@ describe Jobs::DiscoursePostEventSendReminder do
def advance_to_next_occurrence
freeze_time(recurring_event.original_starts_at + 1.day + 1.hour)
- recurring_event.event_dates.pending.update_all(finished_at: Time.current - 1.hour)
+ recurring_event.event_dates.pending.update_all(finished_at: 1.hour.ago)
recurring_event.set_next_date
end
diff --git a/plugins/discourse-calendar/spec/jobs/scheduled/monitor_event_dates_spec.rb b/plugins/discourse-calendar/spec/jobs/scheduled/monitor_event_dates_spec.rb
index a240873ed06..2d3b0f1fad7 100644
--- a/plugins/discourse-calendar/spec/jobs/scheduled/monitor_event_dates_spec.rb
+++ b/plugins/discourse-calendar/spec/jobs/scheduled/monitor_event_dates_spec.rb
@@ -3,9 +3,9 @@
describe Jobs::DiscourseCalendar::MonitorEventDates do
subject(:job) { described_class.new }
- fab!(:post_1) { Fabricate(:post) }
- fab!(:post_2) { Fabricate(:post) }
- fab!(:post_3) { Fabricate(:post) }
+ fab!(:post_1, :post)
+ fab!(:post_2, :post)
+ fab!(:post_3, :post)
fab!(:past_event) do
Fabricate(
:event,
@@ -188,7 +188,7 @@ describe Jobs::DiscourseCalendar::MonitorEventDates do
end
it "doesn’t list events with invalid reminders" do
- freeze_time(7.days.after - 1.minutes)
+ freeze_time(7.days.after - 1.minute)
expect(job.due_reminders(invalid_event.event_dates.first)).to be_blank
expect(job.due_reminders(valid_event.event_dates.first).length).to eq(1)
diff --git a/plugins/discourse-calendar/spec/jobs/scheduled/update_holiday_usernames_spec.rb b/plugins/discourse-calendar/spec/jobs/scheduled/update_holiday_usernames_spec.rb
index db3e05e690e..a82536b6f2f 100644
--- a/plugins/discourse-calendar/spec/jobs/scheduled/update_holiday_usernames_spec.rb
+++ b/plugins/discourse-calendar/spec/jobs/scheduled/update_holiday_usernames_spec.rb
@@ -150,7 +150,7 @@ describe Jobs::DiscourseCalendar::UpdateHolidayUsernames do
custom_status[:ends_at],
)
- freeze_time tomorrow + 2.day
+ freeze_time tomorrow + 2.days
job.execute(nil)
post.user.reload
diff --git a/plugins/discourse-calendar/spec/lib/discourse_post_event/event_finder_spec.rb b/plugins/discourse-calendar/spec/lib/discourse_post_event/event_finder_spec.rb
index 375e50a88e1..9844cf8ba1e 100644
--- a/plugins/discourse-calendar/spec/lib/discourse_post_event/event_finder_spec.rb
+++ b/plugins/discourse-calendar/spec/lib/discourse_post_event/event_finder_spec.rb
@@ -1,7 +1,7 @@
# frozen_string_literal: true
describe DiscoursePostEvent::EventFinder do
- fab!(:current_user) { Fabricate(:user) }
+ fab!(:current_user, :user)
fab!(:user)
subject(:finder) { DiscoursePostEvent::EventFinder }
@@ -13,7 +13,7 @@ describe DiscoursePostEvent::EventFinder do
end
describe "by attending user" do
- fab!(:attending_user) { Fabricate(:user) }
+ fab!(:attending_user, :user)
fab!(:public_event) { Fabricate(:event, status: DiscoursePostEvent::Event.statuses[:public]) }
fab!(:private_event) { Fabricate(:event, status: DiscoursePostEvent::Event.statuses[:private]) }
fab!(:another_event) { Fabricate(:event, status: DiscoursePostEvent::Event.statuses[:public]) }
diff --git a/plugins/discourse-calendar/spec/models/calendar_event_spec.rb b/plugins/discourse-calendar/spec/models/calendar_event_spec.rb
index a5c2262e625..fcef2e56cc7 100644
--- a/plugins/discourse-calendar/spec/models/calendar_event_spec.rb
+++ b/plugins/discourse-calendar/spec/models/calendar_event_spec.rb
@@ -166,8 +166,8 @@ describe CalendarEvent do
CalendarEvent.create!(
topic_id: topic.id,
user_id: user.id,
- start_date: Time.zone.now - 1.day,
- end_date: Time.zone.now + 1.day,
+ start_date: 1.day.ago,
+ end_date: 1.day.from_now,
)
UserDestroyer.new(Discourse.system_user).destroy(user)
diff --git a/plugins/discourse-calendar/spec/models/discourse_post_event/event_spec.rb b/plugins/discourse-calendar/spec/models/discourse_post_event/event_spec.rb
index bb4dad2ac5d..5e1fc76995b 100644
--- a/plugins/discourse-calendar/spec/models/discourse_post_event/event_spec.rb
+++ b/plugins/discourse-calendar/spec/models/discourse_post_event/event_spec.rb
@@ -33,7 +33,7 @@ describe DiscoursePostEvent::Event do
let(:event) do
DiscoursePostEvent::Event.create!(
id: first_post.id,
- original_starts_at: Time.now + 1.hours,
+ original_starts_at: Time.now + 1.hour,
original_ends_at: Time.now + 2.hours,
)
end
@@ -277,7 +277,7 @@ describe DiscoursePostEvent::Event do
post_event =
DiscoursePostEvent::Event.create!(
original_starts_at: 2.hours.ago,
- original_ends_at: 1.hours.ago,
+ original_ends_at: 1.hour.ago,
post: first_post,
)
@@ -337,10 +337,7 @@ describe DiscoursePostEvent::Event do
context "when starts_at > current date" do
it "is not ongoing" do
post_event =
- DiscoursePostEvent::Event.create!(
- original_starts_at: 1.hours.from_now,
- post: first_post,
- )
+ DiscoursePostEvent::Event.create!(original_starts_at: 1.hour.from_now, post: first_post)
expect(post_event.ongoing?).to be(false)
end
@@ -653,9 +650,9 @@ describe DiscoursePostEvent::Event do
Fabricate(
:event,
recurrence: "every_week",
- recurrence_until: Time.current - 1.day,
- original_starts_at: Time.current - 1.week,
- original_ends_at: Time.current - 1.week + 2.hours,
+ recurrence_until: 1.day.ago,
+ original_starts_at: 1.week.ago,
+ original_ends_at: 1.week.ago + 2.hours,
)
event
end
@@ -701,8 +698,8 @@ describe DiscoursePostEvent::Event do
:event,
recurrence: "every_week",
recurrence_until: nil,
- original_starts_at: Time.current - 1.week,
- original_ends_at: Time.current - 1.week + 2.hours,
+ original_starts_at: 1.week.ago,
+ original_ends_at: 1.week.ago + 2.hours,
)
end
@@ -720,8 +717,8 @@ describe DiscoursePostEvent::Event do
Fabricate(
:event,
recurrence: nil,
- original_starts_at: Time.current - 1.week,
- original_ends_at: Time.current - 1.week + 2.hours,
+ original_starts_at: 1.week.ago,
+ original_ends_at: 1.week.ago + 2.hours,
)
end
diff --git a/plugins/discourse-calendar/spec/models/topic_query_spec.rb b/plugins/discourse-calendar/spec/models/topic_query_spec.rb
index a000df9a35c..757a63babaf 100644
--- a/plugins/discourse-calendar/spec/models/topic_query_spec.rb
+++ b/plugins/discourse-calendar/spec/models/topic_query_spec.rb
@@ -3,7 +3,7 @@
describe TopicQuery do
describe "sorts events" do
fab!(:user) { Fabricate(:user, admin: true) }
- fab!(:notified_user) { Fabricate(:user) }
+ fab!(:notified_user, :user)
fab!(:topic_1) { Fabricate(:topic, user: user) }
fab!(:topic_2) { Fabricate(:topic, user: user) }
fab!(:topic_3) { Fabricate(:topic, user: user) }
@@ -23,7 +23,7 @@ describe TopicQuery do
fab!(:future_event_2) do
DiscoursePostEvent::Event.create!(
id: post_2.id,
- original_starts_at: Time.now + 1.hours,
+ original_starts_at: Time.now + 1.hour,
original_ends_at: Time.now + 2.hours,
)
end
diff --git a/plugins/discourse-calendar/spec/requests/admin/admin_holidays_controller_spec.rb b/plugins/discourse-calendar/spec/requests/admin/admin_holidays_controller_spec.rb
index bea9d4978ee..98d01a3128c 100644
--- a/plugins/discourse-calendar/spec/requests/admin/admin_holidays_controller_spec.rb
+++ b/plugins/discourse-calendar/spec/requests/admin/admin_holidays_controller_spec.rb
@@ -3,7 +3,7 @@
module Admin::DiscourseCalendar
describe AdminHolidaysController do
fab!(:admin) { Fabricate(:user, admin: true) }
- fab!(:member) { Fabricate(:user) }
+ fab!(:member, :user)
before { SiteSetting.calendar_enabled = calendar_enabled }
diff --git a/plugins/discourse-calendar/spec/requests/invitees_controller_spec.rb b/plugins/discourse-calendar/spec/requests/invitees_controller_spec.rb
index cfcbaa36d77..a587e82c70a 100644
--- a/plugins/discourse-calendar/spec/requests/invitees_controller_spec.rb
+++ b/plugins/discourse-calendar/spec/requests/invitees_controller_spec.rb
@@ -303,8 +303,8 @@ module DiscoursePostEvent
context "when event has max attendees and is full" do
fab!(:post_2) { create_post(user: Fabricate(:admin), category: Fabricate(:category)) }
- fab!(:user_a) { Fabricate(:user) }
- fab!(:user_b) { Fabricate(:user) }
+ fab!(:user_a, :user)
+ fab!(:user_b, :user)
fab!(:post_event_full) do
pe = Fabricate(:event, post: post_2, max_attendees: 1)
pe.create_invitees([{ user_id: user_a.id, status: Invitee.statuses[:going] }])
diff --git a/plugins/discourse-calendar/spec/requests/sort_event_topics_spec.rb b/plugins/discourse-calendar/spec/requests/sort_event_topics_spec.rb
index 233cec1750b..42c041386eb 100644
--- a/plugins/discourse-calendar/spec/requests/sort_event_topics_spec.rb
+++ b/plugins/discourse-calendar/spec/requests/sort_event_topics_spec.rb
@@ -9,7 +9,7 @@ RSpec.describe ListController do
end
fab!(:post_1) { Fabricate(:post, topic: topic_1) }
fab!(:post_event_1) do
- Fabricate(:event, name: "event1", post: post_1, original_starts_at: 1.days.from_now)
+ Fabricate(:event, name: "event1", post: post_1, original_starts_at: 1.day.from_now)
end
fab!(:topic_2) do
Fabricate(:topic, title: "This is the second topic", user: user, category: category)
diff --git a/plugins/discourse-calendar/spec/serializers/discourse_post_event/event_serializer_spec.rb b/plugins/discourse-calendar/spec/serializers/discourse_post_event/event_serializer_spec.rb
index c6a615073b0..e113fa34ff9 100644
--- a/plugins/discourse-calendar/spec/serializers/discourse_post_event/event_serializer_spec.rb
+++ b/plugins/discourse-calendar/spec/serializers/discourse_post_event/event_serializer_spec.rb
@@ -16,8 +16,8 @@ describe DiscoursePostEvent::EventSerializer do
Fabricate(:event, post: post, status: DiscoursePostEvent::Event.statuses[:private])
end
- fab!(:invitee_1) { Fabricate(:user) }
- fab!(:invitee_2) { Fabricate(:user) }
+ fab!(:invitee_1, :user)
+ fab!(:invitee_2, :user)
fab!(:group_1) do
Fabricate(:group).tap do |g|
g.add(invitee_1)
diff --git a/plugins/discourse-calendar/spec/system/post_event_spec.rb b/plugins/discourse-calendar/spec/system/post_event_spec.rb
index 72f60a119e6..613db800ce1 100644
--- a/plugins/discourse-calendar/spec/system/post_event_spec.rb
+++ b/plugins/discourse-calendar/spec/system/post_event_spec.rb
@@ -2,7 +2,7 @@
describe "Post event", type: :system do
fab!(:admin)
- fab!(:user) { Fabricate(:admin) }
+ fab!(:user, :admin)
fab!(:group)
let(:composer) { PageObjects::Components::Composer.new }
@@ -186,7 +186,7 @@ describe "Post event", type: :system do
# - - element is visible, enabled and stable
visit "/new-topic"
title = "My upcoming l33t event"
- tomorrow = (Time.zone.now + 1.day).strftime("%Y-%m-%d")
+ tomorrow = (1.day.from_now).strftime("%Y-%m-%d")
composer.fill_title(title)
composer.fill_content <<~MD
[event start="#{tomorrow} 13:37" status="public"]
@@ -294,8 +294,8 @@ describe "Post event", type: :system do
)
end
- fab!(:invitable_user_1) { Fabricate(:user) }
- fab!(:invitable_user_2) { Fabricate(:user) }
+ fab!(:invitable_user_1, :user)
+ fab!(:invitable_user_2, :user)
it "can invite users to an event" do
visit(post.topic.url)
diff --git a/plugins/discourse-chat-integration/app/controllers/chat_controller.rb b/plugins/discourse-chat-integration/app/controllers/chat_controller.rb
index ef0804f8377..e850cd564e6 100644
--- a/plugins/discourse-chat-integration/app/controllers/chat_controller.rb
+++ b/plugins/discourse-chat-integration/app/controllers/chat_controller.rb
@@ -36,13 +36,13 @@ class DiscourseChatIntegration::ChatController < ApplicationController
render json: success_json
rescue Discourse::InvalidParameters, ActiveRecord::RecordNotFound => e
- render json: { errors: [e.message] }, status: 422
+ render json: { errors: [e.message] }, status: :unprocessable_entity
rescue DiscourseChatIntegration::ProviderError => e
Rails.logger.error("Test provider failed #{e.info}")
if e.info.key?(:error_key) && !e.info[:error_key].nil?
- render json: { error_key: e.info[:error_key] }, status: 422
+ render json: { error_key: e.info[:error_key] }, status: :unprocessable_entity
else
- render json: { errors: [e.message] }, status: 422
+ render json: { errors: [e.message] }, status: :unprocessable_entity
end
end
end
@@ -84,7 +84,7 @@ class DiscourseChatIntegration::ChatController < ApplicationController
render_serialized channel, DiscourseChatIntegration::ChannelSerializer, root: "channel"
rescue Discourse::InvalidParameters => e
- render json: { errors: [e.message] }, status: 422
+ render json: { errors: [e.message] }, status: :unprocessable_entity
end
end
@@ -104,7 +104,7 @@ class DiscourseChatIntegration::ChatController < ApplicationController
render_serialized channel, DiscourseChatIntegration::ChannelSerializer, root: "channel"
rescue Discourse::InvalidParameters => e
- render json: { errors: [e.message] }, status: 422
+ render json: { errors: [e.message] }, status: :unprocessable_entity
end
end
@@ -126,7 +126,7 @@ class DiscourseChatIntegration::ChatController < ApplicationController
render_serialized rule, DiscourseChatIntegration::RuleSerializer, root: "rule"
rescue Discourse::InvalidParameters => e
- render json: { errors: [e.message] }, status: 422
+ render json: { errors: [e.message] }, status: :unprocessable_entity
end
end
@@ -139,7 +139,7 @@ class DiscourseChatIntegration::ChatController < ApplicationController
render_serialized rule, DiscourseChatIntegration::RuleSerializer, root: "rule"
rescue Discourse::InvalidParameters => e
- render json: { errors: [e.message] }, status: 422
+ render json: { errors: [e.message] }, status: :unprocessable_entity
end
end
diff --git a/plugins/discourse-chat-integration/lib/discourse_chat_integration/provider/slack/slack_provider.rb b/plugins/discourse-chat-integration/lib/discourse_chat_integration/provider/slack/slack_provider.rb
index 70ece080885..386509aeecf 100644
--- a/plugins/discourse-chat-integration/lib/discourse_chat_integration/provider/slack/slack_provider.rb
+++ b/plugins/discourse-chat-integration/lib/discourse_chat_integration/provider/slack/slack_provider.rb
@@ -57,11 +57,7 @@ module DiscourseChatIntegration::Provider::SlackProvider
end
slack_username =
- if SiteSetting.chat_integration_slack_username.present?
- SiteSetting.chat_integration_slack_username
- else
- SiteSetting.title || "Discourse"
- end
+ SiteSetting.chat_integration_slack_username.presence || SiteSetting.title || "Discourse"
message = { channel: channel, username: slack_username, icon_url: icon_url, attachments: [] }
@@ -108,11 +104,7 @@ module DiscourseChatIntegration::Provider::SlackProvider
end
slack_username =
- if SiteSetting.chat_integration_slack_username.present?
- SiteSetting.chat_integration_slack_username
- else
- SiteSetting.title || "Discourse"
- end
+ SiteSetting.chat_integration_slack_username.presence || SiteSetting.title || "Discourse"
message = {
channel: "##{channel_name}",
diff --git a/plugins/discourse-data-explorer/app/controllers/discourse_data_explorer/query_controller.rb b/plugins/discourse-data-explorer/app/controllers/discourse_data_explorer/query_controller.rb
index dc0fc1fc08f..b747ef6b96d 100644
--- a/plugins/discourse-data-explorer/app/controllers/discourse_data_explorer/query_controller.rb
+++ b/plugins/discourse-data-explorer/app/controllers/discourse_data_explorer/query_controller.rb
@@ -184,7 +184,7 @@ module DiscourseDataExplorer
err_msg = "#{err_class}: #{err_msg}"
end
- render json: { success: false, errors: [err_msg] }, status: 422
+ render json: { success: false, errors: [err_msg] }, status: :unprocessable_entity
else
content_disposition =
"attachment; filename=#{query.slug}@#{Slug.for(Discourse.current_hostname, "discourse")}-#{Date.today}.dcqresult"
diff --git a/plugins/discourse-data-explorer/spec/automation/recurring_data_explorer_result_pm_spec.rb b/plugins/discourse-data-explorer/spec/automation/recurring_data_explorer_result_pm_spec.rb
index 279a47a5bb7..29eeb749c1a 100644
--- a/plugins/discourse-data-explorer/spec/automation/recurring_data_explorer_result_pm_spec.rb
+++ b/plugins/discourse-data-explorer/spec/automation/recurring_data_explorer_result_pm_spec.rb
@@ -4,9 +4,9 @@ describe "RecurringDataExplorerResultPM" do
fab!(:admin)
fab!(:user)
- fab!(:another_user) { Fabricate(:user) }
- fab!(:group_user) { Fabricate(:user) }
- fab!(:not_allowed_user) { Fabricate(:user) }
+ fab!(:another_user, :user)
+ fab!(:group_user, :user)
+ fab!(:not_allowed_user, :user)
fab!(:group) { Fabricate(:group, users: [user, another_user]) }
fab!(:another_group) { Fabricate(:group, users: [group_user]) }
diff --git a/plugins/discourse-data-explorer/spec/automation/recurring_data_explorer_result_topic_spec.rb b/plugins/discourse-data-explorer/spec/automation/recurring_data_explorer_result_topic_spec.rb
index 55141a48e9e..2263f8d19f0 100644
--- a/plugins/discourse-data-explorer/spec/automation/recurring_data_explorer_result_topic_spec.rb
+++ b/plugins/discourse-data-explorer/spec/automation/recurring_data_explorer_result_topic_spec.rb
@@ -4,9 +4,9 @@ describe "RecurringDataExplorerResultTopic" do
fab!(:admin)
fab!(:user)
- fab!(:another_user) { Fabricate(:user) }
- fab!(:group_user) { Fabricate(:user) }
- fab!(:not_allowed_user) { Fabricate(:user) }
+ fab!(:another_user, :user)
+ fab!(:group_user, :user)
+ fab!(:not_allowed_user, :user)
fab!(:topic)
fab!(:group) { Fabricate(:group, users: [user, another_user]) }
diff --git a/plugins/discourse-data-explorer/spec/lib/data_explorer/query_group_bookmarkable_spec.rb b/plugins/discourse-data-explorer/spec/lib/data_explorer/query_group_bookmarkable_spec.rb
index e7edff806e7..9399fced1b9 100644
--- a/plugins/discourse-data-explorer/spec/lib/data_explorer/query_group_bookmarkable_spec.rb
+++ b/plugins/discourse-data-explorer/spec/lib/data_explorer/query_group_bookmarkable_spec.rb
@@ -5,13 +5,13 @@ describe DiscourseDataExplorer::QueryGroupBookmarkable do
RegisteredBookmarkable.new(DiscourseDataExplorer::QueryGroupBookmarkable)
end
- fab!(:admin_user) { Fabricate(:admin) }
+ fab!(:admin_user, :admin)
fab!(:user)
fab!(:guardian) { Guardian.new(user) }
- fab!(:group0) { Fabricate(:group) }
- fab!(:group1) { Fabricate(:group) }
- fab!(:group2) { Fabricate(:group) }
- fab!(:group3) { Fabricate(:group) }
+ fab!(:group0, :group)
+ fab!(:group1, :group)
+ fab!(:group2, :group)
+ fab!(:group3, :group)
fab!(:query1) do
Fabricate(
:query,
diff --git a/plugins/discourse-data-explorer/spec/report_generator_spec.rb b/plugins/discourse-data-explorer/spec/report_generator_spec.rb
index fcddfb100d9..2e0b5892849 100644
--- a/plugins/discourse-data-explorer/spec/report_generator_spec.rb
+++ b/plugins/discourse-data-explorer/spec/report_generator_spec.rb
@@ -2,8 +2,8 @@
describe DiscourseDataExplorer::ReportGenerator do
fab!(:user)
- fab!(:unauthorised_user) { Fabricate(:user) }
- fab!(:unauthorised_group) { Fabricate(:group) }
+ fab!(:unauthorised_user, :user)
+ fab!(:unauthorised_group, :group)
fab!(:group) { Fabricate(:group, users: [user]) }
fab!(:query) { DiscourseDataExplorer::Query.find(-1) }
diff --git a/plugins/discourse-data-explorer/spec/requests/group_spec.rb b/plugins/discourse-data-explorer/spec/requests/group_spec.rb
index bb63c92a15e..315b7fd7253 100644
--- a/plugins/discourse-data-explorer/spec/requests/group_spec.rb
+++ b/plugins/discourse-data-explorer/spec/requests/group_spec.rb
@@ -1,8 +1,8 @@
# frozen_string_literal: true
describe "Data explorer group serializer additions" do
- fab!(:group_user) { Fabricate(:user) }
- fab!(:other_user) { Fabricate(:user) }
+ fab!(:group_user, :user)
+ fab!(:other_user, :user)
fab!(:group)
let!(:query) { DiscourseDataExplorer::Query.create!(name: "My query", sql: "") }
diff --git a/plugins/discourse-data-explorer/spec/requests/query_controller_spec.rb b/plugins/discourse-data-explorer/spec/requests/query_controller_spec.rb
index 6b6867e86b6..265f4754d31 100644
--- a/plugins/discourse-data-explorer/spec/requests/query_controller_spec.rb
+++ b/plugins/discourse-data-explorer/spec/requests/query_controller_spec.rb
@@ -86,7 +86,7 @@ describe DiscourseDataExplorer::QueryController do
end
describe "#update" do
- fab!(:user2) { Fabricate(:user) }
+ fab!(:user2, :user)
fab!(:group2) { Fabricate(:group, users: [user2]) }
it "allows group to access system query" do
diff --git a/plugins/discourse-data-explorer/spec/system/bookmark_spec.rb b/plugins/discourse-data-explorer/spec/system/bookmark_spec.rb
index 34395c92d59..1b7095c2bbb 100644
--- a/plugins/discourse-data-explorer/spec/system/bookmark_spec.rb
+++ b/plugins/discourse-data-explorer/spec/system/bookmark_spec.rb
@@ -1,7 +1,7 @@
# frozen_string_literal: true
describe "Bookmarking reports attached to a group", type: :system do
- fab!(:current_user) { Fabricate(:admin) }
+ fab!(:current_user, :admin)
fab!(:query_1) do
Fabricate(
:query,
diff --git a/plugins/discourse-data-explorer/spec/system/param_input_spec.rb b/plugins/discourse-data-explorer/spec/system/param_input_spec.rb
index 67ebff2c8dc..c12128eb22c 100644
--- a/plugins/discourse-data-explorer/spec/system/param_input_spec.rb
+++ b/plugins/discourse-data-explorer/spec/system/param_input_spec.rb
@@ -45,7 +45,7 @@ RSpec.describe "Param input", type: :system do
SELECT 1
SQL
- fab!(:current_user) { Fabricate(:admin) }
+ fab!(:current_user, :admin)
fab!(:all_params_query) do
Fabricate(
:query,
diff --git a/plugins/discourse-data-explorer/spec/system/reports_spec.rb b/plugins/discourse-data-explorer/spec/system/reports_spec.rb
index 3a6fcda9674..3b42a7da215 100644
--- a/plugins/discourse-data-explorer/spec/system/reports_spec.rb
+++ b/plugins/discourse-data-explorer/spec/system/reports_spec.rb
@@ -2,7 +2,7 @@
RSpec.describe "Reports", type: :system do
fab!(:group) { Fabricate(:group, name: "group") }
- fab!(:user) { Fabricate(:admin) }
+ fab!(:user, :admin)
fab!(:group_user) { Fabricate(:group_user, user: user, group: group) }
fab!(:query_1) do
Fabricate(
diff --git a/plugins/discourse-gamification/app/controllers/discourse_gamification/gamification_leaderboard_controller.rb b/plugins/discourse-gamification/app/controllers/discourse_gamification/gamification_leaderboard_controller.rb
index f7afd831df9..d432c74c4d1 100644
--- a/plugins/discourse-gamification/app/controllers/discourse_gamification/gamification_leaderboard_controller.rb
+++ b/plugins/discourse-gamification/app/controllers/discourse_gamification/gamification_leaderboard_controller.rb
@@ -34,7 +34,7 @@ module DiscourseGamification
.new(leaderboard)
.as_json
.merge({ users: [], reason: e.message }),
- status: 202
+ status: :accepted
end
end
end
diff --git a/plugins/discourse-gamification/spec/jobs/delete_leaderboard_positions_spec.rb b/plugins/discourse-gamification/spec/jobs/delete_leaderboard_positions_spec.rb
index f167a45f1bc..ba8e5fb94aa 100644
--- a/plugins/discourse-gamification/spec/jobs/delete_leaderboard_positions_spec.rb
+++ b/plugins/discourse-gamification/spec/jobs/delete_leaderboard_positions_spec.rb
@@ -1,7 +1,7 @@
# frozen_string_literal: true
describe Jobs::DeleteLeaderboardPositions do
- fab!(:leaderboard) { Fabricate(:gamification_leaderboard) }
+ fab!(:leaderboard, :gamification_leaderboard)
fab!(:score) { Fabricate(:gamification_score, user_id: leaderboard.created_by_id) }
let(:leaderboard_positions) { DiscourseGamification::LeaderboardCachedView.new(leaderboard) }
diff --git a/plugins/discourse-gamification/spec/jobs/generate_leaderboard_positions_spec.rb b/plugins/discourse-gamification/spec/jobs/generate_leaderboard_positions_spec.rb
index 2184823ee64..9b09becc91e 100644
--- a/plugins/discourse-gamification/spec/jobs/generate_leaderboard_positions_spec.rb
+++ b/plugins/discourse-gamification/spec/jobs/generate_leaderboard_positions_spec.rb
@@ -1,7 +1,7 @@
# frozen_string_literal: true
describe Jobs::GenerateLeaderboardPositions do
- fab!(:leaderboard) { Fabricate(:gamification_leaderboard) }
+ fab!(:leaderboard, :gamification_leaderboard)
fab!(:score) { Fabricate(:gamification_score, user_id: leaderboard.created_by_id) }
let(:leaderboard_positions) { DiscourseGamification::LeaderboardCachedView.new(leaderboard) }
diff --git a/plugins/discourse-gamification/spec/jobs/recalculate_scores_spec.rb b/plugins/discourse-gamification/spec/jobs/recalculate_scores_spec.rb
index b38e48286ef..f4ddc90a284 100644
--- a/plugins/discourse-gamification/spec/jobs/recalculate_scores_spec.rb
+++ b/plugins/discourse-gamification/spec/jobs/recalculate_scores_spec.rb
@@ -1,7 +1,7 @@
# frozen_string_literal: true
describe Jobs::RecalculateScores do
- fab!(:current_user) { Fabricate(:admin) }
+ fab!(:current_user, :admin)
before { RateLimiter.enable }
diff --git a/plugins/discourse-gamification/spec/jobs/refresh_leaderboard_positions_spec.rb b/plugins/discourse-gamification/spec/jobs/refresh_leaderboard_positions_spec.rb
index 27e7ae5c223..af40ba95a05 100644
--- a/plugins/discourse-gamification/spec/jobs/refresh_leaderboard_positions_spec.rb
+++ b/plugins/discourse-gamification/spec/jobs/refresh_leaderboard_positions_spec.rb
@@ -1,7 +1,7 @@
# frozen_string_literal: true
describe Jobs::RefreshLeaderboardPositions do
- fab!(:leaderboard) { Fabricate(:gamification_leaderboard) }
+ fab!(:leaderboard, :gamification_leaderboard)
let(:leaderboard_positions) { DiscourseGamification::LeaderboardCachedView.new(leaderboard) }
before { leaderboard_positions.create }
diff --git a/plugins/discourse-gamification/spec/jobs/update_scores_for_today_spec.rb b/plugins/discourse-gamification/spec/jobs/update_scores_for_today_spec.rb
index ba7e3247f2a..640c572c968 100644
--- a/plugins/discourse-gamification/spec/jobs/update_scores_for_today_spec.rb
+++ b/plugins/discourse-gamification/spec/jobs/update_scores_for_today_spec.rb
@@ -2,7 +2,7 @@
describe Jobs::UpdateScoresForToday do
fab!(:user)
- fab!(:user_2) { Fabricate(:user) }
+ fab!(:user_2, :user)
fab!(:post) { Fabricate(:post, user: user, post_number: 2) }
fab!(:gamification_score) { Fabricate(:gamification_score, user_id: user.id) }
fab!(:gamification_score_2) do
diff --git a/plugins/discourse-gamification/spec/jobs/update_stale_leaderboard_positions_spec.rb b/plugins/discourse-gamification/spec/jobs/update_stale_leaderboard_positions_spec.rb
index ff61ed1159b..fb38cf5d727 100644
--- a/plugins/discourse-gamification/spec/jobs/update_stale_leaderboard_positions_spec.rb
+++ b/plugins/discourse-gamification/spec/jobs/update_stale_leaderboard_positions_spec.rb
@@ -1,7 +1,7 @@
# frozen_string_literal: true
describe Jobs::UpdateStaleLeaderboardPositions do
- fab!(:leaderboard) { Fabricate(:gamification_leaderboard) }
+ fab!(:leaderboard, :gamification_leaderboard)
fab!(:score) { Fabricate(:gamification_score, user_id: leaderboard.created_by_id) }
let(:leaderboard_positions) { DiscourseGamification::LeaderboardCachedView.new(leaderboard) }
diff --git a/plugins/discourse-gamification/spec/lib/directory_integration_spec.rb b/plugins/discourse-gamification/spec/lib/directory_integration_spec.rb
index 05974cdebdb..11eb0fe774b 100644
--- a/plugins/discourse-gamification/spec/lib/directory_integration_spec.rb
+++ b/plugins/discourse-gamification/spec/lib/directory_integration_spec.rb
@@ -1,9 +1,9 @@
# frozen_string_literal: true
describe DiscourseGamification::DirectoryIntegration do
- fab!(:user_1) { Fabricate(:admin) }
- fab!(:user_2) { Fabricate(:user) }
- fab!(:leaderboard) { Fabricate(:gamification_leaderboard) }
+ fab!(:user_1, :admin)
+ fab!(:user_2, :user)
+ fab!(:leaderboard, :gamification_leaderboard)
fab!(:score_1) { Fabricate(:gamification_score, user_id: user_1.id, score: 10, date: 8.days.ago) }
fab!(:score_2) { Fabricate(:gamification_score, user_id: user_1.id, score: 40, date: 3.days.ago) }
fab!(:score_3) { Fabricate(:gamification_score, user_id: user_2.id, score: 25, date: 5.days.ago) }
diff --git a/plugins/discourse-gamification/spec/lib/leaderboard_cached_view_spec.rb b/plugins/discourse-gamification/spec/lib/leaderboard_cached_view_spec.rb
index fcad7a7f50c..23190ccca85 100644
--- a/plugins/discourse-gamification/spec/lib/leaderboard_cached_view_spec.rb
+++ b/plugins/discourse-gamification/spec/lib/leaderboard_cached_view_spec.rb
@@ -3,7 +3,7 @@
describe DiscourseGamification::LeaderboardCachedView do
fab!(:admin)
fab!(:user)
- fab!(:other_user) { Fabricate(:user) }
+ fab!(:other_user, :user)
fab!(:moderator)
fab!(:leaderboard) { Fabricate(:gamification_leaderboard, created_by_id: admin.id) }
fab!(:gamification_score) { Fabricate(:gamification_score, user_id: user.id, date: 8.days.ago) }
diff --git a/plugins/discourse-gamification/spec/lib/scorables/shared_scorables_spec.rb b/plugins/discourse-gamification/spec/lib/scorables/shared_scorables_spec.rb
index a7b918fefac..bac1e373228 100755
--- a/plugins/discourse-gamification/spec/lib/scorables/shared_scorables_spec.rb
+++ b/plugins/discourse-gamification/spec/lib/scorables/shared_scorables_spec.rb
@@ -1,7 +1,7 @@
# frozen_string_literal: true
RSpec.shared_examples "Scorable Type" do
- fab!(:leaderboard) { Fabricate(:gamification_leaderboard) }
+ fab!(:leaderboard, :gamification_leaderboard)
let(:current_user) { Fabricate(:user) }
let(:other_user) { Fabricate(:user) }
let(:third_user) { Fabricate(:user) }
@@ -21,7 +21,7 @@ RSpec.shared_examples "Scorable Type" do
end
RSpec.shared_examples "Category Scoped Scorable Type" do
- fab!(:leaderboard) { Fabricate(:gamification_leaderboard) }
+ fab!(:leaderboard, :gamification_leaderboard)
let(:user) { Fabricate(:user) }
let(:user_2) { Fabricate(:user) }
let(:category_allowed) { Fabricate(:category) }
@@ -53,7 +53,7 @@ RSpec.shared_examples "Category Scoped Scorable Type" do
end
RSpec.shared_examples "No Score Value" do
- fab!(:leaderboard) { Fabricate(:gamification_leaderboard) }
+ fab!(:leaderboard, :gamification_leaderboard)
let(:current_user) { Fabricate(:user) }
let(:other_user) { Fabricate(:user) }
let(:class_action_fabricator_for_pm) { nil }
diff --git a/plugins/discourse-gamification/spec/lib/scorables/solutions_spec.rb b/plugins/discourse-gamification/spec/lib/scorables/solutions_spec.rb
index 367c0f35257..1f406dfe5f5 100644
--- a/plugins/discourse-gamification/spec/lib/scorables/solutions_spec.rb
+++ b/plugins/discourse-gamification/spec/lib/scorables/solutions_spec.rb
@@ -3,8 +3,8 @@
RSpec.describe DiscourseGamification::Solutions do
fab!(:category)
fab!(:topic) { Fabricate(:topic, category: category) }
- fab!(:question_user) { Fabricate(:user) }
- fab!(:answer_user) { Fabricate(:user) }
+ fab!(:question_user, :user)
+ fab!(:answer_user, :user)
fab!(:answer_post) { Fabricate(:post, topic: topic, user: answer_user) }
before { SiteSetting.solution_score_value = 5 }
diff --git a/plugins/discourse-gamification/spec/models/gamification_leaderboard_spec.rb b/plugins/discourse-gamification/spec/models/gamification_leaderboard_spec.rb
index b7ea4b737dd..0c1c3367ce4 100644
--- a/plugins/discourse-gamification/spec/models/gamification_leaderboard_spec.rb
+++ b/plugins/discourse-gamification/spec/models/gamification_leaderboard_spec.rb
@@ -1,7 +1,7 @@
# frozen_string_literal: true
RSpec.describe DiscourseGamification::GamificationLeaderboard, type: :model do
- fab!(:leaderboard) { Fabricate(:gamification_leaderboard) }
+ fab!(:leaderboard, :gamification_leaderboard)
describe ".resolve_period" do
it "returns default period given a blank period" do
diff --git a/plugins/discourse-gamification/spec/models/gamification_score_spec.rb b/plugins/discourse-gamification/spec/models/gamification_score_spec.rb
index 9513217eb4d..f76e96c6abd 100644
--- a/plugins/discourse-gamification/spec/models/gamification_score_spec.rb
+++ b/plugins/discourse-gamification/spec/models/gamification_score_spec.rb
@@ -2,7 +2,7 @@
RSpec.describe DiscourseGamification::GamificationScore, type: :model do
fab!(:user)
- fab!(:leaderboard) { Fabricate(:gamification_leaderboard) }
+ fab!(:leaderboard, :gamification_leaderboard)
before { DiscourseGamification::LeaderboardCachedView.create_all }
diff --git a/plugins/discourse-gamification/spec/models/user_spec.rb b/plugins/discourse-gamification/spec/models/user_spec.rb
index d23611a7988..9e7af34e58f 100644
--- a/plugins/discourse-gamification/spec/models/user_spec.rb
+++ b/plugins/discourse-gamification/spec/models/user_spec.rb
@@ -2,7 +2,7 @@
describe User, type: :model do
fab!(:user)
- fab!(:leaderboard) { Fabricate(:gamification_leaderboard) }
+ fab!(:leaderboard, :gamification_leaderboard)
before do
Fabricate(:gamification_score, user_id: user.id, score: 10, date: 8.days.ago)
diff --git a/plugins/discourse-gamification/spec/plugin_spec.rb b/plugins/discourse-gamification/spec/plugin_spec.rb
index 8cf43b7cae2..9418a4eed1a 100644
--- a/plugins/discourse-gamification/spec/plugin_spec.rb
+++ b/plugins/discourse-gamification/spec/plugin_spec.rb
@@ -36,9 +36,9 @@ describe DiscourseGamification do
end
context "when merging users" do
- fab!(:user_1) { Fabricate(:user) }
- fab!(:user_2) { Fabricate(:user) }
- fab!(:leaderboard) { Fabricate(:gamification_leaderboard) }
+ fab!(:user_1, :user)
+ fab!(:user_2, :user)
+ fab!(:leaderboard, :gamification_leaderboard)
before do
SiteSetting.discourse_gamification_enabled = true
diff --git a/plugins/discourse-gamification/spec/requests/gamification_leaderboard_controller_spec.rb b/plugins/discourse-gamification/spec/requests/gamification_leaderboard_controller_spec.rb
index 91193cc23c6..831023dd389 100644
--- a/plugins/discourse-gamification/spec/requests/gamification_leaderboard_controller_spec.rb
+++ b/plugins/discourse-gamification/spec/requests/gamification_leaderboard_controller_spec.rb
@@ -3,7 +3,7 @@
RSpec.describe DiscourseGamification::GamificationLeaderboardController do
fab!(:group)
fab!(:current_user) { Fabricate(:user, group_ids: [group.id]) }
- fab!(:user_2) { Fabricate(:user) }
+ fab!(:user_2, :user)
fab!(:staged_user) { Fabricate(:user, staged: true) }
fab!(:anon_user) { Fabricate(:user, email: "[email protected]") }
fab!(:currently_suspended_user) do
@@ -13,7 +13,7 @@ RSpec.describe DiscourseGamification::GamificationLeaderboardController do
Fabricate(:user, suspended_at: Time.now, suspended_till: 5.days.ago)
end
- fab!(:user_3) { Fabricate(:user) }
+ fab!(:user_3, :user)
let!(:create_score) { UserVisit.create(user_id: current_user.id, visited_at: 2.days.ago) }
let!(:create_score_for_user2) { UserVisit.create(user_id: user_2.id, visited_at: 2.days.ago) }
diff --git a/plugins/discourse-gamification/spec/system/admin_leaderboards_spec.rb b/plugins/discourse-gamification/spec/system/admin_leaderboards_spec.rb
index d721f03b69e..7d5561cd0a9 100644
--- a/plugins/discourse-gamification/spec/system/admin_leaderboards_spec.rb
+++ b/plugins/discourse-gamification/spec/system/admin_leaderboards_spec.rb
@@ -1,7 +1,7 @@
# frozen_string_literal: true
describe "Admin leaderboards", type: :system do
- fab!(:current_user) { Fabricate(:admin) }
+ fab!(:current_user, :admin)
let(:admin_leaderboard_page) { PageObjects::Pages::AdminLeaderboards.new }
let(:dialog) { PageObjects::Components::Dialog.new }
diff --git a/plugins/discourse-gamification/spec/system/recalculate_scores_form_spec.rb b/plugins/discourse-gamification/spec/system/recalculate_scores_form_spec.rb
index 7feaf00aed1..7debd3c3907 100644
--- a/plugins/discourse-gamification/spec/system/recalculate_scores_form_spec.rb
+++ b/plugins/discourse-gamification/spec/system/recalculate_scores_form_spec.rb
@@ -4,7 +4,7 @@ describe "Recalculate Scores Form", type: :system do
let(:recalculate_scores_modal) { PageObjects::Modals::RecalculateScoresForm.new }
fab!(:admin)
- fab!(:leaderboard) { Fabricate(:gamification_leaderboard) }
+ fab!(:leaderboard, :gamification_leaderboard)
before do
RateLimiter.enable
diff --git a/plugins/discourse-github/spec/lib/github_badges_spec.rb b/plugins/discourse-github/spec/lib/github_badges_spec.rb
index 37205698522..c24487e90f1 100644
--- a/plugins/discourse-github/spec/lib/github_badges_spec.rb
+++ b/plugins/discourse-github/spec/lib/github_badges_spec.rb
@@ -49,7 +49,7 @@ describe DiscourseGithubPlugin::GithubBadges do
repo2.commits.create!(
sha: "4",
email: bronze_user_repo_2.email,
- committed_at: 2.day.ago,
+ committed_at: 2.days.ago,
role_id: roles[:committer],
)
diff --git a/plugins/discourse-math/spec/system/post_spec.rb b/plugins/discourse-math/spec/system/post_spec.rb
index 50fd96f1b70..25e8847de7c 100644
--- a/plugins/discourse-math/spec/system/post_spec.rb
+++ b/plugins/discourse-math/spec/system/post_spec.rb
@@ -1,7 +1,7 @@
# frozen_string_literal: true
RSpec.describe "Discourse Math - post", type: :system do
- fab!(:current_user) { Fabricate(:admin) }
+ fab!(:current_user, :admin)
before do
SiteSetting.discourse_math_enabled = true
diff --git a/plugins/discourse-microsoft-auth/spec/integration/microsoft_auth_spec.rb b/plugins/discourse-microsoft-auth/spec/integration/microsoft_auth_spec.rb
index 721bb6c7416..a99be4e3c05 100644
--- a/plugins/discourse-microsoft-auth/spec/integration/microsoft_auth_spec.rb
+++ b/plugins/discourse-microsoft-auth/spec/integration/microsoft_auth_spec.rb
@@ -6,7 +6,7 @@ describe "Microsoft OAuth2" do
let(:client_secret) { "adddcccdddd99922" }
let(:temp_code) { "microsoft_temp_code_544254" }
- fab!(:user1) { Fabricate(:user) }
+ fab!(:user1, :user)
def setup_ms_emails_stub(email:)
stub_request(:get, "https://graph.microsoft.com/v1.0/me").with(
diff --git a/plugins/discourse-patreon/app/controllers/patreon/patreon_admin_controller.rb b/plugins/discourse-patreon/app/controllers/patreon/patreon_admin_controller.rb
index ae8b25f6590..074e2b049c9 100644
--- a/plugins/discourse-patreon/app/controllers/patreon/patreon_admin_controller.rb
+++ b/plugins/discourse-patreon/app/controllers/patreon/patreon_admin_controller.rb
@@ -38,7 +38,7 @@ class Patreon::PatreonAdminController < Admin::AdminController
def edit
if params[:rewards_ids].nil? || !is_number?(params[:group_id])
- return render json: { message: "Error" }, status: 500
+ return render json: { message: "Error" }, status: :internal_server_error
end
filters = PluginStore.get(Patreon::PLUGIN_NAME, "filters") || {}
@@ -51,7 +51,9 @@ class Patreon::PatreonAdminController < Admin::AdminController
end
def delete
- return render json: { message: "Error" }, status: 500 unless is_number?(params[:group_id])
+ unless is_number?(params[:group_id])
+ return render json: { message: "Error" }, status: :internal_server_error
+ end
filters = PluginStore.get(Patreon::PLUGIN_NAME, "filters")
@@ -67,7 +69,7 @@ class Patreon::PatreonAdminController < Admin::AdminController
Patreon::Patron.sync_groups
render json: success_json
rescue => e
- render json: { message: e.message }, status: 500
+ render json: { message: e.message }, status: :internal_server_error
end
end
diff --git a/plugins/discourse-patreon/app/controllers/patreon/patreon_webhook_controller.rb b/plugins/discourse-patreon/app/controllers/patreon/patreon_webhook_controller.rb
index aaf6ad40628..e110e965c9b 100644
--- a/plugins/discourse-patreon/app/controllers/patreon/patreon_webhook_controller.rb
+++ b/plugins/discourse-patreon/app/controllers/patreon/patreon_webhook_controller.rb
@@ -56,7 +56,7 @@ class Patreon::PatreonWebhookController < ApplicationController
Jobs.enqueue(:sync_patron_groups, patreon_id: patreon_id)
- render body: nil, status: 200
+ render body: nil, status: :ok
end
def event
diff --git a/plugins/discourse-patreon/spec/integration/patreon_auth_spec.rb b/plugins/discourse-patreon/spec/integration/patreon_auth_spec.rb
index 03cf62d0163..c1b2e781c39 100644
--- a/plugins/discourse-patreon/spec/integration/patreon_auth_spec.rb
+++ b/plugins/discourse-patreon/spec/integration/patreon_auth_spec.rb
@@ -6,8 +6,8 @@ describe "Patreon Oauth2" do
let(:client_secret) { "adddcccdddd99922" }
let(:temp_code) { "patreon_temp_code_544254" }
- fab!(:user1) { Fabricate(:user) }
- fab!(:user2) { Fabricate(:user) }
+ fab!(:user1, :user)
+ fab!(:user2, :user)
def setup_patreon_emails_stub(email:, verified:)
stub_request(:get, "https://api.patreon.com/oauth2/api/current_user").with(
diff --git a/plugins/discourse-policy/spec/lib/check_policy_spec.rb b/plugins/discourse-policy/spec/lib/check_policy_spec.rb
index e33e7767577..b4a337585f1 100644
--- a/plugins/discourse-policy/spec/lib/check_policy_spec.rb
+++ b/plugins/discourse-policy/spec/lib/check_policy_spec.rb
@@ -3,8 +3,8 @@
describe Jobs::DiscoursePolicy::CheckPolicy do
subject(:job) { described_class.new }
- fab!(:user1) { Fabricate(:user) }
- fab!(:user2) { Fabricate(:user) }
+ fab!(:user1, :user)
+ fab!(:user2, :user)
fab!(:group) do
group = Fabricate(:group)
diff --git a/plugins/discourse-policy/spec/mailers/policy_email_spec.rb b/plugins/discourse-policy/spec/mailers/policy_email_spec.rb
index f32b7572f44..fb801ece250 100644
--- a/plugins/discourse-policy/spec/mailers/policy_email_spec.rb
+++ b/plugins/discourse-policy/spec/mailers/policy_email_spec.rb
@@ -1,7 +1,7 @@
# frozen_string_literal: true
describe Jobs::UserEmail do
- fab!(:user1) { Fabricate(:user) }
+ fab!(:user1, :user)
fab!(:group1) do
group = Fabricate(:group)
diff --git a/plugins/discourse-policy/spec/models/post_policy_spec.rb b/plugins/discourse-policy/spec/models/post_policy_spec.rb
index 3e6cec42c83..ee4946fd4a0 100644
--- a/plugins/discourse-policy/spec/models/post_policy_spec.rb
+++ b/plugins/discourse-policy/spec/models/post_policy_spec.rb
@@ -3,8 +3,8 @@
RSpec.describe PostPolicy do
include ActiveSupport::Testing::TimeHelpers
- fab!(:user1) { Fabricate(:user) }
- fab!(:user2) { Fabricate(:user) }
+ fab!(:user1, :user)
+ fab!(:user2, :user)
fab!(:inactive_user) { Fabricate(:user, active: false) }
fab!(:suspended_user) { Fabricate(:user, suspended_till: 1.year.from_now) }
diff --git a/plugins/discourse-policy/spec/plugin_spec.rb b/plugins/discourse-policy/spec/plugin_spec.rb
index 3b66114b7c7..248ae665f1f 100644
--- a/plugins/discourse-policy/spec/plugin_spec.rb
+++ b/plugins/discourse-policy/spec/plugin_spec.rb
@@ -1,7 +1,7 @@
# frozen_string_literal: true
describe DiscoursePolicy do
- fab!(:user1) { Fabricate(:user) }
+ fab!(:user1, :user)
before { enable_current_plugin }
@@ -62,7 +62,7 @@ describe DiscoursePolicy do
end
context "with add_users_to_group present" do
- fab!(:group2) { Fabricate(:group) }
+ fab!(:group2, :group)
fab!(:post) { Fabricate(:post, user: moderator) }
fab!(:policy666) do
policy = Fabricate(:post_policy, post: post, add_users_to_group: group2.id)
diff --git a/plugins/discourse-policy/spec/reports/unaccepted_policies_spec.rb b/plugins/discourse-policy/spec/reports/unaccepted_policies_spec.rb
index 6de454c34a2..8fb0b6c9d3f 100644
--- a/plugins/discourse-policy/spec/reports/unaccepted_policies_spec.rb
+++ b/plugins/discourse-policy/spec/reports/unaccepted_policies_spec.rb
@@ -1,8 +1,8 @@
# frozen_string_literal: true
RSpec.describe Report do
- fab!(:user1) { Fabricate(:user) }
- fab!(:user2) { Fabricate(:user) }
+ fab!(:user1, :user)
+ fab!(:user2, :user)
fab!(:group1) do
group = Fabricate(:group)
diff --git a/plugins/discourse-policy/spec/requests/policy_controller_spec.rb b/plugins/discourse-policy/spec/requests/policy_controller_spec.rb
index c0d0abac8f9..559f962d21f 100644
--- a/plugins/discourse-policy/spec/requests/policy_controller_spec.rb
+++ b/plugins/discourse-policy/spec/requests/policy_controller_spec.rb
@@ -3,8 +3,8 @@
describe DiscoursePolicy::PolicyController do
fab!(:group)
fab!(:moderator)
- fab!(:user1) { Fabricate(:user) }
- fab!(:user2) { Fabricate(:user) }
+ fab!(:user1, :user)
+ fab!(:user2, :user)
before do
enable_current_plugin
@@ -40,7 +40,7 @@ describe DiscoursePolicy::PolicyController do
end
context "when add_users_to_group is present" do
- fab!(:group2) { Fabricate(:group) }
+ fab!(:group2, :group)
fab!(:post) { Fabricate(:post, user: moderator) }
fab!(:policy666) do
policy = Fabricate(:post_policy, post: post, add_users_to_group: group2.id)
@@ -113,7 +113,7 @@ describe DiscoursePolicy::PolicyController do
end
describe "group member visibility restrictions" do
- fab!(:owner) { Fabricate(:user) }
+ fab!(:owner, :user)
let!(:post) do
raw = <<~MD
[policy group=#{group.name}]
diff --git a/plugins/discourse-policy/spec/serializers/post_serializer_spec.rb b/plugins/discourse-policy/spec/serializers/post_serializer_spec.rb
index 2b9841716d7..bbe11997cd3 100644
--- a/plugins/discourse-policy/spec/serializers/post_serializer_spec.rb
+++ b/plugins/discourse-policy/spec/serializers/post_serializer_spec.rb
@@ -3,8 +3,8 @@
describe PostSerializer do
fab!(:group)
fab!(:admin)
- fab!(:user1) { Fabricate(:user) }
- fab!(:user2) { Fabricate(:user) }
+ fab!(:user1, :user)
+ fab!(:user2, :user)
before do
enable_current_plugin
diff --git a/plugins/discourse-post-voting/app/controllers/post_voting/comments_controller.rb b/plugins/discourse-post-voting/app/controllers/post_voting/comments_controller.rb
index 8dc46127f2d..aeddbe420ae 100644
--- a/plugins/discourse-post-voting/app/controllers/post_voting/comments_controller.rb
+++ b/plugins/discourse-post-voting/app/controllers/post_voting/comments_controller.rb
@@ -88,7 +88,7 @@ module PostVoting
end
def flag
- RateLimiter.new(current_user, "flag_post_voting_comment", 4, 1.minutes).performed!
+ RateLimiter.new(current_user, "flag_post_voting_comment", 4, 1.minute).performed!
permitted_params =
params.permit(%i[comment_id flag_type_id message is_warning take_action queue_for_review])
diff --git a/plugins/discourse-post-voting/app/controllers/post_voting/votes_controller.rb b/plugins/discourse-post-voting/app/controllers/post_voting/votes_controller.rb
index ed324be63ba..62efb38d1b8 100644
--- a/plugins/discourse-post-voting/app/controllers/post_voting/votes_controller.rb
+++ b/plugins/discourse-post-voting/app/controllers/post_voting/votes_controller.rb
@@ -15,7 +15,7 @@ module PostVoting
if PostVoting::VoteManager.vote(@post, current_user, direction: vote_params[:direction])
render json: success_json
else
- render json: failed_json, status: 422
+ render json: failed_json, status: :unprocessable_entity
end
end
@@ -31,7 +31,7 @@ module PostVoting
)
render json: success_json
else
- render json: failed_json, status: 422
+ render json: failed_json, status: :unprocessable_entity
end
end
@@ -59,7 +59,7 @@ module PostVoting
if PostVoting::VoteManager.remove_vote(@post, current_user)
render json: success_json
else
- render json: failed_json, status: 422
+ render json: failed_json, status: :unprocessable_entity
end
end
@@ -78,7 +78,7 @@ module PostVoting
if PostVoting::VoteManager.remove_vote(comment, current_user)
render json: success_json
else
- render json: failed_json, status: 422
+ render json: failed_json, status: :unprocessable_entity
end
end
diff --git a/plugins/discourse-post-voting/plugin.rb b/plugins/discourse-post-voting/plugin.rb
index aa878fa5f81..fba651d6010 100644
--- a/plugins/discourse-post-voting/plugin.rb
+++ b/plugins/discourse-post-voting/plugin.rb
@@ -190,7 +190,7 @@ after_initialize do
register_modifier(:topic_embed_import_create_args) do |args|
category_id = args[:category]
next args unless category_id
- next args if args[:archetype] != Archetype.default && !args[:archetype].blank?
+ next args if args[:archetype] != Archetype.default && args[:archetype].present?
category = Category.find_by(id: category_id)
diff --git a/plugins/discourse-post-voting/spec/components/post_voting/vote_manager_spec.rb b/plugins/discourse-post-voting/spec/components/post_voting/vote_manager_spec.rb
index 3564cddb090..09aa62fa961 100644
--- a/plugins/discourse-post-voting/spec/components/post_voting/vote_manager_spec.rb
+++ b/plugins/discourse-post-voting/spec/components/post_voting/vote_manager_spec.rb
@@ -2,8 +2,8 @@
describe PostVoting::VoteManager do
fab!(:user)
- fab!(:user_2) { Fabricate(:user) }
- fab!(:user_3) { Fabricate(:user) }
+ fab!(:user_2, :user)
+ fab!(:user_3, :user)
fab!(:topic) { Fabricate(:topic, subtype: Topic::POST_VOTING_SUBTYPE) }
fab!(:topic_post) { Fabricate(:post, topic: topic) }
fab!(:post) { Fabricate(:post, topic: topic) }
diff --git a/plugins/discourse-post-voting/spec/lib/post_voting/comment_review_queue_spec.rb b/plugins/discourse-post-voting/spec/lib/post_voting/comment_review_queue_spec.rb
index ace10c6866d..8a92dac52eb 100644
--- a/plugins/discourse-post-voting/spec/lib/post_voting/comment_review_queue_spec.rb
+++ b/plugins/discourse-post-voting/spec/lib/post_voting/comment_review_queue_spec.rb
@@ -3,7 +3,7 @@
describe PostVoting::CommentReviewQueue do
subject(:queue) { described_class.new }
- fab!(:comment_poster) { Fabricate(:user) }
+ fab!(:comment_poster, :user)
fab!(:flagger) { Fabricate(:user, group_ids: [Group::AUTO_GROUPS[:trust_level_1]]) }
fab!(:topic) { Fabricate(:topic, subtype: Topic::POST_VOTING_SUBTYPE) }
fab!(:post) { Fabricate(:post, topic: topic) }
diff --git a/plugins/discourse-post-voting/spec/models/post_spec.rb b/plugins/discourse-post-voting/spec/models/post_spec.rb
index 4aa66a487aa..64be20f0010 100644
--- a/plugins/discourse-post-voting/spec/models/post_spec.rb
+++ b/plugins/discourse-post-voting/spec/models/post_spec.rb
@@ -1,9 +1,9 @@
# frozen_string_literal: true
describe Post do
- fab!(:user1) { Fabricate(:user) }
- fab!(:user2) { Fabricate(:user) }
- fab!(:user3) { Fabricate(:user) }
+ fab!(:user1, :user)
+ fab!(:user2, :user)
+ fab!(:user3, :user)
fab!(:topic) { Fabricate(:topic, subtype: Topic::POST_VOTING_SUBTYPE) }
fab!(:topic_post) { Fabricate(:post, topic: topic) }
fab!(:post) { Fabricate(:post, topic: topic) }
diff --git a/plugins/discourse-post-voting/spec/models/reviewable_post_voting_comment_spec.rb b/plugins/discourse-post-voting/spec/models/reviewable_post_voting_comment_spec.rb
index 62263bb1b75..377d74c0a49 100644
--- a/plugins/discourse-post-voting/spec/models/reviewable_post_voting_comment_spec.rb
+++ b/plugins/discourse-post-voting/spec/models/reviewable_post_voting_comment_spec.rb
@@ -1,7 +1,7 @@
# frozen_string_literal: true
RSpec.describe ReviewablePostVotingComment, type: :model do
- fab!(:comment_poster) { Fabricate(:user) }
+ fab!(:comment_poster, :user)
fab!(:flagger) { Fabricate(:user, group_ids: [Group::AUTO_GROUPS[:trust_level_1]]) }
fab!(:topic) { Fabricate(:topic, subtype: Topic::POST_VOTING_SUBTYPE) }
fab!(:post) { Fabricate(:post, topic: topic) }
diff --git a/plugins/discourse-reactions/spec/reports/reactions_spec.rb b/plugins/discourse-reactions/spec/reports/reactions_spec.rb
index b9e55c5c40a..86afe4dfce0 100644
--- a/plugins/discourse-reactions/spec/reports/reactions_spec.rb
+++ b/plugins/discourse-reactions/spec/reports/reactions_spec.rb
@@ -61,7 +61,7 @@ describe Report do
expect(report.data).to contain_exactly(
a_hash_including("cat_count" => 1, :day => 2.days.ago.to_date, :like_count => 0),
- a_hash_including(day: 1.days.ago.to_date, like_count: 0),
+ a_hash_including(day: 1.day.ago.to_date, like_count: 0),
a_hash_including("cat_count" => 1, :day => Time.current.to_date, :like_count => 0),
)
end
diff --git a/plugins/discourse-reactions/spec/requests/custom_reactions_controller_custom_emoji_spec.rb b/plugins/discourse-reactions/spec/requests/custom_reactions_controller_custom_emoji_spec.rb
index 7d0257d05f4..c5558f9c528 100644
--- a/plugins/discourse-reactions/spec/requests/custom_reactions_controller_custom_emoji_spec.rb
+++ b/plugins/discourse-reactions/spec/requests/custom_reactions_controller_custom_emoji_spec.rb
@@ -2,7 +2,7 @@
describe DiscourseReactions::CustomReactionsController do
fab!(:user)
- fab!(:post_1) { Fabricate(:post) }
+ fab!(:post_1, :post)
let(:custom_emoji) { "wink" }
diff --git a/plugins/discourse-reactions/spec/requests/custom_reactions_controller_spec.rb b/plugins/discourse-reactions/spec/requests/custom_reactions_controller_spec.rb
index b69441b3a92..ce516d58055 100644
--- a/plugins/discourse-reactions/spec/requests/custom_reactions_controller_spec.rb
+++ b/plugins/discourse-reactions/spec/requests/custom_reactions_controller_spec.rb
@@ -613,7 +613,7 @@ describe DiscourseReactions::CustomReactionsController do
DiscourseReactions::ReactionUser.count
}.by(1)
- freeze_time(Time.zone.now + 11.minutes)
+ freeze_time(11.minutes.from_now)
expect do
put "/discourse-reactions/posts/#{post_1.id}/custom-reactions/hugs/toggle.json"
end.to not_change { DiscourseReactions::Reaction.count }.and not_change {
diff --git a/plugins/discourse-reactions/spec/services/reaction_notification_spec.rb b/plugins/discourse-reactions/spec/services/reaction_notification_spec.rb
index 6b0a848dce4..3f15b8396cd 100644
--- a/plugins/discourse-reactions/spec/services/reaction_notification_spec.rb
+++ b/plugins/discourse-reactions/spec/services/reaction_notification_spec.rb
@@ -56,7 +56,7 @@ describe DiscourseReactions::ReactionNotification do
Fabricate(:reaction_user, reaction: thumbsup, user: user_2)
expect { described_class.new(thumbsup, user_2).create }.not_to change { Notification.count }
- freeze_time(Time.zone.now + 1.day)
+ freeze_time(1.day.from_now)
cry = Fabricate(:reaction, post: post_1, reaction_value: "cry")
Fabricate(:reaction_user, reaction: cry, user: user_2)
diff --git a/plugins/discourse-rss-polling/app/controllers/discourse_rss_polling/feed_settings_controller.rb b/plugins/discourse-rss-polling/app/controllers/discourse_rss_polling/feed_settings_controller.rb
index 0d746f14843..9ffb69e66e9 100644
--- a/plugins/discourse-rss-polling/app/controllers/discourse_rss_polling/feed_settings_controller.rb
+++ b/plugins/discourse-rss-polling/app/controllers/discourse_rss_polling/feed_settings_controller.rb
@@ -24,10 +24,14 @@ module DiscourseRssPolling
if rss_feed.save
render json: { success: true }
else
- render json: { success: false, errors: rss_feed.errors.full_messages }, status: 422
+ render json: {
+ success: false,
+ errors: rss_feed.errors.full_messages,
+ },
+ status: :unprocessable_entity
end
else
- render json: { success: false, error: "Invalid feed data" }, status: 400
+ render json: { success: false, error: "Invalid feed data" }, status: :bad_request
end
end
@@ -39,7 +43,7 @@ module DiscourseRssPolling
rss_feed.destroy!
render json: { success: true }
else
- render json: { success: false, error: "Feed not found" }, status: 404
+ render json: { success: false, error: "Feed not found" }, status: :not_found
end
end
diff --git a/plugins/discourse-rss-polling/spec/system/admin_spec.rb b/plugins/discourse-rss-polling/spec/system/admin_spec.rb
index ba52a281745..0d98c678ea4 100644
--- a/plugins/discourse-rss-polling/spec/system/admin_spec.rb
+++ b/plugins/discourse-rss-polling/spec/system/admin_spec.rb
@@ -1,9 +1,9 @@
# frozen_string_literal: true
RSpec.describe "Rss Polling - admin", type: :system do
- fab!(:current_user) { Fabricate(:admin) }
- fab!(:category_1) { Fabricate(:category) }
- fab!(:tag_1) { Fabricate(:tag) }
+ fab!(:current_user, :admin)
+ fab!(:category_1, :category)
+ fab!(:tag_1, :tag)
let(:url) { "http://example.com/rss" }
diff --git a/plugins/discourse-solved/spec/components/post_revisor_spec.rb b/plugins/discourse-solved/spec/components/post_revisor_spec.rb
index 2a59f455f2f..043cc98f9f5 100644
--- a/plugins/discourse-solved/spec/components/post_revisor_spec.rb
+++ b/plugins/discourse-solved/spec/components/post_revisor_spec.rb
@@ -3,7 +3,7 @@
require "post_revisor"
describe PostRevisor do
- fab!(:category) { Fabricate(:category_with_definition) }
+ fab!(:category, :category_with_definition)
fab!(:admin) { Fabricate(:admin, refresh_auto_groups: true) }
fab!(:category_solved) do
@@ -37,8 +37,8 @@ describe PostRevisor do
SiteSetting.tagging_enabled = true
end
- fab!(:tag1) { Fabricate(:tag) }
- fab!(:tag2) { Fabricate(:tag) }
+ fab!(:tag1, :tag)
+ fab!(:tag2, :tag)
fab!(:topic)
let(:post) { Fabricate(:post, topic: topic) }
diff --git a/plugins/discourse-solved/spec/integration/solved_spec.rb b/plugins/discourse-solved/spec/integration/solved_spec.rb
index 6184939b878..32beb45e2f9 100644
--- a/plugins/discourse-solved/spec/integration/solved_spec.rb
+++ b/plugins/discourse-solved/spec/integration/solved_spec.rb
@@ -2,7 +2,7 @@
RSpec.describe "Managing Posts solved status" do
let(:topic) { Fabricate(:topic_with_op) }
- fab!(:user) { Fabricate(:trust_level_4) }
+ fab!(:user, :trust_level_4)
let(:p1) { Fabricate(:post, topic: topic) }
before { SiteSetting.allow_solved_on_all_topics = true }
@@ -25,7 +25,7 @@ RSpec.describe "Managing Posts solved status" do
category
end
- fab!(:solvable_tag) { Fabricate(:tag) }
+ fab!(:solvable_tag, :tag)
fab!(:solved_in_category) do
topic = Fabricate(:topic, category: solvable_category)
@@ -48,7 +48,7 @@ RSpec.describe "Managing Posts solved status" do
fab!(:unsolved_in_category) { Fabricate(:topic, category: solvable_category) }
fab!(:unsolved_in_tag) { Fabricate(:topic, tags: [solvable_tag]) }
- fab!(:unsolved_topic) { Fabricate(:topic) }
+ fab!(:unsolved_topic, :topic)
it "can filter by solved status" do
expect(
@@ -265,7 +265,7 @@ RSpec.describe "Managing Posts solved status" do
expect(topic.public_topic_timer.status_type).to eq(TopicTimer.types[:silent_close])
expect(topic.solved.topic_timer).to eq(topic.public_topic_timer)
- expect(topic.public_topic_timer.execute_at).to eq_time(Time.zone.now + 2.hours)
+ expect(topic.public_topic_timer.execute_at).to eq_time(2.hours.from_now)
expect(topic.public_topic_timer.based_on_last_post).to eq(true)
end
@@ -287,7 +287,7 @@ RSpec.describe "Managing Posts solved status" do
expect(topic_2.public_topic_timer.status_type).to eq(TopicTimer.types[:silent_close])
expect(topic_2.solved.topic_timer).to eq(topic_2.public_topic_timer)
- expect(topic_2.public_topic_timer.execute_at).to eq_time(Time.zone.now + 4.hours)
+ expect(topic_2.public_topic_timer.execute_at).to eq_time(4.hours.from_now)
expect(topic_2.public_topic_timer.based_on_last_post).to eq(true)
end
diff --git a/plugins/discourse-solved/spec/lib/guardian_extensions_spec.rb b/plugins/discourse-solved/spec/lib/guardian_extensions_spec.rb
index 9a3d3ad0b1e..e0ddc962c18 100644
--- a/plugins/discourse-solved/spec/lib/guardian_extensions_spec.rb
+++ b/plugins/discourse-solved/spec/lib/guardian_extensions_spec.rb
@@ -3,7 +3,7 @@
describe DiscourseSolved::GuardianExtensions do
fab!(:user) { Fabricate(:user, refresh_auto_groups: true) }
fab!(:other_user) { Fabricate(:user, refresh_auto_groups: true) }
- fab!(:topic) { Fabricate(:topic_with_op) }
+ fab!(:topic, :topic_with_op)
fab!(:post) { Fabricate(:post, topic: topic, user: other_user) }
let(:guardian) { user.guardian }
diff --git a/plugins/discourse-solved/spec/lib/topic_extension_user_deletion_spec.rb b/plugins/discourse-solved/spec/lib/topic_extension_user_deletion_spec.rb
index 74fbecd0a98..f73c782d3f4 100644
--- a/plugins/discourse-solved/spec/lib/topic_extension_user_deletion_spec.rb
+++ b/plugins/discourse-solved/spec/lib/topic_extension_user_deletion_spec.rb
@@ -5,7 +5,7 @@ RSpec.describe DiscourseSolved::TopicExtension do
fab!(:topic)
fab!(:answer_post) { Fabricate(:post, topic:) }
- fab!(:accepter) { Fabricate(:user) }
+ fab!(:accepter, :user)
describe "#accepted_answer_post_info" do
let(:solved_topic) { Fabricate(:solved_topic, topic:, answer_post:, accepter:) }
diff --git a/plugins/discourse-solved/spec/models/directory_item_spec.rb b/plugins/discourse-solved/spec/models/directory_item_spec.rb
index 7b72585f3b2..45c90f8f859 100644
--- a/plugins/discourse-solved/spec/models/directory_item_spec.rb
+++ b/plugins/discourse-solved/spec/models/directory_item_spec.rb
@@ -61,7 +61,7 @@ describe DirectoryItem, type: :model do
end
it "excludes solutions for silenced users" do
- user.update(silenced_till: Time.zone.now + 1.day)
+ user.update(silenced_till: 1.day.from_now)
DiscourseSolved.accept_answer!(topic_post1, admin)
@@ -77,7 +77,7 @@ describe DirectoryItem, type: :model do
it "excludes solutions for suspended users" do
DiscourseSolved.accept_answer!(topic_post1, admin)
- user.update(suspended_till: Time.zone.now + 1.day)
+ user.update(suspended_till: 1.day.from_now)
DirectoryItem.refresh!
diff --git a/plugins/discourse-solved/spec/requests/answer_controller_spec.rb b/plugins/discourse-solved/spec/requests/answer_controller_spec.rb
index bdcbdd63d75..39466c82972 100644
--- a/plugins/discourse-solved/spec/requests/answer_controller_spec.rb
+++ b/plugins/discourse-solved/spec/requests/answer_controller_spec.rb
@@ -2,7 +2,7 @@
describe DiscourseSolved::AnswerController do
fab!(:user)
- fab!(:staff_user) { Fabricate(:admin) }
+ fab!(:staff_user, :admin)
fab!(:category)
fab!(:topic) { Fabricate(:topic, category: category) }
fab!(:p) { Fabricate(:post, topic: topic) }
diff --git a/plugins/discourse-solved/spec/requests/list_controller_spec.rb b/plugins/discourse-solved/spec/requests/list_controller_spec.rb
index 045da09445c..0240bb36d7c 100644
--- a/plugins/discourse-solved/spec/requests/list_controller_spec.rb
+++ b/plugins/discourse-solved/spec/requests/list_controller_spec.rb
@@ -1,7 +1,7 @@
# frozen_string_literal: true
RSpec.describe ListController do
- fab!(:p1) { Fabricate(:post) }
+ fab!(:p1, :post)
fab!(:p2) { Fabricate(:post, topic: p1.topic) }
fab!(:p3) { Fabricate(:post, topic: p1.topic) }
diff --git a/plugins/discourse-solved/spec/requests/solved_topics_controller_spec.rb b/plugins/discourse-solved/spec/requests/solved_topics_controller_spec.rb
index 2cd1ce2de17..8f07aaea358 100644
--- a/plugins/discourse-solved/spec/requests/solved_topics_controller_spec.rb
+++ b/plugins/discourse-solved/spec/requests/solved_topics_controller_spec.rb
@@ -2,7 +2,7 @@
describe DiscourseSolved::SolvedTopicsController do
fab!(:user)
- fab!(:another_user) { Fabricate(:user) }
+ fab!(:another_user, :user)
fab!(:admin)
fab!(:topic)
fab!(:post) { Fabricate(:post, topic:) }
diff --git a/plugins/discourse-solved/spec/system/solved_spec.rb b/plugins/discourse-solved/spec/system/solved_spec.rb
index b39cc3e0366..27ad5bcecee 100644
--- a/plugins/discourse-solved/spec/system/solved_spec.rb
+++ b/plugins/discourse-solved/spec/system/solved_spec.rb
@@ -2,7 +2,7 @@
describe "Solved", type: :system do
fab!(:admin)
- fab!(:solver) { Fabricate(:user) }
+ fab!(:solver, :user)
fab!(:accepter) { Fabricate(:user, name: "<b>DERP<b>") }
fab!(:topic) { Fabricate(:post, user: admin).topic }
fab!(:solver_post) { Fabricate(:post, topic:, user: solver, cooked: "The answer is 42") }
diff --git a/plugins/discourse-subscriptions/app/controllers/discourse_subscriptions/admin_controller.rb b/plugins/discourse-subscriptions/app/controllers/discourse_subscriptions/admin_controller.rb
index c5d69b95384..38b02f60e2f 100644
--- a/plugins/discourse-subscriptions/app/controllers/discourse_subscriptions/admin_controller.rb
+++ b/plugins/discourse-subscriptions/app/controllers/discourse_subscriptions/admin_controller.rb
@@ -5,7 +5,7 @@ module DiscourseSubscriptions
requires_plugin PLUGIN_NAME
def index
- head 200
+ head :ok
end
def refresh_campaign
diff --git a/plugins/discourse-subscriptions/app/controllers/discourse_subscriptions/hooks_controller.rb b/plugins/discourse-subscriptions/app/controllers/discourse_subscriptions/hooks_controller.rb
index 5f7b8cf0ea8..3b36d4d5183 100644
--- a/plugins/discourse-subscriptions/app/controllers/discourse_subscriptions/hooks_controller.rb
+++ b/plugins/discourse-subscriptions/app/controllers/discourse_subscriptions/hooks_controller.rb
@@ -36,7 +36,7 @@ module DiscourseSubscriptions
end
email = checkout_session[:customer_email]
- return head 200 if checkout_session[:status] != "complete"
+ return head :ok if checkout_session[:status] != "complete"
return render_json_error "email not found" if !email
if checkout_session[:customer].nil?
@@ -91,7 +91,7 @@ module DiscourseSubscriptions
when "customer.subscription.updated"
subscription = event[:data][:object]
status = subscription[:status]
- return head 200 if !%w[complete active].include?(status)
+ return head :ok if !%w[complete active].include?(status)
customer = find_active_customer(subscription[:customer], subscription[:plan][:product])
@@ -122,7 +122,7 @@ module DiscourseSubscriptions
end
end
- head 200
+ head :ok
end
private
diff --git a/plugins/discourse-subscriptions/app/controllers/discourse_subscriptions/pricingtable_controller.rb b/plugins/discourse-subscriptions/app/controllers/discourse_subscriptions/pricingtable_controller.rb
index d2ae713f785..a71d9cc913a 100644
--- a/plugins/discourse-subscriptions/app/controllers/discourse_subscriptions/pricingtable_controller.rb
+++ b/plugins/discourse-subscriptions/app/controllers/discourse_subscriptions/pricingtable_controller.rb
@@ -5,7 +5,7 @@ module DiscourseSubscriptions
requires_plugin PLUGIN_NAME
def index
- head 200
+ head :ok
end
end
end
diff --git a/plugins/discourse-subscriptions/spec/serializers/site_serializer_spec.rb b/plugins/discourse-subscriptions/spec/serializers/site_serializer_spec.rb
index a2221899676..a802a8c7962 100644
--- a/plugins/discourse-subscriptions/spec/serializers/site_serializer_spec.rb
+++ b/plugins/discourse-subscriptions/spec/serializers/site_serializer_spec.rb
@@ -18,7 +18,7 @@ describe SiteSerializer do
end
it "is true if the goal_met date is > 7 days old" do
- Discourse.redis.set("subscriptions_goal_met_date", 1.days.ago)
+ Discourse.redis.set("subscriptions_goal_met_date", 1.day.ago)
data = described_class.new(Site.new(guardian), scope: guardian, root: false).as_json
expect(data[:show_campaign_banner]).to be true
diff --git a/plugins/discourse-templates/app/models/discourse_templates/usage_count.rb b/plugins/discourse-templates/app/models/discourse_templates/usage_count.rb
index af23d0db4e1..32dcb1cafdb 100644
--- a/plugins/discourse-templates/app/models/discourse_templates/usage_count.rb
+++ b/plugins/discourse-templates/app/models/discourse_templates/usage_count.rb
@@ -6,7 +6,7 @@ module DiscourseTemplates
belongs_to :topic
- validates_presence_of :topic_id
+ validates :topic_id, presence: true
end
end
diff --git a/plugins/discourse-templates/spec/lib/guardian_extension_spec.rb b/plugins/discourse-templates/spec/lib/guardian_extension_spec.rb
index db07ea8b5fd..6d759ca15eb 100644
--- a/plugins/discourse-templates/spec/lib/guardian_extension_spec.rb
+++ b/plugins/discourse-templates/spec/lib/guardian_extension_spec.rb
@@ -7,7 +7,7 @@ describe DiscourseTemplates::GuardianExtension do
moderator
end
fab!(:user)
- fab!(:other_user) { Fabricate(:user) }
+ fab!(:other_user, :user)
fab!(:group) do
group = Fabricate(:group)
Fabricate(:group_user, group: group, user: user)
@@ -18,7 +18,7 @@ describe DiscourseTemplates::GuardianExtension do
Fabricate(:group_user, group: group, user: other_user)
group
end
- fab!(:discourse_templates_category) { Fabricate(:category_with_definition) }
+ fab!(:discourse_templates_category, :category_with_definition)
fab!(:templates_private_category) do
Fabricate(:private_category_with_definition, group: Group[:moderators])
end
diff --git a/plugins/discourse-templates/spec/lib/topic_extension_spec.rb b/plugins/discourse-templates/spec/lib/topic_extension_spec.rb
index 6c922006321..34c77e1af4c 100644
--- a/plugins/discourse-templates/spec/lib/topic_extension_spec.rb
+++ b/plugins/discourse-templates/spec/lib/topic_extension_spec.rb
@@ -38,13 +38,13 @@ describe DiscourseTemplates::TopicExtension do
fab!(:user)
context "with normal topics" do
- fab!(:templates_category) { Fabricate(:category_with_definition) }
+ fab!(:templates_category, :category_with_definition)
fab!(:template) { Fabricate(:template_item, category: templates_category) }
fab!(:templates_subcategory) do
Fabricate(:category_with_definition, parent_category: templates_category)
end
fab!(:template_on_sub) { Fabricate(:template_item, category: templates_category) }
- fab!(:other_category) { Fabricate(:category_with_definition) }
+ fab!(:other_category, :category_with_definition)
fab!(:other_topic) { Fabricate(:topic, category: other_category) }
before { SiteSetting.discourse_templates_categories = templates_category.id.to_s }
@@ -65,7 +65,7 @@ describe DiscourseTemplates::TopicExtension do
end
describe "private messages" do
- fab!(:other_user) { Fabricate(:user) }
+ fab!(:other_user, :user)
fab!(:tag_a) { Fabricate(:tag, name: "tag-a") }
fab!(:tag_b) { Fabricate(:tag, name: "tag-b") }
diff --git a/plugins/discourse-templates/spec/lib/topic_query_extension_spec.rb b/plugins/discourse-templates/spec/lib/topic_query_extension_spec.rb
index b249f14615b..1afd2f247d2 100644
--- a/plugins/discourse-templates/spec/lib/topic_query_extension_spec.rb
+++ b/plugins/discourse-templates/spec/lib/topic_query_extension_spec.rb
@@ -11,9 +11,9 @@ describe DiscourseTemplates::TopicQueryExtension do
end
describe "list_category_templates" do
- fab!(:other_category) { Fabricate(:category_with_definition) }
+ fab!(:other_category, :category_with_definition)
fab!(:other_topics) { Fabricate.times(5, :topic, category: other_category) }
- fab!(:discourse_templates_category) { Fabricate(:category_with_definition) }
+ fab!(:discourse_templates_category, :category_with_definition)
fab!(:templates) do
Fabricate.times(100, :template_item, category: discourse_templates_category)
end
@@ -111,8 +111,8 @@ describe DiscourseTemplates::TopicQueryExtension do
end
describe "list_private_templates" do
- fab!(:user_a) { Fabricate(:user) }
- fab!(:user_b) { Fabricate(:user) }
+ fab!(:user_a, :user)
+ fab!(:user_b, :user)
fab!(:group) do
group = Fabricate(:group)
Fabricate(:group_user, group: group, user: user)
diff --git a/plugins/discourse-templates/spec/lib/user_extension_spec.rb b/plugins/discourse-templates/spec/lib/user_extension_spec.rb
index 9cfcffaea61..175247afb96 100644
--- a/plugins/discourse-templates/spec/lib/user_extension_spec.rb
+++ b/plugins/discourse-templates/spec/lib/user_extension_spec.rb
@@ -6,7 +6,7 @@ describe DiscourseTemplates::UserExtension do
fab!(:user)
describe "can_use_category_templates?" do
- fab!(:discourse_templates_category) { Fabricate(:category_with_definition) }
+ fab!(:discourse_templates_category, :category_with_definition)
fab!(:templates_private_category) do
Fabricate(:private_category_with_definition, group: Group[:moderators])
end
@@ -61,7 +61,7 @@ describe DiscourseTemplates::UserExtension do
end
describe "can_use_private_templates?" do
- fab!(:other_user) { Fabricate(:user) }
+ fab!(:other_user, :user)
fab!(:group) do
group = Fabricate(:group)
diff --git a/plugins/discourse-templates/spec/requests/templates_controller_spec.rb b/plugins/discourse-templates/spec/requests/templates_controller_spec.rb
index 69e9cc003b0..72b1e59d187 100644
--- a/plugins/discourse-templates/spec/requests/templates_controller_spec.rb
+++ b/plugins/discourse-templates/spec/requests/templates_controller_spec.rb
@@ -8,8 +8,8 @@ describe DiscourseTemplates::TemplatesController do
fab!(:admin)
fab!(:moderator)
fab!(:user)
- fab!(:user_in_group1) { Fabricate(:user) }
- fab!(:user_in_group2) { Fabricate(:user) }
+ fab!(:user_in_group1, :user)
+ fab!(:user_in_group2, :user)
fab!(:group1) do
group = Fabricate(:group)
group.add(user_in_group1)
@@ -22,8 +22,8 @@ describe DiscourseTemplates::TemplatesController do
group.save
group
end
- fab!(:templates_parent_category) { Fabricate(:category_with_definition) }
- fab!(:templates_other_parent_category) { Fabricate(:category_with_definition) }
+ fab!(:templates_parent_category, :category_with_definition)
+ fab!(:templates_other_parent_category, :category_with_definition)
fab!(:templates_sub_category_moderators) do
Fabricate(
:private_category_with_definition,
@@ -59,9 +59,9 @@ describe DiscourseTemplates::TemplatesController do
fab!(:template_item_from_other_parent) do
Fabricate(:template_item, category: templates_other_parent_category)
end
- fab!(:other_topic1) { Fabricate(:template_item) } # uncategorized
- fab!(:other_topic2) { Fabricate(:template_item) } # uncategorized
- fab!(:other_topic3) { Fabricate(:template_item) } # uncategorized
+ fab!(:other_topic1, :template_item) # uncategorized
+ fab!(:other_topic2, :template_item) # uncategorized
+ fab!(:other_topic3, :template_item) # uncategorized
fab!(:tag) do
Fabricate(
:tag,
diff --git a/plugins/discourse-templates/spec/system/chat_composer_spec.rb b/plugins/discourse-templates/spec/system/chat_composer_spec.rb
index 4ecd7783b66..7521a1889f1 100644
--- a/plugins/discourse-templates/spec/system/chat_composer_spec.rb
+++ b/plugins/discourse-templates/spec/system/chat_composer_spec.rb
@@ -1,9 +1,9 @@
# frozen_string_literal: true
RSpec.describe "Inserting templates in the chat composer", type: :system do
- fab!(:current_user) { Fabricate(:user) }
- fab!(:other_user) { Fabricate(:user) }
- fab!(:templates_category) { Fabricate(:category) }
+ fab!(:current_user, :user)
+ fab!(:other_user, :user)
+ fab!(:templates_category, :category)
fab!(:template_simple) { Fabricate(:template_item, category: templates_category) }
fab!(:template_variables) do
Fabricate(
@@ -13,7 +13,7 @@ RSpec.describe "Inserting templates in the chat composer", type: :system do
)
end
- fab!(:channel_1) { Fabricate(:chat_channel) }
+ fab!(:channel_1, :chat_channel)
fab!(:message_1) do
Fabricate(:chat_message, user: current_user, chat_channel: channel_1, use_service: true)
end
diff --git a/plugins/discourse-topic-voting/spec/lib/topic_query_spec.rb b/plugins/discourse-topic-voting/spec/lib/topic_query_spec.rb
index fc47f7142e8..ce3d6fbb1f0 100644
--- a/plugins/discourse-topic-voting/spec/lib/topic_query_spec.rb
+++ b/plugins/discourse-topic-voting/spec/lib/topic_query_spec.rb
@@ -1,8 +1,8 @@
# frozen_string_literal: true
describe TopicQuery do
- fab!(:user0) { Fabricate(:user) }
- fab!(:category1) { Fabricate(:category) }
+ fab!(:user0, :user)
+ fab!(:category1, :category)
fab!(:topic0) { Fabricate(:topic, category: category1) }
fab!(:topic1) { Fabricate(:topic, category: category1) }
fab!(:vote) { DiscourseTopicVoting::Vote.create!(topic_id: topic1.id, user_id: user0.id) }
diff --git a/plugins/discourse-topic-voting/spec/requests/lists_controller_spec.rb b/plugins/discourse-topic-voting/spec/requests/lists_controller_spec.rb
index 2101ae5b74e..300988b166b 100644
--- a/plugins/discourse-topic-voting/spec/requests/lists_controller_spec.rb
+++ b/plugins/discourse-topic-voting/spec/requests/lists_controller_spec.rb
@@ -25,8 +25,8 @@ describe ListController do
end
context "in a category" do
- fab!(:category1) { Fabricate(:category) }
- fab!(:category2) { Fabricate(:category) }
+ fab!(:category1, :category)
+ fab!(:category2, :category)
fab!(:topic1) do
Fabricate(:topic, category: category1, title: "Topic in votes-enabled category 1")
end
diff --git a/plugins/discourse-topic-voting/spec/system/voting_spec.rb b/plugins/discourse-topic-voting/spec/system/voting_spec.rb
index 00d96690cdd..106ee0f78c1 100644
--- a/plugins/discourse-topic-voting/spec/system/voting_spec.rb
+++ b/plugins/discourse-topic-voting/spec/system/voting_spec.rb
@@ -3,8 +3,8 @@
RSpec.describe "Topic voting", type: :system do
fab!(:user)
fab!(:admin) { Fabricate(:admin, trust_level: TrustLevel[4]) }
- fab!(:category1) { Fabricate(:category) }
- fab!(:category2) { Fabricate(:category) }
+ fab!(:category1, :category)
+ fab!(:category2, :category)
fab!(:topic1) { Fabricate(:topic, category: category1) }
fab!(:topic2) { Fabricate(:topic, category: category1) }
fab!(:topic3) { Fabricate(:topic, category: category2) }
diff --git a/plugins/discourse-zendesk-plugin/app/controllers/discourse_zendesk_plugin/sync_controller.rb b/plugins/discourse-zendesk-plugin/app/controllers/discourse_zendesk_plugin/sync_controller.rb
index 6d803bc9000..8cec99bcee5 100644
--- a/plugins/discourse-zendesk-plugin/app/controllers/discourse_zendesk_plugin/sync_controller.rb
+++ b/plugins/discourse-zendesk-plugin/app/controllers/discourse_zendesk_plugin/sync_controller.rb
@@ -16,7 +16,7 @@ module DiscourseZendeskPlugin
def webhook
unless SiteSetting.zendesk_enabled? && SiteSetting.sync_comments_from_zendesk
- return render json: failed_json, status: 422
+ return render json: failed_json, status: :unprocessable_entity
end
ticket_id = params[:ticket_id]
diff --git a/plugins/discourse-zendesk-plugin/lib/discourse_zendesk_plugin/helper.rb b/plugins/discourse-zendesk-plugin/lib/discourse_zendesk_plugin/helper.rb
index fd93fae3c2a..b573a97f9a5 100644
--- a/plugins/discourse-zendesk-plugin/lib/discourse_zendesk_plugin/helper.rb
+++ b/plugins/discourse-zendesk-plugin/lib/discourse_zendesk_plugin/helper.rb
@@ -96,7 +96,7 @@ module DiscourseZendeskPlugin
result = zendesk_client.users.search(query: user.email)
return result.first if result.present? && result.size == 1
zendesk_client.users.create(
- name: (user.name.present? ? user.name : user.username),
+ name: user.name.presence || user.username,
email: user.email,
verified: true,
role: "end-user",
diff --git a/plugins/discourse-zendesk-plugin/spec/integration/topic_extensions_spec.rb b/plugins/discourse-zendesk-plugin/spec/integration/topic_extensions_spec.rb
index 5c4a2a8cedd..f613d9de1b9 100644
--- a/plugins/discourse-zendesk-plugin/spec/integration/topic_extensions_spec.rb
+++ b/plugins/discourse-zendesk-plugin/spec/integration/topic_extensions_spec.rb
@@ -7,7 +7,7 @@ describe "TopicExtensions" do
fab!(:topic_1) { Fabricate(:topic, user: user_1) }
context "when an enabled category is set on the topic" do
- fab!(:category_1) { Fabricate(:category) }
+ fab!(:category_1, :category)
before { SiteSetting.zendesk_autogenerate_categories = "#{category_1.id}" }
@@ -17,7 +17,7 @@ describe "TopicExtensions" do
args: {
topic_id: topic_1.id,
},
- at: Time.zone.now + 5.seconds,
+ at: 5.seconds.from_now,
) do
topic_1.category = category_1
topic_1.save!
@@ -36,7 +36,7 @@ describe "TopicExtensions" do
args: {
topic_id: topic_1.id,
},
- at: Time.zone.now + 5.seconds,
+ at: 5.seconds.from_now,
) do
topic_1.category = nil
topic_1.save!
diff --git a/script/bulk_import/discourse_merger.rb b/script/bulk_import/discourse_merger.rb
index 7cd39298102..c2331096c85 100644
--- a/script/bulk_import/discourse_merger.rb
+++ b/script/bulk_import/discourse_merger.rb
@@ -797,7 +797,7 @@ class BulkImport::DiscourseMerger < BulkImport::Base
processed =
(
if respond_to?(process_method_name)
- send(process_method_name, HashWithIndifferentAccess.new(row))
+ send(process_method_name, ActiveSupport::HashWithIndifferentAccess.new(row))
else
row
end
diff --git a/script/import_scripts/discuz_x.rb b/script/import_scripts/discuz_x.rb
index 211578e9369..ef4b0fb36ad 100644
--- a/script/import_scripts/discuz_x.rb
+++ b/script/import_scripts/discuz_x.rb
@@ -212,7 +212,7 @@ class ImportScripts::DiscuzX < ImportScripts::Base
first_exists(
user["address"],
(
- if !user["resideprovince"].blank?
+ if user["resideprovince"].present?
[
user["resideprovince"],
user["residecity"],
@@ -250,7 +250,8 @@ class ImportScripts::DiscuzX < ImportScripts::Base
end
end
end
- if !user["spacecss"].blank? && newmember.user_profile.profile_background_upload.blank?
+ if user["spacecss"].present? &&
+ newmember.user_profile.profile_background_upload.blank?
# profile background
if matched = user["spacecss"].match(/body\s*{[^}]*url\('?(.+?)'?\)/i)
body_background = matched[1].split(ORIGINAL_SITE_PREFIX, 2).last
@@ -310,7 +311,7 @@ class ImportScripts::DiscuzX < ImportScripts::Base
if newmember.email_digests
newmember.update(email_digests: user["email_confirmed"] == 1)
end
- if !newmember.name.blank? && newmember.name == (newmember.username)
+ if newmember.name.present? && newmember.name == (newmember.username)
newmember.update(name: "")
end
end,
@@ -341,8 +342,8 @@ class ImportScripts::DiscuzX < ImportScripts::Base
max_position = Category.all.max_by(&:position).position
create_categories(results) do |row|
next if row["type"] == ("group") || row["status"] == (2) # or row['status'].to_i == 3 # 如果不想导入群组,取消注释
- extra = PHP.unserialize(row["extra"]) if !row["extra"].blank?
- color = extra["namecolor"][1, 6] if extra && !extra["namecolor"].blank?
+ extra = PHP.unserialize(row["extra"]) if row["extra"].present?
+ color = extra["namecolor"][1, 6] if extra && extra["namecolor"].present?
Category.all.max_by(&:position).position
@@ -1156,7 +1157,7 @@ class ImportScripts::DiscuzX < ImportScripts::Base
end
def first_exists(*items)
- items.find { |item| !item.blank? } || ""
+ items.find { |item| item.present? } || ""
end
def mysql_query(sql)
diff --git a/script/import_scripts/jforum.rb b/script/import_scripts/jforum.rb
index 4ca82a2fe00..fc407a425b8 100644
--- a/script/import_scripts/jforum.rb
+++ b/script/import_scripts/jforum.rb
@@ -89,7 +89,7 @@ class ImportScripts::JForum < ImportScripts::Base
def user_fields
@user_fields ||=
begin
- Hash[UserField.all.map { |field| [field.name, field] }]
+ UserField.all.index_by(&:name)
end
end
diff --git a/script/import_scripts/mybb.rb b/script/import_scripts/mybb.rb
index 1e043d37a74..140e434d0ce 100644
--- a/script/import_scripts/mybb.rb
+++ b/script/import_scripts/mybb.rb
@@ -87,7 +87,7 @@ class ImportScripts::MyBB < ImportScripts::Base
avatar_url: avatar_url,
post_create_action:
proc do |newuser|
- if !user["avatar"].blank?
+ if user["avatar"].present?
avatar = user["avatar"].gsub(/\?.*/, "")
if avatar.match(/^http.*/)
UserAvatar.import_url_for_user(avatar, newuser)
diff --git a/script/import_scripts/phpbb3/importers/post_importer.rb b/script/import_scripts/phpbb3/importers/post_importer.rb
index 4f66560e349..6c5470d702b 100644
--- a/script/import_scripts/phpbb3/importers/post_importer.rb
+++ b/script/import_scripts/phpbb3/importers/post_importer.rb
@@ -31,8 +31,7 @@ module ImportScripts::PhpBB3
def map_post(row)
return if @settings.category_mappings.dig(row[:forum_id].to_s, :skip)
- imported_user_id =
- @settings.prefix(row[:post_username].blank? ? row[:poster_id] : row[:post_username])
+ imported_user_id = @settings.prefix(row[:post_username].presence || row[:poster_id])
user_id = @lookup.user_id_from_imported_user_id(imported_user_id) || -1
is_first_post = row[:post_id] == row[:topic_first_post_id]
diff --git a/script/import_scripts/phpbb3/importers/user_importer.rb b/script/import_scripts/phpbb3/importers/user_importer.rb
index 6f32223232c..d363c1bef5d 100644
--- a/script/import_scripts/phpbb3/importers/user_importer.rb
+++ b/script/import_scripts/phpbb3/importers/user_importer.rb
@@ -108,7 +108,7 @@ module ImportScripts::PhpBB3
def user_fields
@user_fields ||=
begin
- Hash[UserField.all.map { |field| [field.name, field] }]
+ UserField.all.index_by(&:name)
end
end
@@ -152,8 +152,7 @@ module ImportScripts::PhpBB3
if row[:user_inactive_reason] == Constants::INACTIVE_MANUAL
user.suspended_at = Time.now
user.suspended_till = 200.years.from_now
- ban_reason =
- row[:ban_reason].blank? ? "Account deactivated by administrator" : row[:ban_reason] # TODO i18n
+ ban_reason = row[:ban_reason].presence || "Account deactivated by administrator" # TODO i18n
elsif row[:ban_start].present?
user.suspended_at = Time.zone.at(row[:ban_start])
user.suspended_till = row[:ban_end] > 0 ? Time.zone.at(row[:ban_end]) : 200.years.from_now
diff --git a/script/import_scripts/phpbb3/support/settings.rb b/script/import_scripts/phpbb3/support/settings.rb
index e308e322cf5..cee09d6970c 100644
--- a/script/import_scripts/phpbb3/support/settings.rb
+++ b/script/import_scripts/phpbb3/support/settings.rb
@@ -50,7 +50,7 @@ module ImportScripts::PhpBB3
@new_categories = import_settings["new_categories"]
@category_mappings =
- import_settings.fetch("category_mappings", []).to_h { |m| [m[:source_category_id].to_s, m] }
+ import_settings.fetch("category_mappings", []).index_by { _1[:source_category_id].to_s }
@tag_mappings = import_settings["tag_mappings"]
@rank_mapping = import_settings["rank_mapping"]
diff --git a/script/import_scripts/vbulletin3.rb b/script/import_scripts/vbulletin3.rb
index 71ec3ec8d59..1eb6ff3f711 100644
--- a/script/import_scripts/vbulletin3.rb
+++ b/script/import_scripts/vbulletin3.rb
@@ -717,7 +717,7 @@ LEFT OUTER JOIN #{TABLE_PREFIX}avatar a ON a.avatarid = u.avatarid
puts "", "creating category moderator groups..."
forums = mysql_query("SELECT forumid, parentid, title FROM #{TABLE_PREFIX}forum").to_a
forums.each { |f| f["children"] = forums.select { |c| c["parentid"] == f["forumid"] } }
- forum_map = forums.map { |f| [f["forumid"], f] }.to_h
+ forum_map = forums.index_by { _1["forumid"] }
modentries = mysql_query(<<-SQL).to_a
SELECT m.forumid, m.userid, u.usergroupid IN (5,6) is_staff
FROM #{TABLE_PREFIX}moderator m
diff --git a/script/import_scripts/yammer.rb b/script/import_scripts/yammer.rb
index e7aa3f447b4..0530b66eede 100644
--- a/script/import_scripts/yammer.rb
+++ b/script/import_scripts/yammer.rb
@@ -228,7 +228,7 @@ class ImportScripts::Yammer < ImportScripts::Base
def import_categories
puts "", "creating categories"
parent_category = nil
- if !PARENT_CATEGORY_NAME.blank?
+ if PARENT_CATEGORY_NAME.present?
parent_category = Category.find_by(name: PARENT_CATEGORY_NAME)
parent_category =
Category.create(
@@ -310,13 +310,7 @@ class ImportScripts::Yammer < ImportScripts::Base
{
id: import_topic_id(row["id"]),
title:
- (
- if row["title"].present?
- row["title"]
- else
- row["raw"].split(/\W/)[0..(NUM_WORDS_IN_TITLE - 1)].join(" ")
- end
- ),
+ row["title"].presence || row["raw"].split(/\W/)[0..(NUM_WORDS_IN_TITLE - 1)].join(" "),
raw: normalize_raw(row["raw"]),
category:
(
@@ -369,13 +363,7 @@ class ImportScripts::Yammer < ImportScripts::Base
{
id: import_topic_id(row["id"]),
title:
- (
- if row["title"].present?
- row["title"]
- else
- row["raw"].split(/\W/)[0..(NUM_WORDS_IN_TITLE - 1)].join(" ")
- end
- ),
+ row["title"].presence || row["raw"].split(/\W/)[0..(NUM_WORDS_IN_TITLE - 1)].join(" "),
raw: normalize_raw(row["raw"]),
category:
(
diff --git a/script/profile_db_generator.rb b/script/profile_db_generator.rb
index b3b1e759b6d..7631754cecc 100644
--- a/script/profile_db_generator.rb
+++ b/script/profile_db_generator.rb
@@ -62,7 +62,7 @@ require_relative "../config/environment"
Jobs.run_immediately!
-unless Rails.env == "profile"
+unless Rails.env.profile?
puts "This script should only be used in the profile environment"
exit
end
diff --git a/spec/db/migrate/20250714010001_backfill_themeable_site_settings_spec.rb b/spec/db/migrate/20250714010001_backfill_themeable_site_settings_spec.rb
index 51b34629875..7c3b9dde0a2 100644
--- a/spec/db/migrate/20250714010001_backfill_themeable_site_settings_spec.rb
+++ b/spec/db/migrate/20250714010001_backfill_themeable_site_settings_spec.rb
@@ -3,8 +3,8 @@
require Rails.root.join("db/migrate/20250714010001_backfill_themeable_site_settings.rb")
RSpec.describe BackfillThemeableSiteSettings do
- fab!(:theme_1) { Fabricate(:theme) }
- fab!(:theme_2) { Fabricate(:theme) }
+ fab!(:theme_1, :theme)
+ fab!(:theme_2, :theme)
fab!(:theme_3) { Fabricate(:theme, component: true) }
before do
diff --git a/spec/fabricators/bookmark_fabricator.rb b/spec/fabricators/bookmark_fabricator.rb
index ba9271a22e2..74a384a1fee 100644
--- a/spec/fabricators/bookmark_fabricator.rb
+++ b/spec/fabricators/bookmark_fabricator.rb
@@ -12,11 +12,11 @@ Fabricator(:bookmark_next_business_day_reminder, from: :bookmark) do
reminder_at do
date =
if Time.zone.now.friday?
- Time.zone.now + 3.days
+ 3.days.from_now
elsif Time.zone.now.saturday?
- Time.zone.now + 2.days
+ 2.days.from_now
else
- Time.zone.now + 1.day
+ 1.day.from_now
end
date.iso8601
end
diff --git a/spec/jobs/bookmark_reminder_notifications_spec.rb b/spec/jobs/bookmark_reminder_notifications_spec.rb
index 7316d64034b..655c44e8628 100644
--- a/spec/jobs/bookmark_reminder_notifications_spec.rb
+++ b/spec/jobs/bookmark_reminder_notifications_spec.rb
@@ -4,7 +4,7 @@ RSpec.describe Jobs::BookmarkReminderNotifications do
subject(:job) { described_class.new }
fab!(:user)
- let(:five_minutes_ago) { Time.zone.now - 5.minutes }
+ let(:five_minutes_ago) { 5.minutes.ago }
let(:bookmark1) { Fabricate(:bookmark, user: user) }
let(:bookmark2) { Fabricate(:bookmark, user: user) }
let(:bookmark3) { Fabricate(:bookmark, user: user) }
@@ -30,7 +30,7 @@ RSpec.describe Jobs::BookmarkReminderNotifications do
it "will not send a reminder for a bookmark in the future" do
freeze_time
- bookmark4 = Fabricate(:bookmark, reminder_at: Time.zone.now + 1.day)
+ bookmark4 = Fabricate(:bookmark, reminder_at: 1.day.from_now)
expect { job.execute }.to change { Notification.where(user: user).count }.by(3)
expect(bookmark1.reload.reminder_last_sent_at).to eq_time(Time.zone.now)
expect(bookmark2.reload.reminder_last_sent_at).to eq_time(Time.zone.now)
diff --git a/spec/jobs/check_new_features_spec.rb b/spec/jobs/check_new_features_spec.rb
index 1caa61046f6..fd6bb7048ff 100644
--- a/spec/jobs/check_new_features_spec.rb
+++ b/spec/jobs/check_new_features_spec.rb
@@ -10,7 +10,7 @@ RSpec.describe Jobs::CheckNewFeatures do
description: "",
link: "https://meta.discourse.org/t/-/238821",
created_at: created_at.iso8601,
- updated_at: (created_at + 1.minutes).iso8601,
+ updated_at: (created_at + 1.minute).iso8601,
discourse_version: discourse_version,
}
end
diff --git a/spec/jobs/clean_dismissed_topic_users_spec.rb b/spec/jobs/clean_dismissed_topic_users_spec.rb
index b6e411814bb..9dc48055b43 100644
--- a/spec/jobs/clean_dismissed_topic_users_spec.rb
+++ b/spec/jobs/clean_dismissed_topic_users_spec.rb
@@ -1,7 +1,7 @@
# frozen_string_literal: true
RSpec.describe Jobs::CleanDismissedTopicUsers do
- fab!(:user) { Fabricate(:user, created_at: 1.days.ago, previous_visit_at: 1.days.ago) }
+ fab!(:user) { Fabricate(:user, created_at: 1.day.ago, previous_visit_at: 1.day.ago) }
fab!(:topic) { Fabricate(:topic, created_at: 5.hours.ago) }
fab!(:dismissed_topic_user) { Fabricate(:dismissed_topic_user, user: user, topic: topic) }
@@ -15,7 +15,7 @@ RSpec.describe Jobs::CleanDismissedTopicUsers do
user.user_option.update(new_topic_duration_minutes: User::NewTopicDuration::LAST_VISIT)
expect { described_class.new.execute({}) }.not_to change { DismissedTopicUser.count }
- user.update!(previous_visit_at: 1.hours.ago)
+ user.update!(previous_visit_at: 1.hour.ago)
expect { described_class.new.execute({}) }.to change { DismissedTopicUser.count }.by(-1)
end
@@ -29,7 +29,7 @@ RSpec.describe Jobs::CleanDismissedTopicUsers do
end
describe "#delete_over_the_limit_dismissals!" do
- fab!(:user2) { Fabricate(:user, created_at: 1.days.ago, previous_visit_at: 1.days.ago) }
+ fab!(:user2) { Fabricate(:user, created_at: 1.day.ago, previous_visit_at: 1.day.ago) }
fab!(:topic2) { Fabricate(:topic, created_at: 6.hours.ago) }
fab!(:topic3) { Fabricate(:topic, created_at: 2.hours.ago) }
fab!(:dismissed_topic_user2) { Fabricate(:dismissed_topic_user, user: user, topic: topic2) }
diff --git a/spec/jobs/clean_up_user_api_keys_max_life_spec.rb b/spec/jobs/clean_up_user_api_keys_max_life_spec.rb
index a000e908712..de60bfc8391 100644
--- a/spec/jobs/clean_up_user_api_keys_max_life_spec.rb
+++ b/spec/jobs/clean_up_user_api_keys_max_life_spec.rb
@@ -4,7 +4,7 @@ RSpec.describe Jobs::CleanUpUserApiKeysMaxLife do
fab!(:older_key) { Fabricate(:readonly_user_api_key, created_at: 3.days.ago) }
fab!(:newer_key) { Fabricate(:readonly_user_api_key, created_at: 1.day.ago) }
fab!(:revoked_key) do
- Fabricate(:readonly_user_api_key, created_at: 4.day.ago, revoked_at: 1.day.ago)
+ Fabricate(:readonly_user_api_key, created_at: 4.days.ago, revoked_at: 1.day.ago)
end
context "when user api key was created before the max life period" do
diff --git a/spec/jobs/delete_replies_spec.rb b/spec/jobs/delete_replies_spec.rb
index 7dfb7b62b22..b52545903f9 100644
--- a/spec/jobs/delete_replies_spec.rb
+++ b/spec/jobs/delete_replies_spec.rb
@@ -27,7 +27,7 @@ RSpec.describe Jobs::DeleteReplies do
}.by(-2)
topic_timer.reload
- expect(topic_timer.execute_at).to eq_time(2.day.from_now)
+ expect(topic_timer.execute_at).to eq_time(2.days.from_now)
end
it "does not delete posts with likes over the threshold" do
diff --git a/spec/jobs/export_csv_file_spec.rb b/spec/jobs/export_csv_file_spec.rb
index 65d89c6832e..08d59597abd 100644
--- a/spec/jobs/export_csv_file_spec.rb
+++ b/spec/jobs/export_csv_file_spec.rb
@@ -90,8 +90,8 @@ RSpec.describe Jobs::ExportCsvFile do
entity: "staff_action",
args: {
# Fine-tuning for 1 minute to ensure we capture the correct range
- start_date: (5.days.ago - 1.minutes).iso8601,
- end_date: (2.days.ago + 1.minutes).iso8601,
+ start_date: (5.days.ago - 1.minute).iso8601,
+ end_date: (2.days.ago + 1.minute).iso8601,
},
)
end.to change { Upload.count }.by(1)
@@ -119,7 +119,9 @@ RSpec.describe Jobs::ExportCsvFile do
.expects(:staff_action_records)
.with(
admin,
- HashWithIndifferentAccess.new("action_id" => UserHistory.actions[:suspend_user].to_s),
+ ActiveSupport::HashWithIndifferentAccess.new(
+ "action_id" => UserHistory.actions[:suspend_user].to_s,
+ ),
)
.returns(res)
@@ -148,7 +150,10 @@ RSpec.describe Jobs::ExportCsvFile do
exporter = Jobs::ExportCsvFile.new
exporter.entity = "report"
exporter.extra =
- HashWithIndifferentAccess.new(start_date: "2010-01-01", end_date: "2011-01-01")
+ ActiveSupport::HashWithIndifferentAccess.new(
+ start_date: "2010-01-01",
+ end_date: "2011-01-01",
+ )
exporter.current_user = User.find_by(id: user.id)
exporter
end
diff --git a/spec/jobs/export_user_archive_spec.rb b/spec/jobs/export_user_archive_spec.rb
index e1eedbbf9b6..d7f13c3d79a 100644
--- a/spec/jobs/export_user_archive_spec.rb
+++ b/spec/jobs/export_user_archive_spec.rb
@@ -344,7 +344,7 @@ RSpec.describe Jobs::ExportUserArchive do
bookmark1 =
manager.create_for(bookmarkable_id: post1.id, bookmarkable_type: "Post", name: name)
- update1_at = now + 1.hours
+ update1_at = now + 1.hour
bookmark1.update(name: "great food recipe", updated_at: update1_at)
manager.create_for(
diff --git a/spec/jobs/jobs_base_spec.rb b/spec/jobs/jobs_base_spec.rb
index 42630bf13a2..835d4b535a3 100644
--- a/spec/jobs/jobs_base_spec.rb
+++ b/spec/jobs/jobs_base_spec.rb
@@ -111,7 +111,10 @@ RSpec.describe ::Jobs::Base do
end
it "converts to an indifferent access hash" do
- ::Jobs::Base.any_instance.expects(:execute).with(instance_of(HashWithIndifferentAccess))
+ ::Jobs::Base
+ .any_instance
+ .expects(:execute)
+ .with(instance_of(ActiveSupport::HashWithIndifferentAccess))
::Jobs::Base.new.perform("hello" => "world")
end
diff --git a/spec/jobs/old_keys_reminder_spec.rb b/spec/jobs/old_keys_reminder_spec.rb
index f2ccae695d6..c2a70884e51 100644
--- a/spec/jobs/old_keys_reminder_spec.rb
+++ b/spec/jobs/old_keys_reminder_spec.rb
@@ -48,9 +48,9 @@ RSpec.describe Jobs::OldKeysReminder do
As a courtesy, we wanted to let you know that the following credentials used on your Discourse instance have not been updated in more than two years:
- google_oauth2_client_secret - #{google_secret.updated_at.to_date.to_fs(:db)}
- github_client_secret - #{github_secret.updated_at.to_date.to_fs(:db)}
- api key description - #{api_key.created_at.to_date.to_fs(:db)}
+ google_oauth2_client_secret - #{google_secret.updated_at.to_date.to_formatted_s(:db)}
+ github_client_secret - #{github_secret.updated_at.to_date.to_formatted_s(:db)}
+ api key description - #{api_key.created_at.to_date.to_formatted_s(:db)}
No action is required at this time, however, it is considered good security practice to cycle all your important credentials every few years.
TEXT
@@ -65,11 +65,11 @@ RSpec.describe Jobs::OldKeysReminder do
As a courtesy, we wanted to let you know that the following credentials used on your Discourse instance have not been updated in more than two years:
- google_oauth2_client_secret - #{google_secret.updated_at.to_date.to_fs(:db)}
- github_client_secret - #{github_secret.updated_at.to_date.to_fs(:db)}
- twitter_consumer_secret - #{recent_twitter_secret.updated_at.to_date.to_fs(:db)}
- api key description - #{api_key.created_at.to_date.to_fs(:db)}
- recent api key description - #{admin.username} - #{recent_api_key.created_at.to_date.to_fs(:db)}
+ google_oauth2_client_secret - #{google_secret.updated_at.to_date.to_formatted_s(:db)}
+ github_client_secret - #{github_secret.updated_at.to_date.to_formatted_s(:db)}
+ twitter_consumer_secret - #{recent_twitter_secret.updated_at.to_date.to_formatted_s(:db)}
+ api key description - #{api_key.created_at.to_date.to_formatted_s(:db)}
+ recent api key description - #{admin.username} - #{recent_api_key.created_at.to_date.to_formatted_s(:db)}
No action is required at this time, however, it is considered good security practice to cycle all your important credentials every few years.
TEXT
@@ -88,7 +88,7 @@ RSpec.describe Jobs::OldKeysReminder do
expect { described_class.new.execute({}) }.to change { Post.count }.by(1)
Topic.last.trash!
expect { described_class.new.execute({}) }.not_to change { Post.count }
- freeze_time 1.years.from_now
+ freeze_time 1.year.from_now
expect { described_class.new.execute({}) }.not_to change { Post.count }
freeze_time 3.days.from_now
expect { described_class.new.execute({}) }.to change { Post.count }.by(1)
diff --git a/spec/jobs/process_shelved_notifications_spec.rb b/spec/jobs/process_shelved_notifications_spec.rb
index 575e1b4b9c5..4292eead2be 100644
--- a/spec/jobs/process_shelved_notifications_spec.rb
+++ b/spec/jobs/process_shelved_notifications_spec.rb
@@ -8,7 +8,7 @@ RSpec.describe Jobs::ProcessShelvedNotifications do
it "removes all past do not disturb timings" do
future = Fabricate(:do_not_disturb_timing, ends_at: 1.day.from_now)
- past = Fabricate(:do_not_disturb_timing, starts_at: 2.day.ago, ends_at: 1.minute.ago)
+ past = Fabricate(:do_not_disturb_timing, starts_at: 2.days.ago, ends_at: 1.minute.ago)
expect { job.execute({}) }.to change { DoNotDisturbTiming.count }.by(-1)
expect(DoNotDisturbTiming.find_by(id: future.id)).to eq(future)
@@ -42,7 +42,7 @@ RSpec.describe Jobs::ProcessShelvedNotifications do
data: "{}",
notification_type: 1,
)
- user.do_not_disturb_timings.last.update(ends_at: 1.days.ago)
+ user.do_not_disturb_timings.last.update(ends_at: 1.day.ago)
expect(notification.shelved_notification).to be_present
job.execute({})
diff --git a/spec/jobs/topic_timer_enqueuer_spec.rb b/spec/jobs/topic_timer_enqueuer_spec.rb
index 1d8fa534b3c..c2bf80b7640 100644
--- a/spec/jobs/topic_timer_enqueuer_spec.rb
+++ b/spec/jobs/topic_timer_enqueuer_spec.rb
@@ -22,7 +22,7 @@ RSpec.describe Jobs::TopicTimerEnqueuer do
fab!(:future_timer) do
Fabricate(
:topic_timer,
- execute_at: 1.hours.from_now,
+ execute_at: 1.hour.from_now,
created_at: 1.hour.ago,
status_type: TopicTimer.types[:close],
)
@@ -60,7 +60,7 @@ RSpec.describe Jobs::TopicTimerEnqueuer do
it "does not re-enqueue a job that has already been scheduled ahead of time in sidekiq (legacy topic timers)" do
expect_not_enqueued_with(job: :close_topic, args: { topic_timer_id: timer1.id })
- Jobs.enqueue_at(1.hours.from_now, :close_topic, topic_timer_id: timer1.id)
+ Jobs.enqueue_at(1.hour.from_now, :close_topic, topic_timer_id: timer1.id)
job.execute
end
diff --git a/spec/lib/guardian/post_guardian_spec.rb b/spec/lib/guardian/post_guardian_spec.rb
index 30afbcc801d..68955e4bd77 100644
--- a/spec/lib/guardian/post_guardian_spec.rb
+++ b/spec/lib/guardian/post_guardian_spec.rb
@@ -5,7 +5,7 @@ RSpec.describe PostGuardian do
fab!(:user) { Fabricate(:user, refresh_auto_groups: true) }
fab!(:anon, :anonymous)
fab!(:admin)
- fab!(:another_admin) { Fabricate(:admin) }
+ fab!(:another_admin, :admin)
fab!(:moderator)
fab!(:trust_level_0) { Fabricate(:trust_level_0, refresh_auto_groups: true) }
fab!(:trust_level_4) { Fabricate(:trust_level_4, refresh_auto_groups: true) }
diff --git a/spec/lib/guardian/user_guardian_spec.rb b/spec/lib/guardian/user_guardian_spec.rb
index 5b1b2030631..1ebfce2c144 100644
--- a/spec/lib/guardian/user_guardian_spec.rb
+++ b/spec/lib/guardian/user_guardian_spec.rb
@@ -437,7 +437,7 @@ RSpec.describe UserGuardian do
user.user_stat = UserStat.new(new_since: 3.days.ago, first_post_created_at: 1.day.ago)
expect(guardian.can_delete_user?(user)).to eq(true)
- user.user_stat = UserStat.new(new_since: 3.days.ago, first_post_created_at: 3.day.ago)
+ user.user_stat = UserStat.new(new_since: 3.days.ago, first_post_created_at: 3.days.ago)
expect(guardian.can_delete_user?(user)).to eq(false)
end
end
@@ -448,7 +448,7 @@ RSpec.describe UserGuardian do
it "is allowed when even when user created the first post before delete_user_max_post_age days" do
SiteSetting.delete_user_max_post_age = 2
- user.user_stat = UserStat.new(new_since: 3.days.ago, first_post_created_at: 3.day.ago)
+ user.user_stat = UserStat.new(new_since: 3.days.ago, first_post_created_at: 3.days.ago)
expect(guardian.can_delete_user?(user)).to eq(true)
end
end
diff --git a/spec/lib/hijack_spec.rb b/spec/lib/hijack_spec.rb
index 84d949e83a0..cc3cd1124d8 100644
--- a/spec/lib/hijack_spec.rb
+++ b/spec/lib/hijack_spec.rb
@@ -45,7 +45,7 @@ RSpec.describe Hijack do
app =
lambda do |env|
tester = Hijack::Tester.new(env)
- tester.hijack_test { render body: "hello", status: 201 }
+ tester.hijack_test { render body: "hello", status: :created }
end
env = create_request_env(path: "/")
@@ -64,7 +64,7 @@ RSpec.describe Hijack do
tester.hijack_test do
copy_req = request
- render body: "hello world", status: 200
+ render body: "hello world", status: :ok
end
expect(copy_req.object_id).not_to eq(orig_req.object_id)
@@ -77,7 +77,7 @@ RSpec.describe Hijack do
app =
lambda do |env|
tester = Hijack::Tester.new(env)
- tester.hijack_test { render body: "hello", status: 201 }
+ tester.hijack_test { render body: "hello", status: :created }
expect(tester.io.string).to include("Access-Control-Allow-Origin: www.rainbows.com")
end
@@ -112,7 +112,7 @@ RSpec.describe Hijack do
app =
lambda do |env|
tester = Hijack::Tester.new(env)
- tester.hijack_test { render body: "hello", status: 201 }
+ tester.hijack_test { render body: "hello", status: :created }
expect(tester.io.string).to include("Access-Control-Allow-Origin: https://www.rainbows.com")
end
@@ -144,7 +144,7 @@ RSpec.describe Hijack do
tester.response.headers["Hello-World"] = "sam"
tester.hijack_test do
expires_in 1.year
- render body: "hello world", status: 402
+ render body: "hello world", status: :payment_required
end
expect(tester.io.string).to include("Hello-World: sam")
@@ -153,14 +153,14 @@ RSpec.describe Hijack do
it "handles expires_in" do
tester.hijack_test do
expires_in 1.year
- render body: "hello world", status: 402
+ render body: "hello world", status: :payment_required
end
expect(tester.io.string).to include("max-age=31556952")
end
it "renders non 200 status if asked for" do
- tester.hijack_test { render body: "hello world", status: 402 }
+ tester.hijack_test { render body: "hello world", status: :payment_required }
expect(tester.io.string).to include("402")
expect(tester.io.string).to include("world")
diff --git a/spec/lib/js_locale_helper_spec.rb b/spec/lib/js_locale_helper_spec.rb
index 685d3dabd4a..4142f3cd4c6 100644
--- a/spec/lib/js_locale_helper_spec.rb
+++ b/spec/lib/js_locale_helper_spec.rb
@@ -28,7 +28,7 @@ RSpec.describe JsLocaleHelper do
module StubLoadTranslations
def set_translations(locale, translations)
- @loaded_translations ||= HashWithIndifferentAccess.new
+ @loaded_translations ||= ActiveSupport::HashWithIndifferentAccess.new
@loaded_translations[locale] = translations
end
diff --git a/spec/lib/post_creator_spec.rb b/spec/lib/post_creator_spec.rb
index 68636d0ba7a..b14a0cd83f4 100644
--- a/spec/lib/post_creator_spec.rb
+++ b/spec/lib/post_creator_spec.rb
@@ -461,8 +461,8 @@ RSpec.describe PostCreator do
Fabricate(
:topic_timer,
based_on_last_post: true,
- execute_at: Time.zone.now - 12.hours,
- created_at: Time.zone.now - 24.hours,
+ execute_at: 12.hours.ago,
+ created_at: 24.hours.ago,
duration_minutes: 12 * 60,
)
end
@@ -479,7 +479,7 @@ RSpec.describe PostCreator do
topic_timer.reload
- expect(topic_timer.execute_at).to eq_time(Time.zone.now + 12.hours)
+ expect(topic_timer.execute_at).to eq_time(12.hours.from_now)
expect(topic_timer.created_at).to eq_time(Time.zone.now)
end
@@ -952,7 +952,7 @@ RSpec.describe PostCreator do
coding_horror,
raw: "first post in topic",
topic_id: topic.id,
- created_at: Time.zone.now - 24.hours,
+ created_at: 24.hours.ago,
).create
end
diff --git a/spec/lib/post_revisor_spec.rb b/spec/lib/post_revisor_spec.rb
index 5a18110cce3..eef2f2ef646 100644
--- a/spec/lib/post_revisor_spec.rb
+++ b/spec/lib/post_revisor_spec.rb
@@ -533,7 +533,7 @@ describe PostRevisor do
post_revisor.revise!(
post.user,
{ raw: "updated body" },
- revised_at: post.updated_at + SiteSetting.editing_grace_period + 1.seconds,
+ revised_at: post.updated_at + SiteSetting.editing_grace_period + 1.second,
)
# "roll back"
post_revisor.revise!(
@@ -1605,7 +1605,7 @@ describe PostRevisor do
post_revisor.revise!(
post.user,
{ raw: "updated body" },
- revised_at: post.updated_at + SiteSetting.editing_grace_period + 1.seconds,
+ revised_at: post.updated_at + SiteSetting.editing_grace_period + 1.second,
)
}.not_to change { post.topic.bumped_at }
end
@@ -1616,7 +1616,7 @@ describe PostRevisor do
post_revisor.revise!(
post.user,
{ raw: "updated body" },
- revised_at: post.updated_at + SiteSetting.editing_grace_period + 1.seconds,
+ revised_at: post.updated_at + SiteSetting.editing_grace_period + 1.second,
)
}.not_to change { post.topic.bumped_at }
end
@@ -1626,7 +1626,7 @@ describe PostRevisor do
post_revisor.revise!(
post.user,
{ title: "This is an updated topic title" },
- revised_at: post.updated_at + SiteSetting.editing_grace_period + 1.seconds,
+ revised_at: post.updated_at + SiteSetting.editing_grace_period + 1.second,
)
}.not_to change { post.topic.bumped_at }
end
@@ -1636,7 +1636,7 @@ describe PostRevisor do
post_revisor.revise!(
post.user,
{ category_id: Fabricate(:category).id },
- revised_at: post.updated_at + SiteSetting.editing_grace_period + 1.seconds,
+ revised_at: post.updated_at + SiteSetting.editing_grace_period + 1.second,
)
}.not_to change { post.topic.bumped_at }
end
@@ -1674,7 +1674,7 @@ describe PostRevisor do
post_revisor.revise!(
post.user,
{ raw: "updated body" },
- revised_at: post.updated_at + SiteSetting.editing_grace_period + 1.seconds,
+ revised_at: post.updated_at + SiteSetting.editing_grace_period + 1.second,
)
}.not_to change { post.topic.bumped_at }
end
@@ -1688,7 +1688,7 @@ describe PostRevisor do
post_revisor.revise!(
post.user,
{ raw: "updated body" },
- revised_at: post.updated_at + SiteSetting.editing_grace_period + 1.seconds,
+ revised_at: post.updated_at + SiteSetting.editing_grace_period + 1.second,
)
}.to change { post.topic.bumped_at }
end
@@ -1703,7 +1703,7 @@ describe PostRevisor do
post_revisor.revise!(
post.user,
{ raw: "updated body" },
- revised_at: post.updated_at + SiteSetting.editing_grace_period + 1.seconds,
+ revised_at: post.updated_at + SiteSetting.editing_grace_period + 1.second,
)
}.to change { post.topic.bumped_at }
end
@@ -1716,7 +1716,7 @@ describe PostRevisor do
post_revisor_other.revise!(
post.user,
{ raw: "updated body" },
- revised_at: post.updated_at + SiteSetting.editing_grace_period + 1.seconds,
+ revised_at: post.updated_at + SiteSetting.editing_grace_period + 1.second,
)
}.not_to change { post.topic.bumped_at }
end
diff --git a/spec/lib/s3_inventory_spec.rb b/spec/lib/s3_inventory_spec.rb
index 593cd88f879..ee2d756667d 100644
--- a/spec/lib/s3_inventory_spec.rb
+++ b/spec/lib/s3_inventory_spec.rb
@@ -59,7 +59,7 @@ RSpec.describe S3Inventory do
)
end
- @upload_1 = Fabricate(:upload, etag: "ETag", updated_at: 1.days.ago)
+ @upload_1 = Fabricate(:upload, etag: "ETag", updated_at: 1.day.ago)
@upload_2 = Fabricate(:upload, etag: "ETag2", updated_at: Time.now)
@no_etag = Fabricate(:upload, updated_at: 2.days.ago)
@@ -228,7 +228,7 @@ RSpec.describe S3Inventory do
Fabricate(:upload, etag: row[S3Inventory::CSV_ETAG_INDEX], updated_at: 2.days.ago)
end
- upload = Fabricate(:upload, etag: "ETag", updated_at: 1.days.ago)
+ upload = Fabricate(:upload, etag: "ETag", updated_at: 1.day.ago)
Fabricate(:upload, etag: "ETag2", updated_at: Time.now)
no_etag = Fabricate(:upload, updated_at: 2.days.ago)
diff --git a/spec/lib/site_setting_extension_spec.rb b/spec/lib/site_setting_extension_spec.rb
index 9a9e23425a5..8210082ee81 100644
--- a/spec/lib/site_setting_extension_spec.rb
+++ b/spec/lib/site_setting_extension_spec.rb
@@ -996,8 +996,8 @@ RSpec.describe SiteSettingExtension do
end
describe "themeable settings" do
- fab!(:theme_1) { Fabricate(:theme) }
- fab!(:theme_2) { Fabricate(:theme) }
+ fab!(:theme_1, :theme)
+ fab!(:theme_2, :theme)
fab!(:tss_1) do
Fabricate(
:theme_site_setting_with_service,
diff --git a/spec/lib/statistics_spec.rb b/spec/lib/statistics_spec.rb
index 6c8fe74077f..9f64ee563ba 100644
--- a/spec/lib/statistics_spec.rb
+++ b/spec/lib/statistics_spec.rb
@@ -32,10 +32,10 @@ RSpec.describe Statistics do
ApplicationRequest.increment!(:page_view_logged_in_browser)
end
- UserVisit.create!(user_id: users[0].id, visited_at: date - 50.minute)
+ UserVisit.create!(user_id: users[0].id, visited_at: date - 50.minutes)
UserVisit.create!(user_id: users[0].id, visited_at: date - 36.hours)
- UserVisit.create!(user_id: users[1].id, visited_at: date - 2.day)
+ UserVisit.create!(user_id: users[1].id, visited_at: date - 2.days)
UserVisit.create!(user_id: users[0].id, visited_at: date - 4.days)
UserVisit.create!(user_id: users[2].id, visited_at: date - 6.days)
UserVisit.create!(user_id: users[3].id, visited_at: date - 3.days)
diff --git a/spec/lib/topic_query_spec.rb b/spec/lib/topic_query_spec.rb
index 11d5ecbc8ff..7948f62c5a8 100644
--- a/spec/lib/topic_query_spec.rb
+++ b/spec/lib/topic_query_spec.rb
@@ -141,7 +141,7 @@ RSpec.describe TopicQuery do
pinned_globally: true,
like_count: 1,
)
- _topic = Fabricate(:topic, created_at: 5.minute.ago, like_count: 100)
+ _topic = Fabricate(:topic, created_at: 5.minutes.ago, like_count: 100)
topic = Fabricate(:topic, created_at: 1.minute.ago, like_count: 100)
# pinned topic is older so generally it would not hit the batch without
@@ -221,21 +221,21 @@ RSpec.describe TopicQuery do
pinned1 =
Fabricate(
:topic,
- bumped_at: 3.hour.ago,
- pinned_at: 1.hours.ago,
+ bumped_at: 3.hours.ago,
+ pinned_at: 1.hour.ago,
pinned_until: 10.days.from_now,
pinned_globally: true,
)
pinned2 =
Fabricate(
:topic,
- bumped_at: 2.hour.ago,
+ bumped_at: 2.hours.ago,
pinned_at: 4.hours.ago,
pinned_until: 10.days.from_now,
pinned_globally: true,
)
- unpinned1 = Fabricate(:topic, bumped_at: 2.hour.ago)
- unpinned2 = Fabricate(:topic, bumped_at: 3.hour.ago)
+ unpinned1 = Fabricate(:topic, bumped_at: 2.hours.ago)
+ unpinned2 = Fabricate(:topic, bumped_at: 3.hours.ago)
topic_query = TopicQuery.new(user)
results = topic_query.send(:default_results)
@@ -252,20 +252,20 @@ RSpec.describe TopicQuery do
Fabricate(
:topic,
category: cat,
- bumped_at: 3.hour.ago,
- pinned_at: 1.hours.ago,
+ bumped_at: 3.hours.ago,
+ pinned_at: 1.hour.ago,
pinned_until: 10.days.from_now,
)
pinned2 =
Fabricate(
:topic,
category: cat,
- bumped_at: 2.hour.ago,
+ bumped_at: 2.hours.ago,
pinned_at: 4.hours.ago,
pinned_until: 10.days.from_now,
)
- unpinned1 = Fabricate(:topic, category: cat, bumped_at: 2.hour.ago)
- unpinned2 = Fabricate(:topic, category: cat, bumped_at: 3.hour.ago)
+ unpinned1 = Fabricate(:topic, category: cat, bumped_at: 2.hours.ago)
+ unpinned2 = Fabricate(:topic, category: cat, bumped_at: 3.hours.ago)
topic_query = TopicQuery.new(user)
results = topic_query.send(:default_results)
@@ -2275,7 +2275,7 @@ RSpec.describe TopicQuery do
describe "with topic_query_create_list_topics modifier" do
fab!(:topic1) { Fabricate(:topic, created_at: 3.days.ago, bumped_at: 1.hour.ago) }
- fab!(:topic2) { Fabricate(:topic, created_at: 2.days.ago, bumped_at: 3.hour.ago) }
+ fab!(:topic2) { Fabricate(:topic, created_at: 2.days.ago, bumped_at: 3.hours.ago) }
it "allows changing" do
original_topic_query = TopicQuery.new(user)
diff --git a/spec/lib/topics_bulk_action_spec.rb b/spec/lib/topics_bulk_action_spec.rb
index 49f9ec6450d..2d1e13bf8f9 100644
--- a/spec/lib/topics_bulk_action_spec.rb
+++ b/spec/lib/topics_bulk_action_spec.rb
@@ -5,7 +5,7 @@ RSpec.describe TopicsBulkAction do
fab!(:topic) { Fabricate(:topic, user: user) }
describe "#dismiss_topics" do
- fab!(:user) { Fabricate(:user, created_at: 1.days.ago, refresh_auto_groups: true) }
+ fab!(:user) { Fabricate(:user, created_at: 1.day.ago, refresh_auto_groups: true) }
fab!(:category)
fab!(:topic2) { Fabricate(:topic, category: category, created_at: 60.minutes.ago) }
fab!(:topic3) { Fabricate(:topic, category: category, created_at: 120.minutes.ago) }
@@ -161,7 +161,7 @@ RSpec.describe TopicsBulkAction do
fab!(:fist_post) { Fabricate(:post, topic: topic) }
describe "option 'perform action silently'" do
- fab!(:watcher) { Fabricate(:user) }
+ fab!(:watcher, :user)
fab!(:admin)
before do
diff --git a/spec/lib/topics_filter_spec.rb b/spec/lib/topics_filter_spec.rb
index 3954fe9379b..d561eed9fe4 100644
--- a/spec/lib/topics_filter_spec.rb
+++ b/spec/lib/topics_filter_spec.rb
@@ -195,8 +195,8 @@ RSpec.describe TopicsFilter do
end
describe "ordering by hot score" do
- fab!(:t1) { Fabricate(:topic) }
- fab!(:t2) { Fabricate(:topic) }
+ fab!(:t1, :topic)
+ fab!(:t2, :topic)
before do
TopicHotScore.create!(topic_id: t1.id, score: 2.0)
@@ -244,7 +244,7 @@ RSpec.describe TopicsFilter do
end
fab!(:expired_pinned_topic) do
- Fabricate(:topic, pinned_at: 2.hour.ago, pinned_until: 1.hour.ago)
+ Fabricate(:topic, pinned_at: 2.hours.ago, pinned_until: 1.hour.ago)
end
describe "when query string is `in:pinned`" do
@@ -270,7 +270,7 @@ RSpec.describe TopicsFilter do
end
describe "new / unread operators" do
- fab!(:user_for_new_filters) { Fabricate(:user) }
+ fab!(:user_for_new_filters, :user)
let!(:new_topic) { Fabricate(:topic) }
let!(:unread_topic) do
Fabricate(:topic, created_at: 2.days.ago).tap do |t|
diff --git a/spec/models/about_spec.rb b/spec/models/about_spec.rb
index f756ad9932b..e9a805da876 100644
--- a/spec/models/about_spec.rb
+++ b/spec/models/about_spec.rb
@@ -67,9 +67,9 @@ RSpec.describe About do
describe "#category_moderators" do
fab!(:user)
fab!(:public_cat_moderator) { Fabricate(:user, last_seen_at: 1.month.ago) }
- fab!(:private_cat_moderator) { Fabricate(:user, last_seen_at: 2.month.ago) }
- fab!(:common_moderator) { Fabricate(:user, last_seen_at: 3.month.ago) }
- fab!(:common_moderator_2) { Fabricate(:user, last_seen_at: 4.month.ago) }
+ fab!(:private_cat_moderator) { Fabricate(:user, last_seen_at: 2.months.ago) }
+ fab!(:common_moderator) { Fabricate(:user, last_seen_at: 3.months.ago) }
+ fab!(:common_moderator_2) { Fabricate(:user, last_seen_at: 4.months.ago) }
fab!(:public_group) do
Fabricate(:public_group, users: [public_cat_moderator, common_moderator, common_moderator_2])
diff --git a/spec/models/api_key_spec.rb b/spec/models/api_key_spec.rb
index 8bf69c794e5..607ff488a9f 100644
--- a/spec/models/api_key_spec.rb
+++ b/spec/models/api_key_spec.rb
@@ -94,7 +94,7 @@ RSpec.describe ApiKey do
SiteSetting.revoke_api_keys_maxlife_days = 2
older_key = Fabricate(:api_key, created_at: 3.days.ago)
- newer_key = Fabricate(:api_key, created_at: 1.days.ago)
+ newer_key = Fabricate(:api_key, created_at: 1.day.ago)
revoked_key = Fabricate(:api_key, created_at: 3.days.ago, revoked_at: 1.day.ago)
expect { ApiKey.revoke_max_life_keys! }.to change { older_key.reload.revoked_at }.from(nil).to(
diff --git a/spec/models/category_list_spec.rb b/spec/models/category_list_spec.rb
index 6c5d2a3d8fa..68abc136ef5 100644
--- a/spec/models/category_list_spec.rb
+++ b/spec/models/category_list_spec.rb
@@ -305,7 +305,7 @@ RSpec.describe CategoryList do
cat4 = Fabricate(:category_with_definition, position: 3)
cat5 = Fabricate(:category_with_definition, parent_category_id: cat2.id)
- Fabricate(:topic, category_id: cat3.id, bumped_at: 1.minutes.ago)
+ Fabricate(:topic, category_id: cat3.id, bumped_at: 1.minute.ago)
Fabricate(:topic, category_id: cat5.id, bumped_at: 2.minutes.ago)
Fabricate(:topic, category_id: cat1.id, bumped_at: 3.minutes.ago)
Fabricate(:topic, category_id: cat2.id, bumped_at: 5.minutes.ago)
@@ -329,7 +329,7 @@ RSpec.describe CategoryList do
sub_cat_private.set_permissions(admins: :full)
sub_cat_private.save
- Fabricate(:topic, category: sub_cat_private, bumped_at: 1.minutes.ago)
+ Fabricate(:topic, category: sub_cat_private, bumped_at: 1.minute.ago)
Fabricate(:topic, category: public_cat, bumped_at: 3.minutes.ago)
Fabricate(:topic, category: public_cat2, bumped_at: 4.minutes.ago)
diff --git a/spec/models/concerns/reports/associated_accounts_by_provider_spec.rb b/spec/models/concerns/reports/associated_accounts_by_provider_spec.rb
index 232684f73e7..e0903d39ced 100644
--- a/spec/models/concerns/reports/associated_accounts_by_provider_spec.rb
+++ b/spec/models/concerns/reports/associated_accounts_by_provider_spec.rb
@@ -2,12 +2,12 @@
RSpec.describe "Reports::AssociatedAccountsByProvider" do
describe "associated_accounts_by_provider report" do
- fab!(:user1) { Fabricate(:user) }
- fab!(:user2) { Fabricate(:user) }
- fab!(:user3) { Fabricate(:user) }
- fab!(:user4) { Fabricate(:user) } # User with no associated accounts
- fab!(:user5) { Fabricate(:user) } # User with disabled provider
- fab!(:user6) { Fabricate(:user) } # User with DiscourseConnect
+ fab!(:user1, :user)
+ fab!(:user2, :user)
+ fab!(:user3, :user)
+ fab!(:user4, :user) # User with no associated accounts
+ fab!(:user5, :user) # User with disabled provider
+ fab!(:user6, :user) # User with DiscourseConnect
before do
# Mock enabled authenticators to only include specific providers
diff --git a/spec/models/group_spec.rb b/spec/models/group_spec.rb
index 062d88c31ea..f665cb9e8a2 100644
--- a/spec/models/group_spec.rb
+++ b/spec/models/group_spec.rb
@@ -92,7 +92,7 @@ RSpec.describe Group do
it "filters results by datetime using the before parameter" do
p1 = Fabricate(:post)
- p2 = Fabricate(:post, created_at: p1.created_at + 2.minute)
+ p2 = Fabricate(:post, created_at: p1.created_at + 2.minutes)
group.add(p1.user)
posts = group.posts_for(Guardian.new, before: p1.created_at + 1.minute)
@@ -757,7 +757,7 @@ RSpec.describe Group do
end
describe "when a user has qualified for trust level 1" do
- fab!(:user) { Fabricate(:user, trust_level: 1, created_at: Time.zone.now - 10.years) }
+ fab!(:user) { Fabricate(:user, trust_level: 1, created_at: 10.years.ago) }
fab!(:group) { Fabricate(:group, grant_trust_level: 3) }
fab!(:group2) { Fabricate(:group, grant_trust_level: 2) }
diff --git a/spec/models/notification_spec.rb b/spec/models/notification_spec.rb
index 90d1dc226ff..5c7b4be8ad4 100644
--- a/spec/models/notification_spec.rb
+++ b/spec/models/notification_spec.rb
@@ -504,7 +504,7 @@ RSpec.describe Notification do
end
fab!(:unread_high_priority_2) do
- create(high_priority: true, read: false, created_at: 1.minutes.ago)
+ create(high_priority: true, read: false, created_at: 1.minute.ago)
end
fab!(:read_high_priority_2) do
create(high_priority: true, read: true, created_at: 2.minutes.ago)
diff --git a/spec/models/post_mover_spec.rb b/spec/models/post_mover_spec.rb
index 1e550d1bf33..f0069caa842 100644
--- a/spec/models/post_mover_spec.rb
+++ b/spec/models/post_mover_spec.rb
@@ -2055,7 +2055,7 @@ RSpec.describe PostMover do
Fabricate(:post, topic: source_2_topic, user: user, created_at: 2.hours.ago)
create_post_timing(source_2_topic.first_post, user, 400)
source_2_post =
- Fabricate(:post, topic: source_2_topic, user: user, created_at: 1.hours.ago)
+ Fabricate(:post, topic: source_2_topic, user: user, created_at: 1.hour.ago)
create_post_timing(source_2_topic.posts.second, user, 500)
moved_to =
diff --git a/spec/models/report_spec.rb b/spec/models/report_spec.rb
index 72093344ad2..aa8e24cbe2e 100644
--- a/spec/models/report_spec.rb
+++ b/spec/models/report_spec.rb
@@ -734,7 +734,7 @@ RSpec.describe Report do
exporter = Jobs::ExportCsvFile.new
exporter.entity = "report"
- exporter.extra = HashWithIndifferentAccess.new(name: "flags_status")
+ exporter.extra = ActiveSupport::HashWithIndifferentAccess.new(name: "flags_status")
exporter.current_user = flagger
exported_csv = []
exporter.report_export { |entry| exported_csv << entry }
@@ -1882,35 +1882,35 @@ RSpec.describe Report do
topic: topic_1,
anonymous_views: 4,
logged_in_views: 2,
- viewed_at: Time.zone.now - 5.days,
+ viewed_at: 5.days.ago,
)
Fabricate(
:topic_view_stat,
topic: topic_1,
anonymous_views: 5,
logged_in_views: 18,
- viewed_at: Time.zone.now - 3.days,
+ viewed_at: 3.days.ago,
)
Fabricate(
:topic_view_stat,
topic: topic_2,
anonymous_views: 14,
logged_in_views: 21,
- viewed_at: Time.zone.now - 5.days,
+ viewed_at: 5.days.ago,
)
Fabricate(
:topic_view_stat,
topic: topic_2,
anonymous_views: 9,
logged_in_views: 13,
- viewed_at: Time.zone.now - 1.days,
+ viewed_at: 1.day.ago,
)
Fabricate(
:topic_view_stat,
topic: Fabricate(:topic),
anonymous_views: 1,
logged_in_views: 34,
- viewed_at: Time.zone.now - 40.days,
+ viewed_at: 40.days.ago,
)
end
diff --git a/spec/models/site_setting_spec.rb b/spec/models/site_setting_spec.rb
index 7b463735dda..06a4861c2db 100644
--- a/spec/models/site_setting_spec.rb
+++ b/spec/models/site_setting_spec.rb
@@ -98,7 +98,7 @@ RSpec.describe SiteSetting do
end
it "should_return_a_time_period" do
- expect(SiteSetting.min_redirected_to_top_period(1.days.ago)).to eq(:daily)
+ expect(SiteSetting.min_redirected_to_top_period(1.day.ago)).to eq(:daily)
end
end
@@ -110,7 +110,7 @@ RSpec.describe SiteSetting do
end
it "should_return_a_time_period" do
- expect(SiteSetting.min_redirected_to_top_period(1.days.ago)).to eq(nil)
+ expect(SiteSetting.min_redirected_to_top_period(1.day.ago)).to eq(nil)
end
end
end
diff --git a/spec/models/sitemap_spec.rb b/spec/models/sitemap_spec.rb
index fb12a377f61..9c831ab7015 100644
--- a/spec/models/sitemap_spec.rb
+++ b/spec/models/sitemap_spec.rb
@@ -104,8 +104,8 @@ RSpec.describe Sitemap do
end
it "order topics by bumped_at asc" do
- topic_1 = Fabricate(:topic, bumped_at: 3.minute.ago)
- topic_2 = Fabricate(:topic, bumped_at: 1.minutes.ago)
+ topic_1 = Fabricate(:topic, bumped_at: 3.minutes.ago)
+ topic_2 = Fabricate(:topic, bumped_at: 1.minute.ago)
topic_3 = Fabricate(:topic, bumped_at: 20.minutes.ago)
topic_ids = sitemap.topics.map { |td| td[0] }
diff --git a/spec/models/theme_site_setting_spec.rb b/spec/models/theme_site_setting_spec.rb
index 7a67bc990b9..c85ef1f2570 100644
--- a/spec/models/theme_site_setting_spec.rb
+++ b/spec/models/theme_site_setting_spec.rb
@@ -1,8 +1,8 @@
# frozen_string_literal: true
RSpec.describe ThemeSiteSetting do
- fab!(:theme_1) { Fabricate(:theme) }
- fab!(:theme_2) { Fabricate(:theme) }
+ fab!(:theme_1, :theme)
+ fab!(:theme_2, :theme)
fab!(:theme_site_setting_1) do
Fabricate(
:theme_site_setting_with_service,
diff --git a/spec/models/topic_hot_scores_spec.rb b/spec/models/topic_hot_scores_spec.rb
index 936e337e87e..dc1207d0a91 100644
--- a/spec/models/topic_hot_scores_spec.rb
+++ b/spec/models/topic_hot_scores_spec.rb
@@ -13,7 +13,7 @@ RSpec.describe TopicHotScore do
# this will come in with a score
topic = Fabricate(:topic, created_at: 1.hour.ago, bumped_at: 2.minutes.ago)
- post = Fabricate(:post, topic: topic, created_at: 2.minute.ago)
+ post = Fabricate(:post, topic: topic, created_at: 2.minutes.ago)
PostActionCreator.like(user, post)
TopicHotScore.update_scores
diff --git a/spec/models/topic_spec.rb b/spec/models/topic_spec.rb
index 90b4af19c68..ff834f0fead 100644
--- a/spec/models/topic_spec.rb
+++ b/spec/models/topic_spec.rb
@@ -3542,7 +3542,7 @@ describe Topic do
from_address: "[email protected]",
topic: topic,
post: topic.posts.first,
- created_at: 1.minutes.ago,
+ created_at: 1.minute.ago,
)
end
diff --git a/spec/models/topic_timer_spec.rb b/spec/models/topic_timer_spec.rb
index 8acc5685c04..e67b28703e8 100644
--- a/spec/models/topic_timer_spec.rb
+++ b/spec/models/topic_timer_spec.rb
@@ -56,7 +56,7 @@ RSpec.describe TopicTimer, type: :model do
topic_timer =
Fabricate.build(
:topic_timer,
- execute_at: Time.zone.now + 1.hour,
+ execute_at: 1.hour.from_now,
user: Fabricate(:user),
topic: Fabricate(:topic),
)
@@ -70,7 +70,7 @@ RSpec.describe TopicTimer, type: :model do
topic_timer =
Fabricate.build(
:topic_timer,
- execute_at: Time.zone.now - 1.hour,
+ execute_at: 1.hour.ago,
created_at: Time.zone.now,
user: Fabricate(:user),
topic: Fabricate(:topic),
@@ -180,7 +180,7 @@ RSpec.describe TopicTimer, type: :model do
topic_timer =
Fabricate.build(
:topic_timer,
- execute_at: Time.zone.now + 1.hour,
+ execute_at: 1.hour.from_now,
user: Fabricate(:user),
topic: Fabricate(:topic),
)
@@ -192,8 +192,8 @@ RSpec.describe TopicTimer, type: :model do
topic_timer =
Fabricate.create(
:topic_timer,
- execute_at: Time.zone.now - 1.hour,
- created_at: Time.zone.now - 2.hour,
+ execute_at: 1.hour.ago,
+ created_at: 2.hours.ago,
user: Fabricate(:user),
topic: Fabricate(:topic),
)
@@ -206,8 +206,8 @@ RSpec.describe TopicTimer, type: :model do
topic_timer =
Fabricate.build(
:topic_timer,
- execute_at: Time.zone.now - 1.hour,
- created_at: Time.zone.now - 2.hour,
+ execute_at: 1.hour.ago,
+ created_at: 2.hours.ago,
user: Fabricate(:user),
topic: Fabricate(:topic),
)
diff --git a/spec/models/trust_level3_requirements_spec.rb b/spec/models/trust_level3_requirements_spec.rb
index ddff5b73f0a..57be45c8e82 100644
--- a/spec/models/trust_level3_requirements_spec.rb
+++ b/spec/models/trust_level3_requirements_spec.rb
@@ -101,7 +101,7 @@ RSpec.describe TrustLevel3Requirements do
it "does not return if the user been silenced or suspended over 6 months ago" do
freeze_time 1.year.ago do
- UserSilencer.new(user, moderator, silenced_till: 1.months.from_now).silence
+ UserSilencer.new(user, moderator, silenced_till: 1.month.from_now).silence
UserHistory.create!(target_user_id: user.id, action: UserHistory.actions[:suspend_user])
end
@@ -111,7 +111,7 @@ RSpec.describe TrustLevel3Requirements do
freeze_time 3.months.ago do
UserSilencer.new(user).unsilence
- UserSilencer.new(user, moderator, silenced_till: 1.months.from_now).silence
+ UserSilencer.new(user, moderator, silenced_till: 1.month.from_now).silence
UserHistory.create!(target_user_id: user.id, action: UserHistory.actions[:suspend_user])
end
diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb
index 386a34b327b..606d75ee058 100644
--- a/spec/models/user_spec.rb
+++ b/spec/models/user_spec.rb
@@ -1583,7 +1583,7 @@ RSpec.describe User do
it "is false if first post was more than 24 hours ago" do
u = create_test_user(created_at: 28.hours.ago)
- u.user_stat.update!(first_post_created_at: 25.hour.ago)
+ u.user_stat.update!(first_post_created_at: 25.hours.ago)
expect(u.new_user_posting_on_first_day?).to eq(false)
end
end
@@ -3289,12 +3289,7 @@ RSpec.describe User do
end
it "is false when no dnd timing is present for the current time" do
- Fabricate(
- :do_not_disturb_timing,
- user: user,
- starts_at: Time.zone.now - 2.day,
- ends_at: 1.minute.ago,
- )
+ Fabricate(:do_not_disturb_timing, user:, starts_at: 2.days.ago, ends_at: 1.minute.ago)
expect(user.do_not_disturb?).to eq(false)
end
end
@@ -3318,7 +3313,7 @@ RSpec.describe User do
it "excludes invites redeemed after user creation" do
invite = Fabricate(:invite, invited_by: Fabricate(:user))
- Fabricate(:invited_user, invite: invite, user: user, redeemed_at: user.created_at + 6.second)
+ Fabricate(:invited_user, invite: invite, user:, redeemed_at: user.created_at + 6.seconds)
expect(user.invited_by).to eq(nil)
end
diff --git a/spec/models/user_stat_spec.rb b/spec/models/user_stat_spec.rb
index b63f632d468..58a5ce7732a 100644
--- a/spec/models/user_stat_spec.rb
+++ b/spec/models/user_stat_spec.rb
@@ -160,14 +160,14 @@ RSpec.describe UserStat do
end
# User affected
- expect(user.user_stat.reload.first_unread_pm_at).to be_within(1.seconds).of(
+ expect(user.user_stat.reload.first_unread_pm_at).to be_within(1.second).of(
pm_topic.reload.updated_at,
)
- expect(user_2.user_stat.reload.first_unread_pm_at).to be_within(1.seconds).of(
+ expect(user_2.user_stat.reload.first_unread_pm_at).to be_within(1.second).of(
UserStat::UPDATE_UNREAD_MINUTES_AGO.minutes.ago,
)
expect(user_3.user_stat.reload.first_unread_pm_at).to eq_time(user_3_orig_first_unread_pm_at)
- expect(user_4.user_stat.reload.first_unread_pm_at).to be_within(1.seconds).of(
+ expect(user_4.user_stat.reload.first_unread_pm_at).to be_within(1.second).of(
UserStat::UPDATE_UNREAD_MINUTES_AGO.minutes.ago,
)
expect(user_5.user_stat.reload.first_unread_pm_at).to eq_time(pm_topic_2.reload.updated_at)
diff --git a/spec/models/web_hook_events_daily_aggregate_spec.rb b/spec/models/web_hook_events_daily_aggregate_spec.rb
index 92dc9af653f..d9913882c37 100644
--- a/spec/models/web_hook_events_daily_aggregate_spec.rb
+++ b/spec/models/web_hook_events_daily_aggregate_spec.rb
@@ -7,7 +7,7 @@ RSpec.describe WebHookEventsDailyAggregate do
:web_hook_event,
status: 200,
web_hook: web_hook,
- created_at: 1.days.ago,
+ created_at: 1.day.ago,
duration: 280,
)
end
@@ -17,7 +17,7 @@ RSpec.describe WebHookEventsDailyAggregate do
Fabricate(
:web_hook_event,
status: 400,
- created_at: 1.days.ago,
+ created_at: 1.day.ago,
web_hook: web_hook,
duration: 200,
)
@@ -28,7 +28,7 @@ RSpec.describe WebHookEventsDailyAggregate do
:web_hook_event,
status: 400,
web_hook: web_hook,
- created_at: 1.days.ago,
+ created_at: 1.day.ago,
duration: 200,
)
end
@@ -40,11 +40,11 @@ RSpec.describe WebHookEventsDailyAggregate do
it "should be able to purge old web hook event aggregates" do
web_hook = Fabricate(:web_hook)
- WebHookEvent.create!(status: 200, web_hook: web_hook, created_at: 1.days.ago, duration: 180)
+ WebHookEvent.create!(status: 200, web_hook: web_hook, created_at: 1.day.ago, duration: 180)
WebHookEvent.create!(status: 200, web_hook: web_hook, created_at: 2.days.ago, duration: 180)
yesterday_aggregate =
- WebHookEventsDailyAggregate.create!(web_hook_id: web_hook.id, date: 1.days.ago)
+ WebHookEventsDailyAggregate.create!(web_hook_id: web_hook.id, date: 1.day.ago)
WebHookEventsDailyAggregate.create!(
web_hook_id: web_hook.id,
@@ -61,12 +61,12 @@ RSpec.describe WebHookEventsDailyAggregate do
describe "aggregation works" do
it "should be able to aggregate web hook events" do
yesterday_aggregate =
- WebHookEventsDailyAggregate.create!(web_hook_id: web_hook.id, date: 1.days.ago)
+ WebHookEventsDailyAggregate.create!(web_hook_id: web_hook.id, date: 1.day.ago)
yesterday_events = [event, failed_event, failed_event2]
expect(WebHookEventsDailyAggregate.count).to eq(1)
expect(yesterday_aggregate.web_hook_id).to eq(web_hook.id)
- expect(yesterday_aggregate.date).to eq(1.days.ago.to_date)
+ expect(yesterday_aggregate.date).to eq(1.day.ago.to_date)
expect(yesterday_aggregate.mean_duration).to eq(
yesterday_events.sum(&:duration) / yesterday_events.count,
@@ -76,22 +76,22 @@ RSpec.describe WebHookEventsDailyAggregate do
end
it "should be able to filter by day" do
- WebHookEventsDailyAggregate.create!(web_hook_id: web_hook.id, date: 1.days.ago)
+ WebHookEventsDailyAggregate.create!(web_hook_id: web_hook.id, date: 1.day.ago)
WebHookEventsDailyAggregate.create!(web_hook_id: web_hook.id, date: 0.days.ago)
yesterday_events = [event, failed_event, failed_event2]
today_events = [event_today, failed_event_today]
- yesterday_aggregate = WebHookEventsDailyAggregate.by_day(1.days.ago, 1.days.ago)
+ yesterday_aggregate = WebHookEventsDailyAggregate.by_day(1.day.ago, 1.day.ago)
expect(yesterday_aggregate.count).to eq(1)
- expect(yesterday_aggregate.first.date).to eq(1.days.ago.to_date)
+ expect(yesterday_aggregate.first.date).to eq(1.day.ago.to_date)
expect(WebHookEventsDailyAggregate.count).to eq(2)
- today_and_yesterday_aggregate = WebHookEventsDailyAggregate.by_day(1.days.ago, 0.days.ago)
+ today_and_yesterday_aggregate = WebHookEventsDailyAggregate.by_day(1.day.ago, 0.days.ago)
expect(today_and_yesterday_aggregate.count).to eq(2)
expect(today_and_yesterday_aggregate.map(&:date)).to eq(
- [0.days.ago.to_date, 1.days.ago.to_date],
+ [0.days.ago.to_date, 1.day.ago.to_date],
)
expect(today_and_yesterday_aggregate.map(&:mean_duration)).to eq(
[
@@ -102,11 +102,11 @@ RSpec.describe WebHookEventsDailyAggregate do
end
it "should not create a new WebHookEventsDailyAggregate row if AggregateWebHooksEvents runs twice" do
- expect { Jobs::AggregateWebHooksEvents.new.execute(date: 1.days.ago) }.to change {
+ expect { Jobs::AggregateWebHooksEvents.new.execute(date: 1.day.ago) }.to change {
WebHookEventsDailyAggregate.count
}.by(1)
- expect { Jobs::AggregateWebHooksEvents.new.execute(date: 1.days.ago) }.not_to change {
+ expect { Jobs::AggregateWebHooksEvents.new.execute(date: 1.day.ago) }.not_to change {
WebHookEventsDailyAggregate.count
}
end
diff --git a/spec/requests/admin/dashboard_controller_spec.rb b/spec/requests/admin/dashboard_controller_spec.rb
index 42c7311ccc3..1ad3ee7ff1d 100644
--- a/spec/requests/admin/dashboard_controller_spec.rb
+++ b/spec/requests/admin/dashboard_controller_spec.rb
@@ -17,14 +17,14 @@ RSpec.describe Admin::DashboardController do
"emoji" => "🤾",
"title" => "Cool Beans",
"description" => "Now beans are included",
- "created_at" => date1 || (Time.zone.now - 40.minutes),
+ "created_at" => date1 || 40.minutes.ago,
},
{
"id" => "2",
"emoji" => "🙈",
"title" => "Fancy Legumes",
"description" => "Legumes too!",
- "created_at" => date2 || (Time.zone.now - 20.minutes),
+ "created_at" => date2 || 20.minutes.ago,
},
]
diff --git a/spec/requests/admin/staff_action_logs_controller_spec.rb b/spec/requests/admin/staff_action_logs_controller_spec.rb
index 9245aed55f8..06d0ea97096 100644
--- a/spec/requests/admin/staff_action_logs_controller_spec.rb
+++ b/spec/requests/admin/staff_action_logs_controller_spec.rb
@@ -54,7 +54,7 @@ RSpec.describe Admin::StaffActionLogsController do
end
it "filter logs by end_date" do
- get "/admin/logs/staff_action_logs.json", params: { end_date: 1.days.ago.iso8601 }
+ get "/admin/logs/staff_action_logs.json", params: { end_date: 1.day.ago.iso8601 }
json = response.parsed_body
expect(response.status).to eq(200)
@@ -68,7 +68,7 @@ RSpec.describe Admin::StaffActionLogsController do
get "/admin/logs/staff_action_logs.json",
params: {
start_date: 3.days.ago.iso8601,
- end_date: 1.days.ago.iso8601,
+ end_date: 1.day.ago.iso8601,
}
json = response.parsed_body
diff --git a/spec/requests/admin/users_controller_spec.rb b/spec/requests/admin/users_controller_spec.rb
index 865c62da152..a713b21b36e 100644
--- a/spec/requests/admin/users_controller_spec.rb
+++ b/spec/requests/admin/users_controller_spec.rb
@@ -2626,7 +2626,7 @@ RSpec.describe Admin::UsersController do
provider_name: "github",
provider_uid: "123456789",
user_id: user.id,
- last_used: 1.seconds.ago,
+ last_used: 1.second.ago,
)
end
diff --git a/spec/requests/api/topics_spec.rb b/spec/requests/api/topics_spec.rb
index 141a9f15b4a..d5f7df8c76a 100644
--- a/spec/requests/api/topics_spec.rb
+++ b/spec/requests/api/topics_spec.rb
@@ -1040,7 +1040,7 @@ RSpec.describe "topics" do
},
}
- let(:request_body) { { time: Time.current + 1.day, status_type: "close" } }
+ let(:request_body) { { time: 1.day.from_now, status_type: "close" } }
let!(:topic_post) { Fabricate(:post) }
let(:id) { topic_post.topic.id }
diff --git a/spec/requests/bookmarks_controller_spec.rb b/spec/requests/bookmarks_controller_spec.rb
index 90e0b0dfaee..20dd6a09093 100644
--- a/spec/requests/bookmarks_controller_spec.rb
+++ b/spec/requests/bookmarks_controller_spec.rb
@@ -19,7 +19,7 @@ RSpec.describe BookmarksController do
params: {
bookmarkable_id: bookmark_post.id,
bookmarkable_type: "Post",
- reminder_at: (Time.zone.now + 1.day).iso8601,
+ reminder_at: 1.day.from_now.iso8601,
}
expect(response.status).to eq(200)
@@ -40,7 +40,7 @@ RSpec.describe BookmarksController do
params: {
bookmarkable_id: bookmark_post.id,
bookmarkable_type: "Post",
- reminder_at: (Time.zone.now + 1.day).iso8601,
+ reminder_at: 1.day.from_now.iso8601,
}
post "/bookmarks.json",
params: {
@@ -71,7 +71,7 @@ RSpec.describe BookmarksController do
params: {
bookmarkable_id: bookmark_post.id,
bookmarkable_type: "Post",
- reminder_at: (Time.zone.now + 1.day).iso8601,
+ reminder_at: 1.day.from_now.iso8601,
}
expect(response.status).to eq(400)
@@ -83,7 +83,7 @@ RSpec.describe BookmarksController do
params: {
bookmarkable_id: bookmark_topic.id,
bookmarkable_type: "Topic",
- reminder_at: (Time.zone.now + 1.day).iso8601,
+ reminder_at: 1.day.from_now.iso8601,
}
expect(response.status).to eq(400)
diff --git a/spec/requests/groups_controller_spec.rb b/spec/requests/groups_controller_spec.rb
index 4d9f1af452a..072869313d1 100644
--- a/spec/requests/groups_controller_spec.rb
+++ b/spec/requests/groups_controller_spec.rb
@@ -1406,21 +1406,11 @@ RSpec.describe GroupsController do
describe "#members" do
let(:user1) do
- Fabricate(
- :user,
- last_seen_at: Time.zone.now,
- last_posted_at: Time.zone.now - 1.day,
- email: "[email protected]",
- )
+ Fabricate(:user, last_seen_at: Time.zone.now, last_posted_at: 1.day.ago, email: "[email protected]")
end
let(:user2) do
- Fabricate(
- :user,
- last_seen_at: Time.zone.now - 1.day,
- last_posted_at: Time.zone.now,
- email: "[email protected]",
- )
+ Fabricate(:user, last_seen_at: 1.day.ago, last_posted_at: Time.zone.now, email: "[email protected]")
end
fab!(:user3) { Fabricate(:user, last_seen_at: nil, last_posted_at: nil, email: "[email protected]") }
@@ -2540,7 +2530,7 @@ RSpec.describe GroupsController do
it "should create the right PM" do
owner1 = Fabricate(:user, last_seen_at: Time.zone.now)
- owner2 = Fabricate(:user, last_seen_at: Time.zone.now - 1.day)
+ owner2 = Fabricate(:user, last_seen_at: 1.day.ago)
[owner1, owner2].each { |owner| group.add_owner(owner) }
sign_in(user)
diff --git a/spec/requests/reviewables_controller_spec.rb b/spec/requests/reviewables_controller_spec.rb
index 28b22de9df1..ebdd49d607e 100644
--- a/spec/requests/reviewables_controller_spec.rb
+++ b/spec/requests/reviewables_controller_spec.rb
@@ -329,7 +329,7 @@ RSpec.describe ReviewablesController do
end
it "returns reviewable content that matches the date range" do
- reviewable = Fabricate(:reviewable, created_at: 2.day.ago)
+ reviewable = Fabricate(:reviewable, created_at: 2.days.ago)
get "/review.json?from_date=#{from}&to_date=#{to}"
diff --git a/spec/requests/sitemap_controller_spec.rb b/spec/requests/sitemap_controller_spec.rb
index 0a1d62771ec..b622be98581 100644
--- a/spec/requests/sitemap_controller_spec.rb
+++ b/spec/requests/sitemap_controller_spec.rb
@@ -98,18 +98,18 @@ RSpec.describe SitemapController do
page_size = TopicView.chunk_size
incomplete_page_size = TopicView.chunk_size - 1
- topic.update!(posts_count: incomplete_page_size, updated_at: 4.hour.ago)
+ topic.update!(posts_count: incomplete_page_size, updated_at: 4.hours.ago)
get "/sitemap_recent.xml"
url = Nokogiri::XML::Document.parse(response.body).at_css("loc").text
expect(url).not_to include("?page=2")
- topic.update!(posts_count: page_size, updated_at: 3.hour.ago)
+ topic.update!(posts_count: page_size, updated_at: 3.hours.ago)
get "/sitemap_recent.xml"
url = Nokogiri::XML::Document.parse(response.body).at_css("loc").text
expect(url).not_to include("?page=2")
two_page_size = page_size + 1
- topic.update!(posts_count: two_page_size, updated_at: 2.hour.ago)
+ topic.update!(posts_count: two_page_size, updated_at: 2.hours.ago)
get "/sitemap_recent.xml"
url = Nokogiri::XML::Document.parse(response.body).at_css("loc").text
expect(url).to include("?page=2")
diff --git a/spec/requests/static_controller_spec.rb b/spec/requests/static_controller_spec.rb
index 93237d9b8b7..3f302020598 100644
--- a/spec/requests/static_controller_spec.rb
+++ b/spec/requests/static_controller_spec.rb
@@ -70,7 +70,7 @@ RSpec.describe StaticController do
it "can serve assets" do
begin
- assets_path = Rails.root.join("public/assets")
+ assets_path = Rails.public_path.join("assets")
FileUtils.mkdir_p(assets_path)
diff --git a/spec/requests/topics_controller_spec.rb b/spec/requests/topics_controller_spec.rb
index f8216b6fa16..d1900b0f3ff 100644
--- a/spec/requests/topics_controller_spec.rb
+++ b/spec/requests/topics_controller_spec.rb
@@ -4935,7 +4935,7 @@ RSpec.describe TopicsController do
post "/t/#{topic.id}/timer.json",
params: {
- time: Time.current - 1.day,
+ time: 1.day.ago,
status_type: TopicTimer.types[1],
}
expect(response.status).to eq(400)
diff --git a/spec/requests/users_controller_spec.rb b/spec/requests/users_controller_spec.rb
index 3346b6156ac..3078eafb2b9 100644
--- a/spec/requests/users_controller_spec.rb
+++ b/spec/requests/users_controller_spec.rb
@@ -250,7 +250,7 @@ RSpec.describe UsersController do
end
it "fails without a server session" do
- user.update!(created_at: Time.zone.now - 8.minutes)
+ user.update!(created_at: 8.minutes.ago)
put "/u/#{user.username}/remove-password.json"
expect(response.status).to eq(403)
end
@@ -262,7 +262,7 @@ RSpec.describe UsersController do
end
it "succeeds with a newly-created user" do
- user.update!(created_at: Time.zone.now - 1.minute)
+ user.update!(created_at: 1.minute.ago)
put "/u/#{user.username}/remove-password.json"
expect(response.status).to eq(200)
end
@@ -293,7 +293,7 @@ RSpec.describe UsersController do
end
it "fails without a server session" do
- user.update!(created_at: Time.zone.now - 8.minutes)
+ user.update!(created_at: 8.minutes.ago)
put "/u/#{user.username}/remove-password.json" #
expect(response.status).to eq(403)
end
@@ -6904,7 +6904,7 @@ RSpec.describe UsersController do
end
it "returns unconfirmed session response when user was created more than N minutes ago" do
- user1.created_at = Time.zone.now - 10.minutes
+ user1.created_at = 10.minutes.ago
user1.save!(validate: false)
post "/u/second_factors.json"
@@ -6915,7 +6915,7 @@ RSpec.describe UsersController do
end
it "returns empty list for a recently created user" do
- user1.created_at = Time.zone.now - 1.minutes
+ user1.created_at = 1.minute.ago
user1.save!(validate: false)
post "/u/second_factors.json"
@@ -7819,7 +7819,7 @@ RSpec.describe UsersController do
read: true,
user: user,
notification_type: Notification.types[:group_message_summary],
- created_at: 1.minutes.ago,
+ created_at: 1.minute.ago,
)
end
@@ -7915,7 +7915,7 @@ RSpec.describe UsersController do
end
it "responds with an array of personal messages and user watching group messages that are not associated with any of the unread private_message notifications" do
- group_message1.update!(bumped_at: 1.minutes.ago)
+ group_message1.update!(bumped_at: 1.minute.ago)
message_without_notification.update!(bumped_at: 3.minutes.ago)
group_message2.update!(bumped_at: 6.minutes.ago)
message_with_read_notification.update!(bumped_at: 10.minutes.ago)
diff --git a/spec/serializers/basic_user_serializer_spec.rb b/spec/serializers/basic_user_serializer_spec.rb
index aeb0564cae0..8de8c01b048 100644
--- a/spec/serializers/basic_user_serializer_spec.rb
+++ b/spec/serializers/basic_user_serializer_spec.rb
@@ -56,7 +56,7 @@ RSpec.describe BasicUserSerializer do
end
it "doesn't add expired user status" do
- user.user_status.ends_at = 1.minutes.ago
+ user.user_status.ends_at = 1.minute.ago
json = serializer.as_json
expect(json.keys).not_to include :status
end
diff --git a/spec/serializers/current_user_serializer_spec.rb b/spec/serializers/current_user_serializer_spec.rb
index c34fc1bf909..490134f4783 100644
--- a/spec/serializers/current_user_serializer_spec.rb
+++ b/spec/serializers/current_user_serializer_spec.rb
@@ -207,7 +207,7 @@ RSpec.describe CurrentUserSerializer do
it "doesn't add expired user status" do
SiteSetting.enable_user_status = true
- user.user_status.ends_at = 1.minutes.ago
+ user.user_status.ends_at = 1.minute.ago
serializer = described_class.new(user, scope: Guardian.new(user), root: false)
json = serializer.as_json
diff --git a/spec/serializers/found_user_serializer_spec.rb b/spec/serializers/found_user_serializer_spec.rb
index 655c9bd1668..36965f8ea77 100644
--- a/spec/serializers/found_user_serializer_spec.rb
+++ b/spec/serializers/found_user_serializer_spec.rb
@@ -54,7 +54,7 @@ RSpec.describe FoundUserSerializer do
end
it "doesn't add expired user status" do
- user.user_status.ends_at = 1.minutes.ago
+ user.user_status.ends_at = 1.minute.ago
serializer = described_class.new(user, scope: Guardian.new(user), root: false)
json = serializer.as_json
diff --git a/spec/serializers/group_user_serializer_spec.rb b/spec/serializers/group_user_serializer_spec.rb
index 3f80a3f7da3..0132a14e732 100644
--- a/spec/serializers/group_user_serializer_spec.rb
+++ b/spec/serializers/group_user_serializer_spec.rb
@@ -27,7 +27,7 @@ RSpec.describe GroupUserSerializer do
it "doesn't add expired user status" do
SiteSetting.enable_user_status = true
- user.user_status.ends_at = 1.minutes.ago
+ user.user_status.ends_at = 1.minute.ago
serializer = described_class.new(user, scope: Guardian.new(user), root: false)
json = serializer.as_json
diff --git a/spec/serializers/user_card_serializer_spec.rb b/spec/serializers/user_card_serializer_spec.rb
index 3bd7fa90e18..b039d1ac465 100644
--- a/spec/serializers/user_card_serializer_spec.rb
+++ b/spec/serializers/user_card_serializer_spec.rb
@@ -109,7 +109,7 @@ RSpec.describe UserCardSerializer do
it "doesn't add expired user status" do
SiteSetting.enable_user_status = true
- user.user_status.ends_at = 1.minutes.ago
+ user.user_status.ends_at = 1.minute.ago
serializer = described_class.new(user, scope: Guardian.new(user), root: false)
json = serializer.as_json
diff --git a/spec/serializers/user_serializer_spec.rb b/spec/serializers/user_serializer_spec.rb
index 79b1b49c864..3037362db4a 100644
--- a/spec/serializers/user_serializer_spec.rb
+++ b/spec/serializers/user_serializer_spec.rb
@@ -438,7 +438,7 @@ RSpec.describe UserSerializer do
revoked_at: Time.zone.now,
)
user_api_key_1 = Fabricate(:readonly_user_api_key, user: user, last_used_at: 7.days.ago)
- user_api_key_2 = Fabricate(:readonly_user_api_key, user: user, last_used_at: 1.days.ago)
+ user_api_key_2 = Fabricate(:readonly_user_api_key, user: user, last_used_at: 1.day.ago)
user_api_key_3 =
Fabricate(
:readonly_user_api_key,
diff --git a/spec/services/discourse_id/register_spec.rb b/spec/services/discourse_id/register_spec.rb
index 1d03a2e5e91..df8066cefe0 100644
--- a/spec/services/discourse_id/register_spec.rb
+++ b/spec/services/discourse_id/register_spec.rb
@@ -10,8 +10,8 @@ RSpec.describe DiscourseId::Register do
let(:client_secret) { "test_client_secret" }
let(:discourse_id_url) { "https://id.discourse.com" }
- fab!(:logo_upload) { Fabricate(:upload) }
- fab!(:logo_small_upload) { Fabricate(:upload) }
+ fab!(:logo_upload, :upload)
+ fab!(:logo_small_upload, :upload)
before do
SiteSetting.discourse_id_provider_url = discourse_id_url
diff --git a/spec/services/post_alerter_spec.rb b/spec/services/post_alerter_spec.rb
index 1c8d29490d7..beb279402c7 100644
--- a/spec/services/post_alerter_spec.rb
+++ b/spec/services/post_alerter_spec.rb
@@ -1379,7 +1379,7 @@ RSpec.describe PostAlerter do
evil_trout.update!(last_seen_at: 5.minutes.ago)
expect { mention_post }.to change { Jobs::PushNotification.jobs.count }
- expect(Jobs::PushNotification.jobs[0]["at"]).to be_within(30.second).of(
+ expect(Jobs::PushNotification.jobs[0]["at"]).to be_within(30.seconds).of(
5.minutes.from_now.to_f,
)
end
@@ -1406,7 +1406,7 @@ RSpec.describe PostAlerter do
delay = 5.minutes.from_now.to_f
expect { mention_post }.to change { Jobs::SendPushNotification.jobs.count }
- expect(Jobs::SendPushNotification.jobs[0]["at"]).to be_within(30.second).of(delay)
+ expect(Jobs::SendPushNotification.jobs[0]["at"]).to be_within(30.seconds).of(delay)
end
it "does not delay push notification for inactive offline user" do
diff --git a/spec/services/topic_status_updater_spec.rb b/spec/services/topic_status_updater_spec.rb
index b1f5cf3f9d9..0a8cb906260 100644
--- a/spec/services/topic_status_updater_spec.rb
+++ b/spec/services/topic_status_updater_spec.rb
@@ -146,7 +146,7 @@ RSpec.describe TopicStatusUpdater do
timer = TopicTimer.find_by(topic: topic)
expect(timer).not_to eq(nil)
expect(timer.duration_minutes).to eq(72 * 60)
- expect(timer.execute_at).to be_within_one_second_of(Time.zone.now + 72.hours)
+ expect(timer.execute_at).to be_within_one_second_of(72.hours.from_now)
end
end
end
diff --git a/spec/services/topic_timestamp_changer_spec.rb b/spec/services/topic_timestamp_changer_spec.rb
index 45c41cb7bee..dbde22d5ff8 100644
--- a/spec/services/topic_timestamp_changer_spec.rb
+++ b/spec/services/topic_timestamp_changer_spec.rb
@@ -8,7 +8,7 @@ RSpec.describe TopicTimestampChanger do
let!(:p2) { Fabricate(:post, topic: topic, created_at: old_timestamp + 1.day) }
context "when new timestamp is in the future" do
- let(:new_timestamp) { old_timestamp + 2.day }
+ let(:new_timestamp) { old_timestamp + 2.days }
it "should raise the right error" do
expect {
@@ -18,7 +18,7 @@ RSpec.describe TopicTimestampChanger do
end
context "when new timestamp is in the past" do
- let(:new_timestamp) { old_timestamp - 2.day }
+ let(:new_timestamp) { old_timestamp - 2.days }
it "changes the timestamp of the topic and opening post" do
freeze_time
diff --git a/spec/system/about_page_spec.rb b/spec/system/about_page_spec.rb
index eb47ce8508f..fdc6dd0fceb 100644
--- a/spec/system/about_page_spec.rb
+++ b/spec/system/about_page_spec.rb
@@ -199,7 +199,7 @@ describe "About page", type: :system do
it "displays only the 6 most recently seen admins when there are more than 6 admins" do
admins[0].update!(last_seen_at: 4.minutes.ago)
- admins[1].update!(last_seen_at: 1.minutes.ago)
+ admins[1].update!(last_seen_at: 1.minute.ago)
admins[2].update!(last_seen_at: 10.minutes.ago)
about_page.visit
diff --git a/spec/system/admin_config_theme_site_settings_spec.rb b/spec/system/admin_config_theme_site_settings_spec.rb
index c54a9e0c49a..afd83d8201c 100644
--- a/spec/system/admin_config_theme_site_settings_spec.rb
+++ b/spec/system/admin_config_theme_site_settings_spec.rb
@@ -1,7 +1,7 @@
# frozen_string_literal: true
describe "Admin Theme Site Settings", type: :system do
- fab!(:current_user) { Fabricate(:admin) }
+ fab!(:current_user, :admin)
fab!(:theme_1) { Fabricate(:theme, name: "Blue Steel") }
fab!(:theme_2) { Fabricate(:theme, name: "Derelicte") }
fab!(:theme_site_setting_1) do
diff --git a/spec/system/category_localizations_spec.rb b/spec/system/category_localizations_spec.rb
index c0b7308e494..f1f7b087976 100644
--- a/spec/system/category_localizations_spec.rb
+++ b/spec/system/category_localizations_spec.rb
@@ -67,7 +67,7 @@ describe "Category Localizations", type: :system do
end
describe "when editing a category with no category localizations" do
- fab!(:mono_category) { Fabricate(:category) }
+ fab!(:mono_category, :category)
it "should show info hint to add new localizations" do
category_page.visit_edit_localizations(mono_category)
diff --git a/spec/system/create_invite_spec.rb b/spec/system/create_invite_spec.rb
index ddb9b7d0d1e..1aefc519616 100644
--- a/spec/system/create_invite_spec.rb
+++ b/spec/system/create_invite_spec.rb
@@ -55,7 +55,7 @@ describe "Creating Invites", type: :system do
max_redemption_count: 7,
)
expect(user_invited_pending_page.latest_invite.expiry_date).to be_within(2.minutes).of(
- Time.zone.now + 3.days,
+ 3.days.from_now,
)
end
@@ -167,7 +167,7 @@ describe "Creating Invites", type: :system do
expect(user_invited_pending_page.latest_invite).to have_group(another_group)
expect(user_invited_pending_page.latest_invite).to have_topic(topic)
expect(user_invited_pending_page.latest_invite.expiry_date).to be_within(2.minutes).of(
- Time.zone.now + 1.day,
+ 1.day.from_now,
)
sent_email = ActionMailer::Base.deliveries.first
expect(sent_email.to).to contain_exactly("[email protected]")
diff --git a/spec/system/search_spec.rb b/spec/system/search_spec.rb
index 20e0f3c7ed2..01983896420 100644
--- a/spec/system/search_spec.rb
+++ b/spec/system/search_spec.rb
@@ -269,7 +269,7 @@ describe "Search", type: :system do
describe "Private Message Icon in Search Results" do
fab!(:user)
- fab!(:other_user) { Fabricate(:user) }
+ fab!(:other_user, :user)
fab!(:pm_topic) do
Fabricate(
:private_message_topic,