namxam-devise 1.1.0.win

Sign up to get free protection for your applications and to get access to all the features.
Files changed (152) hide show
  1. data/CHANGELOG.rdoc +455 -0
  2. data/Gemfile +23 -0
  3. data/Gemfile.lock +118 -0
  4. data/MIT-LICENSE +20 -0
  5. data/README.rdoc +311 -0
  6. data/Rakefile +55 -0
  7. data/TODO +3 -0
  8. data/app/controllers/devise/confirmations_controller.rb +33 -0
  9. data/app/controllers/devise/passwords_controller.rb +41 -0
  10. data/app/controllers/devise/registrations_controller.rb +57 -0
  11. data/app/controllers/devise/sessions_controller.rb +23 -0
  12. data/app/controllers/devise/unlocks_controller.rb +34 -0
  13. data/app/helpers/devise_helper.rb +17 -0
  14. data/app/mailers/devise/mailer.rb +71 -0
  15. data/app/views/devise/confirmations/new.html.erb +12 -0
  16. data/app/views/devise/mailer/confirmation_instructions.html.erb +5 -0
  17. data/app/views/devise/mailer/reset_password_instructions.html.erb +8 -0
  18. data/app/views/devise/mailer/unlock_instructions.html.erb +7 -0
  19. data/app/views/devise/passwords/edit.html.erb +16 -0
  20. data/app/views/devise/passwords/new.html.erb +12 -0
  21. data/app/views/devise/registrations/edit.html.erb +25 -0
  22. data/app/views/devise/registrations/new.html.erb +18 -0
  23. data/app/views/devise/sessions/new.html.erb +17 -0
  24. data/app/views/devise/shared/_links.erb +19 -0
  25. data/app/views/devise/unlocks/new.html.erb +12 -0
  26. data/config/locales/en.yml +39 -0
  27. data/lib/devise.rb +290 -0
  28. data/lib/devise/controllers/helpers.rb +231 -0
  29. data/lib/devise/controllers/internal_helpers.rb +98 -0
  30. data/lib/devise/controllers/scoped_views.rb +35 -0
  31. data/lib/devise/controllers/url_helpers.rb +41 -0
  32. data/lib/devise/encryptors/authlogic_sha512.rb +19 -0
  33. data/lib/devise/encryptors/base.rb +20 -0
  34. data/lib/devise/encryptors/bcrypt.rb +19 -0
  35. data/lib/devise/encryptors/clearance_sha1.rb +17 -0
  36. data/lib/devise/encryptors/restful_authentication_sha1.rb +22 -0
  37. data/lib/devise/encryptors/sha1.rb +25 -0
  38. data/lib/devise/encryptors/sha512.rb +25 -0
  39. data/lib/devise/failure_app.rb +107 -0
  40. data/lib/devise/hooks/activatable.rb +11 -0
  41. data/lib/devise/hooks/forgetable.rb +11 -0
  42. data/lib/devise/hooks/rememberable.rb +35 -0
  43. data/lib/devise/hooks/timeoutable.rb +22 -0
  44. data/lib/devise/hooks/trackable.rb +9 -0
  45. data/lib/devise/mapping.rb +103 -0
  46. data/lib/devise/models.rb +80 -0
  47. data/lib/devise/models/authenticatable.rb +126 -0
  48. data/lib/devise/models/confirmable.rb +164 -0
  49. data/lib/devise/models/database_authenticatable.rb +110 -0
  50. data/lib/devise/models/lockable.rb +165 -0
  51. data/lib/devise/models/recoverable.rb +81 -0
  52. data/lib/devise/models/registerable.rb +8 -0
  53. data/lib/devise/models/rememberable.rb +104 -0
  54. data/lib/devise/models/timeoutable.rb +26 -0
  55. data/lib/devise/models/token_authenticatable.rb +60 -0
  56. data/lib/devise/models/trackable.rb +30 -0
  57. data/lib/devise/models/validatable.rb +53 -0
  58. data/lib/devise/modules.rb +23 -0
  59. data/lib/devise/orm/active_record.rb +36 -0
  60. data/lib/devise/orm/mongoid.rb +29 -0
  61. data/lib/devise/path_checker.rb +18 -0
  62. data/lib/devise/rails.rb +69 -0
  63. data/lib/devise/rails/routes.rb +248 -0
  64. data/lib/devise/rails/warden_compat.rb +39 -0
  65. data/lib/devise/schema.rb +97 -0
  66. data/lib/devise/strategies/authenticatable.rb +111 -0
  67. data/lib/devise/strategies/base.rb +33 -0
  68. data/lib/devise/strategies/database_authenticatable.rb +21 -0
  69. data/lib/devise/strategies/rememberable.rb +43 -0
  70. data/lib/devise/strategies/token_authenticatable.rb +49 -0
  71. data/lib/devise/test_helpers.rb +90 -0
  72. data/lib/devise/version.rb +3 -0
  73. data/lib/generators/active_record/devise_generator.rb +28 -0
  74. data/lib/generators/active_record/templates/migration.rb +29 -0
  75. data/lib/generators/devise/devise_generator.rb +17 -0
  76. data/lib/generators/devise/install_generator.rb +24 -0
  77. data/lib/generators/devise/orm_helpers.rb +23 -0
  78. data/lib/generators/devise/templates/README +25 -0
  79. data/lib/generators/devise/templates/devise.rb +139 -0
  80. data/lib/generators/devise/views_generator.rb +63 -0
  81. data/lib/generators/devise_install_generator.rb +4 -0
  82. data/lib/generators/devise_views_generator.rb +4 -0
  83. data/lib/generators/mongoid/devise_generator.rb +17 -0
  84. data/test/controllers/helpers_test.rb +213 -0
  85. data/test/controllers/internal_helpers_test.rb +51 -0
  86. data/test/controllers/url_helpers_test.rb +58 -0
  87. data/test/devise_test.rb +65 -0
  88. data/test/encryptors_test.rb +30 -0
  89. data/test/failure_app_test.rb +123 -0
  90. data/test/integration/authenticatable_test.rb +344 -0
  91. data/test/integration/confirmable_test.rb +104 -0
  92. data/test/integration/database_authenticatable_test.rb +38 -0
  93. data/test/integration/http_authenticatable_test.rb +49 -0
  94. data/test/integration/lockable_test.rb +109 -0
  95. data/test/integration/recoverable_test.rb +141 -0
  96. data/test/integration/registerable_test.rb +153 -0
  97. data/test/integration/rememberable_test.rb +91 -0
  98. data/test/integration/timeoutable_test.rb +80 -0
  99. data/test/integration/token_authenticatable_test.rb +88 -0
  100. data/test/integration/trackable_test.rb +64 -0
  101. data/test/mailers/confirmation_instructions_test.rb +80 -0
  102. data/test/mailers/reset_password_instructions_test.rb +68 -0
  103. data/test/mailers/unlock_instructions_test.rb +62 -0
  104. data/test/mapping_test.rb +85 -0
  105. data/test/models/confirmable_test.rb +221 -0
  106. data/test/models/database_authenticatable_test.rb +148 -0
  107. data/test/models/lockable_test.rb +188 -0
  108. data/test/models/recoverable_test.rb +138 -0
  109. data/test/models/rememberable_test.rb +176 -0
  110. data/test/models/timeoutable_test.rb +28 -0
  111. data/test/models/token_authenticatable_test.rb +37 -0
  112. data/test/models/trackable_test.rb +5 -0
  113. data/test/models/validatable_test.rb +99 -0
  114. data/test/models_test.rb +77 -0
  115. data/test/orm/active_record.rb +9 -0
  116. data/test/orm/mongoid.rb +10 -0
  117. data/test/rails_app/app/active_record/admin.rb +3 -0
  118. data/test/rails_app/app/active_record/shim.rb +2 -0
  119. data/test/rails_app/app/active_record/user.rb +7 -0
  120. data/test/rails_app/app/controllers/admins_controller.rb +6 -0
  121. data/test/rails_app/app/controllers/application_controller.rb +9 -0
  122. data/test/rails_app/app/controllers/home_controller.rb +7 -0
  123. data/test/rails_app/app/controllers/publisher/registrations_controller.rb +2 -0
  124. data/test/rails_app/app/controllers/publisher/sessions_controller.rb +2 -0
  125. data/test/rails_app/app/controllers/sessions_controller.rb +6 -0
  126. data/test/rails_app/app/controllers/users_controller.rb +18 -0
  127. data/test/rails_app/app/helpers/application_helper.rb +3 -0
  128. data/test/rails_app/app/mongoid/admin.rb +6 -0
  129. data/test/rails_app/app/mongoid/shim.rb +16 -0
  130. data/test/rails_app/app/mongoid/user.rb +10 -0
  131. data/test/rails_app/config/application.rb +35 -0
  132. data/test/rails_app/config/boot.rb +13 -0
  133. data/test/rails_app/config/environment.rb +5 -0
  134. data/test/rails_app/config/environments/development.rb +19 -0
  135. data/test/rails_app/config/environments/production.rb +33 -0
  136. data/test/rails_app/config/environments/test.rb +33 -0
  137. data/test/rails_app/config/initializers/backtrace_silencers.rb +7 -0
  138. data/test/rails_app/config/initializers/devise.rb +136 -0
  139. data/test/rails_app/config/initializers/inflections.rb +2 -0
  140. data/test/rails_app/config/initializers/secret_token.rb +2 -0
  141. data/test/rails_app/config/routes.rb +47 -0
  142. data/test/rails_app/db/migrate/20100401102949_create_tables.rb +27 -0
  143. data/test/rails_app/db/schema.rb +86 -0
  144. data/test/routes_test.rb +146 -0
  145. data/test/support/assertions.rb +24 -0
  146. data/test/support/helpers.rb +54 -0
  147. data/test/support/integration.rb +88 -0
  148. data/test/support/test_silencer.rb +5 -0
  149. data/test/support/webrat/integrations/rails.rb +32 -0
  150. data/test/test_helper.rb +21 -0
  151. data/test/test_helpers_test.rb +72 -0
  152. metadata +230 -0
@@ -0,0 +1,188 @@
1
+ require 'test_helper'
2
+
3
+ class LockableTest < ActiveSupport::TestCase
4
+ def setup
5
+ setup_mailer
6
+ end
7
+
8
+ test "should respect maximum attempts configuration" do
9
+ user = create_user
10
+ user.confirm!
11
+ swap Devise, :maximum_attempts => 2 do
12
+ 3.times { user.valid_for_authentication?{ false } }
13
+ assert user.reload.access_locked?
14
+ end
15
+ end
16
+
17
+ test "should clear failed_attempts on successfull validation" do
18
+ user = create_user
19
+ user.confirm!
20
+ user.valid_for_authentication?{ false }
21
+ assert_equal 1, user.reload.failed_attempts
22
+ user.valid_for_authentication?{ true }
23
+ assert_equal 0, user.reload.failed_attempts
24
+ end
25
+
26
+ test "should not touch failed_attempts if lock_strategy is none" do
27
+ user = create_user
28
+ user.confirm!
29
+ swap Devise, :lock_strategy => :none, :maximum_attempts => 2 do
30
+ 3.times { user.valid_for_authentication?{ false } }
31
+ assert !user.access_locked?
32
+ assert_equal 0, user.failed_attempts
33
+ end
34
+ end
35
+
36
+ test 'should be valid for authentication with a unlocked user' do
37
+ user = create_user
38
+ user.lock_access!
39
+ user.unlock_access!
40
+ assert user.valid_for_authentication?{ true }
41
+ end
42
+
43
+ test "should verify whether a user is locked or not" do
44
+ user = create_user
45
+ assert_not user.access_locked?
46
+ user.lock_access!
47
+ assert user.access_locked?
48
+ end
49
+
50
+ test "active? should be the opposite of locked?" do
51
+ user = create_user
52
+ user.confirm!
53
+ assert user.active?
54
+ user.lock_access!
55
+ assert_not user.active?
56
+ end
57
+
58
+ test "should unlock an user by cleaning locked_at, falied_attempts and unlock_token" do
59
+ user = create_user
60
+ user.lock_access!
61
+ assert_not_nil user.reload.locked_at
62
+ assert_not_nil user.reload.unlock_token
63
+
64
+ user.unlock_access!
65
+ assert_nil user.reload.locked_at
66
+ assert_nil user.reload.unlock_token
67
+ assert_equal 0, user.reload.failed_attempts
68
+ end
69
+
70
+ test 'should not unlock an unlocked user' do
71
+ user = create_user
72
+ assert_not user.unlock_access!
73
+ assert_match "was not locked", user.errors[:email].join
74
+ end
75
+
76
+ test "new user should not be locked and should have zero failed_attempts" do
77
+ assert_not new_user.access_locked?
78
+ assert_equal 0, create_user.failed_attempts
79
+ end
80
+
81
+ test "should unlock user after unlock_in period" do
82
+ swap Devise, :unlock_in => 3.hours do
83
+ user = new_user
84
+ user.locked_at = 2.hours.ago
85
+ assert user.access_locked?
86
+
87
+ Devise.unlock_in = 1.hour
88
+ assert_not user.access_locked?
89
+ end
90
+ end
91
+
92
+ test "should not unlock in 'unlock_in' if :time unlock strategy is not set" do
93
+ swap Devise, :unlock_strategy => :email do
94
+ user = new_user
95
+ user.locked_at = 2.hours.ago
96
+ assert user.access_locked?
97
+ end
98
+ end
99
+
100
+ test "should set unlock_token when locking" do
101
+ user = create_user
102
+ assert_nil user.unlock_token
103
+ user.lock_access!
104
+ assert_not_nil user.unlock_token
105
+ end
106
+
107
+ test "should never generate the same unlock token for different users" do
108
+ unlock_tokens = []
109
+ 3.times do
110
+ user = create_user
111
+ user.lock_access!
112
+ token = user.unlock_token
113
+ assert !unlock_tokens.include?(token)
114
+ unlock_tokens << token
115
+ end
116
+ end
117
+
118
+ test "should not generate unlock_token when :email is not an unlock strategy" do
119
+ swap Devise, :unlock_strategy => :time do
120
+ user = create_user
121
+ user.lock_access!
122
+ assert_nil user.unlock_token
123
+ end
124
+ end
125
+
126
+ test "should send email with unlock instructions when :email is an unlock strategy" do
127
+ swap Devise, :unlock_strategy => :email do
128
+ user = create_user
129
+ assert_email_sent do
130
+ user.lock_access!
131
+ end
132
+ end
133
+ end
134
+
135
+ test "should not send email with unlock instructions when :email is not an unlock strategy" do
136
+ swap Devise, :unlock_strategy => :time do
137
+ user = create_user
138
+ assert_email_not_sent do
139
+ user.lock_access!
140
+ end
141
+ end
142
+ end
143
+
144
+ test 'should find and unlock an user automatically' do
145
+ user = create_user
146
+ user.lock_access!
147
+ locked_user = User.unlock_access_by_token(user.unlock_token)
148
+ assert_equal locked_user, user
149
+ assert_not user.reload.access_locked?
150
+ end
151
+
152
+ test 'should return a new record with errors when a invalid token is given' do
153
+ locked_user = User.unlock_access_by_token('invalid_token')
154
+ assert_not locked_user.persisted?
155
+ assert_equal "is invalid", locked_user.errors[:unlock_token].join
156
+ end
157
+
158
+ test 'should return a new record with errors when a blank token is given' do
159
+ locked_user = User.unlock_access_by_token('')
160
+ assert_not locked_user.persisted?
161
+ assert_equal "can't be blank", locked_user.errors[:unlock_token].join
162
+ end
163
+
164
+ test 'should find a user to send unlock instructions' do
165
+ user = create_user
166
+ user.lock_access!
167
+ unlock_user = User.send_unlock_instructions(:email => user.email)
168
+ assert_equal unlock_user, user
169
+ end
170
+
171
+ test 'should return a new user if no email was found' do
172
+ unlock_user = User.send_unlock_instructions(:email => "invalid@email.com")
173
+ assert_not unlock_user.persisted?
174
+ end
175
+
176
+ test 'should add error to new user email if no email was found' do
177
+ unlock_user = User.send_unlock_instructions(:email => "invalid@email.com")
178
+ assert_equal 'not found', unlock_user.errors[:email].join
179
+ end
180
+
181
+ test 'should not be able to send instructions if the user is not locked' do
182
+ user = create_user
183
+ assert_not user.resend_unlock_token
184
+ assert_not user.access_locked?
185
+ assert_equal 'was not locked', user.errors[:email].join
186
+ end
187
+
188
+ end
@@ -0,0 +1,138 @@
1
+ require 'test_helper'
2
+
3
+ class RecoverableTest < ActiveSupport::TestCase
4
+
5
+ def setup
6
+ setup_mailer
7
+ end
8
+
9
+ test 'should not generate reset password token after creating a record' do
10
+ assert_nil new_user.reset_password_token
11
+ end
12
+
13
+ test 'should regenerate reset password token each time' do
14
+ user = create_user
15
+ 3.times do
16
+ token = user.reset_password_token
17
+ user.send_reset_password_instructions
18
+ assert_not_equal token, user.reset_password_token
19
+ end
20
+ end
21
+
22
+ test 'should never generate the same reset password token for different users' do
23
+ reset_password_tokens = []
24
+ 3.times do
25
+ user = create_user
26
+ user.send_reset_password_instructions
27
+ token = user.reset_password_token
28
+ assert !reset_password_tokens.include?(token)
29
+ reset_password_tokens << token
30
+ end
31
+ end
32
+
33
+ test 'should reset password and password confirmation from params' do
34
+ user = create_user
35
+ user.reset_password!('123456789', '987654321')
36
+ assert_equal '123456789', user.password
37
+ assert_equal '987654321', user.password_confirmation
38
+ end
39
+
40
+ test 'should reset password and save the record' do
41
+ assert create_user.reset_password!('123456789', '123456789')
42
+ end
43
+
44
+ test 'should clear reset password token while reseting the password' do
45
+ user = create_user
46
+ assert_nil user.reset_password_token
47
+
48
+ user.send_reset_password_instructions
49
+ assert_present user.reset_password_token
50
+ assert user.reset_password!('123456789', '123456789')
51
+ assert_nil user.reset_password_token
52
+ end
53
+
54
+ test 'should not clear reset password token if record is invalid' do
55
+ user = create_user
56
+ user.send_reset_password_instructions
57
+ assert_present user.reset_password_token
58
+ assert_not user.reset_password!('123456789', '987654321')
59
+ assert_present user.reset_password_token
60
+ end
61
+
62
+ test 'should not reset password with invalid data' do
63
+ user = create_user
64
+ user.stubs(:valid?).returns(false)
65
+ assert_not user.reset_password!('123456789', '987654321')
66
+ end
67
+
68
+ test 'should reset reset password token and send instructions by email' do
69
+ user = create_user
70
+ assert_email_sent do
71
+ token = user.reset_password_token
72
+ user.send_reset_password_instructions
73
+ assert_not_equal token, user.reset_password_token
74
+ end
75
+ end
76
+
77
+ test 'should find a user to send instructions by email' do
78
+ user = create_user
79
+ reset_password_user = User.send_reset_password_instructions(:email => user.email)
80
+ assert_equal reset_password_user, user
81
+ end
82
+
83
+ test 'should return a new record with errors if user was not found by e-mail' do
84
+ reset_password_user = User.send_reset_password_instructions(:email => "invalid@email.com")
85
+ assert_not reset_password_user.persisted?
86
+ assert_equal "not found", reset_password_user.errors[:email].join
87
+ end
88
+
89
+ test 'should reset reset_password_token before send the reset instructions email' do
90
+ user = create_user
91
+ token = user.reset_password_token
92
+ reset_password_user = User.send_reset_password_instructions(:email => user.email)
93
+ assert_not_equal token, user.reload.reset_password_token
94
+ end
95
+
96
+ test 'should send email instructions to the user reset his password' do
97
+ user = create_user
98
+ assert_email_sent do
99
+ User.send_reset_password_instructions(:email => user.email)
100
+ end
101
+ end
102
+
103
+ test 'should find a user to reset his password based on reset_password_token' do
104
+ user = create_user
105
+ user.send :generate_reset_password_token!
106
+
107
+ reset_password_user = User.reset_password_by_token(:reset_password_token => user.reset_password_token)
108
+ assert_equal reset_password_user, user
109
+ end
110
+
111
+ test 'should a new record with errors if no reset_password_token is found' do
112
+ reset_password_user = User.reset_password_by_token(:reset_password_token => 'invalid_token')
113
+ assert_not reset_password_user.persisted?
114
+ assert_equal "is invalid", reset_password_user.errors[:reset_password_token].join
115
+ end
116
+
117
+ test 'should a new record with errors if reset_password_token is blank' do
118
+ reset_password_user = User.reset_password_by_token(:reset_password_token => '')
119
+ assert_not reset_password_user.persisted?
120
+ assert_match "can't be blank", reset_password_user.errors[:reset_password_token].join
121
+ end
122
+
123
+ test 'should reset successfully user password given the new password and confirmation' do
124
+ user = create_user
125
+ old_password = user.password
126
+ user.send :generate_reset_password_token!
127
+
128
+ reset_password_user = User.reset_password_by_token(
129
+ :reset_password_token => user.reset_password_token,
130
+ :password => 'new_password',
131
+ :password_confirmation => 'new_password'
132
+ )
133
+ user.reload
134
+
135
+ assert_not user.valid_password?(old_password)
136
+ assert user.valid_password?('new_password')
137
+ end
138
+ end
@@ -0,0 +1,176 @@
1
+ require 'test_helper'
2
+
3
+ class RememberableTest < ActiveSupport::TestCase
4
+ test 'should respond to remember_me attribute' do
5
+ user = new_user
6
+ assert user.respond_to?(:remember_me)
7
+ end
8
+
9
+ test 'remember_me should generate a new token and save the record without validating' do
10
+ user = create_user
11
+ user.expects(:valid?).never
12
+ token = user.remember_token
13
+ user.remember_me!
14
+ assert_not_equal token, user.remember_token
15
+ assert_not user.changed?
16
+ end
17
+
18
+ test 'forget_me should clear remember token and save the record without validating' do
19
+ user = create_user
20
+ user.remember_me!
21
+ assert_not user.remember_token.nil?
22
+ user.expects(:valid?).never
23
+ user.forget_me!
24
+ assert user.remember_token.nil?
25
+ assert_not user.changed?
26
+ end
27
+
28
+ test 'forget_me should clear remember_created_at' do
29
+ user = create_user
30
+ user.remember_me!
31
+ assert_not user.remember_created_at.nil?
32
+ user.forget_me!
33
+ assert user.remember_created_at.nil?
34
+ end
35
+
36
+ test 'forget should do nothing if no remember token exists' do
37
+ user = create_user
38
+ user.expects(:save).never
39
+ user.forget_me!
40
+ end
41
+
42
+ test 'serialize into cookie' do
43
+ user = create_user
44
+ user.remember_me!
45
+ assert_equal [user.id, user.remember_token], User.serialize_into_cookie(user)
46
+ end
47
+
48
+ test 'serialize from cookie' do
49
+ user = create_user
50
+ user.remember_me!
51
+ assert_equal user, User.serialize_from_cookie(user.id, user.remember_token)
52
+ end
53
+
54
+ test 'serialize should return nil if no user is found' do
55
+ assert_nil User.serialize_from_cookie(0, "123")
56
+ end
57
+
58
+ test 'remember me return nil if is a valid user with invalid token' do
59
+ user = create_user
60
+ assert_nil User.serialize_from_cookie(user.id, "123")
61
+ end
62
+
63
+ test 'remember for should fallback to devise remember for default configuration' do
64
+ swap Devise, :remember_for => 1.day do
65
+ user = create_user
66
+ user.remember_me!
67
+ assert_not user.remember_expired?
68
+ end
69
+ end
70
+
71
+ test 'remember expires at should sum date of creation with remember for configuration' do
72
+ swap Devise, :remember_for => 3.days do
73
+ user = create_user
74
+ user.remember_me!
75
+ assert_equal 3.days.from_now.to_date, user.remember_expires_at.to_date
76
+
77
+ Devise.remember_for = 5.days
78
+ assert_equal 5.days.from_now.to_date, user.remember_expires_at.to_date
79
+ end
80
+ end
81
+
82
+ test 'remember should be expired if remember_for is zero' do
83
+ swap Devise, :remember_for => 0.days do
84
+ Devise.remember_for = 0.days
85
+ user = create_user
86
+ user.remember_me!
87
+ assert user.remember_expired?
88
+ end
89
+ end
90
+
91
+ test 'remember should be expired if it was created before limit time' do
92
+ swap Devise, :remember_for => 1.day do
93
+ user = create_user
94
+ user.remember_me!
95
+ user.remember_created_at = 2.days.ago
96
+ user.save
97
+ assert user.remember_expired?
98
+ end
99
+ end
100
+
101
+ test 'remember should not be expired if it was created whitin the limit time' do
102
+ swap Devise, :remember_for => 30.days do
103
+ user = create_user
104
+ user.remember_me!
105
+ user.remember_created_at = (30.days.ago + 2.minutes)
106
+ user.save
107
+ assert_not user.remember_expired?
108
+ end
109
+ end
110
+
111
+ test 'if remember_across_browsers is true, remember_me! should create a new token if no token exists' do
112
+ swap Devise, :remember_across_browsers => true do
113
+ user = create_user
114
+ assert_equal nil, user.remember_token
115
+ user.remember_me!
116
+ assert_not_equal nil, user.remember_token
117
+ end
118
+ end
119
+
120
+ test 'if remember_across_browsers is true, remember_me! should create a new token if a token exists but has expired' do
121
+ swap Devise, :remember_across_browsers => true, :remember_for => 1.day do
122
+ user = create_user
123
+ user.remember_me!
124
+ user.remember_created_at = 2.days.ago
125
+ user.save
126
+ token = user.remember_token
127
+ user.remember_me!
128
+ assert_not_equal token, user.remember_token
129
+ end
130
+ end
131
+
132
+ test 'if remember_across_browsers is true, remember_me! should not create a new token if a token exists and has not expired' do
133
+ swap Devise, :remember_across_browsers => true, :remember_for => 2.days do
134
+ user = create_user
135
+ user.remember_me!
136
+ user.remember_created_at = 1.day.ago
137
+ user.save
138
+ token = user.remember_token
139
+ user.remember_me!
140
+ assert_equal token, user.remember_token
141
+ end
142
+ end
143
+
144
+ test 'if remember_across_browsers is false, remember_me! should create a new token if no token exists' do
145
+ swap Devise, :remember_across_browsers => false do
146
+ user = create_user
147
+ assert_equal nil, user.remember_token
148
+ user.remember_me!
149
+ assert_not_equal nil, user.remember_token
150
+ end
151
+ end
152
+
153
+ test 'if remember_across_browsers is false, remember_me! should create a new token if a token exists but has expired' do
154
+ swap Devise, :remember_across_browsers => false, :remember_for => 1.day do
155
+ user = create_user
156
+ user.remember_me!
157
+ user.remember_created_at = 2.days.ago
158
+ user.save
159
+ token = user.remember_token
160
+ user.remember_me!
161
+ assert_not_equal token, user.remember_token
162
+ end
163
+ end
164
+
165
+ test 'if remember_across_browsers is false, remember_me! should create a new token if a token exists and has not expired' do
166
+ swap Devise, :remember_across_browsers => false, :remember_for => 2.days do
167
+ user = create_user
168
+ user.remember_me!
169
+ user.remember_created_at = 1.day.ago
170
+ user.save
171
+ token = user.remember_token
172
+ user.remember_me!
173
+ assert_not_equal token, user.remember_token
174
+ end
175
+ end
176
+ end