devise_token_auth 1.0.0 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of devise_token_auth might be problematic. Click here for more details.

Files changed (74) hide show
  1. checksums.yaml +5 -5
  2. data/README.md +2 -2
  3. data/app/controllers/devise_token_auth/application_controller.rb +0 -1
  4. data/app/controllers/devise_token_auth/concerns/resource_finder.rb +11 -12
  5. data/app/controllers/devise_token_auth/concerns/set_user_by_token.rb +15 -28
  6. data/app/controllers/devise_token_auth/confirmations_controller.rb +14 -19
  7. data/app/controllers/devise_token_auth/omniauth_callbacks_controller.rb +46 -21
  8. data/app/controllers/devise_token_auth/passwords_controller.rb +15 -19
  9. data/app/controllers/devise_token_auth/registrations_controller.rb +31 -39
  10. data/app/controllers/devise_token_auth/unlocks_controller.rb +1 -1
  11. data/app/models/devise_token_auth/concerns/active_record_support.rb +34 -0
  12. data/app/models/devise_token_auth/concerns/mongoid_support.rb +19 -0
  13. data/app/models/devise_token_auth/concerns/user.rb +9 -23
  14. data/app/models/devise_token_auth/concerns/user_omniauth_callbacks.rb +2 -2
  15. data/app/validators/{email_validator.rb → devise_token_auth/email_validator.rb} +1 -1
  16. data/config/locales/he.yml +50 -0
  17. data/config/locales/ja.yml +1 -1
  18. data/lib/devise_token_auth.rb +5 -3
  19. data/lib/devise_token_auth/blacklist.rb +2 -0
  20. data/lib/devise_token_auth/version.rb +1 -1
  21. data/lib/generators/devise_token_auth/install_generator.rb +3 -87
  22. data/lib/generators/devise_token_auth/install_generator_helpers.rb +98 -0
  23. data/lib/generators/devise_token_auth/install_mongoid_generator.rb +46 -0
  24. data/lib/generators/devise_token_auth/templates/devise_token_auth_create_users.rb.erb +0 -7
  25. data/lib/generators/devise_token_auth/templates/user_mongoid.rb.erb +56 -0
  26. data/test/controllers/custom/custom_confirmations_controller_test.rb +1 -1
  27. data/test/controllers/devise_token_auth/confirmations_controller_test.rb +41 -20
  28. data/test/controllers/devise_token_auth/omniauth_callbacks_controller_test.rb +2 -0
  29. data/test/controllers/devise_token_auth/passwords_controller_test.rb +115 -94
  30. data/test/controllers/devise_token_auth/registrations_controller_test.rb +31 -4
  31. data/test/controllers/devise_token_auth/sessions_controller_test.rb +0 -38
  32. data/test/controllers/devise_token_auth/token_validations_controller_test.rb +2 -1
  33. data/test/dummy/app/{models → active_record}/lockable_user.rb +0 -0
  34. data/test/dummy/app/{models → active_record}/mang.rb +0 -0
  35. data/test/dummy/app/{models → active_record}/only_email_user.rb +0 -0
  36. data/test/dummy/app/{models → active_record}/scoped_user.rb +2 -2
  37. data/test/dummy/app/{models → active_record}/unconfirmable_user.rb +1 -2
  38. data/test/dummy/app/{models → active_record}/unregisterable_user.rb +3 -3
  39. data/test/dummy/app/active_record/user.rb +6 -0
  40. data/test/dummy/app/controllers/overrides/sessions_controller.rb +1 -1
  41. data/test/dummy/app/models/{user.rb → concerns/favorite_color.rb} +7 -8
  42. data/test/dummy/app/mongoid/lockable_user.rb +38 -0
  43. data/test/dummy/app/mongoid/mang.rb +46 -0
  44. data/test/dummy/app/mongoid/only_email_user.rb +33 -0
  45. data/test/dummy/app/mongoid/scoped_user.rb +50 -0
  46. data/test/dummy/app/mongoid/unconfirmable_user.rb +44 -0
  47. data/test/dummy/app/mongoid/unregisterable_user.rb +47 -0
  48. data/test/dummy/app/mongoid/user.rb +49 -0
  49. data/test/dummy/config/application.rb +23 -1
  50. data/test/dummy/config/boot.rb +4 -0
  51. data/test/dummy/config/initializers/devise.rb +12 -0
  52. data/test/dummy/db/migrate/20140715061447_devise_token_auth_create_users.rb +0 -7
  53. data/test/dummy/db/migrate/20140715061805_devise_token_auth_create_mangs.rb +0 -7
  54. data/test/dummy/db/migrate/20141222035835_devise_token_auth_create_only_email_users.rb +0 -7
  55. data/test/dummy/db/migrate/20141222053502_devise_token_auth_create_unregisterable_users.rb +0 -7
  56. data/test/dummy/db/migrate/20150708104536_devise_token_auth_create_unconfirmable_users.rb +0 -7
  57. data/test/dummy/db/migrate/20160103235141_devise_token_auth_create_scoped_users.rb +0 -7
  58. data/test/dummy/db/migrate/20160629184441_devise_token_auth_create_lockable_users.rb +0 -7
  59. data/test/dummy/db/schema.rb +1 -28
  60. data/test/dummy/tmp/generators/app/models/azpire/v1/human_resource/user.rb +9 -0
  61. data/test/dummy/tmp/generators/config/initializers/devise_token_auth.rb +50 -0
  62. data/test/dummy/tmp/generators/config/routes.rb +4 -0
  63. data/test/dummy/tmp/generators/db/migrate/20190112150327_devise_token_auth_create_azpire_v1_human_resource_users.rb +56 -0
  64. data/test/lib/devise_token_auth/blacklist_test.rb +11 -0
  65. data/test/lib/generators/devise_token_auth/install_generator_test.rb +51 -31
  66. data/test/lib/generators/devise_token_auth/install_generator_with_namespace_test.rb +51 -31
  67. data/test/models/concerns/mongoid_support_test.rb +31 -0
  68. data/test/models/only_email_user_test.rb +0 -8
  69. data/test/models/user_test.rb +1 -1
  70. data/test/test_helper.rb +12 -2
  71. metadata +91 -27
  72. data/config/initializers/devise.rb +0 -198
  73. data/test/dummy/tmp/generators/app/views/devise/mailer/confirmation_instructions.html.erb +0 -5
  74. data/test/dummy/tmp/generators/app/views/devise/mailer/reset_password_instructions.html.erb +0 -8
@@ -0,0 +1,49 @@
1
+ # frozen_string_literal: true
2
+
3
+ class User
4
+ include Mongoid::Document
5
+ include Mongoid::Timestamps
6
+ include Mongoid::Locker
7
+
8
+ field :locker_locked_at, type: Time
9
+ field :locker_locked_until, type: Time
10
+
11
+ locker locked_at_field: :locker_locked_at,
12
+ locked_until_field: :locker_locked_until
13
+
14
+ ## User Info
15
+ field :name, type: String
16
+ field :nickname, type: String
17
+ field :image, type: String
18
+ field :favorite_color, type: String
19
+ field :operating_thetan, type: Integer
20
+
21
+ ## Database authenticatable
22
+ field :email, type: String, default: ''
23
+ field :encrypted_password, type: String, default: ''
24
+
25
+ ## Recoverable
26
+ field :reset_password_token, type: String
27
+ field :reset_password_sent_at, type: Time
28
+ field :reset_password_redirect_url, type: String
29
+ field :allow_password_change, type: Boolean, default: false
30
+
31
+ ## Rememberable
32
+ field :remember_created_at, type: Time
33
+
34
+ ## Confirmable
35
+ field :confirmation_token, type: String
36
+ field :confirmed_at, type: Time
37
+ field :confirmation_sent_at, type: Time
38
+ field :unconfirmed_email, type: String # Only if using reconfirmable
39
+
40
+ ## Required
41
+ field :provider, type: String
42
+ field :uid, type: String, default: ''
43
+
44
+ ## Tokens
45
+ field :tokens, type: Hash, default: {}
46
+
47
+ include DeviseTokenAuth::Concerns::User
48
+ include FavoriteColor
49
+ end
@@ -2,10 +2,25 @@
2
2
 
3
3
  require File.expand_path('boot', __dir__)
4
4
 
5
+ require 'action_controller/railtie'
6
+ require 'action_mailer/railtie'
7
+ require 'sprockets/railtie'
8
+ require 'rails/generators'
5
9
  require 'rack/cors'
6
- require 'rails/all'
7
10
 
8
11
  Bundler.require(*Rails.groups)
12
+
13
+ begin
14
+ case DEVISE_TOKEN_AUTH_ORM
15
+ when :active_record
16
+ require 'active_record/railtie'
17
+ when :mongoid
18
+ require 'mongoid'
19
+ require 'mongoid-locker'
20
+ end
21
+ rescue LoadError
22
+ end
23
+
9
24
  require 'devise_token_auth'
10
25
 
11
26
  module Dummy
@@ -22,5 +37,12 @@ module Dummy
22
37
  # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
23
38
  # config.i18n.default_locale = :de
24
39
  config.autoload_paths << Rails.root.join('lib')
40
+ config.autoload_paths += ["#{config.root}/app/#{DEVISE_TOKEN_AUTH_ORM}"]
41
+
42
+ if DEVISE_TOKEN_AUTH_ORM == :mongoid
43
+ Mongoid.configure do |config|
44
+ config.load! Rails.root.join('./config/mongoid.yml')
45
+ end
46
+ end
25
47
  end
26
48
  end
@@ -1,5 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ unless defined?(DEVISE_TOKEN_AUTH_ORM)
4
+ DEVISE_TOKEN_AUTH_ORM = (ENV["DEVISE_TOKEN_AUTH_ORM"] || :active_record).to_sym
5
+ end
6
+
3
7
  # Set up gems listed in the Gemfile.
4
8
  ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../../Gemfile', __dir__)
5
9
 
@@ -2,4 +2,16 @@
2
2
 
3
3
  Devise.setup do |config|
4
4
  config.authentication_keys = [:email, :nickname]
5
+
6
+ # ==> Mailer Configuration
7
+ # Configure the e-mail address which will be shown in Devise::Mailer,
8
+ # note that it will be overwritten if you use your own mailer class
9
+ # with default "from" parameter.
10
+ config.mailer_sender = 'no-reply@example.com'
11
+
12
+ # ==> ORM configuration
13
+ # Load and configure the ORM. Supports :active_record (default) and
14
+ # :mongoid (bson_ext recommended) by default. Other ORMs may be
15
+ # available as additional gems.
16
+ require "devise/orm/#{DEVISE_TOKEN_AUTH_ORM}"
5
17
  end
@@ -18,13 +18,6 @@ class DeviseTokenAuthCreateUsers < ActiveRecord::Migration[4.2]
18
18
  ## Rememberable
19
19
  t.datetime :remember_created_at
20
20
 
21
- ## Trackable
22
- t.integer :sign_in_count, default: 0, null: false
23
- t.datetime :current_sign_in_at
24
- t.datetime :last_sign_in_at
25
- t.string :current_sign_in_ip
26
- t.string :last_sign_in_ip
27
-
28
21
  ## Confirmable
29
22
  t.string :confirmation_token
30
23
  t.datetime :confirmed_at
@@ -18,13 +18,6 @@ class DeviseTokenAuthCreateMangs < ActiveRecord::Migration[4.2]
18
18
  ## Rememberable
19
19
  t.datetime :remember_created_at
20
20
 
21
- ## Trackable
22
- t.integer :sign_in_count, default: 0, null: false
23
- t.datetime :current_sign_in_at
24
- t.datetime :last_sign_in_at
25
- t.string :current_sign_in_ip
26
- t.string :last_sign_in_ip
27
-
28
21
  ## Confirmable
29
22
  t.string :confirmation_token
30
23
  t.datetime :confirmed_at
@@ -19,13 +19,6 @@ class DeviseTokenAuthCreateOnlyEmailUsers < ActiveRecord::Migration[4.2]
19
19
  ## Rememberable
20
20
  #t.datetime :remember_created_at
21
21
 
22
- ## Trackable
23
- #t.integer :sign_in_count, :default => 0, :null => false
24
- #t.datetime :current_sign_in_at
25
- #t.datetime :last_sign_in_at
26
- #t.string :current_sign_in_ip
27
- #t.string :last_sign_in_ip
28
-
29
22
  ## Confirmable
30
23
  #t.string :confirmation_token
31
24
  #t.datetime :confirmed_at
@@ -20,13 +20,6 @@ class DeviseTokenAuthCreateUnregisterableUsers < ActiveRecord::Migration[4.2]
20
20
  ## Rememberable
21
21
  t.datetime :remember_created_at
22
22
 
23
- ## Trackable
24
- t.integer :sign_in_count, default: 0, null: false
25
- t.datetime :current_sign_in_at
26
- t.datetime :last_sign_in_at
27
- t.string :current_sign_in_ip
28
- t.string :last_sign_in_ip
29
-
30
23
  ## Confirmable
31
24
  t.string :confirmation_token
32
25
  t.datetime :confirmed_at
@@ -20,13 +20,6 @@ class DeviseTokenAuthCreateUnconfirmableUsers < ActiveRecord::Migration[4.2]
20
20
  ## Rememberable
21
21
  t.datetime :remember_created_at
22
22
 
23
- ## Trackable
24
- t.integer :sign_in_count, default: 0, null: false
25
- t.datetime :current_sign_in_at
26
- t.datetime :last_sign_in_at
27
- t.string :current_sign_in_ip
28
- t.string :last_sign_in_ip
29
-
30
23
  ## Confirmable
31
24
  # t.string :confirmation_token
32
25
  # t.datetime :confirmed_at
@@ -20,13 +20,6 @@ class DeviseTokenAuthCreateScopedUsers < ActiveRecord::Migration[4.2]
20
20
  ## Rememberable
21
21
  t.datetime :remember_created_at
22
22
 
23
- ## Trackable
24
- t.integer :sign_in_count, default: 0, null: false
25
- t.datetime :current_sign_in_at
26
- t.datetime :last_sign_in_at
27
- t.string :current_sign_in_ip
28
- t.string :last_sign_in_ip
29
-
30
23
  ## Confirmable
31
24
  t.string :confirmation_token
32
25
  t.datetime :confirmed_at
@@ -20,13 +20,6 @@ class DeviseTokenAuthCreateLockableUsers < ActiveRecord::Migration[4.2]
20
20
  ## Rememberable
21
21
  # t.datetime :remember_created_at
22
22
 
23
- ## Trackable
24
- # t.integer :sign_in_count, :default => 0, :null => false
25
- # t.datetime :current_sign_in_at
26
- # t.datetime :last_sign_in_at
27
- # t.string :current_sign_in_ip
28
- # t.string :last_sign_in_ip
29
-
30
23
  ## Confirmable
31
24
  # t.string :confirmation_token
32
25
  # t.datetime :confirmed_at
@@ -1,5 +1,3 @@
1
- # frozen_string_literal: true
2
-
3
1
  # This file is auto-generated from the current state of the database. Instead
4
2
  # of editing this file, please use the migrations feature of Active Record to
5
3
  # incrementally modify your database, and then regenerate this schema definition.
@@ -12,7 +10,7 @@
12
10
  #
13
11
  # It's strongly recommended that you check this file into your version control system.
14
12
 
15
- ActiveRecord::Schema.define(version: 20160629184441) do
13
+ ActiveRecord::Schema.define(version: 2016_06_29_184441) do
16
14
 
17
15
  create_table "lockable_users", force: :cascade do |t|
18
16
  t.string "provider", null: false
@@ -41,11 +39,6 @@ ActiveRecord::Schema.define(version: 20160629184441) do
41
39
  t.string "reset_password_redirect_url"
42
40
  t.boolean "allow_password_change", default: false
43
41
  t.datetime "remember_created_at"
44
- t.integer "sign_in_count", default: 0, null: false
45
- t.datetime "current_sign_in_at"
46
- t.datetime "last_sign_in_at"
47
- t.string "current_sign_in_ip"
48
- t.string "last_sign_in_ip"
49
42
  t.string "confirmation_token"
50
43
  t.datetime "confirmed_at"
51
44
  t.datetime "confirmation_sent_at"
@@ -88,11 +81,6 @@ ActiveRecord::Schema.define(version: 20160629184441) do
88
81
  t.datetime "reset_password_sent_at"
89
82
  t.boolean "allow_password_change", default: false
90
83
  t.datetime "remember_created_at"
91
- t.integer "sign_in_count", default: 0, null: false
92
- t.datetime "current_sign_in_at"
93
- t.datetime "last_sign_in_at"
94
- t.string "current_sign_in_ip"
95
- t.string "last_sign_in_ip"
96
84
  t.string "confirmation_token"
97
85
  t.datetime "confirmed_at"
98
86
  t.datetime "confirmation_sent_at"
@@ -117,11 +105,6 @@ ActiveRecord::Schema.define(version: 20160629184441) do
117
105
  t.datetime "reset_password_sent_at"
118
106
  t.boolean "allow_password_change", default: false
119
107
  t.datetime "remember_created_at"
120
- t.integer "sign_in_count", default: 0, null: false
121
- t.datetime "current_sign_in_at"
122
- t.datetime "last_sign_in_at"
123
- t.string "current_sign_in_ip"
124
- t.string "last_sign_in_ip"
125
108
  t.string "name"
126
109
  t.string "nickname"
127
110
  t.string "image"
@@ -142,11 +125,6 @@ ActiveRecord::Schema.define(version: 20160629184441) do
142
125
  t.datetime "reset_password_sent_at"
143
126
  t.boolean "allow_password_change", default: false
144
127
  t.datetime "remember_created_at"
145
- t.integer "sign_in_count", default: 0, null: false
146
- t.datetime "current_sign_in_at"
147
- t.datetime "last_sign_in_at"
148
- t.string "current_sign_in_ip"
149
- t.string "last_sign_in_ip"
150
128
  t.string "confirmation_token"
151
129
  t.datetime "confirmed_at"
152
130
  t.datetime "confirmation_sent_at"
@@ -171,11 +149,6 @@ ActiveRecord::Schema.define(version: 20160629184441) do
171
149
  t.string "reset_password_redirect_url"
172
150
  t.boolean "allow_password_change", default: false
173
151
  t.datetime "remember_created_at"
174
- t.integer "sign_in_count", default: 0, null: false
175
- t.datetime "current_sign_in_at"
176
- t.datetime "last_sign_in_at"
177
- t.string "current_sign_in_ip"
178
- t.string "last_sign_in_ip"
179
152
  t.string "confirmation_token"
180
153
  t.datetime "confirmed_at"
181
154
  t.datetime "confirmation_sent_at"
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Azpire::V1::HumanResource::User < ActiveRecord::Base
4
+ # Include default devise modules. Others available are:
5
+ # :confirmable, :lockable, :timeoutable and :omniauthable
6
+ devise :database_authenticatable, :registerable,
7
+ :recoverable, :rememberable, :trackable, :validatable
8
+ include DeviseTokenAuth::Concerns::User
9
+ end
@@ -0,0 +1,50 @@
1
+ # frozen_string_literal: true
2
+
3
+ DeviseTokenAuth.setup do |config|
4
+ # By default the authorization headers will change after each request. The
5
+ # client is responsible for keeping track of the changing tokens. Change
6
+ # this to false to prevent the Authorization header from changing after
7
+ # each request.
8
+ # config.change_headers_on_each_request = true
9
+
10
+ # By default, users will need to re-authenticate after 2 weeks. This setting
11
+ # determines how long tokens will remain valid after they are issued.
12
+ # config.token_lifespan = 2.weeks
13
+
14
+ # Sets the max number of concurrent devices per user, which is 10 by default.
15
+ # After this limit is reached, the oldest tokens will be removed.
16
+ # config.max_number_of_devices = 10
17
+
18
+ # Sometimes it's necessary to make several requests to the API at the same
19
+ # time. In this case, each request in the batch will need to share the same
20
+ # auth token. This setting determines how far apart the requests can be while
21
+ # still using the same auth token.
22
+ # config.batch_request_buffer_throttle = 5.seconds
23
+
24
+ # This route will be the prefix for all oauth2 redirect callbacks. For
25
+ # example, using the default '/omniauth', the github oauth2 provider will
26
+ # redirect successful authentications to '/omniauth/github/callback'
27
+ # config.omniauth_prefix = "/omniauth"
28
+
29
+ # By default sending current password is not needed for the password update.
30
+ # Uncomment to enforce current_password param to be checked before all
31
+ # attribute updates. Set it to :password if you want it to be checked only if
32
+ # password is updated.
33
+ # config.check_current_password_before_update = :attributes
34
+
35
+ # By default we will use callbacks for single omniauth.
36
+ # It depends on fields like email, provider and uid.
37
+ # config.default_callbacks = true
38
+
39
+ # Makes it possible to change the headers names
40
+ # config.headers_names = {:'access-token' => 'access-token',
41
+ # :'client' => 'client',
42
+ # :'expiry' => 'expiry',
43
+ # :'uid' => 'uid',
44
+ # :'token-type' => 'token-type' }
45
+
46
+ # By default, only Bearer Token authentication is implemented out of the box.
47
+ # If, however, you wish to integrate with legacy Devise authentication, you can
48
+ # do so by enabling this flag. NOTE: This feature is highly experimental!
49
+ # config.enable_standard_devise_support = false
50
+ end
@@ -0,0 +1,4 @@
1
+ Rails.application.routes.draw do
2
+ mount_devise_token_auth_for 'Azpire::V1::HumanResource::User', at: 'auth'
3
+ patch '/chong', to: 'bong#index'
4
+ end
@@ -0,0 +1,56 @@
1
+ class DeviseTokenAuthCreateAzpireV1HumanResourceUsers < ActiveRecord::Migration[5.2]
2
+ def change
3
+
4
+ create_table(:azpire_v1_human_resource_users) do |t|
5
+ ## Required
6
+ t.string :provider, :null => false, :default => "email"
7
+ t.string :uid, :null => false, :default => ""
8
+
9
+ ## Database authenticatable
10
+ t.string :encrypted_password, :null => false, :default => ""
11
+
12
+ ## Recoverable
13
+ t.string :reset_password_token
14
+ t.datetime :reset_password_sent_at
15
+ t.boolean :allow_password_change, :default => false
16
+
17
+ ## Rememberable
18
+ t.datetime :remember_created_at
19
+
20
+ ## Trackable
21
+ t.integer :sign_in_count, :default => 0, :null => false
22
+ t.datetime :current_sign_in_at
23
+ t.datetime :last_sign_in_at
24
+ t.string :current_sign_in_ip
25
+ t.string :last_sign_in_ip
26
+
27
+ ## Confirmable
28
+ t.string :confirmation_token
29
+ t.datetime :confirmed_at
30
+ t.datetime :confirmation_sent_at
31
+ t.string :unconfirmed_email # Only if using reconfirmable
32
+
33
+ ## Lockable
34
+ # t.integer :failed_attempts, :default => 0, :null => false # Only if lock strategy is :failed_attempts
35
+ # t.string :unlock_token # Only if unlock strategy is :email or :both
36
+ # t.datetime :locked_at
37
+
38
+ ## User Info
39
+ t.string :name
40
+ t.string :nickname
41
+ t.string :image
42
+ t.string :email
43
+
44
+ ## Tokens
45
+ t.text :tokens
46
+
47
+ t.timestamps
48
+ end
49
+
50
+ add_index :azpire_v1_human_resource_users, :email, unique: true
51
+ add_index :azpire_v1_human_resource_users, [:uid, :provider], unique: true
52
+ add_index :azpire_v1_human_resource_users, :reset_password_token, unique: true
53
+ add_index :azpire_v1_human_resource_users, :confirmation_token, unique: true
54
+ # add_index :azpire_v1_human_resource_users, :unlock_token, unique: true
55
+ end
56
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'test_helper'
4
+
5
+ class DeviseTokenAuth::BlacklistTest < ActiveSupport::TestCase
6
+ describe Devise::Models::Authenticatable::BLACKLIST_FOR_SERIALIZATION do
7
+ test 'should include :tokens' do
8
+ assert Devise::Models::Authenticatable::BLACKLIST_FOR_SERIALIZATION.include?(:tokens)
9
+ end
10
+ end
11
+ end
@@ -2,11 +2,13 @@
2
2
 
3
3
  require 'test_helper'
4
4
  require 'fileutils'
5
- require 'generators/devise_token_auth/install_generator'
5
+ require 'generators/devise_token_auth/install_generator' if DEVISE_TOKEN_AUTH_ORM == :active_record
6
+ require 'generators/devise_token_auth/install_mongoid_generator' if DEVISE_TOKEN_AUTH_ORM == :mongoid
6
7
 
7
8
  module DeviseTokenAuth
8
9
  class InstallGeneratorTest < Rails::Generators::TestCase
9
- tests InstallGenerator
10
+ tests InstallGenerator if DEVISE_TOKEN_AUTH_ORM == :active_record
11
+ tests InstallMongoidGenerator if DEVISE_TOKEN_AUTH_ORM == :mongoid
10
12
  destination Rails.root.join('tmp/generators')
11
13
 
12
14
  describe 'default values, clean install' do
@@ -26,28 +28,30 @@ module DeviseTokenAuth
26
28
  assert_file 'config/initializers/devise_token_auth.rb'
27
29
  end
28
30
 
29
- test 'migration is created' do
30
- assert_migration 'db/migrate/devise_token_auth_create_users.rb'
31
+ test 'subsequent runs raise no errors' do
32
+ run_generator
31
33
  end
32
34
 
33
- test 'migration file contains rails version' do
34
- if Rails::VERSION::MAJOR >= 5
35
- assert_migration 'db/migrate/devise_token_auth_create_users.rb', /#{Rails::VERSION::MAJOR}.#{Rails::VERSION::MINOR}/
36
- else
35
+ if DEVISE_TOKEN_AUTH_ORM == :active_record
36
+ test 'migration is created' do
37
37
  assert_migration 'db/migrate/devise_token_auth_create_users.rb'
38
38
  end
39
- end
40
39
 
41
- test 'subsequent runs raise no errors' do
42
- run_generator
43
- end
40
+ test 'migration file contains rails version' do
41
+ if Rails::VERSION::MAJOR >= 5
42
+ assert_migration 'db/migrate/devise_token_auth_create_users.rb', /#{Rails::VERSION::MAJOR}.#{Rails::VERSION::MINOR}/
43
+ else
44
+ assert_migration 'db/migrate/devise_token_auth_create_users.rb'
45
+ end
46
+ end
44
47
 
45
- test 'add primary key type with rails 5 when specified in rails generator' do
46
- run_generator %w[--primary_key_type=uuid --force]
47
- if Rails::VERSION::MAJOR >= 5
48
- assert_migration 'db/migrate/devise_token_auth_create_users.rb', /create_table\(:users, id: :uuid\) do/
49
- else
50
- assert_migration 'db/migrate/devise_token_auth_create_users.rb', /create_table\(:users\) do/
48
+ test 'add primary key type with rails 5 when specified in rails generator' do
49
+ run_generator %w[--primary_key_type=uuid --force]
50
+ if Rails::VERSION::MAJOR >= 5
51
+ assert_migration 'db/migrate/devise_token_auth_create_users.rb', /create_table\(:users, id: :uuid\) do/
52
+ else
53
+ assert_migration 'db/migrate/devise_token_auth_create_users.rb', /create_table\(:users\) do/
54
+ end
51
55
  end
52
56
  end
53
57
  end
@@ -63,18 +67,32 @@ module DeviseTokenAuth
63
67
  # make dir if not exists
64
68
  FileUtils.mkdir_p(@dir)
65
69
 
66
- # account for rails version 5
67
- active_record_needle = (Rails::VERSION::MAJOR == 5) ? 'ApplicationRecord' : 'ActiveRecord::Base'
70
+ case DEVISE_TOKEN_AUTH_ORM
71
+ when :active_record
72
+ # account for rails version 5
73
+ active_record_needle = (Rails::VERSION::MAJOR == 5) ? 'ApplicationRecord' : 'ActiveRecord::Base'
68
74
 
69
- @f = File.open(@fname, 'w') do |f|
70
- f.write <<-RUBY
71
- class User < #{active_record_needle}
75
+ @f = File.open(@fname, 'w') do |f|
76
+ f.write <<-RUBY
77
+ class User < #{active_record_needle}
72
78
 
73
- def whatever
74
- puts 'whatever'
79
+ def whatever
80
+ puts 'whatever'
81
+ end
75
82
  end
76
- end
77
- RUBY
83
+ RUBY
84
+ end
85
+ when :mongoid
86
+ @f = File.open(@fname, 'w') do |f|
87
+ f.write <<-'RUBY'
88
+ class User
89
+
90
+ def whatever
91
+ puts 'whatever'
92
+ end
93
+ end
94
+ RUBY
95
+ end
78
96
  end
79
97
 
80
98
  run_generator
@@ -136,10 +154,6 @@ module DeviseTokenAuth
136
154
  run_generator %w[Mang mangs]
137
155
  end
138
156
 
139
- test 'migration is created' do
140
- assert_migration 'db/migrate/devise_token_auth_create_mangs.rb'
141
- end
142
-
143
157
  test 'route method is appended to routes file' do
144
158
  assert_file 'config/routes.rb' do |routes|
145
159
  assert_match(/mount_devise_token_auth_for 'Mang', at: 'mangs'/, routes)
@@ -152,6 +166,12 @@ module DeviseTokenAuth
152
166
  assert_match(/# Define routes for Mang within this block./, routes)
153
167
  end
154
168
  end
169
+
170
+ if DEVISE_TOKEN_AUTH_ORM == :active_record
171
+ test 'migration is created' do
172
+ assert_migration 'db/migrate/devise_token_auth_create_mangs.rb'
173
+ end
174
+ end
155
175
  end
156
176
  end
157
177