2016-06-17 04:49:02 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
feature 'Projected Branches', feature: true, js: true do
|
2016-07-25 06:09:15 -04:00
|
|
|
include WaitForAjax
|
|
|
|
|
2016-06-17 04:49:02 -04:00
|
|
|
let(:user) { create(:user, :admin) }
|
|
|
|
let(:project) { create(:project) }
|
|
|
|
|
|
|
|
before { login_as(user) }
|
|
|
|
|
|
|
|
def set_protected_branch_name(branch_name)
|
2016-06-30 03:32:05 -04:00
|
|
|
find(".js-protected-branch-select").click
|
|
|
|
find(".dropdown-input-field").set(branch_name)
|
|
|
|
click_on "Create Protected Branch: #{branch_name}"
|
2016-06-17 04:49:02 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
describe "explicit protected branches" do
|
|
|
|
it "allows creating explicit protected branches" do
|
|
|
|
visit namespace_project_protected_branches_path(project.namespace, 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(user, 'some-branch', commit.id)
|
|
|
|
|
|
|
|
visit namespace_project_protected_branches_path(project.namespace, project)
|
|
|
|
set_protected_branch_name('some-branch')
|
|
|
|
click_on "Protect"
|
|
|
|
|
|
|
|
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 namespace_project_protected_branches_path(project.namespace, project)
|
|
|
|
set_protected_branch_name('some-branch')
|
|
|
|
click_on "Protect"
|
|
|
|
|
|
|
|
within(".protected-branches-list") { expect(page).to have_content('branch was removed') }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "wildcard protected branches" do
|
|
|
|
it "allows creating protected branches with a wildcard" do
|
|
|
|
visit namespace_project_protected_branches_path(project.namespace, 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(user, 'production-stable', 'master')
|
|
|
|
project.repository.add_branch(user, 'staging-stable', 'master')
|
|
|
|
|
|
|
|
visit namespace_project_protected_branches_path(project.namespace, 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(user, 'production-stable', 'master')
|
|
|
|
project.repository.add_branch(user, 'staging-stable', 'master')
|
|
|
|
project.repository.add_branch(user, 'development', 'master')
|
|
|
|
create(:protected_branch, project: project, name: "*-stable")
|
|
|
|
|
|
|
|
visit namespace_project_protected_branches_path(project.namespace, project)
|
|
|
|
click_on "2 matching branches"
|
|
|
|
|
|
|
|
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
|
|
|
|
end
|
|
|
|
end
|
2016-07-08 04:48:50 -04:00
|
|
|
|
|
|
|
describe "access control" do
|
2016-07-13 23:42:16 -04:00
|
|
|
ProtectedBranch::PushAccessLevel.human_access_levels.each do |(access_type_id, access_type_name)|
|
2016-07-08 04:48:50 -04:00
|
|
|
it "allows creating protected branches that #{access_type_name} can push to" do
|
|
|
|
visit namespace_project_protected_branches_path(project.namespace, project)
|
|
|
|
set_protected_branch_name('master')
|
|
|
|
within('.new_protected_branch') do
|
|
|
|
find(".allowed-to-push").click
|
2016-07-29 02:13:07 -04:00
|
|
|
within(".dropdown.open .dropdown-menu") { click_on access_type_name }
|
2016-07-08 04:48:50 -04:00
|
|
|
end
|
|
|
|
click_on "Protect"
|
|
|
|
|
|
|
|
expect(ProtectedBranch.count).to eq(1)
|
2016-07-29 02:13:07 -04:00
|
|
|
expect(ProtectedBranch.last.push_access_level.access_level).to eq(access_type_id)
|
2016-07-08 04:48:50 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "allows updating protected branches so that #{access_type_name} can push to them" do
|
|
|
|
visit namespace_project_protected_branches_path(project.namespace, project)
|
|
|
|
set_protected_branch_name('master')
|
|
|
|
click_on "Protect"
|
|
|
|
|
|
|
|
expect(ProtectedBranch.count).to eq(1)
|
|
|
|
|
|
|
|
within(".protected-branches-list") do
|
|
|
|
find(".allowed-to-push").click
|
|
|
|
within('.dropdown-menu.push') { click_on access_type_name }
|
|
|
|
end
|
|
|
|
|
2016-07-25 06:09:15 -04:00
|
|
|
wait_for_ajax
|
2016-07-29 02:13:07 -04:00
|
|
|
expect(ProtectedBranch.last.push_access_level.access_level).to eq(access_type_id)
|
2016-07-08 04:48:50 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-07-13 23:42:16 -04:00
|
|
|
ProtectedBranch::MergeAccessLevel.human_access_levels.each do |(access_type_id, access_type_name)|
|
2016-07-08 04:48:50 -04:00
|
|
|
it "allows creating protected branches that #{access_type_name} can merge to" do
|
|
|
|
visit namespace_project_protected_branches_path(project.namespace, project)
|
|
|
|
set_protected_branch_name('master')
|
|
|
|
within('.new_protected_branch') do
|
|
|
|
find(".allowed-to-merge").click
|
2016-07-29 02:13:07 -04:00
|
|
|
within(".dropdown.open .dropdown-menu") { click_on access_type_name }
|
2016-07-08 04:48:50 -04:00
|
|
|
end
|
|
|
|
click_on "Protect"
|
|
|
|
|
|
|
|
expect(ProtectedBranch.count).to eq(1)
|
2016-07-29 02:13:07 -04:00
|
|
|
expect(ProtectedBranch.last.merge_access_level.access_level).to eq(access_type_id)
|
2016-07-08 04:48:50 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "allows updating protected branches so that #{access_type_name} can merge to them" do
|
|
|
|
visit namespace_project_protected_branches_path(project.namespace, project)
|
|
|
|
set_protected_branch_name('master')
|
|
|
|
click_on "Protect"
|
|
|
|
|
|
|
|
expect(ProtectedBranch.count).to eq(1)
|
|
|
|
|
|
|
|
within(".protected-branches-list") do
|
|
|
|
find(".allowed-to-merge").click
|
|
|
|
within('.dropdown-menu.merge') { click_on access_type_name }
|
|
|
|
end
|
|
|
|
|
2016-07-25 06:09:15 -04:00
|
|
|
wait_for_ajax
|
2016-07-29 02:13:07 -04:00
|
|
|
expect(ProtectedBranch.last.merge_access_level.access_level).to eq(access_type_id)
|
2016-07-08 04:48:50 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2016-06-17 04:49:02 -04:00
|
|
|
end
|