DEV: Replace Ruby numbered parameters by it where applicable (#37810)

Now that we moved to Ruby 3.4, we can use `it` instead of `_1`.
This commit is contained in:
Loïc Guitaut
2026-02-13 13:59:07 +01:00
committed by GitHub
parent 01c17ee5e7
commit a633007bae
57 changed files with 103 additions and 103 deletions
+1 -1
View File
@@ -759,7 +759,7 @@ class ApplicationController < ActionController::Base
NO_DESTINATION_COOKIE = %w[/login /signup /session/ /auth/ /uploads/].freeze
def is_valid_destination_url?(url)
url.present? && url != path("/") && NO_DESTINATION_COOKIE.none? { url.start_with? path(_1) }
url.present? && url != path("/") && NO_DESTINATION_COOKIE.none? { url.start_with? path(it) }
end
def destination_url
@@ -105,7 +105,7 @@ class Users::OmniauthCallbacksController < ApplicationController
true
end
ALLOWED_FAILURE_ERRORS = %w[csrf_detected request_error invalid_iat unauthorized].index_by { _1 }
ALLOWED_FAILURE_ERRORS = %w[csrf_detected request_error invalid_iat unauthorized].index_by { it }
def failure
error_name = params[:message].to_s.gsub(/[^\w-]/, "").presence
@@ -113,7 +113,7 @@ class Users::OmniauthCallbacksController < ApplicationController
if error == "generic"
provider_name = params[:provider].presence || params[:strategy].presence
provider = Discourse.enabled_authenticators.find { _1.name == provider_name }&.display_name
provider = Discourse.enabled_authenticators.find { it.name == provider_name }&.display_name
if provider.blank? && Discourse.enabled_authenticators.one?
provider = Discourse.enabled_authenticators[0].display_name
+1 -1
View File
@@ -882,6 +882,6 @@ class UserNotifications < ActionMailer::Base
.not_suspended
.where("created_at > ?", date)
.count
.tap { Discourse.redis.setex(key, 1.day, _1) }
.tap { Discourse.redis.setex(key, 1.day, it) }
end
end
+1 -1
View File
@@ -327,7 +327,7 @@ class Category < ActiveRecord::Base
sqls =
slugs.map do |slug|
category_slugs =
slug.split(":").first(SiteSetting.max_category_nesting).map { Slug.for(_1, "") }
slug.split(":").first(SiteSetting.max_category_nesting).map { Slug.for(it, "") }
sql = ""
+1 -1
View File
@@ -18,7 +18,7 @@ module CategoryHashtag
slug_path = split_slug_path(slug)
next if slug_path.blank?
slug_path.map! { CGI.escape(_1) } if SiteSetting.slug_generation_method == "encoded"
slug_path.map! { CGI.escape(it) } if SiteSetting.slug_generation_method == "encoded"
parent_slug, child_slug = slug_path.last(2)
# Category slugs can be in the parent:child format, if there
@@ -7,7 +7,7 @@ class Category::Query::HierarchicalSearch
end
def call
build_relation.tap { prepend_allowed_categories_cte(_1) }.to_a
build_relation.tap { prepend_allowed_categories_cte(it) }.to_a
end
private
+2 -2
View File
@@ -124,7 +124,7 @@ class Groups::Create
end
def build_user_attributes(params:)
params.owner_ids.map { { user_id: _1, owner: true } } + params.user_ids.map { { user_id: _1 } }
params.owner_ids.map { { user_id: it, owner: true } } + params.user_ids.map { { user_id: it } }
end
def instantiate_group(params:, guardian:, user_attributes:, options:)
@@ -132,7 +132,7 @@ class Groups::Create
params.except(:owner_usernames, :usernames, :associated_group_ids).merge(
options.dynamic_attributes,
),
) { _1.group_users.build(user_attributes) }
) { it.group_users.build(user_attributes) }
end
def should_associate_groups(guardian:, params:)
+1 -1
View File
@@ -27,7 +27,7 @@ class User::BulkDestroy
end
def can_delete_users(guardian:, users:)
users.all? { guardian.can_delete_user?(_1) }
users.all? { guardian.can_delete_user?(it) }
end
def delete(users:, guardian:, params:)
+1 -1
View File
@@ -43,7 +43,7 @@ class User::Silence
end
def can_silence_all_users(guardian:, users:)
users.all? { guardian.can_silence_user?(_1) }
users.all? { guardian.can_silence_user?(it) }
end
def silence(guardian:, users:, params:)
+1 -1
View File
@@ -43,7 +43,7 @@ class User::Suspend
end
def can_suspend_all_users(guardian:, users:)
users.all? { guardian.can_suspend?(_1) }
users.all? { guardian.can_suspend?(it) }
end
def suspend(guardian:, users:, params:)
+1 -1
View File
@@ -21,7 +21,7 @@ module ActiveSupportTypeExtensions
value.map { |item| Integer(item, exception: false) || item }
else
::Array.wrap(value)
end.tap { _1.compact_blank! if compact_blank }
end.tap { it.compact_blank! if compact_blank }
end
end
end
+2 -2
View File
@@ -701,7 +701,7 @@ module Email
elsif mail.bounced?
# "Final-Recipient" has a specific format (<name> ; <address>)
# cf. https://www.ietf.org/rfc/rfc2298.html#section-3.2.4
address_type, generic_address = mail.final_recipient.to_s.split(";").map { _1.to_s.strip }
address_type, generic_address = mail.final_recipient.to_s.split(";").map { it.to_s.strip }
return generic_address, nil if generic_address.include?("@") && address_type == "rfc822"
end
@@ -751,7 +751,7 @@ module Email
return if list_address.blank?
# the CC header often includes the name of the sender
address_to_name = mail[:cc]&.element&.addresses&.to_h { [_1.address, _1.name] } || {}
address_to_name = mail[:cc]&.element&.addresses.to_h { [it.address, it.name] }
%i[from reply_to x_mailfrom x_original_from].each do |header|
next if mail[header].blank?
+1 -1
View File
@@ -381,7 +381,7 @@ module Email
style
.split(";")
.select(&:present?)
.map { _1.split(":", 2).map(&:strip) }
.map { it.split(":", 2).map(&:strip) }
.each do |k, v|
next if k.blank? || v.blank?
next if styles[k]&.end_with?("!important") && !v.end_with?("!important")
+1 -1
View File
@@ -57,7 +57,7 @@ module Hijack
# this trick avoids double render, also avoids any litter that the controller hooks
# place on the response
instance = controller_class.new
response = ActionDispatch::Response.new.tap { _1.request = request_copy }
response = ActionDispatch::Response.new.tap { it.request = request_copy }
instance.set_response!(response)
instance.set_request!(request_copy)
+1 -1
View File
@@ -238,7 +238,7 @@ module ImportExport
end
def fix_permissions
categories_by_id = @categories.index_by { _1[:id] }
categories_by_id = @categories.index_by { it[:id] }
@categories.each do |category|
if category[:permissions_params].blank?
+1 -1
View File
@@ -153,7 +153,7 @@ module JsLocaleHelper
.mf_locales(l)
.pluck(:translation_key, :value)
.to_h
.transform_keys { _1.sub(/^[a-z_]*js\./, "") },
.transform_keys { it.sub(/^[a-z_]*js\./, "") },
)
end
.compact_blank
+1 -1
View File
@@ -6,7 +6,7 @@ module Onebox
def github_auth_header(github_org)
return {} if SiteSetting.github_onebox_access_tokens.blank?
org_tokens = SiteSetting.github_onebox_access_tokens.split("\n").to_h { _1.split("|") }
org_tokens = SiteSetting.github_onebox_access_tokens.split("\n").to_h { it.split("|") }
token = org_tokens[github_org] || org_tokens["default"]
+5 -5
View File
@@ -104,7 +104,7 @@ module Service
base_class: Service::ContractBase,
&block
)
contract_class = Class.new(base_class).tap { _1.class_eval(&block) if block }
contract_class = Class.new(base_class).tap { it.class_eval(&block) if block }
const_set("#{name.to_s.classify.sub("Default", "")}Contract", contract_class)
steps << ContractStep.new(name, class_name: contract_class, default_values_from:)
end
@@ -126,7 +126,7 @@ module Service
end
def options(&block)
klass = Class.new(Service::OptionsBase).tap { _1.class_eval(&block) }
klass = Class.new(Service::OptionsBase).tap { it.class_eval(&block) }
const_set("Options", klass)
steps << OptionsStep.new(:default, class_name: klass)
end
@@ -172,11 +172,11 @@ module Service
def run_step
object = class_name&.new(context)
method = object&.method(:call) || instance.method(method_name)
if !object && method.parameters.any? { _1[0] != :keyreq }
if !object && method.parameters.any? { it[0] != :keyreq }
raise DefaultValuesNotAllowed,
"In #{type} '#{name}': default values in step implementations are not allowed. Maybe they could be defined in a params or options block?"
end
args = context.slice(*method.parameters.select { _1[0] == :keyreq }.map(&:last))
args = context.slice(*method.parameters.select { it[0] == :keyreq }.map(&:last))
context[result_key][:object] = object if object
instance.instance_exec(**args, &method)
end
@@ -335,7 +335,7 @@ module Service
def filtered_backtrace
Array
.wrap(backtrace)
.chunk { _1.match?(%r{/(gems|lib/service|ruby)/}) }
.chunk { it.match?(%r{/(gems|lib/service|ruby)/}) }
.flat_map do |excluded, lines|
next "(#{lines.size} framework line(s) excluded)" if excluded
lines
+2 -2
View File
@@ -40,7 +40,7 @@ class Service::ContractBase
def to_hash
attributes.symbolize_keys.deep_transform_values do
_1.is_a?(Service::ContractBase) ? _1.to_hash : _1
it.is_a?(Service::ContractBase) ? it.to_hash : it
end
end
@@ -59,7 +59,7 @@ class Service::ContractBase
end
def nested_attributes
@attributes.each_value.select { _1.type.is_a?(Service::NestedContractType) && _1.value }
@attributes.each_value.select { it.type.is_a?(Service::NestedContractType) && it.value }
end
def validate_nested(attribute)
+2 -2
View File
@@ -101,7 +101,7 @@ class Service::Runner
condition: ->(*exceptions) do
next unless result["result.try.default"]&.exception
next true if exceptions.empty?
exceptions.any? { result["result.try.default"].exception.is_a?(_1) }
exceptions.any? { result["result.try.default"].exception.is_a?(it) }
end,
key: %w[result try],
name: "default",
@@ -165,7 +165,7 @@ class Service::Runner
result[
[*action[:key], action[:name] || args.first || action[:default_name]].join(".")
].public_send(action[:property] || :itself),
**result.slice(*block.parameters.filter_map { _1.last if _1.first == :keyreq }),
**result.slice(*block.parameters.filter_map { it.last if it.first == :keyreq }),
&block
)
end,
+3 -3
View File
@@ -119,7 +119,7 @@ class Service::StepsInspector
def steps
[
self,
*step.steps.map { Step.for(_1, result, nesting_level: nesting_level + 1, color:).steps },
*step.steps.map { Step.for(it, result, nesting_level: nesting_level + 1, color:).steps },
]
end
@@ -160,7 +160,7 @@ class Service::StepsInspector
[
self,
*step.steps.map do
Step.for(_1, result, nesting_level: nesting_level + 1, color: skipped_color).steps
Step.for(it, result, nesting_level: nesting_level + 1, color: skipped_color).steps
end,
]
end
@@ -190,7 +190,7 @@ class Service::StepsInspector
attr_reader :steps, :result
def initialize(result)
@steps = result.__steps__.map { Step.for(_1, result).steps }.flatten
@steps = result.__steps__.map { Step.for(it, result).steps }.flatten
@result = result
end
+1 -1
View File
@@ -107,7 +107,7 @@ class TopicsFilter
when "views-max"
filter_by_number_of_views(max: filter_values)
else
if custom_filter = DiscoursePluginRegistry.custom_filter_mappings.find { _1.key?(filter) }
if custom_filter = DiscoursePluginRegistry.custom_filter_mappings.find { it.key?(filter) }
@scope = custom_filter[filter].call(@scope, filter_values, @guardian) || @scope
end
end
+1 -1
View File
@@ -9,7 +9,7 @@ class AllowedIframesValidator
end
def valid_value?(values)
values.split("|").all? { _1.match? VALID_ALLOWED_IFRAME_URL_REGEX }
values.split("|").all? { it.match? VALID_ALLOWED_IFRAME_URL_REGEX }
end
def error_message
+1 -1
View File
@@ -13,7 +13,7 @@ class CspScriptSrcValidator
end
def valid_value?(values)
values.split("|").all? { _1.match? VALID_SOURCE_REGEX }
values.split("|").all? { it.match? VALID_SOURCE_REGEX }
end
def error_message
@@ -7,7 +7,7 @@ module Migrations::Importer::Steps
VALID_TRIGGERS =
Badge::Trigger
.constants(false)
.filter_map { Badge::Trigger.const_get(_1) unless _1 == :DeprecatedPostProcessed }
.filter_map { Badge::Trigger.const_get(it) unless it == :DeprecatedPostProcessed }
.to_set
.freeze
@@ -104,9 +104,9 @@ module Chat
def filtered_messages
messages
.then { apply_username_filters(_1) }
.then { apply_channel_filters(_1) }
.then { apply_ts_query(_1) }
.then { apply_username_filters(it) }
.then { apply_channel_filters(it) }
.then { apply_ts_query(it) }
end
def apply_ts_query(messages)
+1 -1
View File
@@ -246,7 +246,7 @@ module Chat
UserField.all.pluck(:id).map { |fid| "#{User::USER_FIELD_PREFIX}#{fid}" }
User.preload_custom_fields(
channels.flat_map { _1.chatable.direct_message_users.map(&:user).compact },
channels.flat_map { it.chatable.direct_message_users.map(&:user).compact },
preload_fields,
)
@@ -10,7 +10,7 @@ module Chat
schemer = JSONSchemer.schema(Chat::Schemas::MessageBlocks)
if !schemer.valid?(record.blocks)
record.errors.add(:blocks, schemer.validate(record.blocks).map { _1.fetch("error") })
record.errors.add(:blocks, schemer.validate(record.blocks).map { it.fetch("error") })
return
end
@@ -47,11 +47,11 @@ module Chat
# and a count of unread messages per channel
Chat::Message
.includes(:user, :chat_channel)
.where(chat_channel_id: data.map { _1[1] })
.where(chat_channel_id: data.map { it[1] })
.where(
"chat_messages.id >= (
SELECT min_unread_id
FROM (VALUES #{data.map { "(#{_1[1]}, #{_1[2]})" }.join(",")}) AS t(channel_id, min_unread_id)
FROM (VALUES #{data.map { "(#{it[1]}, #{it[2]})" }.join(",")}) AS t(channel_id, min_unread_id)
WHERE t.channel_id = chat_messages.chat_channel_id
)",
)
@@ -63,11 +63,11 @@ module Chat
def messages_for_threads(data, guardian)
Chat::Message
.includes(:user, :chat_channel)
.where(thread_id: data.map { _1[1] })
.where(thread_id: data.map { it[1] })
.where(
"chat_messages.id >= (
SELECT min_unread_id
FROM (VALUES #{data.map { "(#{_1[1]}, #{_1[2]})" }.join(",")}) AS t(thread_id, min_unread_id)
FROM (VALUES #{data.map { "(#{it[1]}, #{it[2]})" }.join(",")}) AS t(thread_id, min_unread_id)
WHERE t.thread_id = chat_messages.thread_id
)",
)
@@ -88,7 +88,7 @@ module Chat
return subject(:private_email, count:) if SiteSetting.private_email
# consider "direct messages" with more than 2 users as group messages (aka. channels)
dms, groups = grouped_dms.keys.partition { _1.user_chat_channel_memberships.count == 2 }
dms, groups = grouped_dms.keys.partition { it.user_chat_channel_memberships.count == 2 }
channels = grouped_channels.keys + groups
@@ -20,7 +20,7 @@ RSpec.describe Chat::Action::SearchForMessages do
SearchIndexer.enable
SiteSetting.chat_enabled = true
channel.add(current_user)
[message_1, message_2, message_3].each { SearchIndexer.index(_1, force: true) }
[message_1, message_2, message_3].each { SearchIndexer.index(it, force: true) }
end
it "returns matching messages" do
@@ -50,7 +50,7 @@ RSpec.describe Chat::Action::SearchForMessages do
before do
[alice_message_1, alice_message_2, bob_message].each do
SearchIndexer.index(_1, force: true)
SearchIndexer.index(it, force: true)
end
end
@@ -115,7 +115,7 @@ RSpec.describe Chat::Action::SearchForMessages do
before do
args[:limit] = 2
[message_4, message_5].each { SearchIndexer.index(_1, force: true) }
[message_4, message_5].each { SearchIndexer.index(it, force: true) }
end
it "limits the number of results" do
@@ -128,7 +128,7 @@ RSpec.describe Chat::Action::SearchForMessages do
fab!(:message_5) { Fabricate(:chat_message, chat_channel: channel, message: "test five") }
fab!(:message_6) { Fabricate(:chat_message, chat_channel: channel, message: "test six") }
before { [message_4, message_5, message_6].each { SearchIndexer.index(_1, force: true) } }
before { [message_4, message_5, message_6].each { SearchIndexer.index(it, force: true) } }
context "with offset parameter" do
let(:all_results) do
@@ -213,7 +213,7 @@ RSpec.describe Chat::Action::SearchForMessages do
before do
[original_message, thread_reply, regular_message].each do
SearchIndexer.index(_1, force: true)
SearchIndexer.index(it, force: true)
end
end
@@ -255,7 +255,7 @@ RSpec.describe Chat::Action::SearchForMessages do
before do
channel_2.add(current_user)
[channel_1_message, channel_2_message, private_channel_message].each do
SearchIndexer.index(_1, force: true)
SearchIndexer.index(it, force: true)
end
end
@@ -16,7 +16,7 @@ RSpec.describe Chat::Action::SearchMessage::ProcessSearchQuery do
channel.add(current_user)
SearchIndexer.enable
SiteSetting.chat_enabled = true
Chat::Message.all.each { SearchIndexer.index(_1, force: true) }
Chat::Message.all.each { SearchIndexer.index(it, force: true) }
end
context "with no filters" do
@@ -115,7 +115,7 @@ RSpec.describe ::Chat::LookupUserThreads do
end
it "doesn't return threads with no replies" do
Fabricate(:chat_thread, channel: channel_1).tap { _1.add(current_user) }
Fabricate(:chat_thread, channel: channel_1).tap { it.add(current_user) }
expect(result.threads).to eq([thread_1])
end
@@ -178,7 +178,7 @@ RSpec.describe Chat::UpdateMessage do
},
)
end
expect(events.map { _1[:event_name] }).to include(:chat_message_edited)
expect(events.map { it[:event_name] }).to include(:chat_message_edited)
end
it "publishes updated message to message bus" do
@@ -31,7 +31,7 @@ class AiSummary < ActiveRecord::Base
],
)
.first
.then { AiSummary.find_by(id: _1["id"]) }
.then { AiSummary.find_by(id: it["id"]) }
end
def self.build_sha(joined_ids)
@@ -63,7 +63,7 @@ module DiscourseAi
.split("\n")
.first
.to_s
.then { _1.match?(/^(["']).*\1$/) ? _1[1..-2] : _1 }
.then { it.match?(/^(["']).*\1$/) ? it[1..-2] : it }
.truncate(100, separator: " ")
end
@@ -89,7 +89,7 @@ module DiscourseAi
.sort_by { |c| -c[:score] }
.take(7)
.then do |tags|
models = Tag.where(name: tags.map { _1[:name] }).index_by(&:name)
models = Tag.where(name: tags.map { it[:name] }).index_by(&:name)
tags.map do |tag|
model = models.dig(tag[:name])
tag[:id] = model&.id
+1 -1
View File
@@ -427,7 +427,7 @@ module DiscourseAi
.rerank(conversation_context.last[:content], guidance)
.to_a
.take(rag_conversation_chunks)
.map { _1[:index] }
.map { it[:index] }
if ranks.empty?
fragments = fragments.take(rag_conversation_chunks)
@@ -112,12 +112,12 @@ module DiscourseAi
else
categories =
if categories_json = json.dig("grouped_search_result", "extra", "categories")
categories_json.index_by { _1["id"] }
categories_json.index_by { it["id"] }
else
self.class.categories
end
topics = (json["topics"]).index_by { _1["id"] }
topics = (json["topics"]).index_by { it["id"] }
format_results(posts, args: parameters) do |post|
topic = topics[post["topic_id"]]
@@ -5,7 +5,7 @@ module DiscourseAi
class PostClassification
def self.backfill_query(from_post_id: nil, max_age_days: nil)
available_classifier_names =
DiscourseAi::Sentiment::SentimentSiteSettingJsonSchema.values.map { _1.model_name }
DiscourseAi::Sentiment::SentimentSiteSettingJsonSchema.values.map { it.model_name }
queries =
available_classifier_names.map do |classifier_name|
@@ -178,7 +178,7 @@ RSpec.describe DiscourseAi::Sentiment::EmotionFilterOrder do
filter =
DiscoursePluginRegistry
.custom_filter_mappings
.find { _1.keys.include? "order:emotion_#{emotion}" }
.find { it.keys.include? "order:emotion_#{emotion}" }
.values
.first
result = filter.call(scope, order_direction, guardian)
+4 -4
View File
@@ -213,9 +213,9 @@ after_initialize do
topics.each do |topic|
if assignments = assignments_map[topic.id]
topic_assignments, post_assignments = assignments.partition { _1.target_type == "Topic" }
topic_assignments, post_assignments = assignments.partition { it.target_type == "Topic" }
direct_assignment = topic_assignments.find { _1.target_id == topic.id }
direct_assignment = topic_assignments.find { it.target_id == topic.id }
indirectly_assigned_to = {}
@@ -270,8 +270,8 @@ after_initialize do
results.posts.each do |post|
if topic_assignments = assignments[post.topic_id]
direct_assignment = topic_assignments.find { _1.target_type == "Topic" }
indirect_assignments = topic_assignments.select { _1.target_type == "Post" }
direct_assignment = topic_assignments.find { it.target_type == "Topic" }
indirect_assignments = topic_assignments.select { it.target_type == "Post" }
end
if indirect_assignments.present?
@@ -378,7 +378,7 @@ describe ListController do
expect(response.status).to eq(200)
expect(
response.parsed_body.dig("topic_list", "topics").map { _1["id"] },
response.parsed_body.dig("topic_list", "topics").map { it["id"] },
).to contain_exactly(topic_1.id, topic_2.id, topic_3.id)
end
end
@@ -395,7 +395,7 @@ describe ListController do
expect(response.status).to eq(200)
expect(
response.parsed_body.dig("topic_list", "topics").map { _1["id"] },
response.parsed_body.dig("topic_list", "topics").map { it["id"] },
).to contain_exactly(topic_1.id)
end
@@ -406,7 +406,7 @@ describe ListController do
expect(response.status).to eq(200)
expect(
response.parsed_body.dig("topic_list", "topics").map { _1["id"] },
response.parsed_body.dig("topic_list", "topics").map { it["id"] },
).to contain_exactly(topic_2.id)
end
@@ -429,7 +429,7 @@ describe ListController do
expect(response.status).to eq(200)
expect(
response.parsed_body.dig("topic_list", "topics").map { _1["id"] },
response.parsed_body.dig("topic_list", "topics").map { it["id"] },
).to contain_exactly(topic_1.id, topic_2.id, topic_3.id)
end
@@ -452,7 +452,7 @@ describe ListController do
expect(response.status).to eq(200)
expect(
response.parsed_body.dig("topic_list", "topics").map { _1["id"] },
response.parsed_body.dig("topic_list", "topics").map { it["id"] },
).to contain_exactly(topic_1.id)
end
@@ -467,7 +467,7 @@ describe ListController do
expect(response.status).to eq(200)
expect(
response.parsed_body.dig("topic_list", "topics").map { _1["id"] },
response.parsed_body.dig("topic_list", "topics").map { it["id"] },
).to contain_exactly(topic_1.id, topic_2.id)
end
@@ -482,7 +482,7 @@ describe ListController do
expect(response.status).to eq(200)
expect(
response.parsed_body.dig("topic_list", "topics").map { _1["id"] },
response.parsed_body.dig("topic_list", "topics").map { it["id"] },
).to contain_exactly(topic_3.id)
end
@@ -496,7 +496,7 @@ describe ListController do
expect(response.status).to eq(200)
expect(
response.parsed_body.dig("topic_list", "topics").map { _1["id"] },
response.parsed_body.dig("topic_list", "topics").map { it["id"] },
).to contain_exactly(topic_1.id, topic_2.id, topic_3.id)
end
@@ -514,7 +514,7 @@ describe ListController do
expect(response.status).to eq(200)
expect(
response.parsed_body.dig("topic_list", "topics").map { _1["id"] },
response.parsed_body.dig("topic_list", "topics").map { it["id"] },
).to contain_exactly(topic_1.id)
end
end
@@ -529,7 +529,7 @@ describe ListController do
expect(response.status).to eq(200)
expect(
response.parsed_body.dig("topic_list", "topics").map { _1["id"] },
response.parsed_body.dig("topic_list", "topics").map { it["id"] },
).to contain_exactly(topic_1.id, topic_2.id, topic_3.id)
end
@@ -542,7 +542,7 @@ describe ListController do
expect(response.status).to eq(200)
expect(
response.parsed_body.dig("topic_list", "topics").map { _1["id"] },
response.parsed_body.dig("topic_list", "topics").map { it["id"] },
).to contain_exactly(topic_1.id, topic_2.id, topic_3.id)
end
end
@@ -27,7 +27,7 @@ RSpec.describe "Assign | User Menu", type: :system do
read_user_assign_2,
read_user_assign,
read_group_assign,
].map { _1.topic.fancy_title }
].map { it.topic.fancy_title }
end
it "orders the items properly" do
@@ -7,11 +7,11 @@ module DiscourseGamification
belongs_to :user
def self.enabled_scorables
Scorable.subclasses.filter { _1.enabled? }
Scorable.subclasses.filter { it.enabled? }
end
def self.scorables_queries
enabled_scorables.map { "( #{_1.query} )" }.join(" UNION ALL ")
enabled_scorables.map { "( #{it.query} )" }.join(" UNION ALL ")
end
def self.calculate_scores(since_date: Date.today, only_subclass: nil)
@@ -7,7 +7,7 @@ module DiscourseGamification
end
def scorable_category_list
SiteSetting.scorable_categories.split("|").map { _1.to_i }.join(", ")
SiteSetting.scorable_categories.split("|").map { it.to_i }.join(", ")
end
end
end
@@ -49,7 +49,7 @@ RSpec.describe DiscourseGamification::AdminGamificationScoreEventController do
get "/admin/plugins/gamification/score_events.json?user_id=#{current_user.id}"
expect(response.status).to eq(200)
expect(response.parsed_body["events"].length).to eq(2)
expect(response.parsed_body["events"].map { _1["points"] }.sum).to eq(24)
expect(response.parsed_body["events"].map { it["points"] }.sum).to eq(24)
end
it "returns users and their calculated scores for a specific user and date" do
+2 -2
View File
@@ -324,7 +324,7 @@ class BulkImport::Generic < BulkImport::Base
SQL
field_names =
query("SELECT DISTINCT name FROM category_custom_fields") { _1.map { |row| row["name"] } }
query("SELECT DISTINCT name FROM category_custom_fields") { it.map { |row| row["name"] } }
existing_category_custom_fields =
CategoryCustomField.where(name: field_names).pluck(:category_id, :name).to_set
@@ -1189,7 +1189,7 @@ class BulkImport::Generic < BulkImport::Base
SQL
field_names =
query("SELECT DISTINCT name FROM post_custom_fields") { _1.map { |row| row["name"] } }
query("SELECT DISTINCT name FROM post_custom_fields") { it.map { |row| row["name"] } }
existing_post_custom_fields =
PostCustomField.where(name: field_names).pluck(:post_id, :name).to_set
@@ -50,7 +50,7 @@ module ImportScripts::PhpBB3
@new_categories = import_settings["new_categories"]
@category_mappings =
import_settings.fetch("category_mappings", []).index_by { _1[:source_category_id].to_s }
import_settings.fetch("category_mappings", []).index_by { it[:source_category_id].to_s }
@tag_mappings = import_settings["tag_mappings"]
@rank_mapping = import_settings["rank_mapping"]
+1 -1
View File
@@ -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.index_by { _1["forumid"] }
forum_map = forums.index_by { it["forumid"] }
modentries = mysql_query(<<-SQL).to_a
SELECT m.forumid, m.userid, u.usergroupid IN (5,6) is_staff
FROM #{TABLE_PREFIX}moderator m
@@ -3,9 +3,9 @@
RSpec.describe "Having multiple tagged loggers", type: :request do
let(:loggers) { 2.times.map { ActiveSupport::TaggedLogging.new(Logger.new(nil)) } }
before { loggers.each { Rails.logger.broadcast_to(_1) } }
before { loggers.each { Rails.logger.broadcast_to(it) } }
after { loggers.each { Rails.logger.stop_broadcasting_to(_1) } }
after { loggers.each { Rails.logger.stop_broadcasting_to(it) } }
it "does not execute request twice" do
expect_any_instance_of(SilenceLogger).to receive(:call_app).once.and_call_original
+6 -6
View File
@@ -268,19 +268,19 @@ RSpec.describe PostCreator do
p = nil
messages = MessageBus.track_publish { p = creator.create }
expect(messages.find { _1.channel == "/latest" }).not_to eq(nil)
expect(messages.find { _1.channel == "/new" }).not_to eq(nil)
expect(messages.find { _1.channel == "/unread/#{p.user_id}" }).not_to eq(nil)
expect(messages.find { _1.channel == "/user-drafts/#{p.user_id}" }).not_to eq(nil)
expect(messages.find { it.channel == "/latest" }).not_to eq(nil)
expect(messages.find { it.channel == "/new" }).not_to eq(nil)
expect(messages.find { it.channel == "/unread/#{p.user_id}" }).not_to eq(nil)
expect(messages.find { it.channel == "/user-drafts/#{p.user_id}" }).not_to eq(nil)
user_action = messages.find { _1.channel == "/u/#{p.user.username}" }
user_action = messages.find { it.channel == "/u/#{p.user.username}" }
expect(user_action).to eq(nil)
topics_stats =
messages.find { |m| m.channel == "/topic/#{p.topic.id}" && m.data[:type] == :stats }
expect(topics_stats).to eq(nil)
expect(messages.filter { _1.channel != "/distributed_hash" }.size).to eq(6)
expect(messages.filter { it.channel != "/distributed_hash" }.size).to eq(6)
end
it "extracts links from the post" do
+1 -1
View File
@@ -3291,7 +3291,7 @@ RSpec.describe Search do
before do
described_class.advanced_order(:chars, enabled: method(:enabled?)) do
_1.reorder("MAX(LENGTH(posts.raw)) DESC")
it.reorder("MAX(LENGTH(posts.raw)) DESC")
end
end
+2 -2
View File
@@ -1566,8 +1566,8 @@ HTML
let!(:another_theme) { Fabricate(:theme) }
before do
users.take(3).each { _1.user_option.update!(theme_ids: [theme.id]) }
users.slice(3..4).each { _1.user_option.update!(theme_ids: [another_theme.id]) }
users.take(3).each { it.user_option.update!(theme_ids: [theme.id]) }
users.slice(3..4).each { it.user_option.update!(theme_ids: [another_theme.id]) }
end
it "returns how many users are currently using the theme" do
+1 -1
View File
@@ -498,7 +498,7 @@ RSpec.describe Admin::ApiController do
end,
).to be_truthy
expect(scopes["users"].find { _1["key"] == "update" }["urls"]).to contain_exactly(
expect(scopes["users"].find { it["key"] == "update" }["urls"]).to contain_exactly(
"/users/:username (PUT)",
"/users/:username/preferences/badge_title (PUT)",
"/users/:username/preferences/avatar/pick (PUT)",
+2 -2
View File
@@ -3732,7 +3732,7 @@ RSpec.describe TopicsController do
expect(response.status).to eq(200)
expect(response.parsed_body.has_key?("suggested_topics")).to eq(false)
expect(response.parsed_body["categories"].map { _1["id"] }).to contain_exactly(
expect(response.parsed_body["categories"].map { it["id"] }).to contain_exactly(
topic.category_id,
)
@@ -3740,7 +3740,7 @@ RSpec.describe TopicsController do
expect(response.status).to eq(200)
expect(response.parsed_body.has_key?("suggested_topics")).to eq(true)
expect(response.parsed_body["categories"].map { _1["id"] }).to contain_exactly(
expect(response.parsed_body["categories"].map { it["id"] }).to contain_exactly(
topic.category_id,
dest_topic.category_id,
)
+1 -1
View File
@@ -4552,7 +4552,7 @@ RSpec.describe UsersController do
links = response.parsed_body["user_summary"]["links"]
expect(links.map { _1["url"] }).to contain_exactly(
expect(links.map { it["url"] }).to contain_exactly(
"https://visible-link.com",
"https://another-visible-link.com",
)
@@ -159,7 +159,7 @@ RSpec.shared_examples_for "having working core features" do |skip_examples: []|
before do
SearchIndexer.enable
topics.each { SearchIndexer.index(_1, force: true) }
topics.each { SearchIndexer.index(it, force: true) }
Fabricate(:theme_site_setting_with_service, name: "enable_welcome_banner", value: false)
end