1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Module#{define_method,alias_method,undef_method,remove_method} become public since Ruby 2.5

https://bugs.ruby-lang.org/issues/14133
This commit is contained in:
Ryuta Kamizono 2018-12-21 01:39:18 +09:00
parent 3da358ea83
commit 8034dde023
22 changed files with 43 additions and 43 deletions

View file

@ -90,11 +90,11 @@ module ActionDispatch
def clear!
@path_helpers.each do |helper|
@path_helpers_module.send :remove_method, helper
@path_helpers_module.remove_method helper
end
@url_helpers.each do |helper|
@url_helpers_module.send :remove_method, helper
@url_helpers_module.remove_method helper
end
@routes.clear
@ -108,8 +108,8 @@ module ActionDispatch
url_name = :"#{name}_url"
if routes.key? key
@path_helpers_module.send :undef_method, path_name
@url_helpers_module.send :undef_method, url_name
@path_helpers_module.undef_method path_name
@url_helpers_module.undef_method url_name
end
routes[key] = route
define_url_helper @path_helpers_module, route, path_name, route.defaults, name, PATH

View file

@ -30,7 +30,7 @@ module AbstractController
end
test "register mime types on method missing" do
AbstractController::Collector.send(:remove_method, :js)
AbstractController::Collector.remove_method :js
begin
collector = MyCollector.new
assert_not_respond_to collector, :js

View file

@ -152,7 +152,7 @@ class IntegrationTestTest < ActiveSupport::TestCase
assert_equal "pass", @test.foo
ensure
# leave other tests as unaffected as possible
mixin.__send__(:remove_method, :method_missing)
mixin.remove_method :method_missing
end
end
end

View file

@ -42,7 +42,7 @@ class ResponseTest < ActiveSupport::TestCase
def test_each_isnt_called_if_str_body_is_written
# Controller writes and reads response body
each_counter = 0
@response.body = Object.new.tap { |o| o.singleton_class.send(:define_method, :each) { |&block| each_counter += 1; block.call "foo" } }
@response.body = Object.new.tap { |o| o.singleton_class.define_method(:each) { |&block| each_counter += 1; block.call "foo" } }
@response["X-Foo"] = @response.body
assert_equal 1, each_counter, "#each was not called once"

View file

@ -24,7 +24,7 @@ module ActionView
registered_details << name
Accessors::DEFAULT_PROCS[name] = block
Accessors.send :define_method, :"default_#{name}", &block
Accessors.define_method(:"default_#{name}", &block)
Accessors.module_eval <<-METHOD, __FILE__, __LINE__ + 1
def #{name}
@details.fetch(:#{name}, [])

View file

@ -17,8 +17,8 @@ module ActionView
class_attribute :escape_ignore_list, default: ["text/plain"]
[self, singleton_class].each do |base|
base.send(:alias_method, :escape_whitelist, :escape_ignore_list)
base.send(:alias_method, :escape_whitelist=, :escape_ignore_list=)
base.alias_method :escape_whitelist, :escape_ignore_list
base.alias_method :escape_whitelist=, :escape_ignore_list=
base.deprecate(
escape_whitelist: "use #escape_ignore_list instead",

View file

@ -507,8 +507,8 @@ module ActiveModel
temp_method_name = "__temp__#{safe_name}#{'=' if writer}"
attr_name_expr = "::ActiveModel::AttributeMethods::AttrNames::#{const_name}"
yield temp_method_name, attr_name_expr
mod.send(:alias_method, method_name, temp_method_name)
mod.send(:undef_method, temp_method_name)
mod.alias_method method_name, temp_method_name
mod.undef_method temp_method_name
end
end
end

View file

@ -427,7 +427,7 @@ class LengthValidationTest < ActiveModel::TestCase
end
def test_validates_length_of_using_proc_as_maximum_with_model_method
Topic.send(:define_method, :max_title_length, lambda { 5 })
Topic.define_method(:max_title_length) { 5 }
Topic.validates_length_of :title, maximum: Proc.new(&:max_title_length)
t = Topic.new("title" => "valid", "content" => "whatever")

View file

@ -66,7 +66,7 @@ class NumericalityValidationTest < ActiveModel::TestCase
end
def test_validates_numericality_of_with_integer_only_and_proc_as_value
Topic.send(:define_method, :allow_only_integers?, lambda { false })
Topic.define_method(:allow_only_integers?) { false }
Topic.validates_numericality_of :approved, only_integer: Proc.new(&:allow_only_integers?)
invalid!(NIL + BLANK + JUNK)
@ -214,23 +214,23 @@ class NumericalityValidationTest < ActiveModel::TestCase
end
def test_validates_numericality_with_proc
Topic.send(:define_method, :min_approved, lambda { 5 })
Topic.define_method(:min_approved) { 5 }
Topic.validates_numericality_of :approved, greater_than_or_equal_to: Proc.new(&:min_approved)
invalid!([3, 4])
valid!([5, 6])
ensure
Topic.send(:remove_method, :min_approved)
Topic.remove_method :min_approved
end
def test_validates_numericality_with_symbol
Topic.send(:define_method, :max_approved, lambda { 5 })
Topic.define_method(:max_approved) { 5 }
Topic.validates_numericality_of :approved, less_than_or_equal_to: :max_approved
invalid!([6])
valid!([4, 5])
ensure
Topic.send(:remove_method, :max_approved)
Topic.remove_method :max_approved
end
def test_validates_numericality_with_numeric_message

View file

@ -158,7 +158,7 @@ module ActiveRecord
# def self.statuses() statuses end
detect_enum_conflict!(name, name.pluralize, true)
singleton_class.send(:define_method, name.pluralize) { enum_values }
singleton_class.define_method(name.pluralize) { enum_values }
defined_enums[name] = enum_values
detect_enum_conflict!(name, name)

View file

@ -54,7 +54,7 @@ module ActiveRecord
end
RUBY
else
generated_relation_methods.send(:define_method, method) do |*args, &block|
generated_relation_methods.define_method(method) do |*args, &block|
scoping { klass.public_send(method, *args, &block) }
end
end

View file

@ -179,13 +179,13 @@ module ActiveRecord
extension = Module.new(&block) if block
if body.respond_to?(:to_proc)
singleton_class.send(:define_method, name) do |*args|
singleton_class.define_method(name) do |*args|
scope = all._exec_scope(*args, &body)
scope = scope.extending(extension) if extension
scope
end
else
singleton_class.send(:define_method, name) do |*args|
singleton_class.define_method(name) do |*args|
scope = body.call(*args) || all
scope = scope.extending(extension) if extension
scope

View file

@ -29,7 +29,7 @@ class PostgresqlActiveSchemaTest < ActiveRecord::PostgreSQLTestCase
def test_add_index
# add_index calls index_name_exists? which can't work since execute is stubbed
ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.send(:define_method, :index_name_exists?) { |*| false }
ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.define_method(:index_name_exists?) { |*| false }
expected = %(CREATE UNIQUE INDEX "index_people_on_last_name" ON "people" ("last_name") WHERE state = 'active')
assert_equal expected, add_index(:people, :last_name, unique: true, where: "state = 'active'")
@ -74,12 +74,12 @@ class PostgresqlActiveSchemaTest < ActiveRecord::PostgreSQLTestCase
add_index(:people, :last_name, algorithm: :copy)
end
ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.send :remove_method, :index_name_exists?
ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.remove_method :index_name_exists?
end
def test_remove_index
# remove_index calls index_name_for_remove which can't work since execute is stubbed
ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.send(:define_method, :index_name_for_remove) do |*|
ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.define_method(:index_name_for_remove) do |*|
"index_people_on_last_name"
end
@ -90,7 +90,7 @@ class PostgresqlActiveSchemaTest < ActiveRecord::PostgreSQLTestCase
add_index(:people, :last_name, algorithm: :copy)
end
ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.send :remove_method, :index_name_for_remove
ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.remove_method :index_name_for_remove
end
def test_remove_index_when_name_is_specified

View file

@ -21,7 +21,7 @@ class CallbackDeveloper < ActiveRecord::Base
def callback_object(callback_method)
klass = Class.new
klass.send(:define_method, callback_method) do |model|
klass.define_method(callback_method) do |model|
model.history << [callback_method, :object]
end
klass.new

View file

@ -12,10 +12,10 @@ class FinderRespondToTest < ActiveRecord::TestCase
end
def test_should_preserve_normal_respond_to_behaviour_and_respond_to_newly_added_method
class << Topic; self; end.send(:define_method, :method_added_for_finder_respond_to_test) { }
Topic.singleton_class.define_method(:method_added_for_finder_respond_to_test) { }
assert_respond_to Topic, :method_added_for_finder_respond_to_test
ensure
class << Topic; self; end.send(:remove_method, :method_added_for_finder_respond_to_test)
Topic.singleton_class.remove_method :method_added_for_finder_respond_to_test
end
def test_should_preserve_normal_respond_to_behaviour_and_respond_to_standard_object_method
@ -56,6 +56,6 @@ class FinderRespondToTest < ActiveRecord::TestCase
private
def ensure_topic_method_is_not_cached(method_id)
class << Topic; self; end.send(:remove_method, method_id) if Topic.public_methods.include? method_id
Topic.singleton_class.remove_method method_id if Topic.public_methods.include? method_id
end
end

View file

@ -1116,7 +1116,7 @@ class FinderTest < ActiveRecord::TestCase
def test_dynamic_finder_on_one_attribute_with_conditions_returns_same_results_after_caching
# ensure this test can run independently of order
class << Account; self; end.send(:remove_method, :find_by_credit_limit) if Account.public_methods.include?(:find_by_credit_limit)
Account.singleton_class.remove_method :find_by_credit_limit if Account.public_methods.include?(:find_by_credit_limit)
a = Account.where("firm_id = ?", 6).find_by_credit_limit(50)
assert_equal a, Account.where("firm_id = ?", 6).find_by_credit_limit(50) # find_by_credit_limit has been cached
end

View file

@ -590,7 +590,7 @@ class ActiveStorage::ManyAttachedTest < ActiveSupport::TestCase
assert_equal "town.jpg", @user.highlights.first.filename.to_s
assert_equal "funky.jpg", @user.highlights.second.filename.to_s
ensure
User.send(:remove_method, :highlights)
User.remove_method :highlights
end
end
end

View file

@ -507,7 +507,7 @@ class ActiveStorage::OneAttachedTest < ActiveSupport::TestCase
assert_equal "gpj.yknuf", @user.avatar
ensure
User.send(:remove_method, :avatar)
User.remove_method :avatar
end
end
end

View file

@ -60,13 +60,13 @@ module ActiveSupport
with_method = "#{aliased_method}_with_deprecation#{punctuation}"
without_method = "#{aliased_method}_without_deprecation#{punctuation}"
target_module.send(:define_method, with_method) do |*args, &block|
target_module.define_method(with_method) do |*args, &block|
deprecator.deprecation_warning(method_name, options[method_name])
send(without_method, *args, &block)
end
target_module.send(:alias_method, without_method, method_name)
target_module.send(:alias_method, method_name, with_method)
target_module.alias_method(without_method, method_name)
target_module.alias_method(method_name, with_method)
case
when target_module.protected_method_defined?(without_method)
@ -75,7 +75,7 @@ module ActiveSupport
target_module.send(:private, method_name)
end
else
mod.send(:define_method, method_name) do |*args, &block|
mod.define_method(method_name) do |*args, &block|
deprecator.deprecation_warning(method_name, options[method_name])
super(*args, &block)
end

View file

@ -22,7 +22,7 @@ module ActiveSupport
@stubs[object.object_id][method_name] = Stub.new(object, method_name, new_name)
object.singleton_class.send :alias_method, new_name, method_name
object.singleton_class.alias_method new_name, method_name
object.define_singleton_method(method_name, &block)
end
@ -43,9 +43,9 @@ module ActiveSupport
def unstub_object(stub)
singleton_class = stub.object.singleton_class
singleton_class.send :silence_redefinition_of_method, stub.method_name
singleton_class.send :alias_method, stub.method_name, stub.original_method
singleton_class.send :undef_method, stub.original_method
singleton_class.silence_redefinition_of_method stub.method_name
singleton_class.alias_method stub.method_name, stub.original_method
singleton_class.undef_method stub.original_method
end
end

View file

@ -31,7 +31,7 @@ module CallbacksTest
def callback_object(callback_method)
klass = Class.new
klass.send(:define_method, callback_method) do |model|
klass.define_method(callback_method) do |model|
model.history << [:"#{callback_method}_save", :object]
end
klass.new

View file

@ -25,7 +25,7 @@ class ConsoleTest < ActiveSupport::TestCase
end
def test_app_method_should_return_integration_session
TestHelpers::Rack.send :remove_method, :app
TestHelpers::Rack.remove_method :app
load_environment
console_session = irb_context.app
assert_instance_of ActionDispatch::Integration::Session, console_session