diff options
author | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2018-02-12 14:16:41 -0500 |
---|---|---|
committer | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2018-02-14 13:10:08 -0500 |
commit | 69645cba727dfa1c18c666d2a2f1c0dedffde938 (patch) | |
tree | dc5fda6749d63a795d12459a8dc2d8994c5bfea6 /activejob/test | |
parent | 71721dc1c9b769d3c06317122dc88cad4a346580 (diff) | |
download | rails-69645cba727dfa1c18c666d2a2f1c0dedffde938.tar.gz rails-69645cba727dfa1c18c666d2a2f1c0dedffde938.tar.bz2 rails-69645cba727dfa1c18c666d2a2f1c0dedffde938.zip |
Simplify the implementation of custom argument serializers
We can speed up things for the supported types by keeping the code in the
way it was.
We can also avoid to loop trough all serializers in the deserialization by
trying to access the class already in the Hash.
We could also speed up the custom serialization if we define the class
that is going to be serialized when registering the serializers, but
that will remove the possibility of defining a serialzer for a
superclass and have the subclass serialized using it.
Diffstat (limited to 'activejob/test')
-rw-r--r-- | activejob/test/cases/argument_serialization_test.rb | 2 | ||||
-rw-r--r-- | activejob/test/cases/serializers_test.rb | 21 |
2 files changed, 20 insertions, 3 deletions
diff --git a/activejob/test/cases/argument_serialization_test.rb b/activejob/test/cases/argument_serialization_test.rb index 8f51a2d238..4e26b9a178 100644 --- a/activejob/test/cases/argument_serialization_test.rb +++ b/activejob/test/cases/argument_serialization_test.rb @@ -14,7 +14,7 @@ class ArgumentSerializationTest < ActiveSupport::TestCase [ nil, 1, 1.0, 1_000_000_000_000_000_000_000, "a", true, false, BigDecimal.new(5), :a, 1.day, Date.new(2001, 2, 3), Time.new(2002, 10, 31, 2, 2, 2, "+02:00"), - DateTime.new(2001, 2, 3, 4, 5, 6, '+03:00'), + DateTime.new(2001, 2, 3, 4, 5, 6, "+03:00"), ActiveSupport::TimeWithZone.new(Time.utc(1999, 12, 31, 23, 59, 59), ActiveSupport::TimeZone["UTC"]), [ 1, "a" ], { "a" => 1 } diff --git a/activejob/test/cases/serializers_test.rb b/activejob/test/cases/serializers_test.rb index 207ae55b49..a86f168d03 100644 --- a/activejob/test/cases/serializers_test.rb +++ b/activejob/test/cases/serializers_test.rb @@ -58,7 +58,24 @@ class SerializersTest < ActiveSupport::TestCase test "won't deserialize unknown hash" do hash = { "_dummy_serializer" => 123, "_aj_symbol_keys" => [] } - assert_equal({ "_dummy_serializer" => 123 }, ActiveJob::Serializers.deserialize(hash)) + error = assert_raises(ArgumentError) do + ActiveJob::Serializers.deserialize(hash) + end + assert_equal( + 'Serializer name is not present in the argument: {"_dummy_serializer"=>123, "_aj_symbol_keys"=>[]}', + error.message + ) + end + + test "won't deserialize unknown serializer" do + hash = { "_aj_serialized" => "DoNotExist", "value" => 123 } + error = assert_raises(ArgumentError) do + ActiveJob::Serializers.deserialize(hash) + end + assert_equal( + "Serializer DoNotExist is not know", + error.message + ) end test "will deserialize know serialized objects" do @@ -74,7 +91,7 @@ class SerializersTest < ActiveSupport::TestCase test "can't add serializer with the same key twice" do ActiveJob::Serializers.add_serializers DummySerializer - assert_no_difference(-> { ActiveJob::Serializers.serializers.size } ) do + assert_no_difference(-> { ActiveJob::Serializers.serializers.size }) do ActiveJob::Serializers.add_serializers DummySerializer end end |