Commit 353edd07 authored by Douwe Maan's avatar Douwe Maan

Merge branch '2586-protected-branches-ee-tests-don-t-need-to_sym-and-send' into 'master'

Clean up Protected branches EE tests, removing unnecessary to_sym usage

Closes #2586

See merge request !2037
parents 7bcb1d21 11996ccc
......@@ -8,20 +8,8 @@ RSpec.shared_examples "protected tags > access control > EE" do
groups.each { |group| project.project_group_links.create(group: group, group_access: Gitlab::Access::DEVELOPER) }
end
def access_type_ids
ProtectedTag.last.create_access_levels
end
def access_levels
access_type_ids.map(&:access_level)
end
def user_ids
access_type_ids.map(&:user_id)
end
def group_ids
access_type_ids.map(&:group_id)
ProtectedTag.last.create_access_levels
end
it "allows creating protected tags that roles, users, and groups can create" do
......@@ -37,9 +25,9 @@ RSpec.shared_examples "protected tags > access control > EE" do
within(".protected-tags-list") { expect(page).to have_content('v1.0') }
expect(ProtectedTag.count).to eq(1)
roles.each { |(access_type_id, _)| expect(access_levels).to include(access_type_id) }
users.each { |user| expect(user_ids).to include(user.id) }
groups.each { |group| expect(group_ids).to include(group.id) }
roles.each { |(access_type_id, _)| expect(access_levels.map(&:access_level)).to include(access_type_id) }
users.each { |user| expect(access_levels.map(&:user_id)).to include(user.id) }
groups.each { |group| expect(access_levels.map(&:group_id)).to include(group.id) }
end
it "allows updating protected tags so that roles and users can create it" do
......@@ -58,9 +46,9 @@ RSpec.shared_examples "protected tags > access control > EE" do
expect(ProtectedTag.count).to eq(1)
roles.each { |(access_type_id, _)| expect(access_levels).to include(access_type_id) }
users.each { |user| expect(user_ids).to include(user.id) }
groups.each { |group| expect(group_ids).to include(group.id) }
roles.each { |(access_type_id, _)| expect(access_levels.map(&:access_level)).to include(access_type_id) }
users.each { |user| expect(access_levels.map(&:user_id)).to include(user.id) }
groups.each { |group| expect(access_levels.map(&:group_id)).to include(group.id) }
end
it "allows updating protected tags so that roles and users cannot create it" do
......@@ -81,7 +69,7 @@ RSpec.shared_examples "protected tags > access control > EE" do
wait_for_requests
expect(ProtectedTag.count).to eq(1)
expect(access_type_ids).to be_empty
expect(access_levels).to be_empty
end
it "prepends selected users that can create" do
......@@ -120,8 +108,8 @@ RSpec.shared_examples "protected tags > access control > EE" do
expect(page).to have_selector '.dropdown-content .is-active', text: users.last.name
expect(ProtectedTag.count).to eq(1)
roles.each { |(access_type_id, _)| expect(access_levels).to include(access_type_id) }
expect(user_ids).to include(users.last.id)
roles.each { |(access_type_id, _)| expect(access_levels.map(&:access_level)).to include(access_type_id) }
expect(access_levels.map(&:user_id)).to include(users.last.id)
end
context 'When updating a protected tag' do
......@@ -136,20 +124,20 @@ RSpec.shared_examples "protected tags > access control > EE" do
wait_for_requests
roles.each do |(access_type_id, _)|
expect(access_levels).to include(access_type_id)
expect(access_levels.map(&:access_level)).to include(access_type_id)
end
expect(access_levels).not_to include(0)
expect(access_levels.map(&:access_level)).not_to include(0)
set_allowed_to('create', 'No one', form: '.js-protected-tag-edit-form')
wait_for_requests
roles.each do |(access_type_id, _)|
expect(access_levels).not_to include(access_type_id)
expect(access_levels.map(&:access_level)).not_to include(access_type_id)
end
expect(access_levels).to include(0)
expect(access_levels.map(&:access_level)).to include(0)
end
end
......@@ -165,10 +153,10 @@ RSpec.shared_examples "protected tags > access control > EE" do
wait_for_requests
roles.each do |(access_type_id, _)|
expect(access_levels).not_to include(access_type_id)
expect(access_levels.map(&:access_level)).not_to include(access_type_id)
end
expect(access_levels).to include(0)
expect(access_levels.map(&:access_level)).to include(0)
end
end
end
......@@ -12,6 +12,10 @@ shared_examples "protected branches > access control > EE" do
groups.each { |group| project.project_group_links.create(group: group, group_access: Gitlab::Access::DEVELOPER) }
end
def last_access_levels(git_operation)
ProtectedBranch.last.public_send("#{git_operation}_access_levels")
end
it "allows creating protected branches that roles, users, and groups can #{git_operation} to" do
visit namespace_project_protected_branches_path(project.namespace, project)
......@@ -25,9 +29,11 @@ shared_examples "protected branches > access control > EE" do
within(".protected-branches-list") { expect(page).to have_content('master') }
expect(ProtectedBranch.count).to eq(1)
roles.each { |(access_type_id, _)| expect(ProtectedBranch.last.send("#{git_operation}_access_levels".to_sym).map(&:access_level)).to include(access_type_id) }
users.each { |user| expect(ProtectedBranch.last.send("#{git_operation}_access_levels".to_sym).map(&:user_id)).to include(user.id) }
groups.each { |group| expect(ProtectedBranch.last.send("#{git_operation}_access_levels".to_sym).map(&:group_id)).to include(group.id) }
access_levels = last_access_levels(git_operation)
roles.each { |(access_type_id, _)| expect(access_levels.map(&:access_level)).to include(access_type_id) }
users.each { |user| expect(access_levels.map(&:user_id)).to include(user.id) }
groups.each { |group| expect(access_levels.map(&:group_id)).to include(group.id) }
end
it "allows updating protected branches so that roles and users can #{git_operation} to it" do
......@@ -45,9 +51,11 @@ shared_examples "protected branches > access control > EE" do
wait_for_requests
expect(ProtectedBranch.count).to eq(1)
roles.each { |(access_type_id, _)| expect(ProtectedBranch.last.send("#{git_operation}_access_levels".to_sym).map(&:access_level)).to include(access_type_id) }
users.each { |user| expect(ProtectedBranch.last.send("#{git_operation}_access_levels".to_sym).map(&:user_id)).to include(user.id) }
groups.each { |group| expect(ProtectedBranch.last.send("#{git_operation}_access_levels".to_sym).map(&:group_id)).to include(group.id) }
access_levels = last_access_levels(git_operation)
roles.each { |(access_type_id, _)| expect(access_levels.map(&:access_level)).to include(access_type_id) }
users.each { |user| expect(access_levels.map(&:user_id)).to include(user.id) }
groups.each { |group| expect(access_levels.map(&:group_id)).to include(group.id) }
end
it "allows updating protected branches so that roles and users cannot #{git_operation} to it" do
......@@ -68,7 +76,9 @@ shared_examples "protected branches > access control > EE" do
wait_for_requests
expect(ProtectedBranch.count).to eq(1)
expect(ProtectedBranch.last.send("#{git_operation}_access_levels".to_sym)).to be_empty
access_levels = last_access_levels(git_operation)
expect(access_levels).to be_empty
end
it "prepends selected users that can #{git_operation} to" do
......@@ -106,8 +116,10 @@ shared_examples "protected branches > access control > EE" do
expect(page).to have_selector '.dropdown-content .is-active', text: users.last.name
expect(ProtectedBranch.count).to eq(1)
roles.each { |(access_type_id, _)| expect(ProtectedBranch.last.send("#{git_operation}_access_levels".to_sym).map(&:access_level)).to include(access_type_id) }
expect(ProtectedBranch.last.send("#{git_operation}_access_levels".to_sym).map(&:user_id)).to include(users.last.id)
access_levels = last_access_levels(git_operation)
roles.each { |(access_type_id, _)| expect(access_levels.map(&:access_level)).to include(access_type_id) }
expect(access_levels.map(&:user_id)).to include(users.last.id)
end
end
......@@ -130,10 +142,11 @@ shared_examples "protected branches > access control > EE" do
wait_for_requests
access_levels = last_access_levels('push')
roles.each do |(access_type_id, _)|
expect(ProtectedBranch.last.push_access_levels.map(&:access_level)).not_to include(access_type_id)
expect(access_levels.map(&:access_level)).not_to include(access_type_id)
end
expect(ProtectedBranch.last.push_access_levels.map(&:access_level)).to include(0)
expect(access_levels.map(&:access_level)).to include(0)
end
end
......@@ -147,10 +160,11 @@ shared_examples "protected branches > access control > EE" do
click_on "Protect"
wait_for_requests
access_levels = last_access_levels('push')
roles.each do |(access_type_id, _)|
expect(ProtectedBranch.last.push_access_levels.map(&:access_level)).not_to include(access_type_id)
expect(access_levels.map(&:access_level)).not_to include(access_type_id)
end
expect(ProtectedBranch.last.push_access_levels.map(&:access_level)).to include(0)
expect(access_levels.map(&:access_level)).to include(0)
end
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