Skip to content

Commit

Permalink
Revert "Merge pull request #38260 from kamipo/fix_kwargs_warning_for_…
Browse files Browse the repository at this point in the history
…activejob"

This reverts commit 80e72c5, reversing
changes made to 0dad1e3.
  • Loading branch information
kamipo committed Jan 20, 2020
1 parent fc07294 commit 482f6d6
Show file tree
Hide file tree
Showing 10 changed files with 5 additions and 66 deletions.
1 change: 0 additions & 1 deletion actionmailer/lib/action_mailer/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -611,7 +611,6 @@ def method_missing(method_name, *args)
super
end
end
ruby2_keywords(:method_missing) if respond_to?(:ruby2_keywords, true)

def respond_to_missing?(method, include_all = false)
action_methods.include?(method.to_s) || super
Expand Down
9 changes: 1 addition & 8 deletions actionmailer/lib/action_mailer/message_delivery.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ def initialize(mailer_class, action, *args) #:nodoc:
@processed_mailer = nil
@mail_message = nil
end
ruby2_keywords(:initialize) if respond_to?(:ruby2_keywords, true)

# Method calls are delegated to the Mail::Message that's ready to deliver.
def __getobj__ #:nodoc:
Expand Down Expand Up @@ -144,16 +143,10 @@ def enqueue_delivery(delivery_method, options = {})

def arguments_for(delivery_job, delivery_method)
if delivery_job <= MailDeliveryJob
ruby2_keywords_arguments \
@mailer_class.name, @action.to_s, delivery_method.to_s, args: @args
[@mailer_class.name, @action.to_s, delivery_method.to_s, args: @args]
else
[@mailer_class.name, @action.to_s, delivery_method.to_s, *@args]
end
end

def ruby2_keywords_arguments(*args)
args
end
ruby2_keywords(:ruby2_keywords_arguments) if respond_to?(:ruby2_keywords, true)
end
end
4 changes: 1 addition & 3 deletions actionmailer/lib/action_mailer/parameterized.rb
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,6 @@ def initialize(mailer_class, action, params, *args)
super(mailer_class, action, *args)
@params = params
end
ruby2_keywords(:initialize) if respond_to?(:ruby2_keywords, true)

private
def processed_mailer
Expand Down Expand Up @@ -162,8 +161,7 @@ def delivery_job_class

def arguments_for(delivery_job, delivery_method)
if delivery_job <= MailDeliveryJob
ruby2_keywords_arguments \
@mailer_class.name, @action.to_s, delivery_method.to_s, params: @params, args: @args
[@mailer_class.name, @action.to_s, delivery_method.to_s, params: @params, args: @args]
else
[@mailer_class.name, @action.to_s, delivery_method.to_s, @params, *@args]
end
Expand Down
4 changes: 0 additions & 4 deletions actionmailer/test/mailers/delayed_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,6 @@ def test_message(*)
mail(from: "test-sender@test.com", to: "test-receiver@test.com", subject: "Test Subject", body: "Test Body")
end

def test_kwargs(argument:)
mail(from: "test-sender@test.com", to: "test-receiver@test.com", subject: "Test Subject", body: "Test Body")
end

def test_raise(klass_name)
raise klass_name.constantize, "boom"
end
Expand Down
7 changes: 0 additions & 7 deletions actionmailer/test/message_delivery_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -164,11 +164,4 @@ def to_global_id(options = {})
assert_equal DelayedMailer, DelayedMailer.last_rescue_from_instance
assert_equal "Error while trying to deserialize arguments: boom, missing find", DelayedMailer.last_error.message
end

test "allows for keyword arguments" do
assert_performed_with(job: ActionMailer::MailDeliveryJob, args: ["DelayedMailer", "test_kwargs", "deliver_now", args: [argument: 1]]) do
message = DelayedMailer.test_kwargs(argument: 1)
message.deliver_later
end
end
end
40 changes: 2 additions & 38 deletions activejob/lib/active_job/arguments.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,6 @@ def deserialize(arguments)
# :nodoc:
SYMBOL_KEYS_KEY = "_aj_symbol_keys"
# :nodoc:
RUBY2_KEYWORDS_KEY = "_aj_ruby2_keywords"
# :nodoc:
WITH_INDIFFERENT_ACCESS_KEY = "_aj_hash_with_indifferent_access"
# :nodoc:
OBJECT_SERIALIZER_KEY = "_aj_serialized"
Expand All @@ -62,39 +60,10 @@ def deserialize(arguments)
RESERVED_KEYS = [
GLOBALID_KEY, GLOBALID_KEY.to_sym,
SYMBOL_KEYS_KEY, SYMBOL_KEYS_KEY.to_sym,
RUBY2_KEYWORDS_KEY, RUBY2_KEYWORDS_KEY.to_sym,
OBJECT_SERIALIZER_KEY, OBJECT_SERIALIZER_KEY.to_sym,
WITH_INDIFFERENT_ACCESS_KEY, WITH_INDIFFERENT_ACCESS_KEY.to_sym,
]
private_constant :PERMITTED_TYPES, :RESERVED_KEYS, :GLOBALID_KEY,
:SYMBOL_KEYS_KEY, :RUBY2_KEYWORDS_KEY, :WITH_INDIFFERENT_ACCESS_KEY

unless Hash.respond_to?(:ruby2_keywords_hash?) && Hash.respond_to?(:ruby2_keywords_hash)
using Module.new {
refine Hash do
class << Hash
if RUBY_VERSION >= "2.7"
def ruby2_keywords_hash?(hash)
!new(*[hash]).default.equal?(hash)
end
else
def ruby2_keywords_hash?(hash)
false
end
end

def ruby2_keywords_hash(hash)
_ruby2_keywords_hash(**hash)
end

private def _ruby2_keywords_hash(*args)
args.last
end
ruby2_keywords(:_ruby2_keywords_hash) if respond_to?(:ruby2_keywords, true)
end
end
}
end
private_constant :PERMITTED_TYPES, :RESERVED_KEYS, :GLOBALID_KEY, :SYMBOL_KEYS_KEY, :WITH_INDIFFERENT_ACCESS_KEY

def serialize_argument(argument)
case argument
Expand All @@ -107,10 +76,9 @@ def serialize_argument(argument)
when ActiveSupport::HashWithIndifferentAccess
serialize_indifferent_hash(argument)
when Hash
symbol_keys = argument.each_key.grep(Symbol).map!(&:to_s)
symbol_keys = argument.each_key.grep(Symbol).map(&:to_s)
result = serialize_hash(argument)
result[SYMBOL_KEYS_KEY] = symbol_keys
result[RUBY2_KEYWORDS_KEY] = true if Hash.ruby2_keywords_hash?(argument)
result
when -> (arg) { arg.respond_to?(:permitted?) }
serialize_indifferent_hash(argument.to_h)
Expand Down Expand Up @@ -164,10 +132,6 @@ def deserialize_hash(serialized_hash)
result = result.with_indifferent_access
elsif symbol_keys = result.delete(SYMBOL_KEYS_KEY)
result = transform_symbol_keys(result, symbol_keys)

if result.delete(RUBY2_KEYWORDS_KEY)
result = Hash.ruby2_keywords_hash(result)
end
end
result
end
Expand Down
1 change: 0 additions & 1 deletion activejob/lib/active_job/core.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ def initialize(*arguments)
@executions = 0
@exception_executions = {}
end
ruby2_keywords(:initialize) if respond_to?(:ruby2_keywords, true)

# Returns a hash with the job data that can safely be passed to the
# queuing adapter.
Expand Down
2 changes: 0 additions & 2 deletions activejob/lib/active_job/enqueuing.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,11 @@ module ClassMethods
def perform_later(*args)
job_or_instantiate(*args).enqueue
end
ruby2_keywords(:perform_later) if respond_to?(:ruby2_keywords, true)

private
def job_or_instantiate(*args) # :doc:
args.first.is_a?(self) ? args.first : new(*args)
end
ruby2_keywords(:job_or_instantiate) if respond_to?(:ruby2_keywords, true)
end

# Enqueues the job to be performed by the queue adapter.
Expand Down
1 change: 0 additions & 1 deletion activejob/lib/active_job/execution.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ module ClassMethods
def perform_now(*args)
job_or_instantiate(*args).perform_now
end
ruby2_keywords(:perform_now) if respond_to?(:ruby2_keywords, true)

def execute(job_data) #:nodoc:
ActiveJob::Callbacks.run_callbacks(:execute) do
Expand Down
2 changes: 1 addition & 1 deletion activejob/test/cases/argument_serialization_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ class ArgumentSerializationTest < ActiveSupport::TestCase
end

test "allows for keyword arguments" do
KwargsJob.perform_now(argument: 2)
KwargsJob.perform_later(argument: 2)

assert_equal "Job with argument: 2", JobBuffer.last_value
end
Expand Down

0 comments on commit 482f6d6

Please sign in to comment.