DEV: Prefer public_send over send.

This commit is contained in:
Guo Xiang Tan 2019-05-07 09:27:05 +08:00
parent 9be70a22cd
commit 152238b4cf
74 changed files with 216 additions and 129 deletions

View File

@ -108,7 +108,7 @@ class Admin::BadgesController < Admin::AdminController
params.permit(*allowed) params.permit(*allowed)
allowed.each do |key| allowed.each do |key|
badge.send("#{key}=" , params[key]) if params[key] badge.public_send("#{key}=" , params[key]) if params[key]
end end
# Badge query contract checks # Badge query contract checks

View File

@ -113,7 +113,11 @@ class Admin::EmailController < Admin::AdminController
params.require(:username) params.require(:username)
params.require(:email) params.require(:email)
user = User.find_by_username(params[:username]) user = User.find_by_username(params[:username])
message, skip_reason = UserNotifications.send(:digest, user, since: params[:last_seen_at])
message, skip_reason = UserNotifications.public_send(:digest, user,
since: params[:last_seen_at]
)
if message if message
message.to = params[:email] message.to = params[:email]
begin begin

View File

@ -16,7 +16,7 @@ class Admin::EmbeddingController < Admin::AdminController
end end
Embedding.settings.each do |s| Embedding.settings.each do |s|
@embedding.send("#{s}=", params[:embedding][s]) @embedding.public_send("#{s}=", params[:embedding][s])
end end
if @embedding.save if @embedding.save

View File

@ -157,7 +157,7 @@ class Admin::ThemesController < Admin::AdminController
[:name, :color_scheme_id, :user_selectable].each do |field| [:name, :color_scheme_id, :user_selectable].each do |field|
if theme_params.key?(field) if theme_params.key?(field)
@theme.send("#{field}=", theme_params[field]) @theme.public_send("#{field}=", theme_params[field])
end end
end end

View File

@ -27,7 +27,7 @@ class Admin::UserFieldsController < Admin::AdminController
Admin::UserFieldsController.columns.each do |col| Admin::UserFieldsController.columns.each do |col|
unless field_params[col].nil? unless field_params[col].nil?
field.send("#{col}=", field_params[col]) field.public_send("#{col}=", field_params[col])
end end
end end
update_options(field) update_options(field)

View File

@ -254,7 +254,7 @@ class Admin::UsersController < Admin::AdminController
level = params[:level].to_i level = params[:level].to_i
if @user.manual_locked_trust_level.nil? if @user.manual_locked_trust_level.nil?
if [0, 1, 2].include?(level) && Promotion.send("tl#{level + 1}_met?", @user) if [0, 1, 2].include?(level) && Promotion.public_send("tl#{level + 1}_met?", @user)
@user.manual_locked_trust_level = level @user.manual_locked_trust_level = level
@user.save @user.save
elsif level == 3 && Promotion.tl3_lost?(@user) elsif level == 3 && Promotion.tl3_lost?(@user)

View File

@ -628,10 +628,10 @@ class ApplicationController < ActionController::Base
error_obj = nil error_obj = nil
if opts[:additional_errors] if opts[:additional_errors]
error_target = opts[:additional_errors].find do |o| error_target = opts[:additional_errors].find do |o|
target = obj.send(o) target = obj.public_send(o)
target && target.errors.present? target && target.errors.present?
end end
error_obj = obj.send(error_target) if error_target error_obj = obj.public_send(error_target) if error_target
end end
render_json_error(error_obj || obj) render_json_error(error_obj || obj)
end end

View File

@ -240,9 +240,9 @@ class CategoriesController < ApplicationController
draft = Draft.get(current_user, draft_key, draft_sequence) if current_user draft = Draft.get(current_user, draft_key, draft_sequence) if current_user
%w{category topic}.each do |type| %w{category topic}.each do |type|
result.send(:"#{type}_list").draft = draft result.public_send(:"#{type}_list").draft = draft
result.send(:"#{type}_list").draft_key = draft_key result.public_send(:"#{type}_list").draft_key = draft_key
result.send(:"#{type}_list").draft_sequence = draft_sequence result.public_send(:"#{type}_list").draft_sequence = draft_sequence
end end
render_serialized(result, CategoryAndTopicListsSerializer, root: false) render_serialized(result, CategoryAndTopicListsSerializer, root: false)

View File

@ -117,20 +117,20 @@ class ListController < ApplicationController
define_method("category_#{filter}") do define_method("category_#{filter}") do
canonical_url "#{Discourse.base_url_no_prefix}#{@category.url}" canonical_url "#{Discourse.base_url_no_prefix}#{@category.url}"
self.send(filter, category: @category.id) self.public_send(filter, category: @category.id)
end end
define_method("category_none_#{filter}") do define_method("category_none_#{filter}") do
self.send(filter, category: @category.id, no_subcategories: true) self.public_send(filter, category: @category.id, no_subcategories: true)
end end
define_method("parent_category_category_#{filter}") do define_method("parent_category_category_#{filter}") do
canonical_url "#{Discourse.base_url_no_prefix}#{@category.url}" canonical_url "#{Discourse.base_url_no_prefix}#{@category.url}"
self.send(filter, category: @category.id) self.public_send(filter, category: @category.id)
end end
define_method("parent_category_category_none_#{filter}") do define_method("parent_category_category_none_#{filter}") do
self.send(filter, category: @category.id) self.public_send(filter, category: @category.id)
end end
end end
@ -142,7 +142,7 @@ class ListController < ApplicationController
if view_method == 'top' if view_method == 'top'
top(category: @category.id) top(category: @category.id)
else else
self.send(view_method) self.public_send(view_method)
end end
end end
@ -237,7 +237,10 @@ class ListController < ApplicationController
@link = "#{Discourse.base_url}/u/#{target_user.username}/activity/topics" @link = "#{Discourse.base_url}/u/#{target_user.username}/activity/topics"
@atom_link = "#{Discourse.base_url}/u/#{target_user.username}/activity/topics.rss" @atom_link = "#{Discourse.base_url}/u/#{target_user.username}/activity/topics.rss"
@description = I18n.t("rss_description.user_topics", username: target_user.username) @description = I18n.t("rss_description.user_topics", username: target_user.username)
@topic_list = TopicQuery.new(nil, order: 'created').send("list_topics_by", target_user)
@topic_list = TopicQuery
.new(nil, order: 'created')
.public_send("list_topics_by", target_user)
render 'list', formats: [:rss] render 'list', formats: [:rss]
end end
@ -285,15 +288,18 @@ class ListController < ApplicationController
end end
define_method("category_top_#{period}") do define_method("category_top_#{period}") do
self.send("top_#{period}", category: @category.id) self.public_send("top_#{period}", category: @category.id)
end end
define_method("category_none_top_#{period}") do define_method("category_none_top_#{period}") do
self.send("top_#{period}", category: @category.id, no_subcategories: true) self.public_send("top_#{period}",
category: @category.id,
no_subcategories: true
)
end end
define_method("parent_category_category_top_#{period}") do define_method("parent_category_category_top_#{period}") do
self.send("top_#{period}", category: @category.id) self.public_send("top_#{period}", category: @category.id)
end end
# rss feed # rss feed
@ -398,7 +404,7 @@ class ListController < ApplicationController
end end
def generate_list_for(action, target_user, opts) def generate_list_for(action, target_user, opts)
TopicQuery.new(current_user, opts).send("list_#{action}", target_user) TopicQuery.new(current_user, opts).public_send("list_#{action}", target_user)
end end
def construct_url_with(action, opts, url_prefix = nil) def construct_url_with(action, opts, url_prefix = nil)

View File

@ -200,7 +200,10 @@ class PostsController < ApplicationController
post.image_sizes = params[:image_sizes] if params[:image_sizes].present? post.image_sizes = params[:image_sizes] if params[:image_sizes].present?
if !guardian.send("can_edit?", post) && post.user_id == current_user.id && post.edit_time_limit_expired? if !guardian.public_send("can_edit?", post) &&
post.user_id == current_user.id &&
post.edit_time_limit_expired?
return render_json_error(I18n.t('too_late_to_edit')) return render_json_error(I18n.t('too_late_to_edit'))
end end

View File

@ -38,7 +38,7 @@ class StaticController < ApplicationController
@page.gsub!(/[^a-z0-9\_\-]/, '') @page.gsub!(/[^a-z0-9\_\-]/, '')
if map.has_key?(@page) if map.has_key?(@page)
@topic = Topic.find_by_id(SiteSetting.send(map[@page][:topic_id])) @topic = Topic.find_by_id(SiteSetting.get(map[@page][:topic_id]))
raise Discourse::NotFound unless @topic raise Discourse::NotFound unless @topic
title_prefix = if I18n.exists?("js.#{@page}") title_prefix = if I18n.exists?("js.#{@page}")
I18n.t("js.#{@page}") I18n.t("js.#{@page}")

View File

@ -1036,7 +1036,7 @@ class UsersController < ApplicationController
result = {} result = {}
%W{number_of_deleted_posts number_of_flagged_posts number_of_flags_given number_of_suspensions warnings_received_count}.each do |info| %W{number_of_deleted_posts number_of_flagged_posts number_of_flags_given number_of_suspensions warnings_received_count}.each do |info|
result[info] = @user.send(info) result[info] = @user.public_send(info)
end end
render json: result render json: result

View File

@ -10,8 +10,14 @@ module Jobs
return unless user.is_singular_admin? return unless user.is_singular_admin?
# let's enable bootstrap mode settings # let's enable bootstrap mode settings
SiteSetting.set_and_log('default_trust_level', TrustLevel[1]) if SiteSetting.get('default_trust_level') == TrustLevel[0] if SiteSetting.default_trust_level == TrustLevel[0]
SiteSetting.set_and_log('default_email_digest_frequency', 1440) if SiteSetting.get('default_email_digest_frequency') == 10080 SiteSetting.set_and_log('default_trust_level', TrustLevel[1])
end
if SiteSetting.default_email_digest_frequency == 10080
SiteSetting.set_and_log('default_email_digest_frequency', 1440)
end
SiteSetting.set_and_log('bootstrap_mode_enabled', true) SiteSetting.set_and_log('bootstrap_mode_enabled', true)
end end
end end

View File

@ -170,7 +170,7 @@ module Jobs
end end
message = EmailLog.unique_email_per_post(post, user) do message = EmailLog.unique_email_per_post(post, user) do
UserNotifications.send(type, user, email_args) UserNotifications.public_send(type, user, email_args)
end end
# Update the to address if we have a custom one # Update the to address if we have a custom one

View File

@ -7,8 +7,14 @@ module Jobs
total_users = User.human_users.count total_users = User.human_users.count
if SiteSetting.bootstrap_mode_min_users == 0 || total_users > SiteSetting.bootstrap_mode_min_users if SiteSetting.bootstrap_mode_min_users == 0 || total_users > SiteSetting.bootstrap_mode_min_users
SiteSetting.set_and_log('default_trust_level', TrustLevel[0]) if SiteSetting.get('default_trust_level') == TrustLevel[1] if SiteSetting.default_trust_level == TrustLevel[1]
SiteSetting.set_and_log('default_email_digest_frequency', 10080) if SiteSetting.get('default_email_digest_frequency') == 1440 SiteSetting.set_and_log('default_trust_level', TrustLevel[0])
end
if SiteSetting.default_email_digest_frequency == 1440
SiteSetting.set_and_log('default_email_digest_frequency', 10080)
end
SiteSetting.set_and_log('bootstrap_mode_enabled', false) SiteSetting.set_and_log('bootstrap_mode_enabled', false)
end end
end end

View File

@ -40,7 +40,7 @@ module Roleable
end end
def set_permission(permission_name, value) def set_permission(permission_name, value)
self.send("#{permission_name}=", value) self.public_send("#{permission_name}=", value)
save_and_refresh_staff_groups! save_and_refresh_staff_groups!
end end

View File

@ -38,7 +38,10 @@ class Embedding < OpenStruct
def self.find def self.find
embedding_args = { id: 'default' } embedding_args = { id: 'default' }
Embedding.settings.each { |s| embedding_args[s] = SiteSetting.send(s) } Embedding.settings.each do |s|
embedding_args[s] = SiteSetting.public_send(s)
end
Embedding.new(embedding_args) Embedding.new(embedding_args)
end end
end end

View File

@ -111,7 +111,7 @@ class GlobalSetting
replica_host replica_host
replica_port replica_port
}.each do |s| }.each do |s|
if val = self.send("db_#{s}") if val = self.public_send("db_#{s}")
hash[s] = val hash[s] = val
end end
end end

View File

@ -321,10 +321,12 @@ class OptimizedImage < ActiveRecord::Base
def self.optimize(operation, from, to, dimensions, opts = {}) def self.optimize(operation, from, to, dimensions, opts = {})
method_name = "#{operation}_instructions" method_name = "#{operation}_instructions"
if !!opts[:allow_animation] && (from =~ /\.GIF$/i) if !!opts[:allow_animation] && (from =~ /\.GIF$/i)
method_name += "_animated" method_name += "_animated"
end end
instructions = self.send(method_name.to_sym, from, to, dimensions, opts)
instructions = self.public_send(method_name.to_sym, from, to, dimensions, opts)
convert_with(instructions, to, opts) convert_with(instructions, to, opts)
end end

View File

@ -257,7 +257,7 @@ class Post < ActiveRecord::Base
raw_links raw_links
has_oneboxes?}.each do |attr| has_oneboxes?}.each do |attr|
define_method(attr) do define_method(attr) do
post_analyzer.send(attr) post_analyzer.public_send(attr)
end end
end end

View File

@ -240,14 +240,14 @@ class Report
def self.basic_report_about(report, subject_class, report_method, *args) def self.basic_report_about(report, subject_class, report_method, *args)
report.data = [] report.data = []
subject_class.send(report_method, *args).each do |date, count| subject_class.public_send(report_method, *args).each do |date, count|
report.data << { x: date, y: count } report.data << { x: date, y: count }
end end
end end
def self.add_prev_data(report, subject_class, report_method, *args) def self.add_prev_data(report, subject_class, report_method, *args)
if report.modes.include?(:chart) && report.facets.include?(:prev_period) if report.modes.include?(:chart) && report.facets.include?(:prev_period)
prev_data = subject_class.send(report_method, *args) prev_data = subject_class.public_send(report_method, *args)
report.prev_data = prev_data.map { |k, v| { x: k, y: v } } report.prev_data = prev_data.map { |k, v| { x: k, y: v } }
end end
end end

View File

@ -53,7 +53,7 @@ class TopTopic < ActiveRecord::Base
def self.update_counts_and_compute_scores_for(period) def self.update_counts_and_compute_scores_for(period)
sort_orders.each do |sort| sort_orders.each do |sort|
TopTopic.send("update_#{sort}_count_for", period) TopTopic.public_send("update_#{sort}_count_for", period)
end end
compute_top_score_for(period) compute_top_score_for(period)
end end

View File

@ -351,7 +351,7 @@ class User < ActiveRecord::Base
def self.unstage(params) def self.unstage(params)
if user = User.where(staged: true).with_email(params[:email].strip.downcase).first if user = User.where(staged: true).with_email(params[:email].strip.downcase).first
params.each { |k, v| user.send("#{k}=", v) } params.each { |k, v| user.public_send("#{k}=", v) }
user.active = false user.active = false
user.unstage user.unstage
end end

View File

@ -9,7 +9,7 @@ class UsernameValidator
# #
# Example: UsernameValidator.perform_validation(user, 'name') # Example: UsernameValidator.perform_validation(user, 'name')
def self.perform_validation(object, field_name) def self.perform_validation(object, field_name)
validator = UsernameValidator.new(object.send(field_name)) validator = UsernameValidator.new(object.public_send(field_name))
unless validator.valid_format? unless validator.valid_format?
validator.errors.each { |e| object.errors.add(field_name.to_sym, e) } validator.errors.each { |e| object.errors.add(field_name.to_sym, e) }
end end

View File

@ -31,7 +31,7 @@ class AdminUserListSerializer < BasicUserSerializer
[:days_visited, :posts_read_count, :topics_entered, :post_count].each do |sym| [:days_visited, :posts_read_count, :topics_entered, :post_count].each do |sym|
attributes sym attributes sym
define_method sym do define_method sym do
object.user_stat.send(sym) object.user_stat.public_send(sym)
end end
end end

View File

@ -54,10 +54,12 @@ class CategoryDetailedSerializer < BasicCategorySerializer
end end
def count_with_subcategories(method) def count_with_subcategories(method)
count = object.send(method) || 0 count = object.public_send(method) || 0
object.subcategories.each do |category| object.subcategories.each do |category|
count += (category.send(method) || 0) count += (category.public_send(method) || 0)
end end
count count
end end

View File

@ -5,7 +5,7 @@ class EmbeddableHostSerializer < ApplicationSerializer
attributes *TO_SERIALIZE attributes *TO_SERIALIZE
TO_SERIALIZE.each do |attr| TO_SERIALIZE.each do |attr|
define_method(attr) { object.send(attr) } define_method(attr) { object.public_send(attr) }
end end
end end

View File

@ -9,6 +9,6 @@ class EmbeddingSerializer < ApplicationSerializer
end end
def read_attribute_for_serialization(attr) def read_attribute_for_serialization(attr)
object.respond_to?(attr) ? object.send(attr) : send(attr) object.respond_to?(attr) ? object.public_send(attr) : public_send(attr)
end end
end end

View File

@ -201,7 +201,9 @@ class PostRevisionSerializer < ApplicationSerializer
# Retrieve any `tracked_topic_fields` # Retrieve any `tracked_topic_fields`
PostRevisor.tracked_topic_fields.each_key do |field| PostRevisor.tracked_topic_fields.each_key do |field|
latest_modifications[field.to_s] = [topic.send(field)] if topic.respond_to?(field) if topic.respond_to?(field)
latest_modifications[field.to_s] = [topic.public_send(field)]
end
end end
latest_modifications["featured_link"] = [post.topic.featured_link] if SiteSetting.topic_featured_link_enabled latest_modifications["featured_link"] = [post.topic.featured_link] if SiteSetting.topic_featured_link_enabled

View File

@ -14,7 +14,7 @@ class PostSerializer < BasicPostSerializer
] ]
INSTANCE_VARS.each do |v| INSTANCE_VARS.each do |v|
self.send(:attr_accessor, v) self.public_send(:attr_accessor, v)
end end
attributes :post_number, attributes :post_number,
@ -80,9 +80,10 @@ class PostSerializer < BasicPostSerializer
def initialize(object, opts) def initialize(object, opts)
super(object, opts) super(object, opts)
PostSerializer::INSTANCE_VARS.each do |name| PostSerializer::INSTANCE_VARS.each do |name|
if opts.include? name if opts.include? name
self.send("#{name}=", opts[name]) self.public_send("#{name}=", opts[name])
end end
end end
end end
@ -242,7 +243,7 @@ class PostSerializer < BasicPostSerializer
PostActionType.types.except(:bookmark).each do |sym, id| PostActionType.types.except(:bookmark).each do |sym, id|
count_col = "#{sym}_count".to_sym count_col = "#{sym}_count".to_sym
count = object.send(count_col) if object.respond_to?(count_col) count = object.public_send(count_col) if object.respond_to?(count_col)
summary = { id: id, count: count } summary = { id: id, count: count }
summary[:hidden] = true if sym == :vote summary[:hidden] = true if sym == :vote

View File

@ -13,7 +13,9 @@ class TopListSerializer < ApplicationSerializer
attribute period attribute period
define_method(period) do define_method(period) do
TopicListSerializer.new(object.send(period), scope: scope).as_json if object.send(period) if object.public_send(period)
TopicListSerializer.new(object.public_send(period), scope: scope).as_json
end
end end
end end

View File

@ -126,7 +126,7 @@ class NotificationEmailer
email_user = EmailUser.new(notification) email_user = EmailUser.new(notification)
email_method = Notification.types[notification.notification_type] email_method = Notification.types[notification.notification_type]
email_user.send(email_method) if email_user.respond_to? email_method email_user.public_send(email_method) if email_user.respond_to? email_method
end end
end end

View File

@ -16,7 +16,11 @@ class StaffActionLogger
def log_user_deletion(deleted_user, opts = {}) def log_user_deletion(deleted_user, opts = {})
raise Discourse::InvalidParameters.new(:deleted_user) unless deleted_user && deleted_user.is_a?(User) raise Discourse::InvalidParameters.new(:deleted_user) unless deleted_user && deleted_user.is_a?(User)
details = USER_FIELDS.map { |x| "#{x}: #{deleted_user.send(x)}" }.join("\n")
details = USER_FIELDS.map do |x|
"#{x}: #{deleted_user.public_send(x)}"
end.join("\n")
UserHistory.create!(params(opts).merge( UserHistory.create!(params(opts).merge(
action: UserHistory.actions[:delete_user], action: UserHistory.actions[:delete_user],
ip_address: deleted_user.ip_address.to_s, ip_address: deleted_user.ip_address.to_s,
@ -268,7 +272,11 @@ class StaffActionLogger
def log_badge_creation(badge) def log_badge_creation(badge)
raise Discourse::InvalidParameters.new(:badge) unless badge raise Discourse::InvalidParameters.new(:badge) unless badge
details = BADGE_FIELDS.map { |f| [f, badge.send(f)] }.select { |f, v| v.present? }.map { |f, v| "#{f}: #{v}" }
details = BADGE_FIELDS.map do |f|
[f, badge.public_send(f)]
end.select { |f, v| v.present? }.map { |f, v| "#{f}: #{v}" }
UserHistory.create!(params.merge( UserHistory.create!(params.merge(
action: UserHistory.actions[:create_badge], action: UserHistory.actions[:create_badge],
details: details.join("\n") details: details.join("\n")
@ -287,7 +295,11 @@ class StaffActionLogger
def log_badge_deletion(badge) def log_badge_deletion(badge)
raise Discourse::InvalidParameters.new(:badge) unless badge raise Discourse::InvalidParameters.new(:badge) unless badge
details = BADGE_FIELDS.map { |f| [f, badge.send(f)] }.select { |f, v| v.present? }.map { |f, v| "#{f}: #{v}" }
details = BADGE_FIELDS.map do |f|
[f, badge.public_send(f)]
end.select { |f, v| v.present? }.map { |f, v| "#{f}: #{v}" }
UserHistory.create!(params.merge( UserHistory.create!(params.merge(
action: UserHistory.actions[:delete_badge], action: UserHistory.actions[:delete_badge],
details: details.join("\n") details: details.join("\n")

View File

@ -32,7 +32,7 @@ TopicStatusUpdater = Struct.new(:topic, :user) do
rc = Topic.where(:id => topic.id, status.name => !status.enabled) rc = Topic.where(:id => topic.id, status.name => !status.enabled)
.update_all(status.name => status.enabled?) .update_all(status.name => status.enabled?)
topic.send("#{status.name}=", status.enabled?) topic.public_send("#{status.name}=", status.enabled?)
result = false if rc == 0 result = false if rc == 0
end end

View File

@ -113,11 +113,11 @@ class UserUpdater
if attributes.key?(attribute) if attributes.key?(attribute)
save_options = true save_options = true
if [true, false].include?(user.user_option.send(attribute)) if [true, false].include?(user.user_option.public_send(attribute))
val = attributes[attribute].to_s == 'true' val = attributes[attribute].to_s == 'true'
user.user_option.send("#{attribute}=", val) user.user_option.public_send("#{attribute}=", val)
else else
user.user_option.send("#{attribute}=", attributes[attribute]) user.user_option.public_send("#{attribute}=", attributes[attribute])
end end
end end
end end

View File

@ -1 +1 @@
ActiveRecord::Base.send(:include, ActiveModel::ForbiddenAttributesProtection) ActiveRecord::Base.public_send(:include, ActiveModel::ForbiddenAttributesProtection)

View File

@ -1,3 +1,3 @@
# fix any bust caches post initial migration # fix any bust caches post initial migration
ActiveRecord::Base.send(:subclasses).each { |m| m.reset_column_information } ActiveRecord::Base.public_send(:subclasses).each { |m| m.reset_column_information }
SiteSetting.refresh! SiteSetting.refresh!

View File

@ -18,11 +18,11 @@ class CustomRenderer < AbstractController::Base
end end
def cookies def cookies
@parent.send(:cookies) @parent.public_send(:cookies)
end end
def session def session
@parent.send(:session) @parent.public_send(:session)
end end
def initialize(parent) def initialize(parent)

View File

@ -95,7 +95,9 @@ class DbHelper
SQL SQL
if rows.size > 0 if rows.size > 0
found["#{r.table_name}.#{r.column_name}"] = rows.map { |row| row.send(r.column_name) } found["#{r.table_name}.#{r.column_name}"] = rows.map do |row|
row.public_send(r.column_name)
end
end end
end end

View File

@ -40,7 +40,8 @@ module DiscourseHub
def self.singular_action(action, rel_url, params = {}) def self.singular_action(action, rel_url, params = {})
connect_opts = connect_opts(params) connect_opts = connect_opts(params)
JSON.parse(Excon.send(action,
JSON.parse(Excon.public_send(action,
"#{hub_base_url}#{rel_url}", "#{hub_base_url}#{rel_url}",
{ {
headers: { 'Referer' => referer, 'Accept' => accepts.join(', ') }, headers: { 'Referer' => referer, 'Accept' => accepts.join(', ') },
@ -53,7 +54,7 @@ module DiscourseHub
def self.collection_action(action, rel_url, params = {}) def self.collection_action(action, rel_url, params = {})
connect_opts = connect_opts(params) connect_opts = connect_opts(params)
response = Excon.send(action, response = Excon.public_send(action,
"#{hub_base_url}#{rel_url}", "#{hub_base_url}#{rel_url}",
{ {
body: JSON[params], body: JSON[params],

View File

@ -20,7 +20,7 @@ class DiscoursePlugin
original_class = mixin.to_s.demodulize.sub("Mixin", "") original_class = mixin.to_s.demodulize.sub("Mixin", "")
dependency_file_name = original_class.underscore dependency_file_name = original_class.underscore
require_dependency(dependency_file_name) require_dependency(dependency_file_name)
original_class.constantize.send(:include, mixin) original_class.constantize.public_send(:include, mixin)
end end
end end

View File

@ -184,7 +184,7 @@ class DiscourseRedis
# prefix the key with the namespace # prefix the key with the namespace
def method_missing(meth, *args, &block) def method_missing(meth, *args, &block)
if @redis.respond_to?(meth) if @redis.respond_to?(meth)
DiscourseRedis.ignore_readonly { @redis.send(meth, *args, &block) } DiscourseRedis.ignore_readonly { @redis.public_send(meth, *args, &block) }
else else
super super
end end
@ -201,7 +201,7 @@ class DiscourseRedis
:zremrangebyscore, :zrevrange, :zrevrangebyscore, :zrevrank, :zrangebyscore ].each do |m| :zremrangebyscore, :zrevrange, :zrevrangebyscore, :zrevrank, :zrangebyscore ].each do |m|
define_method m do |*args| define_method m do |*args|
args[0] = "#{namespace}:#{args[0]}" if @namespace args[0] = "#{namespace}:#{args[0]}" if @namespace
DiscourseRedis.ignore_readonly { @redis.send(m, *args) } DiscourseRedis.ignore_readonly { @redis.public_send(m, *args) }
end end
end end

View File

@ -107,8 +107,9 @@ module Email
styled = Email::Styles.new(html_override, @opts) styled = Email::Styles.new(html_override, @opts)
styled.format_basic styled.format_basic
if style = @opts[:style] if style = @opts[:style]
styled.send("format_#{style}") styled.public_send("format_#{style}")
end end
Mail::Part.new do Mail::Part.new do

View File

@ -345,7 +345,7 @@ module Email
# use the first html extracter that matches # use the first html extracter that matches
if html_extracter = HTML_EXTRACTERS.select { |_, r| html[r] }.min_by { |_, r| html =~ r } if html_extracter = HTML_EXTRACTERS.select { |_, r| html[r] }.min_by { |_, r| html =~ r }
doc = Nokogiri::HTML.fragment(html) doc = Nokogiri::HTML.fragment(html)
self.send(:"extract_from_#{html_extracter[0]}", doc) self.public_send(:"extract_from_#{html_extracter[0]}", doc)
else else
markdown = HtmlToMarkdown.new(html, keep_img_tags: true, keep_cid_imgs: true).to_markdown markdown = HtmlToMarkdown.new(html, keep_img_tags: true, keep_cid_imgs: true).to_markdown
markdown = trim_discourse_markers(markdown) markdown = trim_discourse_markers(markdown)
@ -1176,7 +1176,7 @@ module Email
end end
def send_subscription_mail(action, user) def send_subscription_mail(action, user)
message = SubscriptionMailer.send(action, user) message = SubscriptionMailer.public_send(action, user)
Email::Sender.new(message, :subscription).send Email::Sender.new(message, :subscription).send
end end

View File

@ -16,10 +16,10 @@ class FeedItemAccessor
private private
def element(element_name) def element(element_name)
rss_item.respond_to?(element_name) ? rss_item.send(element_name) : nil rss_item.respond_to?(element_name) ? rss_item.public_send(element_name) : nil
end end
def try_attribute_or_self(element, attribute_name) def try_attribute_or_self(element, attribute_name)
element.respond_to?(attribute_name) ? element.send(attribute_name) : element element.respond_to?(attribute_name) ? element.public_send(attribute_name) : element
end end
end end

View File

@ -27,7 +27,7 @@ class ActiveRecord::Base
Discourse.deprecate("exec_sql should not be used anymore, please use DB.exec or DB.query instead!") Discourse.deprecate("exec_sql should not be used anymore, please use DB.exec or DB.query instead!")
conn = ActiveRecord::Base.connection conn = ActiveRecord::Base.connection
sql = ActiveRecord::Base.send(:sanitize_sql_array, args) sql = ActiveRecord::Base.public_send(:sanitize_sql_array, args)
conn.raw_connection.async_exec(sql) conn.raw_connection.async_exec(sql)
end end

View File

@ -30,7 +30,7 @@ module FreedomPatches
SQL SQL
hostname = `hostname` rescue "" hostname = `hostname` rescue ""
sql = ActiveRecord::Base.send(:sanitize_sql_array, [sql, { sql = ActiveRecord::Base.public_send(:sanitize_sql_array, [sql, {
version: version || "", version: version || "",
duration: (time.real * 1000).to_i, duration: (time.real * 1000).to_i,
hostname: hostname, hostname: hostname,

View File

@ -26,7 +26,7 @@ module ImportExport
data = [] data = []
categories.each do |cat| categories.each do |cat|
data << CATEGORY_ATTRS.inject({}) { |h, a| h[a] = cat.send(a); h } data << CATEGORY_ATTRS.inject({}) { |h, a| h[a] = cat.public_send(a); h }
end end
data data
@ -53,7 +53,7 @@ module ImportExport
return [] if group_names.empty? return [] if group_names.empty?
Group.where(name: group_names).find_each do |group| Group.where(name: group_names).find_each do |group|
attrs = GROUP_ATTRS.inject({}) { |h, a| h[a] = group.send(a); h } attrs = GROUP_ATTRS.inject({}) { |h, a| h[a] = group.public_send(a); h }
attrs[:user_ids] = group.users.pluck(:id) attrs[:user_ids] = group.users.pluck(:id)
groups << attrs groups << attrs
end end
@ -93,11 +93,18 @@ module ImportExport
@topics.each do |topic| @topics.each do |topic|
puts topic.title puts topic.title
topic_data = TOPIC_ATTRS.inject({}) { |h, a| h[a] = topic.send(a); h; } topic_data = TOPIC_ATTRS.inject({}) do |h, a|
h[a] = topic.public_send(a)
h
end
topic_data[:posts] = [] topic_data[:posts] = []
topic.ordered_posts.find_each do |post| topic.ordered_posts.find_each do |post|
attributes = POST_ATTRS.inject({}) { |h, a| h[a] = post.send(a); h; } attributes = POST_ATTRS.inject({}) do |h, a|
h[a] = post.public_send(a)
h
end
attributes[:raw] = attributes[:raw].gsub( attributes[:raw] = attributes[:raw].gsub(
'src="/uploads', 'src="/uploads',
@ -139,7 +146,12 @@ module ImportExport
users.find_each do |u| users.find_each do |u|
next if u.id == Discourse::SYSTEM_USER_ID next if u.id == Discourse::SYSTEM_USER_ID
x = USER_ATTRS.inject({}) { |h, a| h[a] = u.send(a); h; }
x = USER_ATTRS.inject({}) do |h, a|
h[a] = u.public_send(a)
h
end
x.merge(bio_raw: u.user_profile.bio_raw, x.merge(bio_raw: u.user_profile.bio_raw,
website: u.user_profile.website, website: u.user_profile.website,
location: u.user_profile.location) location: u.user_profile.location)

View File

@ -19,7 +19,7 @@ class MiniSqlMultisiteConnection < MiniSql::Postgres::Connection
class ParamEncoder class ParamEncoder
def encode(*sql_array) def encode(*sql_array)
# use active record to avoid any discrepencies # use active record to avoid any discrepencies
ActiveRecord::Base.send(:sanitize_sql_array, sql_array) ActiveRecord::Base.public_send(:sanitize_sql_array, sql_array)
end end
end end

View File

@ -95,11 +95,11 @@ class Plugin::Instance
if define_include_method if define_include_method
# Don't include serialized methods if the plugin is disabled # Don't include serialized methods if the plugin is disabled
klass.send(:define_method, "include_#{attr}?") { plugin.enabled? } klass.public_send(:define_method, "include_#{attr}?") { plugin.enabled? }
end end
end end
klass.send(:define_method, attr, &block) klass.public_send(:define_method, attr, &block)
end end
end end
@ -170,10 +170,10 @@ class Plugin::Instance
reloadable_patch do |plugin| reloadable_patch do |plugin|
klass = class_name.to_s.classify.constantize rescue class_name.to_s.constantize klass = class_name.to_s.classify.constantize rescue class_name.to_s.constantize
hidden_method_name = :"#{attr}_without_enable_check" hidden_method_name = :"#{attr}_without_enable_check"
klass.send(:define_method, hidden_method_name, &block) klass.public_send(:define_method, hidden_method_name, &block)
klass.send(:define_method, attr) do |*args| klass.public_send(:define_method, attr) do |*args|
send(hidden_method_name, *args) if plugin.enabled? public_send(hidden_method_name, *args) if plugin.enabled?
end end
end end
end end
@ -184,10 +184,10 @@ class Plugin::Instance
klass = klass_name.to_s.classify.constantize rescue klass_name.to_s.constantize klass = klass_name.to_s.classify.constantize rescue klass_name.to_s.constantize
hidden_method_name = :"#{attr}_without_enable_check" hidden_method_name = :"#{attr}_without_enable_check"
klass.send(:define_singleton_method, hidden_method_name, &block) klass.public_send(:define_singleton_method, hidden_method_name, &block)
klass.send(:define_singleton_method, attr) do |*args| klass.public_send(:define_singleton_method, attr) do |*args|
send(hidden_method_name, *args) if plugin.enabled? public_send(hidden_method_name, *args) if plugin.enabled?
end end
end end
end end
@ -200,10 +200,10 @@ class Plugin::Instance
method_name = "#{plugin.name}_#{klass.name}_#{callback}#{@idx}".underscore method_name = "#{plugin.name}_#{klass.name}_#{callback}#{@idx}".underscore
@idx += 1 @idx += 1
hidden_method_name = :"#{method_name}_without_enable_check" hidden_method_name = :"#{method_name}_without_enable_check"
klass.send(:define_method, hidden_method_name, &block) klass.public_send(:define_method, hidden_method_name, &block)
klass.send(callback, options) do |*args| klass.public_send(callback, options) do |*args|
send(hidden_method_name, *args) if plugin.enabled? public_send(hidden_method_name, *args) if plugin.enabled?
end end
hidden_method_name hidden_method_name
@ -243,7 +243,7 @@ class Plugin::Instance
# Add validation method but check that the plugin is enabled # Add validation method but check that the plugin is enabled
def validate(klass, name, &block) def validate(klass, name, &block)
klass = klass.to_s.classify.constantize klass = klass.to_s.classify.constantize
klass.send(:define_method, name, &block) klass.public_send(:define_method, name, &block)
plugin = self plugin = self
klass.validate(name, if: -> { plugin.enabled? }) klass.validate(name, if: -> { plugin.enabled? })
@ -609,11 +609,11 @@ class Plugin::Instance
end end
def extend_list_method(klass, method, new_attributes) def extend_list_method(klass, method, new_attributes)
current_list = klass.send(method) current_list = klass.public_send(method)
current_list.concat(new_attributes) current_list.concat(new_attributes)
reloadable_patch do reloadable_patch do
klass.send(:define_singleton_method, method) { current_list } klass.public_send(:define_singleton_method, method) { current_list }
end end
end end

View File

@ -95,7 +95,7 @@ class Plugin::Metadata
attribute = attribute.strip.gsub(/ /, '_').to_sym attribute = attribute.strip.gsub(/ /, '_').to_sym
if FIELDS.include?(attribute) if FIELDS.include?(attribute)
self.send("#{attribute}=", description.strip) self.public_send("#{attribute}=", description.strip)
end end
end end

View File

@ -201,7 +201,7 @@ private
if post_action if post_action
post_action.recover! post_action.recover!
action_attrs.each { |attr, val| post_action.send("#{attr}=", val) } action_attrs.each { |attr, val| post_action.public_send("#{attr}=", val) }
post_action.save post_action.save
PostActionNotifier.post_action_created(post_action) PostActionNotifier.post_action_created(post_action)
else else

View File

@ -465,7 +465,7 @@ class PostCreator
# Attributes we pass through to the post instance if present # Attributes we pass through to the post instance if present
[:post_type, :no_bump, :cooking_options, :image_sizes, :acting_user, :invalidate_oneboxes, :cook_method, :via_email, :raw_email, :action_code].each do |a| [:post_type, :no_bump, :cooking_options, :image_sizes, :acting_user, :invalidate_oneboxes, :cook_method, :via_email, :raw_email, :action_code].each do |a|
post.send("#{a}=", @opts[a]) if @opts[a].present? post.public_send("#{a}=", @opts[a]) if @opts[a].present?
end end
post.extract_quoted_post_numbers post.extract_quoted_post_numbers

View File

@ -226,7 +226,9 @@ class PostRevisor
def post_changed? def post_changed?
POST_TRACKED_FIELDS.each do |field| POST_TRACKED_FIELDS.each do |field|
return true if @fields.has_key?(field) && @fields[field] != @post.send(field) if @fields.has_key?(field) && @fields[field] != @post.public_send(field)
return true
end
end end
advance_draft_sequence advance_draft_sequence
false false
@ -362,7 +364,7 @@ class PostRevisor
end end
POST_TRACKED_FIELDS.each do |field| POST_TRACKED_FIELDS.each do |field|
@post.send("#{field}=", @fields[field]) if @fields.has_key?(field) @post.public_send("#{field}=", @fields[field]) if @fields.has_key?(field)
end end
@post.last_editor_id = @editor.id @post.last_editor_id = @editor.id

View File

@ -47,7 +47,7 @@ class Promotion
if new_level < old_level && @user.manual_locked_trust_level.nil? if new_level < old_level && @user.manual_locked_trust_level.nil?
next_up = new_level + 1 next_up = new_level + 1
key = "tl#{next_up}_met?" key = "tl#{next_up}_met?"
if self.class.respond_to?(key) && self.class.send(key, @user) if self.class.respond_to?(key) && self.class.public_send(key, @user)
raise Discourse::InvalidAccess.new, I18n.t('trust_levels.change_failed_explanation', raise Discourse::InvalidAccess.new, I18n.t('trust_levels.change_failed_explanation',
user_name: @user.name, user_name: @user.name,
new_trust_level: new_level, new_trust_level: new_level,

View File

@ -159,7 +159,11 @@ module SeedData
end end
def find_category(site_setting_name) def find_category(site_setting_name)
<<<<<<< HEAD
category_id = SiteSetting.get(site_setting_name) category_id = SiteSetting.get(site_setting_name)
=======
category_id = SiteSetting.public_send(site_setting_name)
>>>>>>> DEV: Prefer `public_send` over `send`.
Category.find_by(id: category_id) if category_id > 0 Category.find_by(id: category_id) if category_id > 0
end end

View File

@ -81,7 +81,7 @@ class SingleSignOn
if BOOLS.include? k if BOOLS.include? k
val = ["true", "false"].include?(val) ? val == "true" : nil val = ["true", "false"].include?(val) ? val == "true" : nil
end end
sso.send("#{k}=", val) sso.public_send("#{k}=", val)
end end
decoded_hash.each do |k, v| decoded_hash.each do |k, v|

View File

@ -62,7 +62,7 @@ class SqlBuilder
sql = to_sql sql = to_sql
if @klass if @klass
@klass.find_by_sql(ActiveRecord::Base.send(:sanitize_sql_array, [sql, @args])) @klass.find_by_sql(ActiveRecord::Base.public_send(:sanitize_sql_array, [sql, @args]))
else else
if @args == {} if @args == {}
ActiveRecord::Base.exec_sql(sql) ActiveRecord::Base.exec_sql(sql)

View File

@ -92,7 +92,7 @@ class TopicCreator
else "track!" else "track!"
end end
topic.notifier.send(action, gu.user_id) topic.notifier.public_send(action, gu.user_id)
end end
end end
end end

View File

@ -1033,6 +1033,6 @@ class TopicQuery
private private
def sanitize_sql_array(input) def sanitize_sql_array(input)
ActiveRecord::Base.send(:sanitize_sql_array, input.join(',')) ActiveRecord::Base.public_send(:sanitize_sql_array, input.join(','))
end end
end end

View File

@ -125,6 +125,7 @@ class Validators::UploadValidator < ActiveModel::Validator
else else
SiteSetting.get("max_#{type}_size_kb") SiteSetting.get("max_#{type}_size_kb")
end end
max_size_bytes = max_size_kb.kilobytes max_size_bytes = max_size_kb.kilobytes
if upload.filesize > max_size_bytes if upload.filesize > max_size_bytes

View File

@ -48,7 +48,13 @@ module DiscourseNarrativeBot
begin begin
old_data = @data.dup old_data = @data.dup
new_post = (@skip && @state != :end) ? skip_tutorial(next_state) : self.send(action)
new_post =
if (@skip && @state != :end)
skip_tutorial(next_state)
else
self.public_send(action)
end
if new_post if new_post
old_state = old_data[:state] old_state = old_data[:state]

View File

@ -532,7 +532,10 @@ module DiscourseNarrativeBot
end end
def url_helpers(url, opts = {}) def url_helpers(url, opts = {})
Rails.application.routes.url_helpers.send(url, opts.merge(host: Discourse.base_url)) Rails.application.routes.url_helpers.public_send(
url,
opts.merge(host: Discourse.base_url)
)
end end
end end
end end

View File

@ -77,7 +77,7 @@ def top(cols, aggregator, count, aggregator_formatter = nil)
rows.each do |row| rows.each do |row|
cols.length.times do |i| cols.length.times do |i|
print row[i].to_s.send(col_just[i], col_widths[i]) print row[i].to_s.public_send(col_just[i], col_widths[i])
print " " print " "
end end
puts puts

View File

@ -57,8 +57,9 @@ module DiscoursePoll
# update poll # update poll
POLL_ATTRIBUTES.each do |attr| POLL_ATTRIBUTES.each do |attr|
old_poll.send("#{attr}=", poll.send(attr)) old_poll.public_send("#{attr}=", poll.public_send(attr))
end end
old_poll.save! old_poll.save!
# keep track of anonymous votes # keep track of anonymous votes
@ -102,7 +103,7 @@ module DiscoursePoll
def self.is_different?(old_poll, new_poll, new_options) def self.is_different?(old_poll, new_poll, new_options)
# an attribute was changed? # an attribute was changed?
POLL_ATTRIBUTES.each do |attr| POLL_ATTRIBUTES.each do |attr|
return true if old_poll.send(attr) != new_poll.send(attr) return true if old_poll.public_send(attr) != new_poll.public_send(attr)
end end
# an option was changed? # an option was changed?

View File

@ -11,7 +11,7 @@ module ImportScripts
def initialize(cols) def initialize(cols)
cols.each_with_index do |col, idx| cols.each_with_index do |col, idx|
self.class.send(:define_method, col.downcase.gsub(/[\W]/, '_').squeeze('_')) do self.class.public_send(:define_method, col.downcase.gsub(/[\W]/, '_').squeeze('_')) do
@row[idx] @row[idx]
end end
end end

View File

@ -44,7 +44,7 @@ class ImportScripts::Bespoke < ImportScripts::Base
def initialize(cols) def initialize(cols)
cols.each_with_index do |col, idx| cols.each_with_index do |col, idx|
self.class.send(:define_method, col) do self.class.public_send(:define_method, col) do
@row[idx] @row[idx]
end end
end end

View File

@ -46,7 +46,7 @@ class ImportScripts::Jive < ImportScripts::Base
def initialize(cols) def initialize(cols)
cols.each_with_index do |col, idx| cols.each_with_index do |col, idx|
self.class.send(:define_method, col) do self.class.public_send(:define_method, col) do
@row[idx] @row[idx]
end end
end end

View File

@ -48,7 +48,7 @@ class Mapping
def initialize(lines) def initialize(lines)
FIELDS.each do |field| FIELDS.each do |field|
self.send("#{field}=", 0) self.public_send("#{field}=", 0)
end end
parse_first_line(lines.shift) parse_first_line(lines.shift)
@ -72,7 +72,7 @@ class Mapping
field = parts[0].downcase.sub(':', '') field = parts[0].downcase.sub(':', '')
if respond_to? "#{field}=" if respond_to? "#{field}="
value = Float(parts[1]).to_i value = Float(parts[1]).to_i
self.send("#{field}=", value) self.public_send("#{field}=", value)
end end
end end
end end
@ -81,7 +81,7 @@ def consume_mapping(map_lines, totals)
m = Mapping.new(map_lines) m = Mapping.new(map_lines)
Mapping::FIELDS.each do |field| Mapping::FIELDS.each do |field|
totals[field] += m.send(field) totals[field] += m.public_send(field)
end end
return m return m
end end

View File

@ -16,18 +16,19 @@ describe Jobs::ReindexSearch do
model = Fabricate(m.to_sym) model = Fabricate(m.to_sym)
SiteSetting.default_locale = locale SiteSetting.default_locale = locale
subject.execute({}) subject.execute({})
expect(model.send("#{m}_search_data").locale).to eq locale expect(model.public_send("#{m}_search_data").locale).to eq locale
end end
it "should rebuild `#{m}` when INDEX_VERSION changed" do it "should rebuild `#{m}` when INDEX_VERSION changed" do
model = Fabricate(m.to_sym) model = Fabricate(m.to_sym)
# so that search data can be reindexed # so that search data can be reindexed
search_data = model.send("#{m}_search_data") search_data = model.public_send("#{m}_search_data")
search_data.update!(version: 0) search_data.update!(version: 0)
model.reload model.reload
subject.execute({}) subject.execute({})
expect(model.send("#{m}_search_data").version).to eq SearchIndexer::INDEX_VERSION expect(model.public_send("#{m}_search_data").version)
.to eq(SearchIndexer::INDEX_VERSION)
end end
end end

View File

@ -641,10 +641,13 @@ describe UserNotifications do
def expects_build_with(condition) def expects_build_with(condition)
UserNotifications.any_instance.expects(:build_email).with(user.email, condition) UserNotifications.any_instance.expects(:build_email).with(user.email, condition)
mailer = UserNotifications.send(mail_type, user, mailer = UserNotifications.public_send(
notification_type: Notification.types[notification.notification_type], mail_type, user,
notification_data_hash: notification.data_hash, notification_type: Notification.types[notification.notification_type],
post: notification.post) notification_data_hash: notification.data_hash,
post: notification.post
)
mailer.message mailer.message
end end
@ -668,7 +671,8 @@ describe UserNotifications do
context "private_email" do context "private_email" do
it "doesn't support reply by email" do it "doesn't support reply by email" do
SiteSetting.private_email = true SiteSetting.private_email = true
mailer = UserNotifications.send(
mailer = UserNotifications.public_send(
mail_type, mail_type,
user, user,
notification_type: Notification.types[notification.notification_type], notification_type: Notification.types[notification.notification_type],

View File

@ -11,7 +11,7 @@ def create_notification(user_id, resp_code, matcher)
data: { message: 'tada' }.to_json data: { message: 'tada' }.to_json
} }
expect(response.status).to eq(resp_code) expect(response.status).to eq(resp_code)
expect(Notification.count).send(matcher, eq(notification_count)) expect(Notification.count).public_send(matcher, eq(notification_count))
end end
def update_notification(topic_id, resp_code, matcher) def update_notification(topic_id, resp_code, matcher)
@ -19,7 +19,7 @@ def update_notification(topic_id, resp_code, matcher)
put "/notifications/#{notification.id}.json", params: { topic_id: topic_id } put "/notifications/#{notification.id}.json", params: { topic_id: topic_id }
expect(response.status).to eq(resp_code) expect(response.status).to eq(resp_code)
notification.reload notification.reload
expect(notification.topic_id).send(matcher, eq(topic_id)) expect(notification.topic_id).public_send(matcher, eq(topic_id))
end end
def delete_notification(resp_code, matcher) def delete_notification(resp_code, matcher)
@ -27,7 +27,7 @@ def delete_notification(resp_code, matcher)
notification_count = Notification.count notification_count = Notification.count
delete "/notifications/#{notification.id}.json" delete "/notifications/#{notification.id}.json"
expect(response.status).to eq(resp_code) expect(response.status).to eq(resp_code)
expect(Notification.count).send(matcher, eq(notification_count)) expect(Notification.count).public_send(matcher, eq(notification_count))
end end
describe NotificationsController do describe NotificationsController do

View File

@ -78,7 +78,7 @@ describe TopicStatusUpdater do
topic = Fabricate(:topic, status_name => false) topic = Fabricate(:topic, status_name => false)
updated = TopicStatusUpdater.new(topic, admin).update!(status_name, true) updated = TopicStatusUpdater.new(topic, admin).update!(status_name, true)
expect(updated).to eq(true) expect(updated).to eq(true)
expect(topic.send("#{status_name}?")).to eq(true) expect(topic.public_send("#{status_name}?")).to eq(true)
updated = TopicStatusUpdater.new(topic, admin).update!(status_name, true) updated = TopicStatusUpdater.new(topic, admin).update!(status_name, true)
expect(updated).to eq(false) expect(updated).to eq(false)
@ -86,7 +86,7 @@ describe TopicStatusUpdater do
updated = TopicStatusUpdater.new(topic, admin).update!(status_name, false) updated = TopicStatusUpdater.new(topic, admin).update!(status_name, false)
expect(updated).to eq(true) expect(updated).to eq(true)
expect(topic.send("#{status_name}?")).to eq(false) expect(topic.public_send("#{status_name}?")).to eq(false)
updated = TopicStatusUpdater.new(topic, admin).update!(status_name, false) updated = TopicStatusUpdater.new(topic, admin).update!(status_name, false)
expect(updated).to eq(false) expect(updated).to eq(false)

View File

@ -462,7 +462,7 @@ describe UserMerger do
posts.each do |type, post| posts.each do |type, post|
post.reload post.reload
expect(post.send("#{type}_count")).to eq(1) expect(post.public_send("#{type}_count")).to eq(1)
end end
end end
end end