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

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

  background do
    project.team << [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 46 47 48 49 50 51 52 53 54

        fill_in 'deploy_key_title', with: 'new_deploy_key'
        fill_in 'deploy_key_key', with: new_ssh_key
        check 'deploy_key_can_push'
        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 60 61 62 63 64 65 66

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

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

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

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

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

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

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

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

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

88
        accept_confirm { find('li', text: private_deploy_key.title).click_button('Remove') }
89 90 91 92 93 94

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