Skip to content

Commit

Permalink
Merge pull request #32002 from y-yagi/fix_set_serializer
Browse files Browse the repository at this point in the history
Fix custome serializer setting
  • Loading branch information
rafaelfranca committed Feb 17, 2018
2 parents 1f95e5b + 3cc93de commit 21cc043
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
11 changes: 8 additions & 3 deletions activejob/lib/active_job/railtie.rb
Expand Up @@ -14,16 +14,21 @@ class Railtie < Rails::Railtie # :nodoc:
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|
options = app.config.active_job
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

Expand Down
2 changes: 1 addition & 1 deletion activejob/lib/active_job/serializers.rb
Expand Up @@ -49,7 +49,7 @@ def serializers

# 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

Expand Down
12 changes: 12 additions & 0 deletions railties/test/application/configuration_test.rb
Expand Up @@ -1940,6 +1940,18 @@ def index
assert_equal Digest::SHA1, ActiveSupport::Digest.hash_digest_class
end

test "custom serializers should be able to set via config.active_job.custom_serializers in an initializer" do
class ::DummySerializer < ActiveJob::Serializers::ObjectSerializer; end

app_file "config/initializers/custom_serializers.rb", <<-RUBY
Rails.application.config.active_job.custom_serializers << DummySerializer
RUBY

app "development"

assert_includes ActiveJob::Serializers.serializers, DummySerializer
end

private
def force_lazy_load_hooks
yield # Tasty clarifying sugar, homie! We only need to reference a constant to load it.
Expand Down

0 comments on commit 21cc043

Please sign in to comment.