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_not_equal want_uuid, a.uuid, "Non-admin should not assign uuid."
16 assert a.uuid.length==27, "Auto assigned uuid length is wrong."
19 test 'admin can assign valid uuid' do
20 set_user_from_auth :admin_trustedclient
21 want_uuid = Specimen.generate_uuid
22 a = create_with_attrs(uuid: want_uuid)
23 assert_equal want_uuid, a.uuid, "Admin should assign valid uuid."
24 assert a.uuid.length==27, "Auto assigned uuid length is wrong."
27 test 'admin cannot assign empty uuid' do
28 set_user_from_auth :admin_trustedclient
29 a = create_with_attrs(uuid: "")
30 assert_not_equal "", a.uuid, "Admin should not assign empty uuid."
31 assert a.uuid.length==27, "Auto assigned uuid length is wrong."
36 {:a => ['foo', 'bar']},
37 {'a' => [:foo, 'bar']},
38 {'a' => ['foo', :bar]},
40 {:a => {'foo' => {'bar' => 'baz'}}},
41 {'a' => {:foo => {'bar' => 'baz'}}},
42 {'a' => {'foo' => {:bar => 'baz'}}},
43 {'a' => {'foo' => {'bar' => :baz}}},
44 {'a' => {'foo' => ['bar', :baz]}},
45 {'a' => {['foo', :foo] => ['bar', 'baz']}},
47 test "refuse symbol keys in serialized attribute: #{x.inspect}" do
48 set_user_from_auth :admin_trustedclient
49 assert_nothing_raised do
50 Link.create!(link_class: 'test',
53 assert_raises ActiveRecord::RecordInvalid do
54 Link.create!(link_class: 'test',
60 test "Stringify symbols coming from serialized attribute in database" do
61 set_user_from_auth :admin_trustedclient
62 fixed = Link.find_by_uuid(links(:has_symbol_keys_in_database_somehow).uuid)
63 assert_equal(["baz", "foo"], fixed.properties.keys.sort,
64 "Hash symbol keys from DB did not get stringified.")
65 assert_equal(['waz', 'waz', 'waz', 1, nil, false, true],
66 fixed.properties['baz'],
67 "Array symbol values from DB did not get stringified.")
68 assert_equal true, fixed.save, "Failed to save fixed model back to db."
71 test "No HashWithIndifferentAccess in database" do
72 set_user_from_auth :admin_trustedclient
73 assert_raises ActiveRecord::RecordInvalid do
74 Link.create!(link_class: 'test',
75 properties: {'foo' => 'bar'}.with_indifferent_access)