mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Merge pull request #38038 from Shopify/activerecord-ruby-2.7-warnings-6-0-stable-batch-2
Activerecord ruby 2.7 warnings 6 0 stable batch 2
This commit is contained in:
parent
3a6770fb51
commit
57ace94c42
4 changed files with 12 additions and 15 deletions
|
@ -10,6 +10,7 @@ module ActiveModel
|
||||||
|
|
||||||
def register(type_name, klass = nil, **options, &block)
|
def register(type_name, klass = nil, **options, &block)
|
||||||
block ||= proc { |_, *args| klass.new(*args) }
|
block ||= proc { |_, *args| klass.new(*args) }
|
||||||
|
block.ruby2_keywords if block.respond_to?(:ruby2_keywords)
|
||||||
registrations << registration_klass.new(type_name, block, **options)
|
registrations << registration_klass.new(type_name, block, **options)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -903,7 +903,12 @@ module ActiveRecord
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return super unless connection.respond_to?(method)
|
return super unless connection.respond_to?(method)
|
||||||
connection.send(method, *arguments, &block)
|
options = arguments.extract_options!
|
||||||
|
if options.empty?
|
||||||
|
connection.send(method, *arguments, &block)
|
||||||
|
else
|
||||||
|
connection.send(method, *arguments, **options, &block)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -60,15 +60,17 @@ module ActiveRecord
|
||||||
return if method_defined?(method)
|
return if method_defined?(method)
|
||||||
|
|
||||||
if /\A[a-zA-Z_]\w*[!?]?\z/.match?(method)
|
if /\A[a-zA-Z_]\w*[!?]?\z/.match?(method)
|
||||||
|
definition = RUBY_VERSION >= "2.7" ? "..." : "*args, &block"
|
||||||
module_eval <<-RUBY, __FILE__, __LINE__ + 1
|
module_eval <<-RUBY, __FILE__, __LINE__ + 1
|
||||||
def #{method}(*args, &block)
|
def #{method}(#{definition})
|
||||||
scoping { klass.#{method}(*args, &block) }
|
scoping { klass.#{method}(#{definition}) }
|
||||||
end
|
end
|
||||||
RUBY
|
RUBY
|
||||||
else
|
else
|
||||||
define_method(method) do |*args, &block|
|
define_method(method) do |*args, &block|
|
||||||
scoping { klass.public_send(method, *args, &block) }
|
scoping { klass.public_send(method, *args, &block) }
|
||||||
end
|
end
|
||||||
|
ruby2_keywords(method) if respond_to?(:ruby2_keywords, true)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -107,6 +109,7 @@ module ActiveRecord
|
||||||
super
|
super
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
ruby2_keywords :method_missing if respond_to?(:ruby2_keywords, true)
|
||||||
end
|
end
|
||||||
|
|
||||||
module ClassMethods # :nodoc:
|
module ClassMethods # :nodoc:
|
||||||
|
|
|
@ -226,12 +226,6 @@ class EachTest < ActiveRecord::TestCase
|
||||||
assert_equal default_scope.pluck(:id).sort, posts.map(&:id).sort
|
assert_equal default_scope.pluck(:id).sort, posts.map(&:id).sort
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_find_in_batches_should_not_modify_passed_options
|
|
||||||
assert_nothing_raised do
|
|
||||||
Post.find_in_batches({ batch_size: 42, start: 1 }.freeze) { }
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_find_in_batches_should_use_any_column_as_primary_key
|
def test_find_in_batches_should_use_any_column_as_primary_key
|
||||||
nick_order_subscribers = Subscriber.order("nick asc")
|
nick_order_subscribers = Subscriber.order("nick asc")
|
||||||
start_nick = nick_order_subscribers.second.nick
|
start_nick = nick_order_subscribers.second.nick
|
||||||
|
@ -444,12 +438,6 @@ class EachTest < ActiveRecord::TestCase
|
||||||
assert_equal default_scope.pluck(:id).sort, posts.map(&:id).sort
|
assert_equal default_scope.pluck(:id).sort, posts.map(&:id).sort
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_in_batches_should_not_modify_passed_options
|
|
||||||
assert_nothing_raised do
|
|
||||||
Post.in_batches({ of: 42, start: 1 }.freeze) { }
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_in_batches_should_use_any_column_as_primary_key
|
def test_in_batches_should_use_any_column_as_primary_key
|
||||||
nick_order_subscribers = Subscriber.order("nick asc")
|
nick_order_subscribers = Subscriber.order("nick asc")
|
||||||
start_nick = nick_order_subscribers.second.nick
|
start_nick = nick_order_subscribers.second.nick
|
||||||
|
|
Loading…
Reference in a new issue