8784: Fix test for latest firefox.
[arvados.git] / apps / workbench / test / unit / collection_test.rb
1 require 'test_helper'
2
3 class CollectionTest < ActiveSupport::TestCase
4   test 'recognize empty blob locator' do
5     ['d41d8cd98f00b204e9800998ecf8427e+0',
6      'd41d8cd98f00b204e9800998ecf8427e',
7      'd41d8cd98f00b204e9800998ecf8427e+0+Xyzzy'].each do |x|
8       assert_equal true, Collection.is_empty_blob_locator?(x)
9     end
10     ['d41d8cd98f00b204e9800998ecf8427e0',
11      'acbd18db4cc2f85cedef654fccc4a4d8+3',
12      'acbd18db4cc2f85cedef654fccc4a4d8+0'].each do |x|
13       assert_equal false, Collection.is_empty_blob_locator?(x)
14     end
15   end
16
17   def get_files_tree(coll_name)
18     use_token :admin
19     Collection.find(api_fixture('collections')[coll_name]['uuid']).files_tree
20   end
21
22   test "easy files_tree" do
23     files_in = lambda do |dirname|
24       (1..3).map { |n| [dirname, "file#{n}", 0] }
25     end
26     assert_equal([['.', 'dir1', nil], ['./dir1', 'subdir', nil]] +
27                  files_in['./dir1/subdir'] + files_in['./dir1'] +
28                  [['.', 'dir2', nil]] + files_in['./dir2'] + files_in['.'],
29                  get_files_tree('multilevel_collection_1'),
30                  "Collection file tree was malformed")
31   end
32
33   test "files_tree with files deep in subdirectories" do
34     # This test makes sure files_tree generates synthetic directory entries.
35     # The manifest doesn't list directories with no files.
36     assert_equal([['.', 'dir1', nil], ['./dir1', 'sub1', nil],
37                   ['./dir1/sub1', 'a', 0], ['./dir1/sub1', 'b', 0],
38                   ['.', 'dir2', nil], ['./dir2', 'sub2', nil],
39                   ['./dir2/sub2', 'c', 0], ['./dir2/sub2', 'd', 0]],
40                  get_files_tree('multilevel_collection_2'),
41                  "Collection file tree was malformed")
42   end
43
44   test "portable_data_hash never editable" do
45     refute(Collection.new.attribute_editable?("portable_data_hash", :ever))
46   end
47
48   test "admin can edit name" do
49     use_token :admin
50     assert(find_fixture(Collection, "foo_file").attribute_editable?("name"),
51            "admin not allowed to edit collection name")
52   end
53
54   test "project owner can edit name" do
55     use_token :active
56     assert(find_fixture(Collection, "foo_collection_in_aproject")
57              .attribute_editable?("name"),
58            "project owner not allowed to edit collection name")
59   end
60
61   test "project admin can edit name" do
62     use_token :subproject_admin
63     assert(find_fixture(Collection, "baz_file_in_asubproject")
64              .attribute_editable?("name"),
65            "project admin not allowed to edit collection name")
66   end
67
68   test "project viewer cannot edit name" do
69     use_token :project_viewer
70     refute(find_fixture(Collection, "foo_collection_in_aproject")
71              .attribute_editable?("name"),
72            "project viewer allowed to edit collection name")
73   end
74 end