aboutsummaryrefslogtreecommitdiffstats
path: root/activejob/test/cases/serializers_test.rb
diff options
context:
space:
mode:
authorRafael Mendonça França <rafaelmfranca@gmail.com>2018-02-12 14:16:41 -0500
committerRafael Mendonça França <rafaelmfranca@gmail.com>2018-02-14 13:10:08 -0500
commit69645cba727dfa1c18c666d2a2f1c0dedffde938 (patch)
treedc5fda6749d63a795d12459a8dc2d8994c5bfea6 /activejob/test/cases/serializers_test.rb
parent71721dc1c9b769d3c06317122dc88cad4a346580 (diff)
downloadrails-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/cases/serializers_test.rb')
-rw-r--r--activejob/test/cases/serializers_test.rb21
1 files changed, 19 insertions, 2 deletions
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