Merge branch '8567-api-select-docker-fmt' refs #8567
[arvados.git] / services / api / test / unit / seralizer_test.rb
1 require 'test_helper'
2 require 'serializers'
3
4 class SerializerTest < ActiveSupport::TestCase
5   test 'serialize' do
6     assert_equal('{}', HashSerializer.dump({}))
7     assert_equal('{"foo":"bar"}', HashSerializer.dump(foo: 'bar'))
8     assert_equal('{"foo":"bar"}', HashSerializer.dump('foo' => 'bar'))
9     assert_equal('[]', ArraySerializer.dump([]))
10     assert_equal('["foo",{"foo":"bar"}]',
11                  ArraySerializer.dump(['foo', 'foo' => 'bar']))
12     assert_equal(['foo'],
13                  ArraySerializer.load(ArraySerializer.dump([:foo])))
14     assert_equal([1,'bar'],
15                  ArraySerializer.load(ArraySerializer.dump([1,'bar'])))
16   end
17
18   test 'load array that was saved as json, then mangled by an old version' do
19     assert_equal(['foo'],
20                  ArraySerializer.load(YAML.dump(ArraySerializer.dump(['foo']))))
21   end
22 end