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

mgmodell / devise_token_auth_multi_email / #520

06 Mar 2026 02:26AM UTC coverage: 91.224% (+0.5%) from 90.717%
#520

push

mgmodell
bump sqlite3

1081 of 1185 relevant lines covered (91.22%)

212.74 hits per line

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

92.86
/lib/generators/devise_token_auth/install_generator.rb
1
# frozen_string_literal: true
2

3
require_relative 'install_generator_helpers'
1✔
4

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

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

12
    def copy_migrations
1✔
13
      if self.class.migration_exists?('db/migrate', "devise_token_auth_create_#{user_class.pluralize.gsub('::','').underscore}")
46✔
14
        say_status('skipped', "Migration 'devise_token_auth_create_#{user_class.pluralize.gsub('::','').underscore}' already exists")
×
15
      else
16
        migration_template(
46✔
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
1✔
24
      fname = "app/models/#{user_class.underscore}.rb"
46✔
25
      if File.exist?(File.join(destination_root, fname))
46✔
26
        inclusion = 'include DeviseTokenAuth::Concerns::User'
14✔
27
        unless parse_file_for_line(fname, inclusion)
14✔
28

29
          active_record_needle = (Rails::VERSION::MAJOR >= 5) ? 'ApplicationRecord' : 'ActiveRecord::Base'
4✔
30
          inject_into_file fname, after: "class #{user_class} < #{active_record_needle}\n" do <<-'RUBY'
8✔
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)
32✔
41
      end
42
    end
43

44
    private
1✔
45

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

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

54
    def postgres?
1✔
55
      database_name == 'ActiveRecord::ConnectionAdapters::PostgreSQLAdapter'
46✔
56
    end
57

58
    def postgres_correct_version?
1✔
59
      database_version > '9.3'
46✔
60
    end
61

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

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

70
    def database_name
1✔
71
      ActiveRecord::Base.connection.class.name
46✔
72
    end
73

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

78
    def rails_5_or_newer?
1✔
79
      Rails::VERSION::MAJOR >= 5
46✔
80
    end
81

82
    def primary_key_type
1✔
83
      primary_key_string if rails_5_or_newer?
46✔
84
    end
85

86
    def primary_key_string
1✔
87
      key_string = options[:primary_key_type]
46✔
88
      ", id: :#{key_string}" if key_string
46✔
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