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

mgmodell / devise_token_auth_multi_email / #2410

08 Apr 2026 02:16AM UTC coverage: 25.912% (-65.0%) from 90.879%
#2410

push

mgmodell
fixed test to work on my mac

412 of 1590 relevant lines covered (25.91%)

1.92 hits per line

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

0.0
/lib/generators/devise_token_auth/install_generator_helpers.rb
1
module DeviseTokenAuth
×
2
  module InstallGeneratorHelpers
×
3
    class << self
×
4
      def included(mod)
×
5
        mod.class_eval do
×
6
          source_root File.expand_path('templates', __dir__)
×
7

8
          argument :user_class, type: :string, default: 'User'
×
9
          argument :mount_path, type: :string, default: 'auth'
×
10

11
          def create_initializer_file
×
12
            copy_file('devise_token_auth.rb', 'config/initializers/devise_token_auth.rb')
×
13
          end
×
14

15
          def include_controller_concerns
×
16
            fname = 'app/controllers/application_controller.rb'
×
17
            line  = 'include DeviseTokenAuth::Concerns::SetUserByToken'
×
18

19
            if File.exist?(File.join(destination_root, fname))
×
20
              if parse_file_for_line(fname, line)
×
21
                say_status('skipped', 'Concern is already included in the application controller.')
×
22
              elsif is_rails_api?
×
23
                inject_into_file fname, after: "class ApplicationController < ActionController::API\n" do <<-'RUBY'
×
24
        include DeviseTokenAuth::Concerns::SetUserByToken
×
25
                RUBY
×
26
                end
×
27
              else
×
28
                inject_into_file fname, after: "class ApplicationController < ActionController::Base\n" do <<-'RUBY'
×
29
        include DeviseTokenAuth::Concerns::SetUserByToken
×
30
                RUBY
×
31
                end
×
32
              end
×
33
            else
×
34
              say_status('skipped', "app/controllers/application_controller.rb not found. Add 'include DeviseTokenAuth::Concerns::SetUserByToken' to any controllers that require authentication.")
×
35
            end
×
36
          end
×
37

38
          def add_route_mount
×
39
            f    = 'config/routes.rb'
×
40
            str  = "mount_devise_token_auth_for '#{user_class}', at: '#{mount_path}'"
×
41

42
            if File.exist?(File.join(destination_root, f))
×
43
              line = parse_file_for_line(f, 'mount_devise_token_auth_for')
×
44

45
              if line
×
46
                existing_user_class = true
×
47
              else
×
48
                line = 'Rails.application.routes.draw do'
×
49
                existing_user_class = false
×
50
              end
×
51

52
              if parse_file_for_line(f, str)
×
53
                say_status('skipped', "Routes already exist for #{user_class} at #{mount_path}")
×
54
              else
×
55
                insert_after_line(f, line, str)
×
56

57
                if existing_user_class
×
58
                  scoped_routes = ''\
×
59
                    "as :#{user_class.underscore} do\n"\
×
60
                    "    # Define routes for #{user_class} within this block.\n"\
×
61
                    "  end\n"
×
62
                  insert_after_line(f, str, scoped_routes)
×
63
                end
×
64
              end
×
65
            else
×
66
              say_status('skipped', "config/routes.rb not found. Add \"mount_devise_token_auth_for '#{user_class}', at: '#{mount_path}'\" to your routes file.")
×
67
            end
×
68
          end
×
69

70
          private
×
71

72
          def insert_after_line(filename, line, str)
×
73
            gsub_file filename, /(#{Regexp.escape(line)})/mi do |match|
×
74
              "#{match}\n  #{str}"
×
75
            end
×
76
          end
×
77

78
          def parse_file_for_line(filename, str)
×
79
            match = false
×
80

81
            File.open(File.join(destination_root, filename)) do |f|
×
82
              f.each_line do |line|
×
83
                match = line if line =~ /(#{Regexp.escape(str)})/mi
×
84
              end
×
85
            end
×
86
            match
×
87
          end
×
88

89
          def is_rails_api?
×
90
            fname = 'app/controllers/application_controller.rb'
×
91
            line = 'class ApplicationController < ActionController::API'
×
92
            parse_file_for_line(fname, line)
×
93
          end
×
94
        end
×
95
      end
×
96
    end
×
97
  end
×
98
end
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc