From 3f1d04e3bb04d240792112b5b45a9062c72e0df4 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Sun, 14 Sep 2014 19:34:17 -0700 Subject: Fix string/gid collision in job arguments Serialize Global IDs as special objects, distinguishable from Strings --- activejob/test/cases/argument_serialization_test.rb | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'activejob/test/cases/argument_serialization_test.rb') diff --git a/activejob/test/cases/argument_serialization_test.rb b/activejob/test/cases/argument_serialization_test.rb index 5a46c5cdef..dbe36fc572 100644 --- a/activejob/test/cases/argument_serialization_test.rb +++ b/activejob/test/cases/argument_serialization_test.rb @@ -31,12 +31,12 @@ class ArgumentSerializationTest < ActiveSupport::TestCase end test 'should convert records to Global IDs' do - assert_arguments_roundtrip [@person], [@person.to_gid.to_s] + assert_arguments_roundtrip [@person], ['_aj_globalid' => @person.to_gid.to_s] end test 'should dive deep into arrays and hashes' do - assert_arguments_roundtrip [3, [@person]], [3, [@person.to_gid.to_s]] - assert_arguments_roundtrip [{ 'a' => @person }], [{ 'a' => @person.to_gid.to_s }.with_indifferent_access] + assert_arguments_roundtrip [3, [@person]], [3, ['_aj_globalid' => @person.to_gid.to_s]] + assert_arguments_roundtrip [{ 'a' => @person }], [{ 'a' => { '_aj_globalid' => @person.to_gid.to_s }}.with_indifferent_access] end test 'should stringify symbol hash keys' do @@ -51,6 +51,14 @@ class ArgumentSerializationTest < ActiveSupport::TestCase assert_raises ActiveJob::SerializationError do ActiveJob::Arguments.serialize [ { :a => [{ 2 => 3 }] } ] end + + assert_raises ActiveJob::SerializationError do + ActiveJob::Arguments.serialize [ '_aj_globalid' => 1 ] + end + + assert_raises ActiveJob::SerializationError do + ActiveJob::Arguments.serialize [ :_aj_globalid => 1 ] + end end test 'should not allow non-primitive objects' do -- cgit v1.2.3