diff options
author | Cristian Bica <cristian.bica@gmail.com> | 2014-05-31 17:31:20 +0300 |
---|---|---|
committer | Cristian Bica <cristian.bica@gmail.com> | 2014-06-03 00:46:35 +0300 |
commit | ba3ae62a775182c663c6797e21618bb37de3aaba (patch) | |
tree | 0bf3394c6f601b40509efcb3fc01c506af9925bf /test | |
parent | 8a3b137f95ad0ce459ce0eb9808850474da863d4 (diff) | |
download | rails-ba3ae62a775182c663c6797e21618bb37de3aaba.tar.gz rails-ba3ae62a775182c663c6797e21618bb37de3aaba.tar.bz2 rails-ba3ae62a775182c663c6797e21618bb37de3aaba.zip |
Deep serialization
Diffstat (limited to 'test')
-rw-r--r-- | test/cases/parameters_test.rb | 27 |
1 files changed, 26 insertions, 1 deletions
diff --git a/test/cases/parameters_test.rb b/test/cases/parameters_test.rb index 625c59c404..93b34278a5 100644 --- a/test/cases/parameters_test.rb +++ b/test/cases/parameters_test.rb @@ -1,6 +1,7 @@ require 'helper' require 'active_job/arguments' require 'models/person' +require 'active_support/core_ext/hash/indifferent_access' class ParameterSerializationTest < ActiveSupport::TestCase test 'should make no change to regular values' do @@ -14,7 +15,7 @@ class ParameterSerializationTest < ActiveSupport::TestCase assert_equal [ 'a' ], ActiveJob::Arguments.serialize([ 'a' ]) assert_equal [ true ], ActiveJob::Arguments.serialize([ true ]) assert_equal [ false ], ActiveJob::Arguments.serialize([ false ]) - assert_equal [ { a: 1 } ], ActiveJob::Arguments.serialize([ { a: 1 } ]) + assert_equal [ { "a" => 1, "b" => 2 } ], ActiveJob::Arguments.serialize([ { a: 1, "b" => 2 } ]) assert_equal [ [ 1 ] ], ActiveJob::Arguments.serialize([ [ 1 ] ]) assert_equal [ 1_000_000_000_000_000_000_000 ], ActiveJob::Arguments.serialize([ 1_000_000_000_000_000_000_000 ]) @@ -24,6 +25,25 @@ class ParameterSerializationTest < ActiveSupport::TestCase assert_equal "Unsupported argument type: #{self.class.name}", err.message end + test 'should dive deep into arrays or hashes' do + assert_equal [ { "a" => Person.find(5).gid }.with_indifferent_access ], ActiveJob::Arguments.serialize([ { a: Person.find(5) } ]) + assert_equal [ [ Person.find(5).gid ] ], ActiveJob::Arguments.serialize([ [ Person.find(5) ] ]) + end + + test 'should dive deep into arrays or hashes and raise exception on complex objects' do + err = assert_raises RuntimeError do + ActiveJob::Arguments.serialize([ 1, [self] ]) + end + assert_equal "Unsupported argument type: #{self.class.name}", err.message + end + + test 'shoud dive deep into hashes and allow raise exception on not string/symbol keys' do + err = assert_raises RuntimeError do + ActiveJob::Arguments.serialize([ [ { 1 => 2 } ] ]) + end + assert_equal "Unsupported hash key type: Fixnum", err.message + end + test 'should serialize records with global id' do assert_equal [ Person.find(5).gid ], ActiveJob::Arguments.serialize([ Person.find(5) ]) end @@ -45,4 +65,9 @@ class ParameterDeserializationTest < ActiveSupport::TestCase test 'should serialize values and records together' do assert_equal [ 3, Person.find(5) ], ActiveJob::Arguments.deserialize([ 3, Person.find(5).gid ]) end + + test 'should dive deep when desierializing' do + assert_equal [ [ 3, Person.find(5) ] ], ActiveJob::Arguments.deserialize([ [ 3, Person.find(5).gid ] ]) + end + end |