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

mgmodell / devise_token_auth_multi_email / #666

17 Mar 2026 01:12AM UTC coverage: 12.228% (-78.4%) from 90.649%
#666

push

mgmodell
switching back to mult-email

202 of 1652 relevant lines covered (12.23%)

0.39 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.rb
1
# frozen_string_literal: true
2

3
require_relative 'install_generator_helpers'
×
4

5
module DeviseTokenAuth
×
6
  class InstallGenerator < Rails::Generators::Base
×
7
    include Rails::Generators::Migration
×
8
    include DeviseTokenAuth::InstallGeneratorHelpers
×
9

10
    class_option :primary_key_type, type: :string, desc: 'The type for primary key'
×
11

12
    def copy_migrations
×
13
      if self.class.migration_exists?('db/migrate', "devise_token_auth_create_#{user_class.pluralize.gsub('::','').underscore}")
×
14
        say_status('skipped', "Migration 'devise_token_auth_create_#{user_class.pluralize.gsub('::','').underscore}' already exists")
×
15
      else
×
16
        migration_template(
×
17
          'devise_token_auth_create_users.rb.erb',
×
18
          "db/migrate/devise_token_auth_create_#{user_class.pluralize.gsub('::','').underscore}.rb"
×
19
        )
×
20
      end
×
21
    end
×
22

23
    def create_user_model
×
24
      fname = "app/models/#{user_class.underscore}.rb"
×
25
      if File.exist?(File.join(destination_root, fname))
×
26
        inclusion = 'include DeviseTokenAuth::Concerns::User'
×
27
        unless parse_file_for_line(fname, inclusion)
×
28

29
          active_record_needle = (Rails::VERSION::MAJOR >= 5) ? 'ApplicationRecord' : 'ActiveRecord::Base'
×
30
          inject_into_file fname, after: "class #{user_class} < #{active_record_needle}\n" do <<-'RUBY'
×
31
            # Include default devise modules.
32
            devise :database_authenticatable, :registerable,
×
33
                    :recoverable, :rememberable, :trackable, :validatable,
×
34
                    :confirmable, :omniauthable
×
35
            include DeviseTokenAuth::Concerns::User
×
36
            RUBY
×
37
          end
×
38
        end
×
39
      else
×
40
        template('user.rb.erb', fname)
×
41
      end
×
42
    end
×
43

44
    private
×
45

46
    def self.next_migration_number(path)
×
47
      Time.zone.now.utc.strftime('%Y%m%d%H%M%S')
×
48
    end
×
49

50
    def json_supported_database?
×
51
      (postgres? && postgres_correct_version?) || (mysql? && mysql_correct_version?)
×
52
    end
×
53

54
    def postgres?
×
55
      database_name == 'ActiveRecord::ConnectionAdapters::PostgreSQLAdapter'
×
56
    end
×
57

58
    def postgres_correct_version?
×
59
      database_version > '9.3'
×
60
    end
×
61

62
    def mysql?
×
63
      database_name == 'ActiveRecord::ConnectionAdapters::MysqlAdapter'
×
64
    end
×
65

66
    def mysql_correct_version?
×
67
      database_version > '5.7.7'
×
68
    end
×
69

70
    def database_name
×
71
      ActiveRecord::Base.connection.class.name
×
72
    end
×
73

74
    def database_version
×
75
      ActiveRecord::Base.connection.select_value('SELECT VERSION()')
×
76
    end
×
77

78
    def rails_5_or_newer?
×
79
      Rails::VERSION::MAJOR >= 5
×
80
    end
×
81

82
    def primary_key_type
×
83
      primary_key_string if rails_5_or_newer?
×
84
    end
×
85

86
    def primary_key_string
×
87
      key_string = options[:primary_key_type]
×
88
      ", id: :#{key_string}" if key_string
×
89
    end
×
90
  end
×
91
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