2016-08-24 12:49:21 +05:30
|
|
|
require 'spec_helper'
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
feature 'Protected Branches', :js do
|
|
|
|
let(:user) { create(:user) }
|
|
|
|
let(:admin) { create(:admin) }
|
2017-08-17 22:00:37 +05:30
|
|
|
let(:project) { create(:project, :repository) }
|
2016-08-24 12:49:21 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
context 'logged in as developer' do
|
|
|
|
before do
|
|
|
|
project.add_developer(user)
|
|
|
|
sign_in(user)
|
|
|
|
end
|
2016-08-24 12:49:21 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
describe 'Delete protected branch' do
|
|
|
|
before do
|
|
|
|
create(:protected_branch, project: project, name: 'fix')
|
|
|
|
expect(ProtectedBranch.count).to eq(1)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not allow developer to removes protected branch' do
|
|
|
|
visit project_branches_path(project)
|
2016-08-24 12:49:21 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
fill_in 'branch-search', with: 'fix'
|
|
|
|
find('#branch-search').native.send_keys(:enter)
|
|
|
|
|
|
|
|
expect(page).to have_css('.btn-remove.disabled')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2016-08-24 12:49:21 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
context 'logged in as master' do
|
|
|
|
before do
|
|
|
|
project.add_master(user)
|
|
|
|
sign_in(user)
|
2016-08-24 12:49:21 +05:30
|
|
|
end
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
describe 'Delete protected branch' do
|
|
|
|
before do
|
|
|
|
create(:protected_branch, project: project, name: 'fix')
|
|
|
|
expect(ProtectedBranch.count).to eq(1)
|
|
|
|
end
|
2016-08-24 12:49:21 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
it 'removes branch after modal confirmation' do
|
|
|
|
visit project_branches_path(project)
|
2016-08-24 12:49:21 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
fill_in 'branch-search', with: 'fix'
|
|
|
|
find('#branch-search').native.send_keys(:enter)
|
|
|
|
|
|
|
|
expect(page).to have_content('fix')
|
|
|
|
expect(find('.all-branches')).to have_selector('li', count: 1)
|
|
|
|
page.find('[data-target="#modal-delete-branch"]').click
|
2016-08-24 12:49:21 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
expect(page).to have_css('.js-delete-branch[disabled]')
|
|
|
|
fill_in 'delete_branch_input', with: 'fix'
|
|
|
|
click_link 'Delete protected branch'
|
2016-08-24 12:49:21 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
fill_in 'branch-search', with: 'fix'
|
|
|
|
find('#branch-search').native.send_keys(:enter)
|
|
|
|
|
|
|
|
expect(page).to have_content('No branches to show')
|
|
|
|
end
|
2016-08-24 12:49:21 +05:30
|
|
|
end
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
describe "Saved defaults" do
|
|
|
|
it "keeps the allowed to merge and push dropdowns defaults based on the previous selection" do
|
|
|
|
visit project_protected_branches_path(project)
|
|
|
|
form = '.js-new-protected-branch'
|
|
|
|
|
|
|
|
within form do
|
|
|
|
find(".js-allowed-to-merge").click
|
|
|
|
click_link 'No one'
|
|
|
|
find(".js-allowed-to-push").click
|
|
|
|
click_link 'Developers + Masters'
|
|
|
|
end
|
|
|
|
|
|
|
|
visit project_protected_branches_path(project)
|
|
|
|
|
|
|
|
within form do
|
|
|
|
page.within(".js-allowed-to-merge") do
|
|
|
|
expect(page.find(".dropdown-toggle-text")).to have_content("No one")
|
|
|
|
end
|
|
|
|
page.within(".js-allowed-to-push") do
|
|
|
|
expect(page.find(".dropdown-toggle-text")).to have_content("Developers + Masters")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2016-08-24 12:49:21 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
context 'logged in as admin' do
|
|
|
|
before do
|
|
|
|
sign_in(admin)
|
2016-08-24 12:49:21 +05:30
|
|
|
end
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
describe "explicit protected branches" do
|
|
|
|
it "allows creating explicit protected branches" do
|
|
|
|
visit project_protected_branches_path(project)
|
|
|
|
set_protected_branch_name('some-branch')
|
|
|
|
click_on "Protect"
|
|
|
|
|
|
|
|
within(".protected-branches-list") { expect(page).to have_content('some-branch') }
|
|
|
|
expect(ProtectedBranch.count).to eq(1)
|
|
|
|
expect(ProtectedBranch.last.name).to eq('some-branch')
|
|
|
|
end
|
|
|
|
|
|
|
|
it "displays the last commit on the matching branch if it exists" do
|
|
|
|
commit = create(:commit, project: project)
|
|
|
|
project.repository.add_branch(admin, 'some-branch', commit.id)
|
|
|
|
|
|
|
|
visit project_protected_branches_path(project)
|
|
|
|
set_protected_branch_name('some-branch')
|
|
|
|
click_on "Protect"
|
2016-08-24 12:49:21 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
within(".protected-branches-list") { expect(page).to have_content(commit.id[0..7]) }
|
|
|
|
end
|
|
|
|
|
|
|
|
it "displays an error message if the named branch does not exist" do
|
|
|
|
visit project_protected_branches_path(project)
|
|
|
|
set_protected_branch_name('some-branch')
|
|
|
|
click_on "Protect"
|
2016-08-24 12:49:21 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
within(".protected-branches-list") { expect(page).to have_content('branch was removed') }
|
|
|
|
end
|
2016-08-24 12:49:21 +05:30
|
|
|
end
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
describe "wildcard protected branches" do
|
|
|
|
it "allows creating protected branches with a wildcard" do
|
|
|
|
visit project_protected_branches_path(project)
|
|
|
|
set_protected_branch_name('*-stable')
|
|
|
|
click_on "Protect"
|
|
|
|
|
|
|
|
within(".protected-branches-list") { expect(page).to have_content('*-stable') }
|
|
|
|
expect(ProtectedBranch.count).to eq(1)
|
|
|
|
expect(ProtectedBranch.last.name).to eq('*-stable')
|
|
|
|
end
|
|
|
|
|
|
|
|
it "displays the number of matching branches" do
|
|
|
|
project.repository.add_branch(admin, 'production-stable', 'master')
|
|
|
|
project.repository.add_branch(admin, 'staging-stable', 'master')
|
|
|
|
|
|
|
|
visit project_protected_branches_path(project)
|
|
|
|
set_protected_branch_name('*-stable')
|
|
|
|
click_on "Protect"
|
|
|
|
|
|
|
|
within(".protected-branches-list") { expect(page).to have_content("2 matching branches") }
|
|
|
|
end
|
|
|
|
|
|
|
|
it "displays all the branches matching the wildcard" do
|
|
|
|
project.repository.add_branch(admin, 'production-stable', 'master')
|
|
|
|
project.repository.add_branch(admin, 'staging-stable', 'master')
|
|
|
|
project.repository.add_branch(admin, 'development', 'master')
|
2016-09-13 17:45:13 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
visit project_protected_branches_path(project)
|
|
|
|
set_protected_branch_name('*-stable')
|
|
|
|
click_on "Protect"
|
2016-08-24 12:49:21 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
visit project_protected_branches_path(project)
|
|
|
|
click_on "2 matching branches"
|
2016-08-24 12:49:21 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
within(".protected-branches-list") do
|
|
|
|
expect(page).to have_content("production-stable")
|
|
|
|
expect(page).to have_content("staging-stable")
|
|
|
|
expect(page).not_to have_content("development")
|
|
|
|
end
|
2016-08-24 12:49:21 +05:30
|
|
|
end
|
|
|
|
end
|
2018-03-17 18:26:18 +05:30
|
|
|
|
|
|
|
describe "access control" do
|
|
|
|
include_examples "protected branches > access control > CE"
|
|
|
|
end
|
2016-08-24 12:49:21 +05:30
|
|
|
end
|
2016-09-13 17:45:13 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
def set_protected_branch_name(branch_name)
|
|
|
|
find(".js-protected-branch-select").click
|
|
|
|
find(".dropdown-input-field").set(branch_name)
|
|
|
|
click_on("Create wildcard #{branch_name}")
|
2016-09-13 17:45:13 +05:30
|
|
|
end
|
2016-08-24 12:49:21 +05:30
|
|
|
end
|