diff options
Diffstat (limited to 'activejob/test')
-rw-r--r-- | activejob/test/cases/argument_serialization_test.rb | 8 | ||||
-rw-r--r-- | activejob/test/cases/serializers_test.rb | 64 |
2 files changed, 65 insertions, 7 deletions
diff --git a/activejob/test/cases/argument_serialization_test.rb b/activejob/test/cases/argument_serialization_test.rb index 20296038a0..13e6fcb727 100644 --- a/activejob/test/cases/argument_serialization_test.rb +++ b/activejob/test/cases/argument_serialization_test.rb @@ -4,7 +4,6 @@ require "helper" require "active_job/arguments" require "models/person" require "active_support/core_ext/hash/indifferent_access" -require "active_support/duration" require "jobs/kwargs_job" class ArgumentSerializationTest < ActiveSupport::TestCase @@ -14,7 +13,6 @@ class ArgumentSerializationTest < ActiveSupport::TestCase [ nil, 1, 1.0, 1_000_000_000_000_000_000_000, "a", true, false, BigDecimal.new(5), - :a, self, 1.day, [ 1, "a" ], { "a" => 1 } ].each do |arg| @@ -23,7 +21,7 @@ class ArgumentSerializationTest < ActiveSupport::TestCase end end - [ Object.new, Person.find("5").to_gid ].each do |arg| + [ :a, Object.new, self, Person.find("5").to_gid ].each do |arg| test "does not serialize #{arg.class}" do assert_raises ActiveJob::SerializationError do ActiveJob::Arguments.serialize [ arg ] @@ -35,10 +33,6 @@ class ArgumentSerializationTest < ActiveSupport::TestCase end end - test "serializes Struct" do - assert_arguments_unchanged Struct.new("Rectangle", :width, :height).new(10, 15) - end - test "should convert records to Global IDs" do assert_arguments_roundtrip [@person] end diff --git a/activejob/test/cases/serializers_test.rb b/activejob/test/cases/serializers_test.rb new file mode 100644 index 0000000000..90d4155b3b --- /dev/null +++ b/activejob/test/cases/serializers_test.rb @@ -0,0 +1,64 @@ +# frozen_string_literal: true + +require "helper" +require "active_job/serializers" + +class SerializersTest < ActiveSupport::TestCase + class DummyValueObject + attr_accessor :value + + def initialize(value) + @value = value + end + end + + class DummySerializer < ActiveJob::Serializers::ObjectSerializer + class << self + def serialize(object) + { key => object.value } + end + + def deserialize(hash) + DummyValueObject.new(hash[key]) + end + + def key + "_dummy_serializer" + end + + private + + def klass + DummyValueObject + end + end + end + + setup do + @value_object = DummyValueObject.new 123 + ActiveJob::Base._additional_serializers = [] + end + + test "can't serialize unknown object" do + assert_raises ActiveJob::SerializationError do + ActiveJob::Serializers.serialize @value_object + end + end + + test "won't deserialize unknown hash" do + hash = { "_dummy_serializer" => 123, "_aj_symbol_keys" => [] } + assert ActiveJob::Serializers.deserialize(hash), hash.except("_aj_symbol_keys") + end + + test "adds new serializer" do + ActiveJob::Base.add_serializers DummySerializer + assert ActiveJob::Base.serializers.include?(DummySerializer) + end + + test "can't add serializer with the same key twice" do + ActiveJob::Base.add_serializers DummySerializer + assert_raises ArgumentError do + ActiveJob::Base.add_serializers DummySerializer + end + end +end |