From 3cc93de6ad58ee306b906a3d979b46276900711a Mon Sep 17 00:00:00 2001 From: Yuji Yaginuma Date: Thu, 15 Feb 2018 15:46:42 +0900 Subject: Fix custome serializer setting The serializer should be set up in `after_initialize` so that it work properly even if the user specifies serializer with initializers. Also, since `custom_serializers` is `Array`, it needs to be flattened before setting the value. --- activejob/lib/active_job/railtie.rb | 11 ++++++++--- activejob/lib/active_job/serializers.rb | 2 +- 2 files changed, 9 insertions(+), 4 deletions(-) (limited to 'activejob/lib/active_job') diff --git a/activejob/lib/active_job/railtie.rb b/activejob/lib/active_job/railtie.rb index 427ad1e3af..d0294854d3 100644 --- a/activejob/lib/active_job/railtie.rb +++ b/activejob/lib/active_job/railtie.rb @@ -14,8 +14,10 @@ module ActiveJob end initializer "active_job.custom_serializers" do |app| - custom_serializers = app.config.active_job.delete(:custom_serializers) - ActiveJob::Serializers.add_serializers custom_serializers + config.after_initialize do + custom_serializers = app.config.active_job.delete(:custom_serializers) + ActiveJob::Serializers.add_serializers custom_serializers + end end initializer "active_job.set_configs" do |app| @@ -23,7 +25,10 @@ module ActiveJob options.queue_adapter ||= :async ActiveSupport.on_load(:active_job) do - options.each { |k, v| send("#{k}=", v) } + options.each do |k, v| + k = "#{k}=" + send(k, v) if respond_to? k + end end end diff --git a/activejob/lib/active_job/serializers.rb b/activejob/lib/active_job/serializers.rb index d9a130fa73..9930ae0823 100644 --- a/activejob/lib/active_job/serializers.rb +++ b/activejob/lib/active_job/serializers.rb @@ -49,7 +49,7 @@ module ActiveJob # Adds a new serializer to a list of known serializers def add_serializers(*new_serializers) - self._additional_serializers += new_serializers + self._additional_serializers += new_serializers.flatten end end -- cgit v1.2.3