devise_token_auth 1.1.4 → 1.2.1

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.
Files changed (56) hide show
  1. checksums.yaml +4 -4
  2. data/app/controllers/devise_token_auth/application_controller.rb +17 -0
  3. data/app/controllers/devise_token_auth/concerns/resource_finder.rb +14 -1
  4. data/app/controllers/devise_token_auth/concerns/set_user_by_token.rb +45 -8
  5. data/app/controllers/devise_token_auth/confirmations_controller.rb +8 -4
  6. data/app/controllers/devise_token_auth/omniauth_callbacks_controller.rb +8 -4
  7. data/app/controllers/devise_token_auth/passwords_controller.rb +10 -2
  8. data/app/controllers/devise_token_auth/sessions_controller.rb +21 -3
  9. data/app/controllers/devise_token_auth/unlocks_controller.rb +6 -2
  10. data/app/models/devise_token_auth/concerns/active_record_support.rb +0 -2
  11. data/app/models/devise_token_auth/concerns/confirmable_support.rb +2 -1
  12. data/app/models/devise_token_auth/concerns/tokens_serialization.rb +16 -4
  13. data/app/models/devise_token_auth/concerns/user.rb +31 -15
  14. data/app/models/devise_token_auth/concerns/user_omniauth_callbacks.rb +12 -5
  15. data/app/validators/devise_token_auth_email_validator.rb +10 -2
  16. data/app/views/devise_token_auth/omniauth_external_window.html.erb +1 -1
  17. data/config/locales/en.yml +3 -0
  18. data/config/locales/ja.yml +12 -0
  19. data/lib/devise_token_auth/blacklist.rb +5 -1
  20. data/lib/devise_token_auth/controllers/helpers.rb +5 -9
  21. data/lib/devise_token_auth/engine.rb +11 -2
  22. data/lib/devise_token_auth/rails/routes.rb +17 -12
  23. data/lib/devise_token_auth/version.rb +1 -1
  24. data/lib/generators/devise_token_auth/install_generator.rb +1 -1
  25. data/lib/generators/devise_token_auth/templates/devise_token_auth.rb +3 -0
  26. data/lib/generators/devise_token_auth/templates/devise_token_auth_create_users.rb.erb +1 -1
  27. data/test/controllers/demo_mang_controller_test.rb +37 -8
  28. data/test/controllers/demo_user_controller_test.rb +37 -8
  29. data/test/controllers/devise_token_auth/confirmations_controller_test.rb +100 -19
  30. data/test/controllers/devise_token_auth/omniauth_callbacks_controller_test.rb +2 -2
  31. data/test/controllers/devise_token_auth/passwords_controller_test.rb +73 -21
  32. data/test/controllers/devise_token_auth/registrations_controller_test.rb +28 -15
  33. data/test/controllers/devise_token_auth/sessions_controller_test.rb +39 -10
  34. data/test/controllers/devise_token_auth/token_validations_controller_test.rb +41 -1
  35. data/test/controllers/devise_token_auth/unlocks_controller_test.rb +44 -5
  36. data/test/controllers/overrides/confirmations_controller_test.rb +1 -1
  37. data/test/dummy/app/views/layouts/application.html.erb +0 -2
  38. data/test/dummy/config/application.rb +0 -1
  39. data/test/dummy/config/environments/development.rb +0 -10
  40. data/test/dummy/config/environments/production.rb +0 -16
  41. data/test/dummy/db/schema.rb +5 -5
  42. data/test/dummy/tmp/generators/app/models/user.rb +11 -0
  43. data/test/dummy/tmp/generators/config/initializers/devise_token_auth.rb +60 -0
  44. data/test/dummy/tmp/generators/db/migrate/20220822003050_devise_token_auth_create_users.rb +49 -0
  45. data/test/lib/devise_token_auth/blacklist_test.rb +11 -3
  46. data/test/lib/devise_token_auth/rails/custom_routes_test.rb +29 -0
  47. data/test/lib/devise_token_auth/rails/routes_test.rb +87 -0
  48. data/test/lib/generators/devise_token_auth/install_generator_test.rb +1 -1
  49. data/test/lib/generators/devise_token_auth/install_generator_with_namespace_test.rb +1 -1
  50. data/test/models/concerns/tokens_serialization_test.rb +39 -5
  51. data/test/models/user_test.rb +22 -0
  52. data/test/test_helper.rb +35 -4
  53. metadata +16 -26
  54. data/test/dummy/config/initializers/assets.rb +0 -10
  55. data/test/dummy/tmp/generators/app/views/devise/mailer/confirmation_instructions.html.erb +0 -5
  56. data/test/dummy/tmp/generators/app/views/devise/mailer/reset_password_instructions.html.erb +0 -8
@@ -17,11 +17,12 @@ class DeviseTokenAuth::SessionsControllerTest < ActionController::TestCase
17
17
 
18
18
  describe 'success' do
19
19
  before do
20
- post :create,
21
- params: {
22
- email: @existing_user.email,
23
- password: @existing_user.password
24
- }
20
+ @user_session_params = {
21
+ email: @existing_user.email,
22
+ password: @existing_user.password
23
+ }
24
+
25
+ post :create, params: @user_session_params
25
26
 
26
27
  @resource = assigns(:resource)
27
28
  @data = JSON.parse(response.body)
@@ -35,17 +36,27 @@ class DeviseTokenAuth::SessionsControllerTest < ActionController::TestCase
35
36
  assert_equal @existing_user.email, @data['data']['email']
36
37
  end
37
38
 
39
+ describe 'using auth cookie' do
40
+ before do
41
+ DeviseTokenAuth.cookie_enabled = true
42
+ end
43
+
44
+ test 'request should return auth cookie' do
45
+ post :create, params: @user_session_params
46
+ assert response.cookies[DeviseTokenAuth.cookie_name]
47
+ end
48
+
49
+ after do
50
+ DeviseTokenAuth.cookie_enabled = false
51
+ end
52
+ end
53
+
38
54
  describe "with multiple clients and headers don't change in each request" do
39
55
  before do
40
56
  # Set the max_number_of_devices to a lower number
41
57
  # to expedite tests! (Default is 10)
42
58
  DeviseTokenAuth.max_number_of_devices = 2
43
59
  DeviseTokenAuth.change_headers_on_each_request = false
44
-
45
- @user_session_params = {
46
- email: @existing_user.email,
47
- password: @existing_user.password
48
- }
49
60
  end
50
61
 
51
62
  test 'should limit the maximum number of concurrent devices' do
@@ -159,6 +170,24 @@ class DeviseTokenAuth::SessionsControllerTest < ActionController::TestCase
159
170
  test 'session was destroyed' do
160
171
  assert_equal true, @controller.reset_session_called
161
172
  end
173
+
174
+ describe 'using auth cookie' do
175
+ before do
176
+ DeviseTokenAuth.cookie_enabled = true
177
+ @auth_token = @existing_user.create_new_auth_token
178
+ @controller.send(:cookies)[DeviseTokenAuth.cookie_name] = { value: @auth_token.to_json }
179
+ end
180
+
181
+ test 'auth cookie was destroyed' do
182
+ assert_equal @auth_token.to_json, @controller.send(:cookies)[DeviseTokenAuth.cookie_name] # sanity check
183
+ delete :destroy, format: :json
184
+ assert_nil @controller.send(:cookies)[DeviseTokenAuth.cookie_name]
185
+ end
186
+
187
+ after do
188
+ DeviseTokenAuth.cookie_enabled = false
189
+ end
190
+ end
162
191
  end
163
192
 
164
193
  describe 'unauthed user sign out' do
@@ -18,11 +18,51 @@ class DeviseTokenAuth::TokenValidationsControllerTest < ActionDispatch::Integrat
18
18
  @token = @auth_headers['access-token']
19
19
  @client_id = @auth_headers['client']
20
20
  @expiry = @auth_headers['expiry']
21
-
21
+ @authorization_header = @auth_headers.slice('Authorization')
22
22
  # ensure that request is not treated as batch request
23
23
  age_token(@resource, @client_id)
24
24
  end
25
25
 
26
+ describe 'using only Authorization header' do
27
+ describe 'using valid Authorization header' do
28
+ before do
29
+ get '/auth/validate_token', params: {}, headers: @authorization_header
30
+ end
31
+
32
+ test 'token valid' do
33
+ assert_equal 200, response.status
34
+ end
35
+ end
36
+
37
+ describe 'using invalid Authorization header' do
38
+ describe 'with invalid base64' do
39
+ before do
40
+ get '/auth/validate_token', params: {}, headers: {'Authorization': 'Bearer invalidtoken=='}
41
+ end
42
+
43
+ test 'returns access denied' do
44
+ assert_equal 401, response.status
45
+ end
46
+ end
47
+
48
+ describe 'with valid base64' do
49
+ before do
50
+ valid_base64 = Base64.strict_encode64({
51
+ "access-token": 'invalidtoken',
52
+ "token-type": 'Bearer',
53
+ "client": 'client',
54
+ "expiry": '1234567'
55
+ }.to_json)
56
+ get '/auth/validate_token', params: {}, headers: {'Authorization': "Bearer #{valid_base64}"}
57
+ end
58
+
59
+ test 'returns access denied' do
60
+ assert_equal 401, response.status
61
+ end
62
+ end
63
+ end
64
+ end
65
+
26
66
  describe 'vanilla user' do
27
67
  before do
28
68
  get '/auth/validate_token', params: {}, headers: @auth_headers
@@ -57,7 +57,7 @@ class DeviseTokenAuth::UnlocksControllerTest < ActionController::TestCase
57
57
  end
58
58
 
59
59
  describe 'request unlock' do
60
- describe 'unknown user should return 404' do
60
+ describe 'without paranoid mode' do
61
61
  before do
62
62
  post :create, params: { email: 'chester@cheet.ah' }
63
63
  @data = JSON.parse(response.body)
@@ -68,13 +68,32 @@ class DeviseTokenAuth::UnlocksControllerTest < ActionController::TestCase
68
68
 
69
69
  test 'errors should be returned' do
70
70
  assert @data['errors']
71
- assert_equal @data['errors'],
72
- [I18n.t('devise_token_auth.passwords.user_not_found',
73
- email: 'chester@cheet.ah')]
71
+ assert_equal @data['errors'], [I18n.t('devise_token_auth.unlocks.user_not_found',
72
+ email: 'chester@cheet.ah')]
74
73
  end
75
74
  end
76
75
 
77
- describe 'successfully requested unlock' do
76
+ describe 'with paranoid mode' do
77
+ before do
78
+ swap Devise, paranoid: true do
79
+ post :create, params: { email: 'chester@cheet.ah' }
80
+ @data = JSON.parse(response.body)
81
+ end
82
+ end
83
+
84
+ test 'should always return success' do
85
+ assert_equal 200, response.status
86
+ end
87
+
88
+ test 'errors should not be returned' do
89
+ assert @data['success']
90
+ assert_equal \
91
+ @data['message'],
92
+ I18n.t('devise_token_auth.unlocks.sended_paranoid')
93
+ end
94
+ end
95
+
96
+ describe 'successfully requested unlock without paranoid mode' do
78
97
  before do
79
98
  post :create, params: { email: @resource.email }
80
99
 
@@ -86,6 +105,26 @@ class DeviseTokenAuth::UnlocksControllerTest < ActionController::TestCase
86
105
  end
87
106
  end
88
107
 
108
+ describe 'successfully requested unlock with paranoid mode' do
109
+ before do
110
+ swap Devise, paranoid: true do
111
+ post :create, params: { email: @resource.email }
112
+ @data = JSON.parse(response.body)
113
+ end
114
+ end
115
+
116
+ test 'should always return success' do
117
+ assert_equal 200, response.status
118
+ end
119
+
120
+ test 'errors should not be returned' do
121
+ assert @data['success']
122
+ assert_equal \
123
+ @data['message'],
124
+ I18n.t('devise_token_auth.unlocks.sended_paranoid')
125
+ end
126
+ end
127
+
89
128
  describe 'case-sensitive email' do
90
129
  before do
91
130
  post :create, params: { email: @resource.email }
@@ -38,7 +38,7 @@ class Overrides::ConfirmationsControllerTest < ActionDispatch::IntegrationTest
38
38
  override_proof_str = '(^^,)'
39
39
 
40
40
  # ensure present in redirect URL
41
- override_proof_param = URI.unescape(response.headers['Location']
41
+ override_proof_param = CGI.unescape(response.headers['Location']
42
42
  .match(/override_proof=([^&]*)&/)[1])
43
43
 
44
44
  assert_equal override_proof_str, override_proof_param
@@ -2,8 +2,6 @@
2
2
  <html>
3
3
  <head>
4
4
  <title>Dummy</title>
5
- <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %>
6
- <%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
7
5
  <%= csrf_meta_tags %>
8
6
  </head>
9
7
  <body>
@@ -4,7 +4,6 @@ require File.expand_path('boot', __dir__)
4
4
 
5
5
  require 'action_controller/railtie'
6
6
  require 'action_mailer/railtie'
7
- require 'sprockets/railtie'
8
7
  require 'rails/generators'
9
8
  require 'rack/cors'
10
9
 
@@ -29,16 +29,6 @@ Rails.application.configure do
29
29
  # Raise an error on page load if there are pending migrations.
30
30
  config.active_record.migration_error = :page_load
31
31
 
32
- # Debug mode disables concatenation and preprocessing of assets.
33
- # This option may cause significant delays in view rendering with a large
34
- # number of complex assets.
35
- config.assets.debug = true
36
-
37
- # Adds additional error checking when serving assets at runtime.
38
- # Checks for improperly declared sprockets dependencies.
39
- # Raises helpful error messages.
40
- config.assets.raise_runtime_errors = true
41
-
42
32
  # Raises error for missing translations
43
33
  # config.action_view.raise_on_missing_translations = true
44
34
 
@@ -24,18 +24,6 @@ Rails.application.configure do
24
24
  # Disable Rails's static asset server (Apache or nginx will already do this).
25
25
  config.serve_static_files = false
26
26
 
27
- # Compress JavaScripts and CSS.
28
- config.assets.js_compressor = :uglifier
29
- # config.assets.css_compressor = :sass
30
-
31
- # Do not fallback to assets pipeline if a precompiled asset is missed.
32
- config.assets.compile = false
33
-
34
- # Generate digests for assets URLs.
35
- config.assets.digest = true
36
-
37
- # `config.assets.precompile` has moved to config/initializers/assets.rb
38
-
39
27
  # Specifies the header that your server uses for sending files.
40
28
  # config.action_dispatch.x_sendfile_header = "X-Sendfile" # for apache
41
29
  # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for nginx
@@ -58,10 +46,6 @@ Rails.application.configure do
58
46
  # Enable serving of images, stylesheets, and JavaScripts from an asset server.
59
47
  # config.action_controller.asset_host = "http://assets.example.com"
60
48
 
61
- # Precompile additional assets.
62
- # application.js, application.css, and all non-JS/CSS in app/assets folder are already added.
63
- # config.assets.precompile += %w( search.js )
64
-
65
49
  # Ignore bad email addresses and do not raise email delivery errors.
66
50
  # Set this to true and configure the email server for immediate delivery to raise delivery errors.
67
51
  # config.action_mailer.raise_delivery_errors = false
@@ -2,11 +2,11 @@
2
2
  # of editing this file, please use the migrations feature of Active Record to
3
3
  # incrementally modify your database, and then regenerate this schema definition.
4
4
  #
5
- # Note that this schema.rb definition is the authoritative source for your
6
- # database schema. If you need to create the application database on another
7
- # system, you should be using db:schema:load, not running all the migrations
8
- # from scratch. The latter is a flawed and unsustainable approach (the more migrations
9
- # you'll amass, the slower it'll run and the greater likelihood for issues).
5
+ # This file is the source Rails uses to define your schema when running `bin/rails
6
+ # db:schema:load`. When creating a new database, `bin/rails db:schema:load` tends to
7
+ # be faster and is potentially less error prone than running all of your
8
+ # migrations from scratch. Old migrations may fail to apply correctly if those
9
+ # migrations use external dependencies or application code.
10
10
  #
11
11
  # It's strongly recommended that you check this file into your version control system.
12
12
 
@@ -0,0 +1,11 @@
1
+ class User < ApplicationRecord
2
+ # Include default devise modules.
3
+ devise :database_authenticatable, :registerable,
4
+ :recoverable, :rememberable, :trackable, :validatable,
5
+ :confirmable, :omniauthable
6
+ include DeviseTokenAuth::Concerns::User
7
+
8
+ def whatever
9
+ puts 'whatever'
10
+ end
11
+ end
@@ -0,0 +1,60 @@
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
+ # Limiting the token_cost to just 4 in testing will increase the performance of
15
+ # your test suite dramatically. The possible cost value is within range from 4
16
+ # to 31. It is recommended to not use a value more than 10 in other environments.
17
+ config.token_cost = Rails.env.test? ? 4 : 10
18
+
19
+ # Sets the max number of concurrent devices per user, which is 10 by default.
20
+ # After this limit is reached, the oldest tokens will be removed.
21
+ # config.max_number_of_devices = 10
22
+
23
+ # Sometimes it's necessary to make several requests to the API at the same
24
+ # time. In this case, each request in the batch will need to share the same
25
+ # auth token. This setting determines how far apart the requests can be while
26
+ # still using the same auth token.
27
+ # config.batch_request_buffer_throttle = 5.seconds
28
+
29
+ # This route will be the prefix for all oauth2 redirect callbacks. For
30
+ # example, using the default '/omniauth', the github oauth2 provider will
31
+ # redirect successful authentications to '/omniauth/github/callback'
32
+ # config.omniauth_prefix = "/omniauth"
33
+
34
+ # By default sending current password is not needed for the password update.
35
+ # Uncomment to enforce current_password param to be checked before all
36
+ # attribute updates. Set it to :password if you want it to be checked only if
37
+ # password is updated.
38
+ # config.check_current_password_before_update = :attributes
39
+
40
+ # By default we will use callbacks for single omniauth.
41
+ # It depends on fields like email, provider and uid.
42
+ # config.default_callbacks = true
43
+
44
+ # Makes it possible to change the headers names
45
+ # config.headers_names = {:'access-token' => 'access-token',
46
+ # :'client' => 'client',
47
+ # :'expiry' => 'expiry',
48
+ # :'uid' => 'uid',
49
+ # :'token-type' => 'token-type' }
50
+
51
+ # By default, only Bearer Token authentication is implemented out of the box.
52
+ # If, however, you wish to integrate with legacy Devise authentication, you can
53
+ # do so by enabling this flag. NOTE: This feature is highly experimental!
54
+ # config.enable_standard_devise_support = false
55
+
56
+ # By default DeviseTokenAuth will not send confirmation email, even when including
57
+ # devise confirmable module. If you want to use devise confirmable module and
58
+ # send email, set it to true. (This is a setting for compatibility)
59
+ # config.send_confirmation_email = true
60
+ end
@@ -0,0 +1,49 @@
1
+ class DeviseTokenAuthCreateUsers < ActiveRecord::Migration[5.2]
2
+ def change
3
+
4
+ create_table(: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
+ ## Confirmable
21
+ t.string :confirmation_token
22
+ t.datetime :confirmed_at
23
+ t.datetime :confirmation_sent_at
24
+ t.string :unconfirmed_email # Only if using reconfirmable
25
+
26
+ ## Lockable
27
+ # t.integer :failed_attempts, :default => 0, :null => false # Only if lock strategy is :failed_attempts
28
+ # t.string :unlock_token # Only if unlock strategy is :email or :both
29
+ # t.datetime :locked_at
30
+
31
+ ## User Info
32
+ t.string :name
33
+ t.string :nickname
34
+ t.string :image
35
+ t.string :email
36
+
37
+ ## Tokens
38
+ t.text :tokens
39
+
40
+ t.timestamps
41
+ end
42
+
43
+ add_index :users, :email, unique: true
44
+ add_index :users, [:uid, :provider], unique: true
45
+ add_index :users, :reset_password_token, unique: true
46
+ add_index :users, :confirmation_token, unique: true
47
+ # add_index :users, :unlock_token, unique: true
48
+ end
49
+ end
@@ -3,9 +3,17 @@
3
3
  require 'test_helper'
4
4
 
5
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)
6
+ if defined? Devise::Models::Authenticatable::UNSAFE_ATTRIBUTES_FOR_SERIALIZATION
7
+ describe Devise::Models::Authenticatable::UNSAFE_ATTRIBUTES_FOR_SERIALIZATION do
8
+ test 'should include :tokens' do
9
+ assert Devise::Models::Authenticatable::UNSAFE_ATTRIBUTES_FOR_SERIALIZATION.include?(:tokens)
10
+ end
11
+ end
12
+ else
13
+ describe Devise::Models::Authenticatable::BLACKLIST_FOR_SERIALIZATION do
14
+ test 'should include :tokens' do
15
+ assert Devise::Models::Authenticatable::BLACKLIST_FOR_SERIALIZATION.include?(:tokens)
16
+ end
9
17
  end
10
18
  end
11
19
  end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'test_helper'
4
+
5
+ class DeviseTokenAuth::CustomRoutesTest < ActiveSupport::TestCase
6
+ after do
7
+ Rails.application.reload_routes!
8
+ end
9
+ test 'custom controllers' do
10
+ class ActionDispatch::Routing::Mapper
11
+ include Mocha::ParameterMatchers
12
+ end
13
+ Rails.application.routes.draw do
14
+ self.expects(:devise_for).with(
15
+ :users,
16
+ has_entries(
17
+ controllers: has_entries(
18
+ invitations: "custom/invitations", foo: "custom/foo"
19
+ )
20
+ )
21
+ )
22
+
23
+ mount_devise_token_auth_for 'User', at: 'my_custom_users', controllers: {
24
+ invitations: 'custom/invitations',
25
+ foo: 'custom/foo'
26
+ }
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,87 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'test_helper'
4
+
5
+ # Needed for MiniTest to start a controller test so we can use assert_recognizes
6
+ class DeviseTokenAuth::RoutesTestController < DeviseTokenAuth::ApplicationController
7
+ end
8
+
9
+ class DeviseTokenAuth::RoutesTest < ActionController::TestCase
10
+ self.controller_class = DeviseTokenAuth::RoutesTestController
11
+ before do
12
+ Rails.application.routes.draw do
13
+ mount_devise_token_auth_for 'User', at: 'my_custom_users', controllers: {
14
+ invitations: 'custom/invitations',
15
+ foo: 'custom/foo'
16
+ }
17
+ end
18
+ end
19
+
20
+ after do
21
+ Rails.application.reload_routes!
22
+ end
23
+
24
+ test 'map new user session' do
25
+ assert_recognizes({controller: 'devise_token_auth/sessions', action: 'new'}, {path: 'my_custom_users/sign_in', method: :get})
26
+ end
27
+
28
+ test 'map create user session' do
29
+ assert_recognizes({controller: 'devise_token_auth/sessions', action: 'create'}, {path: 'my_custom_users/sign_in', method: :post})
30
+ end
31
+
32
+ test 'map destroy user session' do
33
+ assert_recognizes({controller: 'devise_token_auth/sessions', action: 'destroy'}, {path: 'my_custom_users/sign_out', method: :delete})
34
+ end
35
+
36
+ test 'map new user confirmation' do
37
+ assert_recognizes({controller: 'devise_token_auth/confirmations', action: 'new'}, 'my_custom_users/confirmation/new')
38
+ end
39
+
40
+ test 'map create user confirmation' do
41
+ assert_recognizes({controller: 'devise_token_auth/confirmations', action: 'create'}, {path: 'my_custom_users/confirmation', method: :post})
42
+ end
43
+
44
+ test 'map show user confirmation' do
45
+ assert_recognizes({controller: 'devise_token_auth/confirmations', action: 'show'}, {path: 'my_custom_users/confirmation', method: :get})
46
+ end
47
+
48
+ test 'map new user password' do
49
+ assert_recognizes({controller: 'devise_token_auth/passwords', action: 'new'}, 'my_custom_users/password/new')
50
+ end
51
+
52
+ test 'map create user password' do
53
+ assert_recognizes({controller: 'devise_token_auth/passwords', action: 'create'}, {path: 'my_custom_users/password', method: :post})
54
+ end
55
+
56
+ test 'map edit user password' do
57
+ assert_recognizes({controller: 'devise_token_auth/passwords', action: 'edit'}, 'my_custom_users/password/edit')
58
+ end
59
+
60
+ test 'map update user password' do
61
+ assert_recognizes({controller: 'devise_token_auth/passwords', action: 'update'}, {path: 'my_custom_users/password', method: :put})
62
+ end
63
+
64
+ test 'map new user registration' do
65
+ assert_recognizes({controller: 'devise_token_auth/registrations', action: 'new'}, 'my_custom_users/sign_up')
66
+ end
67
+
68
+ test 'map create user registration' do
69
+ assert_recognizes({controller: 'devise_token_auth/registrations', action: 'create'}, {path: 'my_custom_users', method: :post})
70
+ end
71
+
72
+ test 'map edit user registration' do
73
+ assert_recognizes({controller: 'devise_token_auth/registrations', action: 'edit'}, {path: 'my_custom_users/edit', method: :get})
74
+ end
75
+
76
+ test 'map update user registration' do
77
+ assert_recognizes({controller: 'devise_token_auth/registrations', action: 'update'}, {path: 'my_custom_users', method: :put})
78
+ end
79
+
80
+ test 'map destroy user registration' do
81
+ assert_recognizes({controller: 'devise_token_auth/registrations', action: 'destroy'}, {path: 'my_custom_users', method: :delete})
82
+ end
83
+
84
+ test 'map cancel user registration' do
85
+ assert_recognizes({controller: 'devise_token_auth/registrations', action: 'cancel'}, {path: 'my_custom_users/cancel', method: :get})
86
+ end
87
+ end
@@ -70,7 +70,7 @@ module DeviseTokenAuth
70
70
  case DEVISE_TOKEN_AUTH_ORM
71
71
  when :active_record
72
72
  # account for rails version 5
73
- active_record_needle = (Rails::VERSION::MAJOR == 5) ? 'ApplicationRecord' : 'ActiveRecord::Base'
73
+ active_record_needle = (Rails::VERSION::MAJOR >= 5) ? 'ApplicationRecord' : 'ActiveRecord::Base'
74
74
 
75
75
  @f = File.open(@fname, 'w') do |f|
76
76
  f.write <<-RUBY
@@ -75,7 +75,7 @@ module DeviseTokenAuth
75
75
  case DEVISE_TOKEN_AUTH_ORM
76
76
  when :active_record
77
77
  # account for rails version 5
78
- active_record_needle = (Rails::VERSION::MAJOR == 5) ? 'ApplicationRecord' : 'ActiveRecord::Base'
78
+ active_record_needle = (Rails::VERSION::MAJOR >= 5) ? 'ApplicationRecord' : 'ActiveRecord::Base'
79
79
 
80
80
  @f = File.open(@fname, 'w') do |f|
81
81
  f.write <<-RUBY
@@ -13,7 +13,6 @@ if DEVISE_TOKEN_AUTH_ORM == :active_record
13
13
 
14
14
  user.tokens
15
15
  end
16
- let(:json) { JSON.generate(tokens) }
17
16
 
18
17
  it 'is defined' do
19
18
  assert_equal(ts.present?, true)
@@ -21,6 +20,9 @@ if DEVISE_TOKEN_AUTH_ORM == :active_record
21
20
  end
22
21
 
23
22
  describe '.load(json)' do
23
+
24
+ let(:json) { JSON.generate(tokens) }
25
+
24
26
  let(:default) { {} }
25
27
 
26
28
  it 'is defined' do
@@ -55,16 +57,48 @@ if DEVISE_TOKEN_AUTH_ORM == :active_record
55
57
  assert_equal(ts.dump({}), '{}')
56
58
  end
57
59
 
58
- it 'deserialize tokens' do
59
- assert_equal(ts.dump(tokens), json)
60
- end
61
-
62
60
  it 'removes nil values' do
63
61
  new_tokens = tokens.dup
64
62
  new_tokens[new_tokens.first[0]][:kos] = nil
65
63
 
66
64
  assert_equal(ts.dump(tokens), ts.dump(new_tokens))
67
65
  end
66
+
67
+ describe 'updated_at' do
68
+ before do
69
+ @default_format = ::Time::DATE_FORMATS[:default]
70
+ ::Time::DATE_FORMATS[:default] = 'imprecise format'
71
+ end
72
+
73
+ after do
74
+ ::Time::DATE_FORMATS[:default] = @default_format
75
+ end
76
+
77
+ def updated_ats(tokens)
78
+ tokens.
79
+ values.
80
+ flat_map do |token|
81
+ [:updated_at, 'updated_at'].map do |key|
82
+ token[key]
83
+ end
84
+ end.
85
+ compact
86
+ end
87
+
88
+ it 'is defined' do
89
+ refute_empty updated_ats(tokens)
90
+ end
91
+
92
+ it 'uses iso8601' do
93
+ updated_ats(JSON.parse(ts.dump(tokens))).each do |updated_at|
94
+ Time.strptime(updated_at, '%Y-%m-%dT%H:%M:%SZ')
95
+ end
96
+ end
97
+
98
+ it 'does not rely on Time#to_s' do
99
+ refute_includes(updated_ats(tokens), 'imprecise format')
100
+ end
101
+ end
68
102
  end
69
103
  end
70
104
  end