Add 'build/' from commit '555b039609a3c8700c27767c255fdfe00eb42063'
[arvados.git] / apps / workbench / test / controllers / repositories_controller_test.rb
1 require 'test_helper'
2 require 'helpers/repository_stub_helper'
3 require 'helpers/share_object_helper'
4
5 class RepositoriesControllerTest < ActionController::TestCase
6   include RepositoryStubHelper
7   include ShareObjectHelper
8
9   [
10     :active, #owner
11     :admin,
12   ].each do |user|
13     test "#{user} shares repository with a user and group" do
14       uuid_list = [api_fixture("groups")["future_project_viewing_group"]["uuid"],
15                    api_fixture("users")["future_project_user"]["uuid"]]
16       post(:share_with, {
17              id: api_fixture("repositories")["foo"]["uuid"],
18              uuids: uuid_list,
19              format: "json"},
20            session_for(user))
21       assert_response :success
22       assert_equal(uuid_list, json_response["success"])
23     end
24   end
25
26   test "user with repository read permission cannot add permissions" do
27     share_uuid = api_fixture("users")["project_viewer"]["uuid"]
28     post(:share_with, {
29            id: api_fixture("repositories")["arvados"]["uuid"],
30            uuids: [share_uuid],
31            format: "json"},
32          session_for(:spectator))
33     assert_response 422
34     assert(json_response["errors"].andand.
35              any? { |msg| msg.start_with?("#{share_uuid}: ") },
36            "JSON response missing properly formatted sharing error")
37   end
38
39   test "admin can_manage repository" do
40     assert user_can_manage(:admin, api_fixture("repositories")["foo"])
41   end
42
43   test "owner can_manage repository" do
44     assert user_can_manage(:active, api_fixture("repositories")["foo"])
45   end
46
47   test "viewer cannot manage repository" do
48     refute user_can_manage(:spectator, api_fixture("repositories")["arvados"])
49   end
50
51   [
52     [:active, ['#Sharing', '#Advanced']],
53     [:admin,  ['#Attributes', '#Sharing', '#Advanced']],
54   ].each do |user, expected_panes|
55     test "#{user} sees panes #{expected_panes}" do
56       get :show, {
57         id: api_fixture('repositories')['foo']['uuid']
58       }, session_for(user)
59       assert_response :success
60
61       panes = css_select('[data-toggle=tab]').each do |pane|
62         pane_name = pane.attributes['href']
63         assert_includes expected_panes, pane_name
64       end
65     end
66   end
67
68   ### Browse repository content
69
70   [:active, :spectator].each do |user|
71     test "show tree to #{user}" do
72       reset_api_fixtures_after_test false
73       sha1, _, _ = stub_repo_content
74       get :show_tree, {
75         id: api_fixture('repositories')['foo']['uuid'],
76         commit: sha1,
77       }, session_for(user)
78       assert_response :success
79       assert_select 'tr td a', 'COPYING'
80       assert_select 'tr td', '625 bytes'
81       assert_select 'tr td a', 'apps'
82       assert_select 'tr td a', 'workbench'
83       assert_select 'tr td a', 'Gemfile'
84       assert_select 'tr td', '33.7 KiB'
85     end
86
87     test "show commit to #{user}" do
88       reset_api_fixtures_after_test false
89       sha1, commit, _ = stub_repo_content
90       get :show_commit, {
91         id: api_fixture('repositories')['foo']['uuid'],
92         commit: sha1,
93       }, session_for(user)
94       assert_response :success
95       assert_select 'pre', h(commit)
96     end
97
98     test "show blob to #{user}" do
99       reset_api_fixtures_after_test false
100       sha1, _, filedata = stub_repo_content filename: 'COPYING'
101       get :show_blob, {
102         id: api_fixture('repositories')['foo']['uuid'],
103         commit: sha1,
104         path: 'COPYING',
105       }, session_for(user)
106       assert_response :success
107       assert_select 'pre', h(filedata)
108     end
109   end
110
111   ['', '/'].each do |path|
112     test "show tree with path '#{path}'" do
113       reset_api_fixtures_after_test false
114       sha1, _, _ = stub_repo_content filename: 'COPYING'
115       get :show_tree, {
116         id: api_fixture('repositories')['foo']['uuid'],
117         commit: sha1,
118         path: path,
119       }, session_for(:active)
120       assert_response :success
121       assert_select 'tr td', 'COPYING'
122     end
123   end
124 end