diff options
author | Jacopo <beschi.jacopo@gmail.com> | 2017-07-09 10:51:59 +0200 |
---|---|---|
committer | Jacopo <beschi.jacopo@gmail.com> | 2017-07-20 18:36:53 +0200 |
commit | 0b5133bac2cbcf6f75aaa90acec269a1a7d02c7c (patch) | |
tree | 886aedd6f640aeb3875a1d03cc7605e196ac2bb1 /spec/support | |
parent | 64701b51aeacf4f4f932f205a2d831880b757a43 (diff) | |
download | gitlab-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.rb | 14 | ||||
-rw-r--r-- | spec/support/login_helpers.rb | 4 |
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' |