Commit 9199449f authored by James Edwards-Jones's avatar James Edwards-Jones

Memoized access levels in ProtectedBranch EE specs

parent e1643e6c
...@@ -16,16 +16,16 @@ shared_examples "protected branches > access control > EE" do ...@@ -16,16 +16,16 @@ shared_examples "protected branches > access control > EE" do
ProtectedBranch.last.public_send("#{git_operation}_access_levels") ProtectedBranch.last.public_send("#{git_operation}_access_levels")
end end
def access_levels(git_operation) def access_levels(access_level_types)
access_type_ids(git_operation).map(&:access_level) access_level_types.map(&:access_level)
end end
def user_ids(git_operation) def user_ids(access_level_types)
access_type_ids(git_operation).map(&:user_id) access_level_types.map(&:user_id)
end end
def group_ids(git_operation) def group_ids(access_level_types)
access_type_ids(git_operation).map(&:group_id) access_level_types.map(&:group_id)
end 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
...@@ -41,9 +41,11 @@ shared_examples "protected branches > access control > EE" do ...@@ -41,9 +41,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(access_levels(git_operation)).to include(access_type_id) }
users.each { |user| expect(user_ids(git_operation)).to include(user.id) } access_level_types = access_type_ids(git_operation)
groups.each { |group| expect(group_ids(git_operation)).to include(group.id) } roles.each { |(access_type_id, _)| expect(access_levels(access_level_types)).to include(access_type_id) }
users.each { |user| expect(user_ids(access_level_types)).to include(user.id) }
groups.each { |group| expect(group_ids(access_level_types)).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
...@@ -61,9 +63,11 @@ shared_examples "protected branches > access control > EE" do ...@@ -61,9 +63,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(access_levels(git_operation)).to include(access_type_id) }
users.each { |user| expect(user_ids(git_operation)).to include(user.id) } access_level_types = access_type_ids(git_operation)
groups.each { |group| expect(group_ids(git_operation)).to include(group.id) } roles.each { |(access_type_id, _)| expect(access_levels(access_level_types)).to include(access_type_id) }
users.each { |user| expect(user_ids(access_level_types)).to include(user.id) }
groups.each { |group| expect(group_ids(access_level_types)).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
...@@ -84,7 +88,9 @@ shared_examples "protected branches > access control > EE" do ...@@ -84,7 +88,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(access_type_ids(git_operation)).to be_empty
access_level_types = access_type_ids(git_operation)
expect(access_type_ids(access_level_types)).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
...@@ -122,7 +128,9 @@ shared_examples "protected branches > access control > EE" do ...@@ -122,7 +128,9 @@ 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(access_levels(git_operation)).to include(access_type_id) }
access_level_types = access_type_ids(git_operation)
roles.each { |(access_type_id, _)| expect(access_levels(access_level_types)).to include(access_type_id) }
expect(user_ids(git_operation)).to include(users.last.id) expect(user_ids(git_operation)).to include(users.last.id)
end end
end end
...@@ -146,10 +154,11 @@ shared_examples "protected branches > access control > EE" do ...@@ -146,10 +154,11 @@ shared_examples "protected branches > access control > EE" do
wait_for_requests wait_for_requests
access_level_types = access_type_ids('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(access_level_types)).not_to include(access_type_id)
end end
expect(ProtectedBranch.last.push_access_levels.map(&:access_level)).to include(0) expect(access_levels(access_level_types)).to include(0)
end end
end end
...@@ -163,10 +172,11 @@ shared_examples "protected branches > access control > EE" do ...@@ -163,10 +172,11 @@ shared_examples "protected branches > access control > EE" do
click_on "Protect" click_on "Protect"
wait_for_requests wait_for_requests
access_level_types = access_type_ids('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(access_level_types)).not_to include(access_type_id)
end end
expect(ProtectedBranch.last.push_access_levels.map(&:access_level)).to include(0) expect(access_levels(access_level_types)).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