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