3 class ArvadosModelTest < ActiveSupport::TestCase
6 def create_with_attrs attrs
7 a = Specimen.create({material: 'caloric'}.merge(attrs))
11 test 'non-admin cannot assign uuid' do
12 set_user_from_auth :active_trustedclient
13 want_uuid = Specimen.generate_uuid
14 a = create_with_attrs(uuid: want_uuid)
15 assert_nil a, "Non-admin should not assign uuid."
18 test 'admin can assign valid uuid' do
19 set_user_from_auth :admin_trustedclient
20 want_uuid = Specimen.generate_uuid
21 a = create_with_attrs(uuid: want_uuid)
22 assert_equal want_uuid, a.uuid, "Admin should assign valid uuid."
23 assert a.uuid.length==27, "Auto assigned uuid length is wrong."
26 test 'admin cannot assign empty uuid' do
27 set_user_from_auth :admin_trustedclient
28 a = create_with_attrs(uuid: "")
29 assert_not_equal "", a.uuid, "Admin should not assign empty uuid."
30 assert a.uuid.length==27, "Auto assigned uuid length is wrong."
35 {:a => ['foo', 'bar']},
36 {'a' => [:foo, 'bar']},
37 {'a' => ['foo', :bar]},
39 {:a => {'foo' => {'bar' => 'baz'}}},
40 {'a' => {:foo => {'bar' => 'baz'}}},
41 {'a' => {'foo' => {:bar => 'baz'}}},
42 {'a' => {'foo' => {'bar' => :baz}}},
43 {'a' => {'foo' => ['bar', :baz]}},
44 {'a' => {['foo', :foo] => ['bar', 'baz']}},
46 test "refuse symbol keys in serialized attribute: #{x.inspect}" do
47 set_user_from_auth :admin_trustedclient
48 assert_nothing_raised do
49 Link.create!(link_class: 'test',
52 assert_raises ActiveRecord::RecordInvalid do
53 Link.create!(link_class: 'test',
59 test "Stringify symbols coming from serialized attribute in database" do
60 set_user_from_auth :admin_trustedclient
61 fixed = Link.find_by_uuid(links(:has_symbol_keys_in_database_somehow).uuid)
62 assert_equal(["baz", "foo"], fixed.properties.keys.sort,
63 "Hash symbol keys from DB did not get stringified.")
64 assert_equal(['waz', 'waz', 'waz', 1, nil, false, true],
65 fixed.properties['baz'],
66 "Array symbol values from DB did not get stringified.")
67 assert_equal true, fixed.save, "Failed to save fixed model back to db."
70 test "No HashWithIndifferentAccess in database" do
71 set_user_from_auth :admin_trustedclient
72 assert_raises ActiveRecord::RecordInvalid do
73 Link.create!(link_class: 'test',
74 properties: {'foo' => 'bar'}.with_indifferent_access)