• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

mgmodell / devise_token_auth_multi_email / #19303

08 Apr 2026 03:19PM UTC coverage: 21.319% (-7.4%) from 28.73%
#19303

push

GitHub
Add tests for DeviseTokenAuth::Controllers::Helpers

333 of 1562 relevant lines covered (21.32%)

1.24 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

73.47
/lib/devise_token_auth/rails/routes.rb
1
# frozen_string_literal: true
2

3
module ActionDispatch::Routing
1✔
4
  class Mapper
1✔
5
    def mount_devise_token_auth_for(resource, opts)
1✔
6
      # ensure objects exist to simplify attr checks
7
      opts[:controllers] ||= {}
32✔
8
      opts[:skip]        ||= []
32✔
9

10
      # check for ctrl overrides, fall back to defaults
11
      sessions_ctrl          = opts[:controllers].delete(:sessions) || 'devise_token_auth/sessions'
32✔
12
      registrations_ctrl     = opts[:controllers].delete(:registrations) || 'devise_token_auth/registrations'
32✔
13
      passwords_ctrl         = opts[:controllers].delete(:passwords) || 'devise_token_auth/passwords'
32✔
14
      confirmations_ctrl     = opts[:controllers].delete(:confirmations) || 'devise_token_auth/confirmations'
32✔
15
      token_validations_ctrl = opts[:controllers].delete(:token_validations) || 'devise_token_auth/token_validations'
32✔
16
      omniauth_ctrl          = opts[:controllers].delete(:omniauth_callbacks) || 'devise_token_auth/omniauth_callbacks'
32✔
17
      unlocks_ctrl           = opts[:controllers].delete(:unlocks) || 'devise_token_auth/unlocks'
32✔
18

19
      # check for resource override
20
      route                  = opts[:as] || resource.pluralize.underscore.gsub('/', '_')
32✔
21

22
      # define devise controller mappings
23
      controllers = opts[:controllers].merge(
32✔
24
                      sessions: sessions_ctrl,
25
                      registrations: registrations_ctrl,
26
                      passwords: passwords_ctrl,
27
                      confirmations: confirmations_ctrl
28
                    )
29

30
      controllers[:unlocks] = unlocks_ctrl if unlocks_ctrl
32✔
31

32
      # remove any unwanted devise modules
33
      opts[:skip].each{ |item| controllers.delete(item) }
41✔
34

35
      devise_for route.to_sym,
32✔
36
                 class_name: resource,
37
                 module: :devise,
38
                 path: opts[:at].to_s,
39
                 controllers: controllers,
40
                 skip: opts[:skip] + [:omniauth_callbacks]
41

42
      unnest_namespace do
32✔
43
        # get full url path as if it were namespaced
44
        full_path = "#{@scope[:path]}/#{opts[:at]}"
32✔
45

46
        # get namespace name
47
        namespace_name = @scope[:as]
32✔
48

49
        # clear scope so controller routes aren't namespaced
50
        @scope = ActionDispatch::Routing::Mapper::Scope.new(
32✔
51
          path:         '',
52
          shallow_path: '',
53
          constraints:  {},
54
          defaults:     {},
55
          options:      {},
56
          parent:       nil
57
        )
58

59
        mapping_name = resource.underscore.gsub('/', '_')
32✔
60
        mapping_name = "#{namespace_name}_#{mapping_name}" if namespace_name
32✔
61

62
        devise_scope mapping_name.to_sym do
32✔
63
          # path to verify token validity
64
          get "#{full_path}/validate_token", controller: token_validations_ctrl.to_s, action: 'validate_token' if !opts[:skip].include?(:token_validations)
32✔
65

66
          # omniauth routes. only define if omniauth is installed and not skipped.
67
          if defined?(::OmniAuth) && !opts[:skip].include?(:omniauth_callbacks)
32✔
68
            match "#{full_path}/failure",             controller: omniauth_ctrl, action: 'omniauth_failure', via: [:get, :post]
26✔
69
            match "#{full_path}/:provider/callback",  controller: omniauth_ctrl, action: 'omniauth_success', via: [:get, :post]
26✔
70

71
            match "#{DeviseTokenAuth.omniauth_prefix}/:provider/callback", controller: omniauth_ctrl, action: 'redirect_callbacks', via: [:get, :post]
26✔
72
            match "#{DeviseTokenAuth.omniauth_prefix}/failure", controller: omniauth_ctrl, action: 'omniauth_failure', via: [:get, :post]
26✔
73

74
            # preserve the resource class thru oauth authentication by setting name of
75
            # resource as "resource_class" param
76
            match "#{full_path}/:provider", to: redirect(status: 307) { |params, request|
26✔
77
              # get the current querystring
78
              # TODO: deprecate in favor of using params
79
              qs = CGI::parse(request.env['QUERY_STRING'].empty? ? request.body.read : request.env['QUERY_STRING'] )
×
80

81
              # append name of current resource
82
              qs['resource_class'] = [resource]
×
83
              qs['namespace_name'] = [namespace_name] if namespace_name
×
84

85
              set_omniauth_path_prefix!(DeviseTokenAuth.omniauth_prefix)
×
86

87
              redirect_params = {}.tap { |hash| qs.each{ |k, v| hash[k] = v.first } }
×
88

89
              if DeviseTokenAuth.redirect_whitelist
×
90
                redirect_url = request.params['auth_origin_url']
×
91
                unless DeviseTokenAuth::Url.whitelisted?(redirect_url)
×
92
                  message = I18n.t(
×
93
                    'devise_token_auth.registrations.redirect_url_not_allowed',
94
                    redirect_url: redirect_url
95
                  )
96
                  redirect_params['message'] = message
×
97
                  next "#{::OmniAuth.config.path_prefix}/failure?#{redirect_params.to_param}"
×
98
                end
99
              end
100

101
              # re-construct the path for omniauth
102
              "#{::OmniAuth.config.path_prefix}/#{params[:provider]}?#{redirect_params.to_param}"
×
103
            }, via: [:get, :post]
104
          end
105
        end
106
      end
107
    end
108

109
    # this allows us to use namespaced paths without namespacing the routes
110
    def unnest_namespace
1✔
111
      current_scope = @scope.dup
32✔
112
      yield
32✔
113
    ensure
114
      @scope = current_scope
32✔
115
    end
116

117
    # ignore error about omniauth/multiple model support
118
    def set_omniauth_path_prefix!(path_prefix)
1✔
119
      ::OmniAuth.config.path_prefix = path_prefix
×
120
    end
121
  end
122
end
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc