sorcery 0.8.6 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


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

Files changed (126) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +2 -1
  3. data/.travis.yml +75 -14
  4. data/CHANGELOG.md +23 -1
  5. data/Gemfile +1 -0
  6. data/README.md +137 -86
  7. data/gemfiles/active_record-rails40.gemfile +7 -0
  8. data/gemfiles/active_record-rails41.gemfile +3 -2
  9. data/gemfiles/mongo_mapper-rails40.gemfile +9 -0
  10. data/gemfiles/mongo_mapper-rails41.gemfile +2 -1
  11. data/gemfiles/mongoid-rails40.gemfile +9 -0
  12. data/gemfiles/mongoid-rails41.gemfile +3 -5
  13. data/gemfiles/mongoid3-rails32.gemfile +9 -0
  14. data/lib/generators/sorcery/USAGE +1 -1
  15. data/lib/generators/sorcery/install_generator.rb +19 -5
  16. data/lib/generators/sorcery/templates/initializer.rb +34 -9
  17. data/lib/generators/sorcery/templates/migration/brute_force_protection.rb +3 -1
  18. data/lib/generators/sorcery/templates/migration/core.rb +2 -2
  19. data/lib/generators/sorcery/templates/migration/external.rb +3 -1
  20. data/lib/sorcery.rb +75 -43
  21. data/lib/sorcery/adapters/active_record_adapter.rb +120 -0
  22. data/lib/sorcery/adapters/base_adapter.rb +30 -0
  23. data/lib/sorcery/adapters/data_mapper_adapter.rb +176 -0
  24. data/lib/sorcery/adapters/mongo_mapper_adapter.rb +110 -0
  25. data/lib/sorcery/adapters/mongoid_adapter.rb +97 -0
  26. data/lib/sorcery/controller.rb +5 -64
  27. data/lib/sorcery/controller/config.rb +65 -0
  28. data/lib/sorcery/controller/submodules/activity_logging.rb +16 -21
  29. data/lib/sorcery/controller/submodules/brute_force_protection.rb +6 -6
  30. data/lib/sorcery/controller/submodules/external.rb +8 -28
  31. data/lib/sorcery/controller/submodules/remember_me.rb +4 -4
  32. data/lib/sorcery/controller/submodules/session_timeout.rb +10 -6
  33. data/lib/sorcery/model.rb +43 -175
  34. data/lib/sorcery/model/config.rb +96 -0
  35. data/lib/sorcery/model/submodules/activity_logging.rb +29 -36
  36. data/lib/sorcery/model/submodules/brute_force_protection.rb +21 -37
  37. data/lib/sorcery/model/submodules/external.rb +53 -9
  38. data/lib/sorcery/model/submodules/remember_me.rb +12 -31
  39. data/lib/sorcery/model/submodules/reset_password.rb +21 -39
  40. data/lib/sorcery/model/submodules/user_activation.rb +21 -63
  41. data/lib/sorcery/model/temporary_token.rb +4 -4
  42. data/lib/sorcery/providers/base.rb +11 -0
  43. data/lib/sorcery/providers/facebook.rb +1 -1
  44. data/lib/sorcery/providers/github.rb +1 -1
  45. data/lib/sorcery/providers/google.rb +1 -1
  46. data/lib/sorcery/providers/heroku.rb +57 -0
  47. data/lib/sorcery/providers/jira.rb +77 -0
  48. data/lib/sorcery/providers/linkedin.rb +1 -1
  49. data/lib/sorcery/providers/liveid.rb +1 -1
  50. data/lib/sorcery/providers/salesforce.rb +50 -0
  51. data/lib/sorcery/providers/twitter.rb +1 -1
  52. data/lib/sorcery/providers/vk.rb +6 -4
  53. data/lib/sorcery/providers/xing.rb +1 -1
  54. data/lib/sorcery/test_helpers/internal.rb +7 -3
  55. data/lib/sorcery/test_helpers/rails/controller.rb +5 -1
  56. data/lib/sorcery/version.rb +3 -0
  57. data/sorcery.gemspec +6 -2
  58. data/spec/active_record/user_activity_logging_spec.rb +9 -0
  59. data/spec/controllers/controller_activity_logging_spec.rb +124 -0
  60. data/spec/controllers/controller_brute_force_protection_spec.rb +43 -0
  61. data/spec/{active_record → controllers}/controller_http_basic_auth_spec.rb +14 -11
  62. data/spec/{active_record → controllers}/controller_oauth2_spec.rb +128 -56
  63. data/spec/{active_record → controllers}/controller_oauth_spec.rb +94 -70
  64. data/spec/{active_record → controllers}/controller_remember_me_spec.rb +32 -12
  65. data/spec/{active_record → controllers}/controller_session_timeout_spec.rb +15 -5
  66. data/spec/{shared_examples/controller_shared_examples.rb → controllers/controller_spec.rb} +34 -19
  67. data/spec/{datamapper → data_mapper}/user_activation_spec.rb +1 -1
  68. data/spec/data_mapper/user_activity_logging_spec.rb +14 -0
  69. data/spec/{datamapper → data_mapper}/user_brute_force_protection_spec.rb +1 -1
  70. data/spec/{datamapper → data_mapper}/user_oauth_spec.rb +1 -1
  71. data/spec/{datamapper → data_mapper}/user_remember_me_spec.rb +1 -1
  72. data/spec/{datamapper → data_mapper}/user_reset_password_spec.rb +1 -1
  73. data/spec/{datamapper → data_mapper}/user_spec.rb +1 -1
  74. data/spec/mongoid/user_spec.rb +13 -0
  75. data/spec/orm/active_record.rb +12 -0
  76. data/spec/orm/{datamapper.rb → data_mapper.rb} +16 -2
  77. data/spec/orm/mongo_mapper.rb +0 -1
  78. data/spec/orm/mongoid.rb +4 -0
  79. data/spec/rails_app/app/controllers/sorcery_controller.rb +62 -1
  80. data/spec/rails_app/app/{datamapper → data_mapper}/authentication.rb +0 -0
  81. data/spec/rails_app/app/{datamapper → data_mapper}/user.rb +0 -0
  82. data/spec/rails_app/app/mongo_mapper/user.rb +2 -0
  83. data/spec/rails_app/config/routes.rb +9 -0
  84. data/spec/rails_app/db/migrate/core/20101224223620_create_users.rb +2 -2
  85. data/spec/shared_examples/user_activation_shared_examples.rb +7 -7
  86. data/spec/shared_examples/user_activity_logging_shared_examples.rb +73 -5
  87. data/spec/shared_examples/user_brute_force_protection_shared_examples.rb +127 -9
  88. data/spec/shared_examples/user_oauth_shared_examples.rb +3 -6
  89. data/spec/shared_examples/user_remember_me_shared_examples.rb +6 -3
  90. data/spec/shared_examples/user_reset_password_shared_examples.rb +10 -10
  91. data/spec/shared_examples/user_shared_examples.rb +117 -30
  92. data/spec/spec_helper.rb +7 -22
  93. metadata +36 -58
  94. data/Gemfile.rails4 +0 -22
  95. data/VERSION +0 -1
  96. data/lib/sorcery/model/adapters/active_record.rb +0 -54
  97. data/lib/sorcery/model/adapters/datamapper.rb +0 -123
  98. data/lib/sorcery/model/adapters/mongo_mapper.rb +0 -60
  99. data/lib/sorcery/model/adapters/mongoid.rb +0 -88
  100. data/lib/sorcery/test_helpers/rails.rb +0 -7
  101. data/spec/active_record/controller_activity_logging_spec.rb +0 -29
  102. data/spec/active_record/controller_brute_force_protection_spec.rb +0 -158
  103. data/spec/active_record/controller_spec.rb +0 -8
  104. data/spec/active_record/integration_spec.rb +0 -23
  105. data/spec/datamapper/controller_activity_logging_spec.rb +0 -17
  106. data/spec/datamapper/controller_spec.rb +0 -8
  107. data/spec/datamapper/user_activity_logging_spec.rb +0 -9
  108. data/spec/mongo_mapper/controller_spec.rb +0 -8
  109. data/spec/mongoid/controller_activity_logging_spec.rb +0 -16
  110. data/spec/mongoid/controller_spec.rb +0 -8
  111. data/spec/rails_app/public/404.html +0 -26
  112. data/spec/rails_app/public/422.html +0 -26
  113. data/spec/rails_app/public/500.html +0 -26
  114. data/spec/rails_app/public/favicon.ico +0 -0
  115. data/spec/rails_app/public/images/rails.png +0 -0
  116. data/spec/rails_app/public/javascripts/application.js +0 -2
  117. data/spec/rails_app/public/javascripts/controls.js +0 -965
  118. data/spec/rails_app/public/javascripts/dragdrop.js +0 -974
  119. data/spec/rails_app/public/javascripts/effects.js +0 -1123
  120. data/spec/rails_app/public/javascripts/prototype.js +0 -6001
  121. data/spec/rails_app/public/javascripts/rails.js +0 -175
  122. data/spec/rails_app/public/robots.txt +0 -5
  123. data/spec/rails_app/public/stylesheets/.gitkeep +0 -0
  124. data/spec/shared_examples/controller_activity_logging_shared_examples.rb +0 -125
  125. data/spec/shared_examples/controller_oauth2_shared_examples.rb +0 -52
  126. data/spec/shared_examples/controller_oauth_shared_examples.rb +0 -62
@@ -3,7 +3,7 @@ require 'spec_helper'
3
3
  require 'rails_app/app/mailers/sorcery_mailer'
4
4
  require 'shared_examples/user_activation_shared_examples'
5
5
 
6
- describe User, "with activation submodule", :datamapper => true do
6
+ describe User, "with activation submodule", :data_mapper => true do
7
7
 
8
8
  it_behaves_like "rails_3_activation_model"
9
9
 
@@ -0,0 +1,14 @@
1
+ require 'spec_helper'
2
+
3
+ require 'shared_examples/user_activity_logging_shared_examples'
4
+
5
+ describe User, "with activity logging submodule", :data_mapper => true do
6
+
7
+ it_behaves_like "rails_3_activity_logging_model"
8
+
9
+ it "raises an error when incompatible adapter" do
10
+ allow(User.repository.adapter).to receive(:is_a?).with(DataMapper::Adapters::MysqlAdapter) { false }
11
+ expect(-> { sorcery_reload!(:activity_logging) }).to raise_error(Exception)
12
+ end
13
+
14
+ end
@@ -2,7 +2,7 @@ require 'spec_helper'
2
2
 
3
3
  require 'shared_examples/user_brute_force_protection_shared_examples'
4
4
 
5
- describe User, "with brute_force_protection submodule", :datamapper => true do
5
+ describe User, "with brute_force_protection submodule", :data_mapper => true do
6
6
 
7
7
  it_behaves_like "rails_3_brute_force_protection_model"
8
8
 
@@ -2,7 +2,7 @@ require 'spec_helper'
2
2
 
3
3
  require 'shared_examples/user_oauth_shared_examples'
4
4
 
5
- describe User, "with oauth submodule", :datamapper => true do
5
+ describe User, "with oauth submodule", :data_mapper => true do
6
6
 
7
7
  it_behaves_like "rails_3_oauth_model"
8
8
 
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
  require 'shared_examples/user_remember_me_shared_examples'
3
3
 
4
- describe User, "with remember_me submodule", :datamapper => true do
4
+ describe User, "with remember_me submodule", :data_mapper => true do
5
5
 
6
6
  it_behaves_like "rails_3_remember_me_model"
7
7
 
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
  require 'shared_examples/user_reset_password_shared_examples'
3
3
 
4
- describe User, "with reset_password submodule", :datamapper => true do
4
+ describe User, "with reset_password submodule", :data_mapper => true do
5
5
 
6
6
  it_behaves_like "rails_3_reset_password_model"
7
7
 
@@ -3,7 +3,7 @@ require 'spec_helper'
3
3
  require 'rails_app/app/mailers/sorcery_mailer'
4
4
  require 'shared_examples/user_shared_examples'
5
5
 
6
- describe User, "with no submodules (core)", :datamapper => true do
6
+ describe User, "with no submodules (core)", :data_mapper => true do
7
7
  before(:all) do
8
8
  sorcery_reload!
9
9
  end
@@ -35,4 +35,17 @@ describe User, "with no submodules (core)", :mongoid => true do
35
35
  end
36
36
  end
37
37
 
38
+ describe "increment" do
39
+ it "increments attribute" do
40
+ User.class_eval do
41
+ field :some_number, type: Integer
42
+ end
43
+
44
+ user = User.new(some_number: 3)
45
+ user.sorcery_adapter.increment(:some_number)
46
+
47
+ expect(user.some_number).to eql 4
48
+ end
49
+ end
50
+
38
51
  end
@@ -7,3 +7,15 @@ ActiveRecord::Migration.verbose = false
7
7
  class TestUser < ActiveRecord::Base
8
8
  authenticates_with_sorcery!
9
9
  end
10
+
11
+ def setup_orm
12
+ ActiveRecord::Migrator.migrate(migrations_path)
13
+ end
14
+
15
+ def teardown_orm
16
+ ActiveRecord::Migrator.rollback(migrations_path)
17
+ end
18
+
19
+ def migrations_path
20
+ Rails.root.join("db", "migrate", "core")
21
+ end
@@ -30,5 +30,19 @@ class TestUser
30
30
  property :id, Serial
31
31
  authenticates_with_sorcery!
32
32
  end
33
- TestUser.finalize
34
- DataMapper.auto_migrate!
33
+
34
+ def setup_orm
35
+ TestUser.finalize
36
+ DataMapper.auto_migrate!
37
+ end
38
+
39
+ module Sorcery
40
+ module TestHelpers
41
+ module Internal
42
+ def update_model(&block)
43
+ User.class_exec(&block)
44
+ User.finalize
45
+ end
46
+ end
47
+ end
48
+ end
@@ -8,4 +8,3 @@ class TestUser
8
8
  include MongoMapper::Document
9
9
  authenticates_with_sorcery!
10
10
  end
11
-
@@ -16,3 +16,7 @@ end
16
16
  class TestUser
17
17
  include Mongoid::Document
18
18
  end
19
+
20
+ def setup_orm
21
+ Mongoid.purge!
22
+ end
@@ -98,6 +98,18 @@ class SorceryController < ActionController::Base
98
98
  login_at(:liveid)
99
99
  end
100
100
 
101
+ def login_at_test_jira
102
+ login_at(:jira)
103
+ end
104
+
105
+ def login_at_test_vk
106
+ login_at(:vk)
107
+ end
108
+
109
+ def login_at_test_salesforce
110
+ login_at(:salesforce)
111
+ end
112
+
101
113
  def login_at_test_with_state
102
114
  login_at(:facebook, {state: 'bla'})
103
115
  end
@@ -144,6 +156,30 @@ class SorceryController < ActionController::Base
144
156
  end
145
157
  end
146
158
 
159
+ def test_login_from_vk
160
+ if @user = login_from(:vk)
161
+ redirect_to 'bla', notice: 'Success!'
162
+ else
163
+ redirect_to 'blu', alert: 'Failed!'
164
+ end
165
+ end
166
+
167
+ def test_login_from_jira
168
+ if @user = login_from(:jira)
169
+ redirect_to 'bla', notice: 'Success!'
170
+ else
171
+ redirect_to 'blu', alert: 'Failed!'
172
+ end
173
+ end
174
+
175
+ def test_login_from_salesforce
176
+ if @user = login_from(:salesforce)
177
+ redirect_to 'bla', notice: 'Success!'
178
+ else
179
+ redirect_to 'blu', alert: 'Failed!'
180
+ end
181
+ end
182
+
147
183
  def test_return_to_with_external_twitter
148
184
  if @user = login_from(:twitter)
149
185
  redirect_back_or_to 'bla', notice: 'Success!'
@@ -152,6 +188,14 @@ class SorceryController < ActionController::Base
152
188
  end
153
189
  end
154
190
 
191
+ def test_return_to_with_external_jira
192
+ if @user = login_from(:jira)
193
+ redirect_back_or_to 'bla', notice: 'Success!'
194
+ else
195
+ redirect_to 'blu', alert: 'Failed!'
196
+ end
197
+ end
198
+
155
199
  alias :test_return_to_with_external :test_return_to_with_external_twitter
156
200
 
157
201
  def test_return_to_with_external_facebook
@@ -186,6 +230,22 @@ class SorceryController < ActionController::Base
186
230
  end
187
231
  end
188
232
 
233
+ def test_return_to_with_external_vk
234
+ if @user = login_from(:vk)
235
+ redirect_back_or_to 'bla', notice: 'Success!'
236
+ else
237
+ redirect_to 'blu', alert: 'Failed!'
238
+ end
239
+ end
240
+
241
+ def test_return_to_with_external_salesforce
242
+ if @user = login_from(:salesforce)
243
+ redirect_back_or_to 'bla', notice: 'Success!'
244
+ else
245
+ redirect_to 'blu', alert: 'Failed!'
246
+ end
247
+ end
248
+
189
249
  def test_create_from_provider
190
250
  provider = params[:provider]
191
251
  login_from(provider)
@@ -212,7 +272,8 @@ class SorceryController < ActionController::Base
212
272
  login_from(provider)
213
273
  @user = create_from(provider) do |user|
214
274
  # check uniqueness of email
215
- User.where(email: user.email).empty?
275
+ # User.where(email: user.email).empty?
276
+ false
216
277
  end
217
278
  if @user
218
279
  redirect_to 'bla', notice: 'Success!'
@@ -1,5 +1,7 @@
1
1
  class User
2
2
  include MongoMapper::Document
3
3
 
4
+ key :username
5
+
4
6
  many :authentications, :dependent => :destroy
5
7
  end
@@ -21,18 +21,27 @@ AppRoot::Application.routes.draw do
21
21
  get :test_login_from_github
22
22
  get :test_login_from_google
23
23
  get :test_login_from_liveid
24
+ get :test_login_from_vk
25
+ get :test_login_from_jira
26
+ get :test_login_from_salesforce
24
27
  get :login_at_test
25
28
  get :login_at_test_twitter
26
29
  get :login_at_test_facebook
27
30
  get :login_at_test_github
28
31
  get :login_at_test_google
29
32
  get :login_at_test_liveid
33
+ get :login_at_test_vk
34
+ get :login_at_test_jira
35
+ get :login_at_test_salesforce
30
36
  get :test_return_to_with_external
31
37
  get :test_return_to_with_external_twitter
32
38
  get :test_return_to_with_external_facebook
33
39
  get :test_return_to_with_external_github
34
40
  get :test_return_to_with_external_google
35
41
  get :test_return_to_with_external_liveid
42
+ get :test_return_to_with_external_vk
43
+ get :test_return_to_with_external_jira
44
+ get :test_return_to_with_external_salesforce
36
45
  get :test_http_basic_auth
37
46
  get :some_action_making_a_non_persisted_change_to_the_user
38
47
  post :test_login_with_remember
@@ -3,8 +3,8 @@ class CreateUsers < ActiveRecord::Migration
3
3
  create_table :users do |t|
4
4
  t.string :username, :null => false
5
5
  t.string :email, :default => nil
6
- t.string :crypted_password, :default => nil
7
- t.string :salt, :default => nil
6
+ t.string :crypted_password
7
+ t.string :salt
8
8
 
9
9
  t.timestamps
10
10
  end
@@ -72,11 +72,11 @@ shared_examples_for "rails_3_activation_model" do
72
72
  it "clears activation code and change state to 'active' on activation" do
73
73
  activation_token = user.activation_token
74
74
  user.activate!
75
- user2 = User.find(user.id) # go to db to make sure it was saved and not just in memory
75
+ user2 = User.sorcery_adapter.find(user.id) # go to db to make sure it was saved and not just in memory
76
76
 
77
77
  expect(user2.activation_token).to be_nil
78
78
  expect(user2.activation_state).to eq "active"
79
- expect(User.find_by_activation_token activation_token).to be_nil
79
+ expect(User.sorcery_adapter.find_by_activation_token activation_token).to be_nil
80
80
  end
81
81
 
82
82
 
@@ -91,14 +91,14 @@ shared_examples_for "rails_3_activation_model" do
91
91
  it "calls send_activation_needed_email! method of user" do
92
92
  expect(new_user).to receive(:send_activation_needed_email!).once
93
93
 
94
- new_user.sorcery_save(:raise_on_failure => true)
94
+ new_user.sorcery_adapter.save(:raise_on_failure => true)
95
95
  end
96
96
 
97
97
  it "subsequent saves do not send activation email" do
98
98
  user
99
99
  old_size = ActionMailer::Base.deliveries.size
100
100
  user.email = "Shauli"
101
- user.sorcery_save(:raise_on_failure => true)
101
+ user.sorcery_adapter.save(:raise_on_failure => true)
102
102
 
103
103
  expect(ActionMailer::Base.deliveries.size).to eq old_size
104
104
  end
@@ -121,7 +121,7 @@ shared_examples_for "rails_3_activation_model" do
121
121
  user.activate!
122
122
  old_size = ActionMailer::Base.deliveries.size
123
123
  user.email = "Shauli"
124
- user.sorcery_save(:raise_on_failure => true)
124
+ user.sorcery_adapter.save(:raise_on_failure => true)
125
125
 
126
126
  expect(ActionMailer::Base.deliveries.size).to eq old_size
127
127
  end
@@ -158,7 +158,7 @@ shared_examples_for "rails_3_activation_model" do
158
158
 
159
159
  expect(user).to receive(:send_activation_needed_email!).never
160
160
 
161
- user.sorcery_save(:raise_on_failure => true)
161
+ user.sorcery_adapter.save(:raise_on_failure => true)
162
162
  end
163
163
 
164
164
  it "does not send the user an activation success email on successful activation" do
@@ -182,7 +182,7 @@ shared_examples_for "rails_3_activation_model" do
182
182
  end
183
183
 
184
184
  before(:each) do
185
- User.delete_all
185
+ User.sorcery_adapter.delete_all
186
186
  end
187
187
 
188
188
  it "does not allow a non-active user to authenticate" do
@@ -3,22 +3,22 @@ shared_examples_for "rails_3_activity_logging_model" do
3
3
  before(:all) do
4
4
  sorcery_reload!([:activity_logging])
5
5
  end
6
-
6
+
7
7
  after(:each) do
8
8
  User.sorcery_config.reset!
9
9
  end
10
-
10
+
11
11
  it "allows configuration option 'last_login_at_attribute_name'" do
12
12
  sorcery_model_property_set(:last_login_at_attribute_name, :login_time)
13
13
 
14
14
  expect(User.sorcery_config.last_login_at_attribute_name).to eq :login_time
15
15
  end
16
-
16
+
17
17
  it "allows configuration option 'last_logout_at_attribute_name'" do
18
18
  sorcery_model_property_set(:last_logout_at_attribute_name, :logout_time)
19
19
  expect(User.sorcery_config.last_logout_at_attribute_name).to eq :logout_time
20
20
  end
21
-
21
+
22
22
  it "allows configuration option 'last_activity_at_attribute_name'" do
23
23
  sorcery_model_property_set(:last_activity_at_attribute_name, :activity_time)
24
24
  expect(User.sorcery_config.last_activity_at_attribute_name).to eq :activity_time
@@ -28,5 +28,73 @@ shared_examples_for "rails_3_activity_logging_model" do
28
28
  sorcery_model_property_set(:last_login_from_ip_address_name, :ip_address)
29
29
  expect(User.sorcery_config.last_login_from_ip_address_name).to eq :ip_address
30
30
  end
31
+
32
+ describe ".current_users" do
33
+ let(:user) { create_new_user }
34
+
35
+ it "is empty when no users are logged in" do
36
+ skip('unavailable in MongoMapper') if SORCERY_ORM == :mongo_mapper
37
+ expect(User.current_users).to be_empty
38
+ end
39
+
40
+ it "holds the user object when 1 user is logged in" do
41
+ skip('unavailable in MongoMapper') if SORCERY_ORM == :mongo_mapper
42
+ user.set_last_activity_at(Time.now.in_time_zone)
43
+
44
+ expect(User.current_users).to match([User.sorcery_adapter.find(user.id)])
45
+ end
46
+
47
+ it "'current_users' shows all current_users, whether they have logged out before or not." do
48
+ skip('unavailable in MongoMapper') if SORCERY_ORM == :mongo_mapper
49
+ User.sorcery_adapter.delete_all
50
+ user1 = create_new_user({:username => 'gizmo1', :email => "bla1@bla.com", :password => 'secret1'})
51
+ user2 = create_new_user({:username => 'gizmo2', :email => "bla2@bla.com", :password => 'secret2'})
52
+ user3 = create_new_user({:username => 'gizmo3', :email => "bla3@bla.com", :password => 'secret3'})
53
+
54
+ now = Time.now.in_time_zone
55
+ [user1, user2, user3].each do |user|
56
+ user.set_last_login_at(now)
57
+ user.set_last_activity_at(now)
58
+ end
59
+
60
+ expect(User.current_users.map(&:id)).to match_array([user1, user2, user3].map(&:id))
61
+ Timecop.travel now + 5
62
+ user1.set_last_logout_at(Time.now.in_time_zone)
63
+ expect(User.current_users.map(&:id)).to match_array([user2, user3].map(&:id))
64
+ Timecop.return
65
+ end
66
+
67
+ end
68
+
69
+ it '.set_last_login_at update last_login_at' do
70
+ user = create_new_user
71
+ now = Time.now.in_time_zone
72
+ expect(user.sorcery_adapter).to receive(:update_attribute).with(:last_login_at, now)
73
+
74
+ user.set_last_login_at(now)
75
+ end
76
+
77
+ it '.set_last_logout_at update last_logout_at' do
78
+ user = create_new_user
79
+ now = Time.now.in_time_zone
80
+ expect(user.sorcery_adapter).to receive(:update_attribute).with(:last_logout_at, now)
81
+
82
+ user.set_last_logout_at(now)
83
+ end
84
+
85
+ it '.set_last_activity_at update last_activity_at' do
86
+ user = create_new_user
87
+ now = Time.now.in_time_zone
88
+ expect(user.sorcery_adapter).to receive(:update_attribute).with(:last_activity_at, now)
89
+
90
+ user.set_last_activity_at(now)
91
+ end
92
+
93
+ it '.set_last_ip_addess update last_login_from_ip_address' do
94
+ user = create_new_user
95
+ expect(user.sorcery_adapter).to receive(:update_attribute).with(:last_login_from_ip_address, '0.0.0.0')
96
+
97
+ user.set_last_ip_addess('0.0.0.0')
98
+ end
31
99
  end
32
- end
100
+ end