Read about our upcoming Code of Conduct on this issue

repository_settings_spec.rb 4.17 KB
Newer Older
1
2
require 'spec_helper'

3
feature 'Repository settings' do
4
5
6
7
8
  let(:project) { create(:project_empty_repo) }
  let(:user) { create(:user) }
  let(:role) { :developer }

  background do
9
    project.add_role(user, role)
10
    sign_in(user)
11
12
13
14
15
16
  end

  context 'for developer' do
    given(:role) { :developer }

    scenario 'is not allowed to view' do
17
      visit project_settings_repository_path(project)
18
19
20
21
22
23
24
25

      expect(page.status_code).to eq(404)
    end
  end

  context 'for master' do
    given(:role) { :master }

26
    context 'Deploy Keys', :js do
27
28
29
30
31
32
33
34
      let(:private_deploy_key) { create(:deploy_key, title: 'private_deploy_key', public: false) }
      let(:public_deploy_key) { create(:another_deploy_key, title: 'public_deploy_key', public: true) }
      let(:new_ssh_key) { attributes_for(:key)[:key] }

      scenario 'get list of keys' do
        project.deploy_keys << private_deploy_key
        project.deploy_keys << public_deploy_key

35
        visit project_settings_repository_path(project)
36
37
38
39
40
41

        expect(page).to have_content('private_deploy_key')
        expect(page).to have_content('public_deploy_key')
      end

      scenario 'add a new deploy key' do
42
        visit project_settings_repository_path(project)
43
44
45

        fill_in 'deploy_key_title', with: 'new_deploy_key'
        fill_in 'deploy_key_key', with: new_ssh_key
46
        check 'deploy_key_deploy_keys_projects_attributes_0_can_push'
47
48
49
50
51
52
53
54
        click_button 'Add key'

        expect(page).to have_content('new_deploy_key')
        expect(page).to have_content('Write access allowed')
      end

      scenario 'edit an existing deploy key' do
        project.deploy_keys << private_deploy_key
55
        visit project_settings_repository_path(project)
56
57
58
59

        find('li', text: private_deploy_key.title).click_link('Edit')

        fill_in 'deploy_key_title', with: 'updated_deploy_key'
60
        check 'deploy_key_deploy_keys_projects_attributes_0_can_push'
61
62
63
64
65
66
        click_button 'Save changes'

        expect(page).to have_content('updated_deploy_key')
        expect(page).to have_content('Write access allowed')
      end

67
68
      scenario 'edit a deploy key from projects user has access to' do
        project2 = create(:project_empty_repo)
69
        project2.add_role(user, role)
70
71
        project2.deploy_keys << private_deploy_key

72
        visit project_settings_repository_path(project)
73
74
75
76
77
78
79
80
81

        find('li', text: private_deploy_key.title).click_link('Edit')

        fill_in 'deploy_key_title', with: 'updated_deploy_key'
        click_button 'Save changes'

        expect(page).to have_content('updated_deploy_key')
      end

82
83
      scenario 'remove an existing deploy key' do
        project.deploy_keys << private_deploy_key
84
        visit project_settings_repository_path(project)
85

86
        accept_confirm { find('li', text: private_deploy_key.title).click_button('Remove') }
87
88
89
90

        expect(page).not_to have_content(private_deploy_key.title)
      end
    end
91
92

    context 'Deploy tokens' do
Mayra Cabrera's avatar
Mayra Cabrera committed
93
94
      let(:deploy_token_project) { create(:project_deploy_token, project: project) }
      let!(:deploy_token) { deploy_token_project.deploy_token }
95
96
97

      before do
        visit project_settings_repository_path(project)
Mayra Cabrera's avatar
Mayra Cabrera committed
98
      end
99
100
101
102

      scenario 'view deploy tokens' do
        within('.deploy-tokens') do
          expect(page).to have_content(deploy_token.name)
Mayra Cabrera's avatar
Mayra Cabrera committed
103
104
          expect(page).to have_content('read_repository')
          expect(page).to have_content('read_registry')
105
106
107
108
109
110
        end
      end

      scenario 'add a new deploy token' do
        fill_in 'deploy_token_name', with: 'new_deploy_key'
        fill_in 'deploy_token_expires_at', with: (Date.today + 1.month).to_s
Mayra Cabrera's avatar
Mayra Cabrera committed
111
112
        check 'deploy_token_read_repository'
        check 'deploy_token_read_registry'
113
114
115
116
117
118
119
120
121
122
123
        click_button 'Create deploy token'

        expect(page).to have_content('Your new project deploy token has been created')
      end

      scenario 'revoke a deploy token', :js do
        within('.deploy-tokens') do
          click_link 'Revoke'
          click_link "Revoke #{deploy_token.name}"

          expect(page).not_to have_content(deploy_token.name)
Mayra Cabrera's avatar
Mayra Cabrera committed
124
125
          expect(page).not_to have_content('read_repository')
          expect(page).not_to have_content('read_registry')
126
127
128
        end
      end
    end
129
130
  end
end