18004: Fixes a couple of race condition bugs related to caching remote users.
[arvados.git] / services / api / test / unit / seralizer_test.rb
1 # Copyright (C) The Arvados Authors. All rights reserved.
2 #
3 # SPDX-License-Identifier: AGPL-3.0
4
5 require 'test_helper'
6 require 'serializers'
7
8 class SerializerTest < ActiveSupport::TestCase
9   test 'serialize' do
10     assert_equal('{}', HashSerializer.dump({}))
11     assert_equal('{"foo":"bar"}', HashSerializer.dump(foo: 'bar'))
12     assert_equal('{"foo":"bar"}', HashSerializer.dump('foo' => 'bar'))
13     assert_equal('[]', ArraySerializer.dump([]))
14     assert_equal('["foo",{"foo":"bar"}]',
15                  ArraySerializer.dump(['foo', 'foo' => 'bar']))
16     assert_equal(['foo'],
17                  ArraySerializer.load(ArraySerializer.dump([:foo])))
18     assert_equal([1,'bar'],
19                  ArraySerializer.load(ArraySerializer.dump([1,'bar'])))
20   end
21
22   test 'load array that was saved as json, then mangled by an old version' do
23     assert_equal(['foo'],
24                  ArraySerializer.load(YAML.dump(ArraySerializer.dump(['foo']))))
25   end
26 end