devise_jwt_auth 0.1.1 → 0.1.6

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 (88) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +3 -3
  3. data/app/controllers/devise_jwt_auth/application_controller.rb +15 -13
  4. data/app/controllers/devise_jwt_auth/concerns/resource_finder.rb +2 -6
  5. data/app/controllers/devise_jwt_auth/concerns/{set_user_by_jwt_token.rb → set_user_by_token.rb} +23 -19
  6. data/app/controllers/devise_jwt_auth/confirmations_controller.rb +10 -19
  7. data/app/controllers/devise_jwt_auth/omniauth_callbacks_controller.rb +32 -33
  8. data/app/controllers/devise_jwt_auth/passwords_controller.rb +29 -19
  9. data/app/controllers/devise_jwt_auth/refresh_token_controller.rb +4 -1
  10. data/app/controllers/devise_jwt_auth/registrations_controller.rb +40 -21
  11. data/app/controllers/devise_jwt_auth/sessions_controller.rb +21 -21
  12. data/app/controllers/devise_jwt_auth/unlocks_controller.rb +5 -4
  13. data/app/models/devise_jwt_auth/concerns/active_record_support.rb +3 -0
  14. data/app/models/devise_jwt_auth/concerns/confirmable_support.rb +7 -4
  15. data/app/models/devise_jwt_auth/concerns/mongoid_support.rb +3 -0
  16. data/app/models/devise_jwt_auth/concerns/tokens_serialization.rb +4 -1
  17. data/app/models/devise_jwt_auth/concerns/user.rb +18 -9
  18. data/app/models/devise_jwt_auth/concerns/user_omniauth_callbacks.rb +11 -3
  19. data/app/validators/devise_jwt_auth_email_validator.rb +5 -4
  20. data/lib/devise_jwt_auth/blacklist.rb +2 -0
  21. data/lib/devise_jwt_auth/controllers/url_helpers.rb +1 -2
  22. data/lib/devise_jwt_auth/engine.rb +4 -4
  23. data/lib/devise_jwt_auth/rails/routes.rb +35 -24
  24. data/lib/devise_jwt_auth/token_factory.rb +3 -2
  25. data/lib/devise_jwt_auth/url.rb +2 -4
  26. data/lib/devise_jwt_auth/version.rb +1 -1
  27. data/lib/generators/devise_jwt_auth/install_generator.rb +7 -6
  28. data/lib/generators/devise_jwt_auth/install_generator_helpers.rb +27 -6
  29. data/lib/generators/devise_jwt_auth/install_mongoid_generator.rb +3 -2
  30. data/lib/generators/devise_jwt_auth/templates/devise_jwt_auth.rb +15 -16
  31. data/lib/generators/devise_jwt_auth/templates/devise_jwt_auth_create_users.rb.erb +15 -11
  32. data/lib/generators/devise_jwt_auth/templates/user.rb.erb +2 -2
  33. data/test/controllers/custom/custom_confirmations_controller_test.rb +2 -2
  34. data/test/controllers/custom/custom_passwords_controller_test.rb +4 -4
  35. data/test/controllers/custom/custom_refresh_token_controller_test.rb +2 -3
  36. data/test/controllers/custom/custom_registrations_controller_test.rb +2 -2
  37. data/test/controllers/demo_mang_controller_test.rb +206 -210
  38. data/test/controllers/demo_user_controller_test.rb +358 -374
  39. data/test/controllers/devise_jwt_auth/confirmations_controller_test.rb +5 -5
  40. data/test/controllers/devise_jwt_auth/omniauth_callbacks_controller_test.rb +6 -7
  41. data/test/controllers/devise_jwt_auth/passwords_controller_test.rb +11 -13
  42. data/test/controllers/devise_jwt_auth/refresh_token_controller_test.rb +8 -12
  43. data/test/controllers/devise_jwt_auth/registrations_controller_test.rb +23 -25
  44. data/test/controllers/devise_jwt_auth/sessions_controller_test.rb +32 -34
  45. data/test/controllers/devise_jwt_auth/unlocks_controller_test.rb +2 -2
  46. data/test/controllers/overrides/confirmations_controller_test.rb +1 -1
  47. data/test/controllers/overrides/passwords_controller_test.rb +1 -1
  48. data/test/controllers/overrides/refresh_token_controller_test.rb +1 -2
  49. data/test/controllers/overrides/registrations_controller_test.rb +1 -1
  50. data/test/dummy/app/controllers/application_controller.rb +1 -1
  51. data/test/dummy/app/controllers/custom/refresh_token_controller.rb +2 -1
  52. data/test/dummy/app/controllers/custom/registrations_controller.rb +1 -1
  53. data/test/dummy/app/controllers/overrides/confirmations_controller.rb +4 -4
  54. data/test/dummy/app/controllers/overrides/omniauth_callbacks_controller.rb +4 -4
  55. data/test/dummy/app/controllers/overrides/passwords_controller.rb +4 -4
  56. data/test/dummy/app/controllers/overrides/refresh_token_controller.rb +1 -1
  57. data/test/dummy/app/controllers/overrides/registrations_controller.rb +2 -2
  58. data/test/dummy/app/controllers/overrides/sessions_controller.rb +2 -2
  59. data/test/dummy/app/models/concerns/favorite_color.rb +11 -9
  60. data/test/dummy/config.ru +2 -2
  61. data/test/dummy/config/application.rb +1 -0
  62. data/test/dummy/config/boot.rb +1 -1
  63. data/test/dummy/config/environments/test.rb +11 -7
  64. data/test/dummy/config/initializers/figaro.rb +1 -1
  65. data/test/dummy/config/initializers/omniauth.rb +2 -2
  66. data/test/dummy/config/routes.rb +8 -8
  67. data/test/dummy/db/migrate/{20140715061447_devise_token_auth_create_users.rb → 20140715061447_devise_jwt_auth_create_users.rb} +0 -0
  68. data/test/dummy/db/migrate/{20140715061805_devise_token_auth_create_mangs.rb → 20140715061805_devise_jwt_auth_create_mangs.rb} +0 -0
  69. data/test/dummy/db/migrate/{20141222035835_devise_token_auth_create_only_email_users.rb → 20141222035835_devise_jwt_auth_create_only_email_users.rb} +9 -9
  70. data/test/dummy/db/migrate/{20141222053502_devise_token_auth_create_unregisterable_users.rb → 20141222053502_devise_jwt_auth_create_unregisterable_users.rb} +0 -0
  71. data/test/dummy/db/migrate/{20150708104536_devise_token_auth_create_unconfirmable_users.rb → 20150708104536_devise_jwt_auth_create_unconfirmable_users.rb} +0 -0
  72. data/test/dummy/db/migrate/{20160103235141_devise_token_auth_create_scoped_users.rb → 20160103235141_devise_jwt_auth_create_scoped_users.rb} +0 -0
  73. data/test/dummy/db/migrate/{20160629184441_devise_token_auth_create_lockable_users.rb → 20160629184441_devise_jwt_auth_create_lockable_users.rb} +0 -0
  74. data/test/dummy/db/migrate/{20190924101113_devise_token_auth_create_confirmable_users.rb → 20190924101113_devise_jwt_auth_create_confirmable_users.rb} +6 -5
  75. data/test/dummy/db/schema.rb +170 -170
  76. data/test/dummy/tmp/generators/app/controllers/application_controller.rb +6 -0
  77. data/test/dummy/tmp/generators/app/models/user.rb +9 -0
  78. data/test/dummy/tmp/generators/config/initializers/devise_jwt_auth.rb +73 -0
  79. data/test/dummy/tmp/generators/db/migrate/20201006030349_devise_jwt_auth_create_users.rb +54 -0
  80. data/test/factories/users.rb +5 -3
  81. data/test/lib/devise_jwt_auth/token_factory_test.rb +6 -6
  82. data/test/lib/generators/devise_jwt_auth/install_generator_test.rb +3 -20
  83. data/test/lib/generators/devise_jwt_auth/install_generator_with_namespace_test.rb +4 -21
  84. data/test/models/concerns/tokens_serialization_test.rb +68 -68
  85. data/test/models/user_test.rb +35 -37
  86. data/test/support/controllers/routes.rb +7 -5
  87. data/test/test_helper.rb +1 -1
  88. metadata +70 -76
@@ -0,0 +1,6 @@
1
+ class ApplicationController < ActionController::Base
2
+ include DeviseJwtAuth::Concerns::SetUserByToken
3
+ def whatever
4
+ 'whatever'
5
+ end
6
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ class User < ActiveRecord::Base
4
+ # Include default devise modules. Others available are:
5
+ # :confirmable, :lockable, :timeoutable, :trackable and :omniauthable
6
+ devise :database_authenticatable, :registerable,
7
+ :recoverable, :rememberable, :validatable
8
+ include DeviseJwtAuth::Concerns::User
9
+ end
@@ -0,0 +1,73 @@
1
+ # frozen_string_literal: true
2
+
3
+ DeviseJwtAuth.setup do |config|
4
+ # By default, you will only receive an access token when authenticating a
5
+ # user. To receive new access tokens, you should either reauthenticate or
6
+ # use the HTTP only refresh cookie that is sent during the authentication
7
+ # process and make refresh token requests.
8
+ # config.send_new_access_token_on_each_request = false
9
+
10
+ # By default, refresh token HTTP Only cookies last for 2 weeks. These tokens
11
+ # are used for requesting shorter-lived acccess tokens.
12
+ # config.refresh_token_lifespan = 2.weeks
13
+
14
+ # By default, access tokens last for 15 minutes. These tokens are used to
15
+ # access protected resources. When these tokens expire, you need to
16
+ # reauthenticate the user or use a refresh token cookie to get a new access
17
+ # token.
18
+ # config.access_token_lifespan = 15.minutes
19
+
20
+ # This is the name of the HTTP Only cookie that will be sent to the client
21
+ # for the purpose of requesting new access tokens.
22
+ # config.refresh_token_name = 'refresh-token'
23
+
24
+ # This is the name of the token that will be sent in the JSON responses used
25
+ # for accessing protected resources. NEVER store this token in a cookie or
26
+ # any form of local storage on the client. Save it in memory as a javascript
27
+ # variable or in some kind of context manager like Redux. Send it in your
28
+ # request headers when you want to be authenticated.
29
+ # config.access_token_name = 'access-token'
30
+
31
+ # This is the refresh token encryption key. You should set this in an
32
+ # environment variable or secret key base that isn't store in a repository.
33
+ # Also, its a good idea to NOT use the same key for access tokens.
34
+ config.refresh_token_encryption_key = 'your-refresh-token-secret-key-here'
35
+
36
+ # This is the refresh token encryption key. You should set this in an
37
+ # environment variable or secret key base that isn't store in a repository.
38
+ # Also, its a good idea to NOT use the same key for access tokens.
39
+ config.access_token_encryption_key = 'your-access-token-secret-key-here'
40
+
41
+ # This route will be the prefix for all oauth2 redirect callbacks. For
42
+ # example, using the default '/omniauth', the github oauth2 provider will
43
+ # redirect successful authentications to '/omniauth/github/callback'
44
+ # config.omniauth_prefix = "/omniauth"
45
+
46
+ # By default sending current password is not needed for the password update.
47
+ # Uncomment to enforce current_password param to be checked before all
48
+ # attribute updates. Set it to :password if you want it to be checked only if
49
+ # password is updated.
50
+ # config.check_current_password_before_update = :attributes
51
+
52
+ # By default we will use callbacks for single omniauth.
53
+ # It depends on fields like email, provider and uid.
54
+ # config.default_callbacks = true
55
+
56
+ # By default, only Bearer Token authentication is implemented out of the box.
57
+ # If, however, you wish to integrate with legacy Devise authentication, you can
58
+ # do so by enabling this flag. NOTE: This feature is highly experimental!
59
+ # config.enable_standard_devise_support = false
60
+
61
+ # By default DeviseJwtAuth will not send confirmation email, even when including
62
+ # devise confirmable module. If you want to use devise confirmable module and
63
+ # send email, set it to true. (This is a setting for compatibility)
64
+ # config.send_confirmation_email = true
65
+
66
+ # TODO: Document these settings
67
+ # config.default_confirm_success_url = nil
68
+ # config.default_password_reset_url = nil
69
+ # config.redirect_whitelist = nil
70
+ # config.update_token_version_after_password_reset = true
71
+ # config.bypass_sign_in = true
72
+ # config.require_client_password_reset_token = false
73
+ end
@@ -0,0 +1,54 @@
1
+ # frozen_string_literal: true
2
+
3
+ class DeviseJwtAuthCreateUsers < ActiveRecord::Migration[6.0]
4
+ def change
5
+ create_table(:users) do |t|
6
+ ## Required
7
+ t.string :provider, null: false, default: 'email'
8
+ t.string :uid, null: false, default: ''
9
+
10
+ ## User Info
11
+ t.string :name
12
+ t.string :nickname
13
+ t.string :image
14
+ t.string :email
15
+
16
+ ## Database authenticatable
17
+ t.string :encrypted_password, null: false, default: ''
18
+
19
+ ## Recoverable
20
+ t.string :reset_password_token
21
+ t.datetime :reset_password_sent_at
22
+ t.boolean :allow_password_change, default: false
23
+
24
+ ## Rememberable
25
+ t.datetime :remember_created_at
26
+
27
+ ## Trackable
28
+ # t.integer :sign_in_count, default: 0, null: false
29
+ # t.datetime :current_sign_in_at
30
+ # t.datetime :last_sign_in_at
31
+ # t.string :current_sign_in_ip
32
+ # t.string :last_sign_in_ip
33
+
34
+ ## Confirmable
35
+ t.string :confirmation_token
36
+ t.datetime :confirmed_at
37
+ t.datetime :confirmation_sent_at
38
+ t.string :unconfirmed_email # Only if using reconfirmable
39
+
40
+ ## Lockable
41
+ # t.integer :failed_attempts, default: 0, null: false # Only if lock strategy is :failed_attempts
42
+ # t.string :unlock_token # Only if unlock strategy is :email or :both
43
+ # t.datetime :locked_at
44
+
45
+ t.timestamps
46
+ end
47
+
48
+ add_index :users, :email, unique: true
49
+ add_index :users, [:uid, :provider], unique: true
50
+ add_index :users, :reset_password_token, unique: true
51
+ add_index :users, :confirmation_token, unique: true
52
+ # add_index :users, :unlock_token, unique: true
53
+ end
54
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  FactoryBot.define do
2
4
  factory :user do
3
5
  email { Faker::Internet.unique.safe_email }
@@ -13,13 +15,13 @@ FactoryBot.define do
13
15
  end
14
16
 
15
17
  trait :confirmed do
16
- after(:create) { |user| user.confirm }
18
+ after(:create, &:confirm)
17
19
  end
18
20
 
19
21
  # confirmation period is expired
20
22
  trait :unconfirmed do
21
23
  after(:create) do |user, evaluator|
22
- user.update_attribute(:confirmation_sent_at, evaluator.allow_unconfirmed_period - 1.day )
24
+ user.update_attribute(:confirmation_sent_at, evaluator.allow_unconfirmed_period - 1.day)
23
25
  end
24
26
  end
25
27
 
@@ -29,7 +31,7 @@ FactoryBot.define do
29
31
  end
30
32
 
31
33
  trait :locked do
32
- after(:create) { |user| user.lock_access! }
34
+ after(:create, &:lock_access!)
33
35
  end
34
36
 
35
37
  factory :lockable_user, class: 'LockableUser'
@@ -5,15 +5,15 @@ require 'test_helper'
5
5
  class DeviseJwtAuth::TokenFactoryTest < ActiveSupport::TestCase
6
6
  describe 'TokenFactory module' do
7
7
  let(:tf) { DeviseJwtAuth::TokenFactory }
8
- let(:token_regexp) { /^[A-Za-z0-9\-_=]+\.[A-Za-z0-9\-_=]+\.?[A-Za-z0-9\-_.+\/=]*$/ }
9
-
8
+ let(:token_regexp) { %r{^[A-Za-z0-9\-_=]+\.[A-Za-z0-9\-_=]+\.?[A-Za-z0-9\-_.+/=]*$} }
9
+
10
10
  it 'should be defined' do
11
11
  assert_equal(tf.present?, true)
12
12
  assert_kind_of(Module, tf)
13
13
  end
14
-
14
+
15
15
  describe 'interface' do
16
- let(:payload) { { foo: 'test'} }
16
+ let(:payload) { { foo: 'test' } }
17
17
  let(:future_exp) { (Time.zone.now + 1.hour).to_i }
18
18
  let(:past_exp) { (Time.zone.now - 1.hour).to_i }
19
19
 
@@ -50,7 +50,7 @@ class DeviseJwtAuth::TokenFactoryTest < ActiveSupport::TestCase
50
50
  result = tf.decode_refresh_token(token)
51
51
  assert_nil result['exp']
52
52
  end
53
-
53
+
54
54
  it 'invalidates bogus token' do
55
55
  result = tf.decode_refresh_token('bogus token')
56
56
  assert_empty result
@@ -91,7 +91,7 @@ class DeviseJwtAuth::TokenFactoryTest < ActiveSupport::TestCase
91
91
  result = tf.decode_access_token(token)
92
92
  assert_nil result['exp']
93
93
  end
94
-
94
+
95
95
  it 'invalidates bogus token' do
96
96
  result = tf.decode_access_token('bogus token')
97
97
  assert_empty result
@@ -44,17 +44,6 @@ module DeviseJwtAuth
44
44
  assert_migration 'db/migrate/devise_jwt_auth_create_users.rb'
45
45
  end
46
46
  end
47
-
48
- =begin
49
- test 'add primary key type with rails 5 when specified in rails generator' do
50
- run_generator %w[--primary_key_type=uuid --force]
51
- if Rails::VERSION::MAJOR >= 5
52
- assert_migration 'db/migrate/devise_jwt_auth_create_users.rb', /create_table\(:users, id: :uuid\) do/
53
- else
54
- assert_migration 'db/migrate/devise_jwt_auth_create_users.rb', /create_table\(:users\) do/
55
- end
56
- end
57
- =end
58
47
  end
59
48
  end
60
49
 
@@ -72,15 +61,12 @@ module DeviseJwtAuth
72
61
  case DEVISE_JWT_AUTH_ORM
73
62
  when :active_record
74
63
  # account for rails version 5
75
- active_record_needle = (Rails::VERSION::MAJOR == 5) ? 'ApplicationRecord' : 'ActiveRecord::Base'
64
+ active_record_needle = Rails::VERSION::MAJOR == 5 ? 'ApplicationRecord' : 'ActiveRecord::Base'
76
65
 
77
66
  @f = File.open(@fname, 'w') do |f|
78
67
  f.write <<-RUBY
79
68
  class User < #{active_record_needle}
80
-
81
- def whatever
82
- puts 'whatever'
83
- end
69
+ def whatever; puts 'whatever'; end
84
70
  end
85
71
  RUBY
86
72
  end
@@ -88,10 +74,7 @@ module DeviseJwtAuth
88
74
  @f = File.open(@fname, 'w') do |f|
89
75
  f.write <<-'RUBY'
90
76
  class User
91
-
92
- def whatever
93
- puts 'whatever'
94
- end
77
+ def whatever; puts 'whatever'; end
95
78
  end
96
79
  RUBY
97
80
  end
@@ -14,7 +14,7 @@ module DeviseJwtAuth
14
14
  # The namespaced user model for testing
15
15
  let(:user_class) { 'Azpire::V1::HumanResource::User' }
16
16
  let(:namespace_path) { user_class.underscore }
17
- let(:table_name) { user_class.pluralize.underscore.gsub('/','_') }
17
+ let(:table_name) { user_class.pluralize.underscore.gsub('/', '_') }
18
18
 
19
19
  describe 'user model with namespace, clean install' do
20
20
  setup :prepare_destination
@@ -49,17 +49,6 @@ module DeviseJwtAuth
49
49
  assert_migration "db/migrate/devise_jwt_auth_create_#{table_name}.rb"
50
50
  end
51
51
  end
52
-
53
- =begin
54
- test 'add primary key type with rails 5 when specified in rails generator' do
55
- run_generator %W[#{user_class} auth --primary_key_type=uuid --force]
56
- if Rails::VERSION::MAJOR >= 5
57
- assert_migration "db/migrate/devise_jwt_auth_create_#{table_name}.rb", /create_table\(:#{table_name}, id: :uuid\) do/
58
- else
59
- assert_migration "db/migrate/devise_jwt_auth_create_#{table_name}.rb", /create_table\(:#{table_name}\) do/
60
- end
61
- end
62
- =end
63
52
  end
64
53
  end
65
54
 
@@ -77,15 +66,12 @@ module DeviseJwtAuth
77
66
  case DEVISE_JWT_AUTH_ORM
78
67
  when :active_record
79
68
  # account for rails version 5
80
- active_record_needle = (Rails::VERSION::MAJOR == 5) ? 'ApplicationRecord' : 'ActiveRecord::Base'
69
+ active_record_needle = Rails::VERSION::MAJOR == 5 ? 'ApplicationRecord' : 'ActiveRecord::Base'
81
70
 
82
71
  @f = File.open(@fname, 'w') do |f|
83
72
  f.write <<-RUBY
84
73
  class User < #{active_record_needle}
85
-
86
- def whatever
87
- puts 'whatever'
88
- end
74
+ def whatever; puts 'whatever'; end
89
75
  end
90
76
  RUBY
91
77
  end
@@ -93,10 +79,7 @@ module DeviseJwtAuth
93
79
  @f = File.open(@fname, 'w') do |f|
94
80
  f.write <<-'RUBY'
95
81
  class User
96
-
97
- def whatever
98
- puts 'whatever'
99
- end
82
+ def whatever; puts 'whatever'; end
100
83
  end
101
84
  RUBY
102
85
  end
@@ -1,72 +1,72 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'test_helper'
2
4
 
3
5
  if DEVISE_JWT_AUTH_ORM == :active_record
4
- =begin
5
- describe 'DeviseJwtAuth::Concerns::TokensSerialization' do
6
- let(:ts) { DeviseJwtAuth::Concerns::TokensSerialization }
7
- let(:user) { FactoryBot.create(:user) }
8
- let(:tokens) do
9
- # Сreate all possible token's attributes combinations
10
- user.create_token
11
- 2.times { user.create_new_auth_token(user.tokens.first[0]) }
12
- user.create_new_auth_token
13
- user.create_token
14
-
15
- user.tokens
16
- end
17
- let(:json) { JSON.generate(tokens) }
18
-
19
- it 'is defined' do
20
- assert_equal(ts.present?, true)
21
- assert_kind_of(Module, ts)
22
- end
23
-
24
- describe '.load(json)' do
25
- let(:default) { {} }
26
-
27
- it 'is defined' do
28
- assert_respond_to(ts, :load)
29
- end
30
-
31
- it 'handles nil' do
32
- assert_equal(ts.load(nil), default)
33
- end
34
-
35
- it 'handles string' do
36
- assert_equal(ts.load(json), JSON.parse(json))
37
- end
38
-
39
- it 'returns object of undesirable class' do
40
- assert_equal(ts.load([]), [])
41
- end
42
- end
43
-
44
- describe '.dump(object)' do
45
- let(:default) { 'null' }
46
-
47
- it 'is defined' do
48
- assert_respond_to(ts, :dump)
49
- end
50
-
51
- it 'handles nil' do
52
- assert_equal(ts.dump(nil), default)
53
- end
54
-
55
- it 'handles empty hash' do
56
- assert_equal(ts.dump({}), '{}')
57
- end
58
-
59
- it 'deserialize tokens' do
60
- assert_equal(ts.dump(tokens), json)
61
- end
62
-
63
- it 'removes nil values' do
64
- new_tokens = tokens.dup
65
- new_tokens[new_tokens.first[0]][:kos] = nil
66
-
67
- assert_equal(ts.dump(tokens), ts.dump(new_tokens))
68
- end
69
- end
70
- end
71
- =end
6
+ # describe 'DeviseJwtAuth::Concerns::TokensSerialization' do
7
+ # let(:ts) { DeviseJwtAuth::Concerns::TokensSerialization }
8
+ # let(:user) { FactoryBot.create(:user) }
9
+ # let(:tokens) do
10
+ # # Create all possible token's attributes combinations
11
+ # user.create_token
12
+ # 2.times { user.create_new_auth_token(user.tokens.first[0]) }
13
+ # user.create_new_auth_token
14
+ # user.create_token
15
+ #
16
+ # user.tokens
17
+ # end
18
+ # let(:json) { JSON.generate(tokens) }
19
+ #
20
+ # it 'is defined' do
21
+ # assert_equal(ts.present?, true)
22
+ # assert_kind_of(Module, ts)
23
+ # end
24
+ #
25
+ # describe '.load(json)' do
26
+ # let(:default) { {} }
27
+ #
28
+ # it 'is defined' do
29
+ # assert_respond_to(ts, :load)
30
+ # end
31
+ #
32
+ # it 'handles nil' do
33
+ # assert_equal(ts.load(nil), default)
34
+ # end
35
+ #
36
+ # it 'handles string' do
37
+ # assert_equal(ts.load(json), JSON.parse(json))
38
+ # end
39
+ #
40
+ # it 'returns object of undesirable class' do
41
+ # assert_equal(ts.load([]), [])
42
+ # end
43
+ # end
44
+ #
45
+ # describe '.dump(object)' do
46
+ # let(:default) { 'null' }
47
+ #
48
+ # it 'is defined' do
49
+ # assert_respond_to(ts, :dump)
50
+ # end
51
+ #
52
+ # it 'handles nil' do
53
+ # assert_equal(ts.dump(nil), default)
54
+ # end
55
+ #
56
+ # it 'handles empty hash' do
57
+ # assert_equal(ts.dump({}), '{}')
58
+ # end
59
+ #
60
+ # it 'deserialize tokens' do
61
+ # assert_equal(ts.dump(tokens), json)
62
+ # end
63
+ #
64
+ # it 'removes nil values' do
65
+ # new_tokens = tokens.dup
66
+ # new_tokens[new_tokens.first[0]][:kos] = nil
67
+ #
68
+ # assert_equal(ts.dump(tokens), ts.dump(new_tokens))
69
+ # end
70
+ # end
71
+ # end
72
72
  end