Commit 88d6bdcf authored by Rémy Coutable's avatar Rémy Coutable

Reduce differences in spec/support/matchers/access_matchers.rb

Signed-off-by: default avatarRémy Coutable <remy@rymai.me>
parent be44024c
...@@ -7,29 +7,28 @@ module AccessMatchers ...@@ -7,29 +7,28 @@ module AccessMatchers
extend RSpec::Matchers::DSL extend RSpec::Matchers::DSL
include Warden::Test::Helpers include Warden::Test::Helpers
def emulate_user(user, membership = nil) def emulate_user(user_type_or_trait, membership = nil)
case user case user_type_or_trait
when :user when :user, :admin
login_as(create(:user)) login_as(create(user_type_or_trait))
when :external, :auditor
login_as(create(:user, user_type_or_trait))
when :visitor when :visitor
logout logout
when :admin
login_as(create(:admin))
when :external
login_as(create(:user, external: true))
when User when User
login_as(user) login_as(user_type_or_trait)
when *Gitlab::Access.sym_options_with_owner.keys when *Gitlab::Access.sym_options_with_owner.keys
raise ArgumentError, "cannot emulate #{user} without membership parent" unless membership raise ArgumentError, "cannot emulate #{user_type_or_trait} without membership parent" unless membership
role = user
if role == :owner && membership.owner role = user_type_or_trait
user = membership.owner user =
else if role == :owner && membership.owner
user = create(:user) membership.owner
membership.public_send(:"add_#{role}", user) else
end create(:user).tap do |new_user|
membership.public_send(:"add_#{role}", new_user)
end
end
login_as(user) login_as(user)
else else
......
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