debian-mirror-gitlab/spec/support/helpers/devise_helpers.rb

25 lines
845 B
Ruby
Raw Normal View History

2017-09-10 17:25:29 +05:30
module DeviseHelpers
# explicitly tells Devise which mapping to use
# this is needed when we are testing a Devise controller bypassing the router
def set_devise_mapping(context:)
2018-03-17 18:26:18 +05:30
env = env_from_context(context)
2017-09-10 17:25:29 +05:30
env['devise.mapping'] = Devise.mappings[:user] if env
end
2018-03-17 18:26:18 +05:30
def env_from_context(context)
2018-12-13 13:39:08 +05:30
# When we modify env_config, that is on the global
# Rails.application, and we need to stub it and allow it to be
# modified in-place, without polluting later tests.
2018-03-17 18:26:18 +05:30
if context.respond_to?(:env_config)
2018-12-13 13:39:08 +05:30
context.env_config.deep_dup.tap do |env|
allow(context).to receive(:env_config).and_return(env)
end
# When we modify env, then the context is a request, or something
# else that only lives for a single spec.
2018-03-17 18:26:18 +05:30
elsif context.respond_to?(:env)
context.env
end
end
2017-09-10 17:25:29 +05:30
end