2 require 'helpers/repository_stub_helper'
3 require 'helpers/share_object_helper'
5 class RepositoriesControllerTest < ActionController::TestCase
6 include RepositoryStubHelper
7 include ShareObjectHelper
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"]]
17 id: api_fixture("repositories")["foo"]["uuid"],
21 assert_response :success
22 assert_equal(uuid_list, json_response["success"])
26 test "user with repository read permission cannot add permissions" do
27 share_uuid = api_fixture("users")["project_viewer"]["uuid"]
29 id: api_fixture("repositories")["arvados"]["uuid"],
32 session_for(:spectator))
34 assert(json_response["errors"].andand.
35 any? { |msg| msg.start_with?("#{share_uuid}: ") },
36 "JSON response missing properly formatted sharing error")
39 test "admin can_manage repository" do
40 assert user_can_manage(:admin, api_fixture("repositories")["foo"])
43 test "owner can_manage repository" do
44 assert user_can_manage(:active, api_fixture("repositories")["foo"])
47 test "viewer cannot manage repository" do
48 refute user_can_manage(:spectator, api_fixture("repositories")["arvados"])
52 [:active, ['#Sharing', '#Advanced']],
53 [:admin, ['#Attributes', '#Sharing', '#Advanced']],
54 ].each do |user, expected_panes|
55 test "#{user} sees panes #{expected_panes}" do
57 id: api_fixture('repositories')['foo']['uuid']
59 assert_response :success
61 panes = css_select('[data-toggle=tab]').each do |pane|
62 pane_name = pane.attributes['href']
63 assert_includes expected_panes, pane_name
68 ### Browse repository content
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
75 id: api_fixture('repositories')['foo']['uuid'],
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'
87 test "show commit to #{user}" do
88 reset_api_fixtures_after_test false
89 sha1, commit, _ = stub_repo_content
91 id: api_fixture('repositories')['foo']['uuid'],
94 assert_response :success
95 assert_select 'pre', h(commit)
98 test "show blob to #{user}" do
99 reset_api_fixtures_after_test false
100 sha1, _, filedata = stub_repo_content filename: 'COPYING'
102 id: api_fixture('repositories')['foo']['uuid'],
106 assert_response :success
107 assert_select 'pre', h(filedata)
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'
116 id: api_fixture('repositories')['foo']['uuid'],
119 }, session_for(:active)
120 assert_response :success
121 assert_select 'tr td', 'COPYING'