Commit b34ddf93 authored by Oswaldo Ferreira's avatar Oswaldo Ferreira

Extract EE specific tests for protected branches/tags

We have the spec files containing EE specific code for
spec/features/protected_branches_spec.rb and
spec/features/protected_tags_spec.rb.
This commit extracts the EE behavior into ee/ folder.
parent 05513ff5
# frozen_string_literal: true
require 'spec_helper'
describe 'Protected Branches', :js do
include ProtectedBranchHelpers
let(:user) { create(:user, :admin) }
let(:project) { create(:project, :repository) }
before do
sign_in(user)
end
describe 'access control' do
describe 'with ref permissions for users enabled' do
before do
stub_licensed_features(protected_refs_for_users: true)
end
include_examples 'protected branches > access control > EE'
end
describe 'with ref permissions for users disabled' do
before do
stub_licensed_features(protected_refs_for_users: false)
end
include_examples 'protected branches > access control > CE'
context 'with existing access levels' do
let(:protected_branch) { create(:protected_branch, project: project) }
it 'shows users that can push to the branch' do
protected_branch.push_access_levels.new(user: create(:user, name: 'Jane'))
.save!(validate: false)
visit project_settings_repository_path(project)
expect(page).to have_content("The following user can also push to this branch: "\
"Jane")
end
it 'shows groups that can push to the branch' do
protected_branch.push_access_levels.new(group: create(:group, name: 'Team Awesome'))
.save!(validate: false)
visit project_settings_repository_path(project)
expect(page).to have_content("Members of this group can also push to "\
"this branch: Team Awesome")
end
it 'shows users that can merge into the branch' do
protected_branch.merge_access_levels.new(user: create(:user, name: 'Jane'))
.save!(validate: false)
visit project_settings_repository_path(project)
expect(page).to have_content("The following user can also merge into "\
"this branch: Jane")
end
it 'shows groups that have can push to the branch' do
protected_branch.merge_access_levels.new(group: create(:group, name: 'Team Awesome'))
.save!(validate: false)
protected_branch.merge_access_levels.new(group: create(:group, name: 'Team B'))
.save!(validate: false)
visit project_settings_repository_path(project)
expect(page).to have_content("Members of these groups can also merge into "\
"this branch:")
expect(page).to have_content(/(Team Awesome|Team B) and (Team Awesome|Team B)/)
end
end
end
end
end
# frozen_string_literal: true
require 'spec_helper'
describe 'Protected Tags', :js do
include ProtectedTagHelpers
let(:user) { create(:user, :admin) }
let(:project) { create(:project, :repository) }
before do
sign_in(user)
end
describe 'access control' do
describe 'with ref permissions for users enabled' do
before do
stub_licensed_features(protected_refs_for_users: true)
end
include_examples 'protected tags > access control > EE'
end
describe 'with ref permissions for users disabled' do
before do
stub_licensed_features(protected_refs_for_users: false)
end
include_examples 'protected tags > access control > CE'
describe 'with existing access levels' do
let(:protected_tag) { create(:protected_tag, project: project) }
it 'shows users that can push to the branch' do
protected_tag.create_access_levels.new(user: create(:user, name: 'Jane'))
.save!(validate: false)
visit project_settings_repository_path(project)
expect(page).to have_content("The following user can also create tags: "\
"Jane")
end
it 'shows groups that can create to the branch' do
protected_tag.create_access_levels.new(group: create(:group, name: 'Team Awesome'))
.save!(validate: false)
visit project_settings_repository_path(project)
expect(page).to have_content("Members of this group can also create tags: "\
"Team Awesome")
end
end
end
end
end
module EE
module ProtectedBranchHelpers
def set_allowed_to(operation, option = 'Maintainers', form: '.js-new-protected-branch')
within form do
find(".js-allowed-to-#{operation}").click
wait_for_requests
within('.dropdown-content') do
Array(option).each { |opt| click_on(opt) }
end
find(".js-allowed-to-#{operation}").click # needed to submit form in some cases
end
end
end
end
require 'spec_helper'
describe 'Branches' do
include EE::ProtectedBranchHelpers
let(:user) { create(:user) }
let(:project) { create(:project, :public, :repository) }
let(:repository) { project.repository }
......
require 'spec_helper'
describe 'Protected Branches', :js do
include EE::ProtectedBranchHelpers
include ProtectedBranchHelpers
let(:user) { create(:user) }
let(:admin) { create(:admin) }
......@@ -72,9 +72,8 @@ describe 'Protected Branches', :js do
describe "explicit protected branches" do
it "allows creating explicit protected branches" do
visit project_protected_branches_path(project)
set_defaults
set_protected_branch_name('some-branch')
set_allowed_to('merge')
set_allowed_to('push')
click_on "Protect"
within(".protected-branches-list") { expect(page).to have_content('some-branch') }
......@@ -87,9 +86,8 @@ describe 'Protected Branches', :js do
project.repository.add_branch(admin, 'some-branch', commit.id)
visit project_protected_branches_path(project)
set_defaults
set_protected_branch_name('some-branch')
set_allowed_to('merge')
set_allowed_to('push')
click_on "Protect"
within(".protected-branches-list") { expect(page).to have_content(commit.id[0..7]) }
......@@ -97,9 +95,8 @@ describe 'Protected Branches', :js do
it "displays an error message if the named branch does not exist" do
visit project_protected_branches_path(project)
set_defaults
set_protected_branch_name('some-branch')
set_allowed_to('merge')
set_allowed_to('push')
click_on "Protect"
within(".protected-branches-list") { expect(page).to have_content('branch was deleted') }
......@@ -109,9 +106,8 @@ describe 'Protected Branches', :js do
describe "wildcard protected branches" do
it "allows creating protected branches with a wildcard" do
visit project_protected_branches_path(project)
set_defaults
set_protected_branch_name('*-stable')
set_allowed_to('merge')
set_allowed_to('push')
click_on "Protect"
within(".protected-branches-list") { expect(page).to have_content('*-stable') }
......@@ -124,9 +120,8 @@ describe 'Protected Branches', :js do
project.repository.add_branch(admin, 'staging-stable', 'master')
visit project_protected_branches_path(project)
set_defaults
set_protected_branch_name('*-stable')
set_allowed_to('merge')
set_allowed_to('push')
click_on "Protect"
within(".protected-branches-list") do
......@@ -142,8 +137,7 @@ describe 'Protected Branches', :js do
visit project_protected_branches_path(project)
set_protected_branch_name('*-stable')
set_allowed_to('merge')
set_allowed_to('push')
set_defaults
click_on "Protect"
visit project_protected_branches_path(project)
......@@ -158,74 +152,11 @@ describe 'Protected Branches', :js do
end
describe "access control" do
describe 'with ref permissions for users enabled' do
before do
stub_licensed_features(protected_refs_for_users: true)
end
include_examples "protected branches > access control > EE"
before do
stub_licensed_features(protected_refs_for_users: false)
end
describe 'with ref permissions for users disabled' do
before do
stub_licensed_features(protected_refs_for_users: false)
end
include_examples "protected branches > access control > CE"
context 'with existing access levels' do
let(:protected_branch) { create(:protected_branch, project: project) }
it 'shows users that can push to the branch' do
protected_branch.push_access_levels.new(user: create(:user, name: 'Jane'))
.save!(validate: false)
visit project_settings_repository_path(project)
expect(page).to have_content("The following user can also push to this branch: "\
"Jane")
end
it 'shows groups that can push to the branch' do
protected_branch.push_access_levels.new(group: create(:group, name: 'Team Awesome'))
.save!(validate: false)
visit project_settings_repository_path(project)
expect(page).to have_content("Members of this group can also push to "\
"this branch: Team Awesome")
end
it 'shows users that can merge into the branch' do
protected_branch.merge_access_levels.new(user: create(:user, name: 'Jane'))
.save!(validate: false)
visit project_settings_repository_path(project)
expect(page).to have_content("The following user can also merge into "\
"this branch: Jane")
end
it 'shows groups that have can push to the branch' do
protected_branch.merge_access_levels.new(group: create(:group, name: 'Team Awesome'))
.save!(validate: false)
protected_branch.merge_access_levels.new(group: create(:group, name: 'Team B'))
.save!(validate: false)
visit project_settings_repository_path(project)
expect(page).to have_content("Members of these groups can also merge into "\
"this branch:")
expect(page).to have_content(/(Team Awesome|Team B) and (Team Awesome|Team B)/)
end
end
end
include_examples "protected branches > access control > CE"
end
end
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}")
end
end
require 'spec_helper'
describe 'Protected Tags', :js do
include ProtectedTagHelpers
let(:user) { create(:user, :admin) }
let(:project) { create(:project, :repository) }
......@@ -8,26 +10,6 @@ describe 'Protected Tags', :js do
sign_in(user)
end
def set_allowed_to(operation, option = 'Maintainers', form: '.new-protected-tag')
within form do
find(".js-allowed-to-#{operation}").click
wait_for_requests
within('.dropdown-content') do
Array(option).each { |opt| click_on(opt) }
end
find(".js-allowed-to-#{operation}").click # needed to submit form in some cases
end
end
def set_protected_tag_name(tag_name)
find(".js-protected-tag-select").click
find(".dropdown-input-field").set(tag_name)
click_on("Create wildcard #{tag_name}")
find('.protected-tags-dropdown .dropdown-menu', visible: false)
end
describe "explicit protected tags" do
it "allows creating explicit protected tags" do
visit project_protected_tags_path(project)
......@@ -111,44 +93,10 @@ describe 'Protected Tags', :js do
end
describe "access control" do
describe 'with ref permissions for users enabled' do
before do
stub_licensed_features(protected_refs_for_users: true)
end
include_examples "protected tags > access control > EE"
before do
stub_licensed_features(protected_refs_for_users: false)
end
describe 'with ref permissions for users disabled' do
before do
stub_licensed_features(protected_refs_for_users: false)
end
include_examples "protected tags > access control > CE"
describe 'with existing access levels' do
let(:protected_tag) { create(:protected_tag, project: project) }
it 'shows users that can push to the branch' do
protected_tag.create_access_levels.new(user: create(:user, name: 'Jane'))
.save!(validate: false)
visit project_settings_repository_path(project)
expect(page).to have_content("The following user can also create tags: "\
"Jane")
end
it 'shows groups that can create to the branch' do
protected_tag.create_access_levels.new(group: create(:group, name: 'Team Awesome'))
.save!(validate: false)
visit project_settings_repository_path(project)
expect(page).to have_content("Members of this group can also create tags: "\
"Team Awesome")
end
end
end
include_examples "protected tags > access control > CE"
end
end
# frozen_string_literal: true
module ProtectedBranchHelpers
def set_allowed_to(operation, option = 'Maintainers', form: '.js-new-protected-branch')
within form do
select_elem = find(".js-allowed-to-#{operation}")
select_elem.click
wait_for_requests
within('.dropdown-content') do
Array(option).each { |opt| click_on(opt) }
end
# Enhanced select is used in EE, therefore an extra click is needed.
select_elem.click if select_elem['aria-expanded'] == 'true'
end
end
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}")
end
def set_defaults
set_allowed_to('merge')
set_allowed_to('push')
end
end
# frozen_string_literal: true
require_relative 'protected_branch_helpers'
module ProtectedTagHelpers
include ::ProtectedBranchHelpers
def set_allowed_to(operation, option = 'Maintainers', form: '.new-protected-tag')
super
end
def set_protected_tag_name(tag_name)
find('.js-protected-tag-select').click
find('.dropdown-input-field').set(tag_name)
click_on("Create wildcard #{tag_name}")
find('.protected-tags-dropdown .dropdown-menu', visible: false)
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment