authlogic 3.4.6 → 4.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (140) hide show
  1. checksums.yaml +5 -5
  2. data/.github/ISSUE_TEMPLATE.md +13 -0
  3. data/.github/triage.md +87 -0
  4. data/.gitignore +4 -0
  5. data/.rubocop.yml +127 -0
  6. data/.rubocop_todo.yml +65 -0
  7. data/.travis.yml +18 -10
  8. data/CHANGELOG.md +156 -6
  9. data/CONTRIBUTING.md +71 -3
  10. data/Gemfile +2 -2
  11. data/README.md +386 -0
  12. data/Rakefile +13 -7
  13. data/UPGRADING.md +22 -0
  14. data/authlogic.gemspec +33 -22
  15. data/lib/authlogic.rb +60 -52
  16. data/lib/authlogic/acts_as_authentic/base.rb +40 -26
  17. data/lib/authlogic/acts_as_authentic/email.rb +96 -32
  18. data/lib/authlogic/acts_as_authentic/logged_in_status.rb +36 -12
  19. data/lib/authlogic/acts_as_authentic/login.rb +114 -49
  20. data/lib/authlogic/acts_as_authentic/magic_columns.rb +17 -6
  21. data/lib/authlogic/acts_as_authentic/password.rb +296 -139
  22. data/lib/authlogic/acts_as_authentic/perishable_token.rb +34 -20
  23. data/lib/authlogic/acts_as_authentic/persistence_token.rb +20 -24
  24. data/lib/authlogic/acts_as_authentic/queries/find_with_case.rb +67 -0
  25. data/lib/authlogic/acts_as_authentic/restful_authentication.rb +68 -23
  26. data/lib/authlogic/acts_as_authentic/session_maintenance.rb +128 -85
  27. data/lib/authlogic/acts_as_authentic/single_access_token.rb +41 -25
  28. data/lib/authlogic/acts_as_authentic/validations_scope.rb +8 -8
  29. data/lib/authlogic/authenticates_many/association.rb +22 -14
  30. data/lib/authlogic/authenticates_many/base.rb +35 -16
  31. data/lib/authlogic/config.rb +10 -10
  32. data/lib/authlogic/controller_adapters/abstract_adapter.rb +40 -12
  33. data/lib/authlogic/controller_adapters/rack_adapter.rb +15 -8
  34. data/lib/authlogic/controller_adapters/rails_adapter.rb +42 -22
  35. data/lib/authlogic/controller_adapters/sinatra_adapter.rb +3 -3
  36. data/lib/authlogic/crypto_providers.rb +91 -0
  37. data/lib/authlogic/crypto_providers/aes256.rb +42 -14
  38. data/lib/authlogic/crypto_providers/bcrypt.rb +35 -20
  39. data/lib/authlogic/crypto_providers/md5.rb +11 -9
  40. data/lib/authlogic/crypto_providers/scrypt.rb +26 -13
  41. data/lib/authlogic/crypto_providers/sha1.rb +14 -8
  42. data/lib/authlogic/crypto_providers/sha256.rb +16 -12
  43. data/lib/authlogic/crypto_providers/sha512.rb +8 -24
  44. data/lib/authlogic/crypto_providers/wordpress.rb +44 -15
  45. data/lib/authlogic/i18n.rb +33 -20
  46. data/lib/authlogic/i18n/translator.rb +1 -1
  47. data/lib/authlogic/random.rb +12 -29
  48. data/lib/authlogic/regex.rb +59 -27
  49. data/lib/authlogic/session/activation.rb +36 -23
  50. data/lib/authlogic/session/active_record_trickery.rb +13 -10
  51. data/lib/authlogic/session/base.rb +20 -8
  52. data/lib/authlogic/session/brute_force_protection.rb +87 -56
  53. data/lib/authlogic/session/callbacks.rb +99 -49
  54. data/lib/authlogic/session/cookies.rb +128 -59
  55. data/lib/authlogic/session/existence.rb +29 -19
  56. data/lib/authlogic/session/foundation.rb +70 -16
  57. data/lib/authlogic/session/http_auth.rb +39 -31
  58. data/lib/authlogic/session/id.rb +27 -15
  59. data/lib/authlogic/session/klass.rb +17 -13
  60. data/lib/authlogic/session/magic_columns.rb +78 -59
  61. data/lib/authlogic/session/magic_states.rb +50 -27
  62. data/lib/authlogic/session/params.rb +79 -50
  63. data/lib/authlogic/session/password.rb +197 -118
  64. data/lib/authlogic/session/perishable_token.rb +12 -6
  65. data/lib/authlogic/session/persistence.rb +20 -14
  66. data/lib/authlogic/session/priority_record.rb +20 -16
  67. data/lib/authlogic/session/scopes.rb +63 -33
  68. data/lib/authlogic/session/session.rb +40 -25
  69. data/lib/authlogic/session/timeout.rb +51 -34
  70. data/lib/authlogic/session/unauthorized_record.rb +24 -18
  71. data/lib/authlogic/session/validation.rb +32 -21
  72. data/lib/authlogic/test_case.rb +123 -35
  73. data/lib/authlogic/test_case/mock_controller.rb +14 -13
  74. data/lib/authlogic/test_case/mock_cookie_jar.rb +14 -5
  75. data/lib/authlogic/test_case/mock_logger.rb +1 -1
  76. data/lib/authlogic/test_case/mock_request.rb +9 -4
  77. data/lib/authlogic/test_case/rails_request_adapter.rb +8 -7
  78. data/lib/authlogic/version.rb +21 -0
  79. data/test/acts_as_authentic_test/base_test.rb +1 -1
  80. data/test/acts_as_authentic_test/email_test.rb +80 -63
  81. data/test/acts_as_authentic_test/logged_in_status_test.rb +14 -8
  82. data/test/acts_as_authentic_test/login_test.rb +91 -49
  83. data/test/acts_as_authentic_test/magic_columns_test.rb +13 -13
  84. data/test/acts_as_authentic_test/password_test.rb +82 -60
  85. data/test/acts_as_authentic_test/perishable_token_test.rb +31 -25
  86. data/test/acts_as_authentic_test/persistence_token_test.rb +9 -5
  87. data/test/acts_as_authentic_test/restful_authentication_test.rb +18 -9
  88. data/test/acts_as_authentic_test/session_maintenance_test.rb +86 -22
  89. data/test/acts_as_authentic_test/single_access_test.rb +15 -15
  90. data/test/adapter_test.rb +21 -0
  91. data/test/authenticates_many_test.rb +26 -11
  92. data/test/config_test.rb +9 -9
  93. data/test/crypto_provider_test/aes256_test.rb +3 -3
  94. data/test/crypto_provider_test/bcrypt_test.rb +1 -1
  95. data/test/crypto_provider_test/scrypt_test.rb +2 -2
  96. data/test/crypto_provider_test/sha1_test.rb +4 -4
  97. data/test/crypto_provider_test/sha256_test.rb +2 -2
  98. data/test/crypto_provider_test/sha512_test.rb +3 -3
  99. data/test/crypto_provider_test/wordpress_test.rb +24 -0
  100. data/test/gemfiles/Gemfile.rails-4.2.x +2 -2
  101. data/test/gemfiles/Gemfile.rails-5.0.x +6 -0
  102. data/test/gemfiles/Gemfile.rails-5.1.x +6 -0
  103. data/test/gemfiles/Gemfile.rails-5.2.x +6 -0
  104. data/test/gemfiles/Gemfile.rails-master +6 -0
  105. data/test/i18n_test.rb +9 -9
  106. data/test/libs/affiliate.rb +2 -2
  107. data/test/libs/company.rb +4 -4
  108. data/test/libs/employee.rb +2 -2
  109. data/test/libs/employee_session.rb +1 -1
  110. data/test/libs/ldaper.rb +1 -1
  111. data/test/libs/project.rb +1 -1
  112. data/test/libs/user_session.rb +2 -2
  113. data/test/random_test.rb +9 -38
  114. data/test/session_test/activation_test.rb +7 -7
  115. data/test/session_test/active_record_trickery_test.rb +9 -6
  116. data/test/session_test/brute_force_protection_test.rb +26 -21
  117. data/test/session_test/callbacks_test.rb +10 -4
  118. data/test/session_test/cookies_test.rb +54 -20
  119. data/test/session_test/existence_test.rb +45 -23
  120. data/test/session_test/foundation_test.rb +17 -1
  121. data/test/session_test/http_auth_test.rb +11 -12
  122. data/test/session_test/id_test.rb +3 -3
  123. data/test/session_test/klass_test.rb +2 -2
  124. data/test/session_test/magic_columns_test.rb +15 -17
  125. data/test/session_test/magic_states_test.rb +17 -19
  126. data/test/session_test/params_test.rb +26 -20
  127. data/test/session_test/password_test.rb +11 -12
  128. data/test/session_test/perishability_test.rb +5 -5
  129. data/test/session_test/persistence_test.rb +4 -3
  130. data/test/session_test/scopes_test.rb +15 -9
  131. data/test/session_test/session_test.rb +7 -6
  132. data/test/session_test/timeout_test.rb +16 -14
  133. data/test/session_test/unauthorized_record_test.rb +3 -3
  134. data/test/session_test/validation_test.rb +5 -5
  135. data/test/test_helper.rb +115 -49
  136. metadata +107 -36
  137. data/README.rdoc +0 -232
  138. data/test/gemfiles/Gemfile.rails-3.2.x +0 -7
  139. data/test/gemfiles/Gemfile.rails-4.0.x +0 -7
  140. data/test/gemfiles/Gemfile.rails-4.1.x +0 -7
@@ -1,12 +1,20 @@
1
1
  module Authlogic
2
2
  module TestCase
3
+ # A mock of `ActionDispatch::Cookies::CookieJar`.
3
4
  class MockCookieJar < Hash # :nodoc:
5
+ attr_accessor :set_cookies
6
+
4
7
  def [](key)
5
8
  hash = super
6
9
  hash && hash[:value]
7
10
  end
8
-
9
- def delete(key, options = {})
11
+
12
+ def []=(key, options)
13
+ (@set_cookies ||= {})[key.to_s] = options
14
+ super
15
+ end
16
+
17
+ def delete(key, _options = {})
10
18
  super(key)
11
19
  end
12
20
 
@@ -23,8 +31,9 @@ module Authlogic
23
31
  end
24
32
 
25
33
  def [](val)
26
- if signed_message = @parent_jar[val]
27
- payload, signature = signed_message.split('--')
34
+ signed_message = @parent_jar[val]
35
+ if signed_message
36
+ payload, signature = signed_message.split("--")
28
37
  raise "Invalid signature" unless Digest::SHA1.hexdigest(payload) == signature
29
38
  payload
30
39
  end
@@ -36,4 +45,4 @@ module Authlogic
36
45
  end
37
46
  end
38
47
  end
39
- end
48
+ end
@@ -7,4 +7,4 @@ module Authlogic
7
7
  end
8
8
  end
9
9
  end
10
- end
10
+ end
@@ -8,12 +8,17 @@ module Authlogic
8
8
  end
9
9
 
10
10
  def ip
11
- (controller && controller.respond_to?(:env) && controller.env.is_a?(Hash) && controller.env['REMOTE_ADDR']) || "1.1.1.1"
11
+ controller &&
12
+ controller.respond_to?(:env) &&
13
+ controller.env.is_a?(Hash) &&
14
+ controller.env["REMOTE_ADDR"] ||
15
+ "1.1.1.1"
12
16
  end
13
17
 
14
18
  private
15
- def method_missing(*args, &block)
16
- end
19
+
20
+ def method_missing(*args, &block)
21
+ end
17
22
  end
18
23
  end
19
- end
24
+ end
@@ -1,11 +1,12 @@
1
1
  module Authlogic
2
2
  module TestCase
3
- # Adapts authlogic to work with the @request object when testing. This way Authlogic can set cookies and what not before
4
- # a request is made, ultimately letting you log in users in functional tests.
3
+ # Adapts authlogic to work with the @request object when testing. This way Authlogic
4
+ # can set cookies and what not before a request is made, ultimately letting you log in
5
+ # users in functional tests.
5
6
  class RailsRequestAdapter < ControllerAdapters::AbstractAdapter
6
7
  def authenticate_with_http_basic(&block)
7
8
  end
8
-
9
+
9
10
  def cookies
10
11
  new_cookies = MockCookieJar.new
11
12
  super.each do |key, value|
@@ -13,18 +14,18 @@ module Authlogic
13
14
  end
14
15
  new_cookies
15
16
  end
16
-
17
+
17
18
  def cookie_domain
18
19
  nil
19
20
  end
20
-
21
+
21
22
  def request
22
23
  @request ||= MockRequest.new(controller)
23
24
  end
24
-
25
+
25
26
  def request_content_type
26
27
  request.format.to_s
27
28
  end
28
29
  end
29
30
  end
30
- end
31
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "rubygems"
4
+
5
+ module Authlogic
6
+ # Returns a `::Gem::Version`, the version number of the authlogic gem.
7
+ #
8
+ # It is preferable for a library to provide a `gem_version` method, rather
9
+ # than a `VERSION` string, because `::Gem::Version` is easier to use in a
10
+ # comparison.
11
+ #
12
+ # We cannot return a frozen `Version`, because rubygems will try to modify it.
13
+ # https://github.com/binarylogic/authlogic/pull/590
14
+ #
15
+ # Added in 4.0.0
16
+ #
17
+ # @api public
18
+ def self.gem_version
19
+ ::Gem::Version.new("4.2.0")
20
+ end
21
+ end
@@ -1,4 +1,4 @@
1
- require 'test_helper'
1
+ require "test_helper"
2
2
 
3
3
  module ActsAsAuthenticTest
4
4
  class BaseTest < ActiveSupport::TestCase
@@ -1,16 +1,15 @@
1
- # encoding: utf-8
2
- require 'test_helper'
1
+ require "test_helper"
3
2
 
4
3
  module ActsAsAuthenticTest
5
4
  class EmailTest < ActiveSupport::TestCase
6
-
7
5
  GOOD_ASCII_EMAILS = [
8
6
  "a@a.com",
9
7
  "damien+test1...etc..@mydomain.com",
10
8
  "dakota.dux+1@gmail.com",
11
9
  "dakota.d'ux@gmail.com",
12
10
  "a&b@c.com",
13
- ]
11
+ "someuser@somedomain.travelersinsurance"
12
+ ].freeze
14
13
 
15
14
  BAD_ASCII_EMAILS = [
16
15
  "",
@@ -18,13 +17,14 @@ module ActsAsAuthenticTest
18
17
  "question?mark@gmail.com",
19
18
  "backslash@g\\mail.com",
20
19
  "<script>alert(123);</script>\nnobody@example.com",
21
- ]
20
+ "someuser@somedomain.isreallytoolongandimeanreallytoolong"
21
+ ].freeze
22
22
 
23
23
  # http://en.wikipedia.org/wiki/ISO/IEC_8859-1#Codepage_layout
24
24
  GOOD_ISO88591_EMAILS = [
25
25
  "töm.öm@dömain.fi", # https://github.com/binarylogic/authlogic/issues/176
26
26
  "Pelé@examplé.com", # http://en.wikipedia.org/wiki/Email_address#Internationalization_examples
27
- ]
27
+ ].freeze
28
28
 
29
29
  BAD_ISO88591_EMAILS = [
30
30
  "",
@@ -33,34 +33,34 @@ module ActsAsAuthenticTest
33
33
  "é[@example.com", # L bracket
34
34
  "question?mark@gmail.com", # question mark
35
35
  "back\\slash@gmail.com", # backslash
36
- ]
36
+ ].freeze
37
37
 
38
38
  GOOD_UTF8_EMAILS = [
39
- "δκιμή@παράδεγμα.δοκμή", # http://en.wikipedia.org/wiki/Email_address#Internationalization_examples
39
+ "δκιμή@παράδεγμα.δοκμή", # http://en.wikipedia.org/wiki/Email_address#Internationalization_examples
40
40
  "我本@屋企.香港", # http://en.wikipedia.org/wiki/Email_address#Internationalization_examples
41
41
  "甲斐@黒川.日買", # http://en.wikipedia.org/wiki/Email_address#Internationalization_examples
42
- "чебурша@ящик-с-пельнами.рф", # Contains dashes in domain head
43
- "企斐@黒川.みんな", # https://github.com/binarylogic/authlogic/issues/176#issuecomment-55829320
44
- ]
42
+ "чебурша@ящик-с-пельнами.рф", # Contains dashes in domain head
43
+ "企斐@黒川.みんな", # https://github.com/binarylogic/authlogic/issues/176#issuecomment-55829320
44
+ ].freeze
45
45
 
46
46
  BAD_UTF8_EMAILS = [
47
47
  "",
48
- ".みんな", # https://github.com/binarylogic/authlogic/issues/176#issuecomment-55829320
49
- 'δκιμή@παράδεγμα.δ', # short TLD
48
+ ".みんな", # https://github.com/binarylogic/authlogic/issues/176#issuecomment-55829320
49
+ "δκιμή@παράδεγμα.δ", # short TLD
50
50
  "öm(@ava.fi", # L paren
51
51
  "é)@domain.com", # R paren
52
52
  "é[@example.com", # L bracket
53
53
  "δ]@πράιγμα.δοκμή", # R bracket
54
54
  "我\.香港", # slash
55
55
  "甲;.日本", # semicolon
56
- "ч:@ящик-с-пельнами.рф", # colon
57
- "斐,.みんな", # comma
56
+ "ч:@ящик-с-пельнами.рф", # colon
57
+ "斐,.みんな", # comma
58
58
  "香<.香港", # less than
59
59
  "我>.香港", # greater than
60
- "我?本@屋企.香港", # question mark
61
- "чебурша@ьн\\ами.рф", # backslash
62
- "user@domain.com%0A<script>alert('hello')</script>",
63
- ]
60
+ "我?本@屋企.香港", # question mark
61
+ "чебурша@ьн\\ами.рф", # backslash
62
+ "user@domain.com%0A<script>alert('hello')</script>"
63
+ ].freeze
64
64
 
65
65
  def test_email_field_config
66
66
  assert_equal :email, User.email_field
@@ -77,44 +77,59 @@ module ActsAsAuthenticTest
77
77
  assert Employee.validate_email_field
78
78
 
79
79
  User.validate_email_field = false
80
- assert !User.validate_email_field
80
+ refute User.validate_email_field
81
81
  User.validate_email_field true
82
82
  assert User.validate_email_field
83
83
  end
84
84
 
85
85
  def test_validates_length_of_email_field_options_config
86
- assert_equal({:maximum => 100}, User.validates_length_of_email_field_options)
87
- assert_equal({:maximum => 100}, Employee.validates_length_of_email_field_options)
86
+ assert_equal({ maximum: 100 }, User.validates_length_of_email_field_options)
87
+ assert_equal({ maximum: 100 }, Employee.validates_length_of_email_field_options)
88
88
 
89
- User.validates_length_of_email_field_options = {:yes => "no"}
90
- assert_equal({:yes => "no"}, User.validates_length_of_email_field_options)
91
- User.validates_length_of_email_field_options({:within => 6..100})
92
- assert_equal({:within => 6..100}, User.validates_length_of_email_field_options)
89
+ User.validates_length_of_email_field_options = { yes: "no" }
90
+ assert_equal({ yes: "no" }, User.validates_length_of_email_field_options)
91
+ User.validates_length_of_email_field_options(within: 6..100)
92
+ assert_equal({ within: 6..100 }, User.validates_length_of_email_field_options)
93
93
  end
94
94
 
95
95
  def test_validates_format_of_email_field_options_config
96
- default = {:with => Authlogic::Regex.email, :message => Proc.new{I18n.t('error_messages.email_invalid', :default => "should look like an email address.")}}
97
- dmessage = default.delete(:message).call
96
+ default = {
97
+ with: Authlogic::Regex::EMAIL,
98
+ message: proc do
99
+ I18n.t(
100
+ "error_messages.email_invalid",
101
+ default: "should look like an email address."
102
+ )
103
+ end
104
+ }
105
+ default_message = default.delete(:message).call
98
106
 
99
107
  options = User.validates_format_of_email_field_options
100
108
  message = options.delete(:message)
101
- assert message.kind_of?(Proc)
102
- assert_equal dmessage, message.call
109
+ assert message.is_a?(Proc)
110
+ assert_equal default_message, message.call
103
111
  assert_equal default, options
104
112
 
105
113
  options = Employee.validates_format_of_email_field_options
106
114
  message = options.delete(:message)
107
- assert message.kind_of?(Proc)
108
- assert_equal dmessage, message.call
115
+ assert message.is_a?(Proc)
116
+ assert_equal default_message, message.call
109
117
  assert_equal default, options
110
118
 
111
-
112
- User.validates_format_of_email_field_options = {:yes => "no"}
113
- assert_equal({:yes => "no"}, User.validates_format_of_email_field_options)
119
+ User.validates_format_of_email_field_options = { yes: "no" }
120
+ assert_equal({ yes: "no" }, User.validates_format_of_email_field_options)
114
121
  User.validates_format_of_email_field_options default
115
122
  assert_equal default, User.validates_format_of_email_field_options
116
123
 
117
- with_email_nonascii = {:with => Authlogic::Regex.email_nonascii, :message => Proc.new{I18n.t('error_messages.email_invalid_international', :default => "should look like an international email address.")}}
124
+ with_email_nonascii = {
125
+ with: Authlogic::Regex::EMAIL_NONASCII,
126
+ message: proc do
127
+ I18n.t(
128
+ "error_messages.email_invalid_international",
129
+ default: "should look like an international email address."
130
+ )
131
+ end
132
+ }
118
133
  User.validates_format_of_email_field_options = with_email_nonascii
119
134
  assert_equal(with_email_nonascii, User.validates_format_of_email_field_options)
120
135
  User.validates_format_of_email_field_options with_email_nonascii
@@ -125,11 +140,11 @@ module ActsAsAuthenticTest
125
140
  # ensure we successfully loaded the test locale
126
141
  assert I18n.available_locales.include?(:lol), "Test locale failed to load"
127
142
 
128
- I18n.with_locale('lol') do
143
+ I18n.with_locale("lol") do
129
144
  message = I18n.t("authlogic.error_messages.email_invalid")
130
145
 
131
146
  cat = User.new
132
- cat.email = 'meow'
147
+ cat.email = "meow"
133
148
  cat.valid?
134
149
 
135
150
  # filter duplicate error messages
@@ -141,11 +156,15 @@ module ActsAsAuthenticTest
141
156
  end
142
157
 
143
158
  def test_validates_uniqueness_of_email_field_options_config
144
- default = {:case_sensitive => false, :scope => Employee.validations_scope, :if => "#{Employee.email_field}_changed?".to_sym}
159
+ default = {
160
+ case_sensitive: false,
161
+ scope: Employee.validations_scope,
162
+ if: "#{Employee.email_field}_changed?".to_sym
163
+ }
145
164
  assert_equal default, Employee.validates_uniqueness_of_email_field_options
146
165
 
147
- Employee.validates_uniqueness_of_email_field_options = {:yes => "no"}
148
- assert_equal({:yes => "no"}, Employee.validates_uniqueness_of_email_field_options)
166
+ Employee.validates_uniqueness_of_email_field_options = { yes: "no" }
167
+ assert_equal({ yes: "no" }, Employee.validates_uniqueness_of_email_field_options)
149
168
  Employee.validates_uniqueness_of_email_field_options default
150
169
  assert_equal default, Employee.validates_uniqueness_of_email_field_options
151
170
  end
@@ -153,70 +172,68 @@ module ActsAsAuthenticTest
153
172
  def test_validates_length_of_email_field
154
173
  u = User.new
155
174
  u.email = "a@a.a"
156
- assert !u.valid?
157
- assert u.errors[:email].size > 0
175
+ refute u.valid?
176
+ refute u.errors[:email].empty?
158
177
 
159
178
  u.email = "a@a.com"
160
- assert !u.valid?
161
- assert u.errors[:email].size == 0
179
+ refute u.valid?
180
+ assert u.errors[:email].empty?
162
181
  end
163
182
 
164
183
  def test_validates_format_of_email_field
165
184
  u = User.new
166
185
  u.email = "aaaaaaaaaaaaa"
167
186
  u.valid?
168
- assert u.errors[:email].size > 0
187
+ refute u.errors[:email].empty?
169
188
 
170
189
  u.email = "a@a.com"
171
190
  u.valid?
172
- assert u.errors[:email].size == 0
191
+ assert u.errors[:email].empty?
173
192
 
174
193
  u.email = "damien+test1...etc..@mydomain.com"
175
194
  u.valid?
176
- assert u.errors[:email].size == 0
195
+ assert u.errors[:email].empty?
177
196
 
178
197
  u.email = "dakota.dux+1@gmail.com"
179
198
  u.valid?
180
- assert u.errors[:email].size == 0
199
+ assert u.errors[:email].empty?
181
200
 
182
201
  u.email = "dakota.d'ux@gmail.com"
183
202
  u.valid?
184
- assert u.errors[:email].size == 0
203
+ assert u.errors[:email].empty?
185
204
 
186
205
  u.email = "<script>alert(123);</script>\nnobody@example.com"
187
- assert !u.valid?
188
- assert u.errors[:email].size > 0
206
+ refute u.valid?
207
+ refute u.errors[:email].empty?
189
208
 
190
209
  u.email = "a&b@c.com"
191
210
  u.valid?
192
- assert u.errors[:email].size == 0
211
+ assert u.errors[:email].empty?
193
212
  end
194
213
 
195
214
  def test_validates_format_of_nonascii_email_field
196
-
197
215
  (GOOD_ASCII_EMAILS + GOOD_ISO88591_EMAILS + GOOD_UTF8_EMAILS).each do |e|
198
- assert e =~ Authlogic::Regex.email_nonascii, "Good email should validate: #{e}"
216
+ assert e =~ Authlogic::Regex::EMAIL_NONASCII, "Good email should validate: #{e}"
199
217
  end
200
218
 
201
219
  (BAD_ASCII_EMAILS + BAD_ISO88591_EMAILS + BAD_UTF8_EMAILS).each do |e|
202
- assert e !~ Authlogic::Regex.email_nonascii, "Bad email should not validate: #{e}"
220
+ assert e !~ Authlogic::Regex::EMAIL_NONASCII, "Bad email should not validate: #{e}"
203
221
  end
204
-
205
222
  end
206
223
 
207
224
  def test_validates_uniqueness_of_email_field
208
225
  u = User.new
209
226
  u.email = "bjohnson@binarylogic.com"
210
- assert !u.valid?
211
- assert u.errors[:email].size > 0
227
+ refute u.valid?
228
+ refute u.errors[:email].empty?
212
229
 
213
230
  u.email = "BJOHNSON@binarylogic.com"
214
- assert !u.valid?
215
- assert u.errors[:email].size > 0
231
+ refute u.valid?
232
+ refute u.errors[:email].empty?
216
233
 
217
234
  u.email = "a@a.com"
218
- assert !u.valid?
219
- assert u.errors[:email].size == 0
235
+ refute u.valid?
236
+ assert u.errors[:email].empty?
220
237
  end
221
238
  end
222
239
  end
@@ -1,8 +1,8 @@
1
- require 'test_helper'
1
+ require "test_helper"
2
2
 
3
3
  module ActsAsAuthenticTest
4
4
  class LoggedInStatusTest < ActiveSupport::TestCase
5
- ERROR_MSG = 'Multiple calls to %s should result in different relations'
5
+ ERROR_MSG = "Multiple calls to %s should result in different relations".freeze
6
6
 
7
7
  def test_logged_in_timeout_config
8
8
  assert_equal 10.minutes.to_i, User.logged_in_timeout
@@ -19,10 +19,13 @@ module ActsAsAuthenticTest
19
19
  # slightly different. This is an attempt to make sure the scope is lambda wrapped
20
20
  # so that it is re-evaluated every time its called. My biggest concern is that the
21
21
  # test happens so fast that the test fails... I just don't know a better way to test it!
22
- query1 = User.logged_in.where_values
22
+
23
+ # for rails 5 I've changed the where_values to to_sql to compare
24
+
25
+ query1 = User.logged_in.to_sql
23
26
  sleep 0.1
24
- query2 = User.logged_in.where_values
25
- assert query1 != query2, ERROR_MSG % '#logged_in'
27
+ query2 = User.logged_in.to_sql
28
+ assert query1 != query2, ERROR_MSG % "#logged_in"
26
29
 
27
30
  assert_equal 0, User.logged_in.count
28
31
  user = User.first
@@ -37,7 +40,10 @@ module ActsAsAuthenticTest
37
40
  # slightly different. This is an attempt to make sure the scope is lambda wrapped
38
41
  # so that it is re-evaluated every time its called. My biggest concern is that the
39
42
  # test happens so fast that the test fails... I just don't know a better way to test it!
40
- assert User.logged_in.where_values != User.logged_out.where_values, ERROR_MSG % '#logged_out'
43
+
44
+ # for rails 5 I've changed the where_values to to_sql to compare
45
+
46
+ assert User.logged_in.to_sql != User.logged_out.to_sql, ERROR_MSG % "#logged_out"
41
47
 
42
48
  assert_equal 3, User.logged_out.count
43
49
  User.first.update_attribute(:last_request_at, Time.now)
@@ -46,11 +52,11 @@ module ActsAsAuthenticTest
46
52
 
47
53
  def test_logged_in_logged_out
48
54
  u = User.first
49
- assert !u.logged_in?
55
+ refute u.logged_in?
50
56
  assert u.logged_out?
51
57
  u.last_request_at = Time.now
52
58
  assert u.logged_in?
53
- assert !u.logged_out?
59
+ refute u.logged_out?
54
60
  end
55
61
  end
56
62
  end