Reduce differences in spec/support/matchers/access_matchers.rb
Signed-off-by: Rémy Coutable <remy@rymai.me>
This commit is contained in:
parent
be44024c51
commit
88d6bdcfec
1 changed files with 17 additions and 18 deletions
|
@ -7,28 +7,27 @@ module AccessMatchers
|
|||
extend RSpec::Matchers::DSL
|
||||
include Warden::Test::Helpers
|
||||
|
||||
def emulate_user(user, membership = nil)
|
||||
case user
|
||||
when :user
|
||||
login_as(create(:user))
|
||||
def emulate_user(user_type_or_trait, membership = nil)
|
||||
case user_type_or_trait
|
||||
when :user, :admin
|
||||
login_as(create(user_type_or_trait))
|
||||
when :external, :auditor
|
||||
login_as(create(:user, user_type_or_trait))
|
||||
when :visitor
|
||||
logout
|
||||
when :admin
|
||||
login_as(create(:admin))
|
||||
when :external
|
||||
login_as(create(:user, external: true))
|
||||
when User
|
||||
login_as(user)
|
||||
login_as(user_type_or_trait)
|
||||
when *Gitlab::Access.sym_options_with_owner.keys
|
||||
raise ArgumentError, "cannot emulate #{user} without membership parent" unless membership
|
||||
|
||||
role = user
|
||||
raise ArgumentError, "cannot emulate #{user_type_or_trait} without membership parent" unless membership
|
||||
|
||||
role = user_type_or_trait
|
||||
user =
|
||||
if role == :owner && membership.owner
|
||||
user = membership.owner
|
||||
membership.owner
|
||||
else
|
||||
user = create(:user)
|
||||
membership.public_send(:"add_#{role}", user)
|
||||
create(:user).tap do |new_user|
|
||||
membership.public_send(:"add_#{role}", new_user)
|
||||
end
|
||||
end
|
||||
|
||||
login_as(user)
|
||||
|
|
Loading…
Reference in a new issue