From 57ace94c42a2006b5efc0fba0539a5cc72d9a5db Mon Sep 17 00:00:00 2001 From: Ryuta Kamizono Date: Fri, 20 Dec 2019 19:40:40 +0900 Subject: [PATCH] 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 --- activemodel/lib/active_model/type/registry.rb | 1 + activerecord/lib/active_record/migration.rb | 7 ++++++- .../lib/active_record/relation/delegation.rb | 7 +++++-- activerecord/test/cases/batches_test.rb | 12 ------------ 4 files changed, 12 insertions(+), 15 deletions(-) diff --git a/activemodel/lib/active_model/type/registry.rb b/activemodel/lib/active_model/type/registry.rb index 7d1ac79b42..179438a784 100644 --- a/activemodel/lib/active_model/type/registry.rb +++ b/activemodel/lib/active_model/type/registry.rb @@ -10,6 +10,7 @@ def initialize def register(type_name, klass = nil, **options, &block) block ||= proc { |_, *args| klass.new(*args) } + block.ruby2_keywords if block.respond_to?(:ruby2_keywords) registrations << registration_klass.new(type_name, block, **options) end diff --git a/activerecord/lib/active_record/migration.rb b/activerecord/lib/active_record/migration.rb index 5e429c14ff..54525b6a08 100644 --- a/activerecord/lib/active_record/migration.rb +++ b/activerecord/lib/active_record/migration.rb @@ -903,7 +903,12 @@ def method_missing(method, *arguments, &block) end end 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 diff --git a/activerecord/lib/active_record/relation/delegation.rb b/activerecord/lib/active_record/relation/delegation.rb index 8c6e3df7d6..5d5138ad26 100644 --- a/activerecord/lib/active_record/relation/delegation.rb +++ b/activerecord/lib/active_record/relation/delegation.rb @@ -60,15 +60,17 @@ def generate_method(method) return if method_defined?(method) if /\A[a-zA-Z_]\w*[!?]?\z/.match?(method) + definition = RUBY_VERSION >= "2.7" ? "..." : "*args, &block" module_eval <<-RUBY, __FILE__, __LINE__ + 1 - def #{method}(*args, &block) - scoping { klass.#{method}(*args, &block) } + def #{method}(#{definition}) + scoping { klass.#{method}(#{definition}) } end RUBY else define_method(method) do |*args, &block| scoping { klass.public_send(method, *args, &block) } end + ruby2_keywords(method) if respond_to?(:ruby2_keywords, true) end end end @@ -107,6 +109,7 @@ def method_missing(method, *args, &block) super end end + ruby2_keywords :method_missing if respond_to?(:ruby2_keywords, true) end module ClassMethods # :nodoc: diff --git a/activerecord/test/cases/batches_test.rb b/activerecord/test/cases/batches_test.rb index 2287745e41..f36730333b 100644 --- a/activerecord/test/cases/batches_test.rb +++ b/activerecord/test/cases/batches_test.rb @@ -226,12 +226,6 @@ def test_find_in_batches_should_not_ignore_the_default_scope_if_it_is_other_then assert_equal default_scope.pluck(:id).sort, posts.map(&:id).sort 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 nick_order_subscribers = Subscriber.order("nick asc") start_nick = nick_order_subscribers.second.nick @@ -444,12 +438,6 @@ def test_in_batches_should_not_ignore_default_scope_without_order_statements assert_equal default_scope.pluck(:id).sort, posts.map(&:id).sort 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 nick_order_subscribers = Subscriber.order("nick asc") start_nick = nick_order_subscribers.second.nick