Merge branch '5176-escape-filenames'
[arvados.git] / apps / workbench / test / controllers / repositories_controller_test.rb
1 require 'test_helper'
2 require 'helpers/share_object_helper'
3
4 class RepositoriesControllerTest < ActionController::TestCase
5   include ShareObjectHelper
6
7   [
8     :active, #owner
9     :admin,
10   ].each do |user|
11     test "#{user} shares repository with a user and group" do
12       uuid_list = [api_fixture("groups")["future_project_viewing_group"]["uuid"],
13                    api_fixture("users")["future_project_user"]["uuid"]]
14       post(:share_with, {
15              id: api_fixture("repositories")["foo"]["uuid"],
16              uuids: uuid_list,
17              format: "json"},
18            session_for(user))
19       assert_response :success
20       assert_equal(uuid_list, json_response["success"])
21     end
22   end
23
24   test "user with repository read permission cannot add permissions" do
25     share_uuid = api_fixture("users")["project_viewer"]["uuid"]
26     post(:share_with, {
27            id: api_fixture("repositories")["arvados"]["uuid"],
28            uuids: [share_uuid],
29            format: "json"},
30          session_for(:spectator))
31     assert_response 422
32     assert(json_response["errors"].andand.
33              any? { |msg| msg.start_with?("#{share_uuid}: ") },
34            "JSON response missing properly formatted sharing error")
35   end
36
37   test "admin can_manage repository" do
38     assert user_can_manage(:admin, api_fixture("repositories")["foo"])
39   end
40
41   test "owner can_manage repository" do
42     assert user_can_manage(:active, api_fixture("repositories")["foo"])
43   end
44
45   test "viewer cannot manage repository" do
46     refute user_can_manage(:spectator, api_fixture("repositories")["arvados"])
47   end
48
49   [
50     [:active, ['#Sharing', '#Advanced']],
51     [:admin,  ['#Attributes', '#Sharing', '#Advanced']],
52   ].each do |user, expected_panes|
53     test "#{user} sees panes #{expected_panes}" do
54       get :show, {
55         id: api_fixture('repositories')['foo']['uuid']
56       }, session_for(user)
57       assert_response :success
58
59       panes = css_select('[data-toggle=tab]').each do |pane|
60         pane_name = pane.attributes['href']
61         assert_includes expected_panes, pane_name
62       end
63     end
64   end
65 end