summaryrefslogtreecommitdiff
path: root/spec/support
diff options
context:
space:
mode:
authorJacopo <beschi.jacopo@gmail.com>2017-07-09 10:51:59 +0200
committerJacopo <beschi.jacopo@gmail.com>2017-07-20 18:36:53 +0200
commit0b5133bac2cbcf6f75aaa90acec269a1a7d02c7c (patch)
tree886aedd6f640aeb3875a1d03cc7605e196ac2bb1 /spec/support
parent64701b51aeacf4f4f932f205a2d831880b757a43 (diff)
downloadgitlab-ce-0b5133bac2cbcf6f75aaa90acec269a1a7d02c7c.tar.gz
Extract "@request.env['devise.mapping'] = Devise.mappings[:user]" to a test helper
Extracted `@request.env['devise.mapping'] = Devise.mappings[:user]` and `Rails.application.env_config['devise.mapping'] = Devise.mappings[:user]` in our tests into the helper method `set_devise_mapping`
Diffstat (limited to 'spec/support')
-rw-r--r--spec/support/devise_helpers.rb14
-rw-r--r--spec/support/login_helpers.rb4
2 files changed, 17 insertions, 1 deletions
diff --git a/spec/support/devise_helpers.rb b/spec/support/devise_helpers.rb
new file mode 100644
index 00000000000..890a2d9d287
--- /dev/null
+++ b/spec/support/devise_helpers.rb
@@ -0,0 +1,14 @@
+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:)
+ env =
+ if context.respond_to?(:env_config)
+ context.env_config
+ elsif context.respond_to?(:env)
+ context.env
+ end
+
+ env['devise.mapping'] = Devise.mappings[:user] if env
+ end
+end
diff --git a/spec/support/login_helpers.rb b/spec/support/login_helpers.rb
index b410a652126..701de9c8c19 100644
--- a/spec/support/login_helpers.rb
+++ b/spec/support/login_helpers.rb
@@ -1,4 +1,6 @@
module LoginHelpers
+ include DeviseHelpers
+
# Internal: Log in as a specific user or a new user of a specific role
#
# user_or_role - User object, or a role to create (e.g., :admin, :user)
@@ -106,7 +108,7 @@ module LoginHelpers
end
def stub_omniauth_saml_config(messages)
- Rails.application.env_config['devise.mapping'] = Devise.mappings[:user]
+ set_devise_mapping(context: Rails.application)
Rails.application.routes.disable_clear_and_finalize = true
Rails.application.routes.draw do
post '/users/auth/saml' => 'omniauth_callbacks#saml'