1 # Copyright (C) The Arvados Authors. All rights reserved.
3 # SPDX-License-Identifier: AGPL-3.0
7 class CollectionTest < ActiveSupport::TestCase
8 test 'recognize empty blob locator' do
9 ['d41d8cd98f00b204e9800998ecf8427e+0',
10 'd41d8cd98f00b204e9800998ecf8427e',
11 'd41d8cd98f00b204e9800998ecf8427e+0+Xyzzy'].each do |x|
12 assert_equal true, Collection.is_empty_blob_locator?(x)
14 ['d41d8cd98f00b204e9800998ecf8427e0',
15 'acbd18db4cc2f85cedef654fccc4a4d8+3',
16 'acbd18db4cc2f85cedef654fccc4a4d8+0'].each do |x|
17 assert_equal false, Collection.is_empty_blob_locator?(x)
21 def get_files_tree(coll_name)
23 Collection.find(api_fixture('collections')[coll_name]['uuid']).files_tree
26 test "easy files_tree" do
27 files_in = lambda do |dirname|
28 (1..3).map { |n| [dirname, "file#{n}", 0] }
30 assert_equal([['.', 'dir1', nil], ['./dir1', 'subdir', nil]] +
31 files_in['./dir1/subdir'] + files_in['./dir1'] +
32 [['.', 'dir2', nil]] + files_in['./dir2'] + files_in['.'],
33 get_files_tree('multilevel_collection_1'),
34 "Collection file tree was malformed")
37 test "files_tree with files deep in subdirectories" do
38 # This test makes sure files_tree generates synthetic directory entries.
39 # The manifest doesn't list directories with no files.
40 assert_equal([['.', 'dir1', nil], ['./dir1', 'sub1', nil],
41 ['./dir1/sub1', 'a', 0], ['./dir1/sub1', 'b', 0],
42 ['.', 'dir2', nil], ['./dir2', 'sub2', nil],
43 ['./dir2/sub2', 'c', 0], ['./dir2/sub2', 'd', 0]],
44 get_files_tree('multilevel_collection_2'),
45 "Collection file tree was malformed")
48 test "portable_data_hash never editable" do
49 refute(Collection.new.attribute_editable?("portable_data_hash", :ever))
52 test "admin can edit name" do
54 assert(find_fixture(Collection, "foo_file").attribute_editable?("name"),
55 "admin not allowed to edit collection name")
58 test "project owner can edit name" do
60 assert(find_fixture(Collection, "foo_collection_in_aproject")
61 .attribute_editable?("name"),
62 "project owner not allowed to edit collection name")
65 test "project admin can edit name" do
66 use_token :subproject_admin
67 assert(find_fixture(Collection, "baz_file_in_asubproject")
68 .attribute_editable?("name"),
69 "project admin not allowed to edit collection name")
72 test "project viewer cannot edit name" do
73 use_token :project_viewer
74 refute(find_fixture(Collection, "foo_collection_in_aproject")
75 .attribute_editable?("name"),
76 "project viewer allowed to edit collection name")