authlogic 3.8.0 → 4.0.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 (102) hide show
  1. checksums.yaml +7 -0
  2. data/.github/triage.md +87 -0
  3. data/.gitignore +2 -1
  4. data/.rubocop.yml +62 -6
  5. data/.rubocop_todo.yml +51 -267
  6. data/.travis.yml +4 -26
  7. data/CHANGELOG.md +226 -2
  8. data/CONTRIBUTING.md +15 -5
  9. data/Gemfile +2 -2
  10. data/README.md +183 -91
  11. data/Rakefile +1 -1
  12. data/UPGRADING.md +20 -0
  13. data/authlogic.gemspec +25 -16
  14. data/lib/authlogic.rb +45 -45
  15. data/lib/authlogic/acts_as_authentic/base.rb +18 -11
  16. data/lib/authlogic/acts_as_authentic/email.rb +32 -28
  17. data/lib/authlogic/acts_as_authentic/logged_in_status.rb +1 -1
  18. data/lib/authlogic/acts_as_authentic/login.rb +32 -42
  19. data/lib/authlogic/acts_as_authentic/magic_columns.rb +6 -6
  20. data/lib/authlogic/acts_as_authentic/password.rb +53 -31
  21. data/lib/authlogic/acts_as_authentic/perishable_token.rb +18 -17
  22. data/lib/authlogic/acts_as_authentic/persistence_token.rb +7 -12
  23. data/lib/authlogic/acts_as_authentic/queries/find_with_case.rb +64 -0
  24. data/lib/authlogic/acts_as_authentic/restful_authentication.rb +11 -3
  25. data/lib/authlogic/acts_as_authentic/session_maintenance.rb +30 -10
  26. data/lib/authlogic/acts_as_authentic/single_access_token.rb +4 -4
  27. data/lib/authlogic/authenticates_many/association.rb +3 -3
  28. data/lib/authlogic/authenticates_many/base.rb +2 -2
  29. data/lib/authlogic/config.rb +0 -1
  30. data/lib/authlogic/controller_adapters/abstract_adapter.rb +11 -4
  31. data/lib/authlogic/controller_adapters/rack_adapter.rb +7 -3
  32. data/lib/authlogic/controller_adapters/rails_adapter.rb +2 -0
  33. data/lib/authlogic/crypto_providers/aes256.rb +1 -1
  34. data/lib/authlogic/crypto_providers/bcrypt.rb +1 -1
  35. data/lib/authlogic/crypto_providers/scrypt.rb +6 -6
  36. data/lib/authlogic/crypto_providers/sha1.rb +10 -5
  37. data/lib/authlogic/crypto_providers/sha256.rb +11 -8
  38. data/lib/authlogic/crypto_providers/wordpress.rb +2 -2
  39. data/lib/authlogic/i18n.rb +4 -2
  40. data/lib/authlogic/random.rb +10 -28
  41. data/lib/authlogic/regex.rb +11 -8
  42. data/lib/authlogic/session/activation.rb +6 -3
  43. data/lib/authlogic/session/active_record_trickery.rb +13 -9
  44. data/lib/authlogic/session/base.rb +15 -4
  45. data/lib/authlogic/session/brute_force_protection.rb +14 -7
  46. data/lib/authlogic/session/callbacks.rb +53 -30
  47. data/lib/authlogic/session/cookies.rb +57 -16
  48. data/lib/authlogic/session/existence.rb +21 -11
  49. data/lib/authlogic/session/foundation.rb +56 -10
  50. data/lib/authlogic/session/http_auth.rb +15 -8
  51. data/lib/authlogic/session/klass.rb +7 -5
  52. data/lib/authlogic/session/magic_columns.rb +24 -11
  53. data/lib/authlogic/session/magic_states.rb +11 -4
  54. data/lib/authlogic/session/params.rb +6 -2
  55. data/lib/authlogic/session/password.rb +46 -73
  56. data/lib/authlogic/session/persistence.rb +11 -7
  57. data/lib/authlogic/session/priority_record.rb +7 -4
  58. data/lib/authlogic/session/scopes.rb +15 -6
  59. data/lib/authlogic/session/session.rb +20 -10
  60. data/lib/authlogic/session/timeout.rb +2 -2
  61. data/lib/authlogic/session/unauthorized_record.rb +1 -1
  62. data/lib/authlogic/session/validation.rb +1 -1
  63. data/lib/authlogic/test_case.rb +65 -2
  64. data/lib/authlogic/test_case/mock_controller.rb +5 -4
  65. data/lib/authlogic/test_case/mock_cookie_jar.rb +11 -2
  66. data/lib/authlogic/test_case/mock_request.rb +5 -1
  67. data/lib/authlogic/test_case/rails_request_adapter.rb +3 -2
  68. data/lib/authlogic/version.rb +16 -0
  69. data/test/acts_as_authentic_test/email_test.rb +33 -34
  70. data/test/acts_as_authentic_test/logged_in_status_test.rb +1 -1
  71. data/test/acts_as_authentic_test/login_test.rb +73 -78
  72. data/test/acts_as_authentic_test/password_test.rb +30 -18
  73. data/test/acts_as_authentic_test/perishable_token_test.rb +9 -3
  74. data/test/acts_as_authentic_test/persistence_token_test.rb +4 -0
  75. data/test/acts_as_authentic_test/session_maintenance_test.rb +66 -14
  76. data/test/adapter_test.rb +21 -0
  77. data/test/gemfiles/Gemfile.rails-4.2.x +2 -2
  78. data/test/gemfiles/Gemfile.rails-5.0.x +2 -2
  79. data/test/gemfiles/Gemfile.rails-master +6 -0
  80. data/test/i18n_test.rb +1 -1
  81. data/test/libs/company.rb +2 -2
  82. data/test/random_test.rb +7 -37
  83. data/test/session_test/active_record_trickery_test.rb +4 -3
  84. data/test/session_test/brute_force_protection_test.rb +8 -8
  85. data/test/session_test/callbacks_test.rb +1 -1
  86. data/test/session_test/cookies_test.rb +27 -4
  87. data/test/session_test/existence_test.rb +15 -4
  88. data/test/session_test/foundation_test.rb +16 -0
  89. data/test/session_test/http_auth_test.rb +3 -1
  90. data/test/session_test/magic_columns_test.rb +10 -12
  91. data/test/session_test/params_test.rb +4 -1
  92. data/test/session_test/password_test.rb +7 -7
  93. data/test/session_test/persistence_test.rb +1 -0
  94. data/test/session_test/scopes_test.rb +7 -7
  95. data/test/session_test/session_test.rb +2 -2
  96. data/test/session_test/timeout_test.rb +1 -1
  97. data/test/session_test/unauthorized_record_test.rb +1 -1
  98. data/test/test_helper.rb +111 -103
  99. metadata +68 -64
  100. data/test/gemfiles/Gemfile.rails-3.2.x +0 -7
  101. data/test/gemfiles/Gemfile.rails-4.0.x +0 -7
  102. data/test/gemfiles/Gemfile.rails-4.1.x +0 -7
@@ -69,7 +69,7 @@ module Authlogic
69
69
  # The name of your cookies will be:
70
70
  #
71
71
  # secure_account_2_user_credentials
72
- def with_scope(options = {}, &block)
72
+ def with_scope(options = {})
73
73
  raise ArgumentError.new("You must provide a block") unless block_given?
74
74
  self.scope = options
75
75
  result = yield
@@ -103,14 +103,23 @@ module Authlogic
103
103
  [scope[:id], super].compact.join("_")
104
104
  end
105
105
 
106
+ # `args[0]` is the name of an AR method, like
107
+ # `find_by_single_access_token`.
106
108
  def search_for_record(*args)
107
- session_scope = if scope[:find_options].is_a?(ActiveRecord::Relation)
109
+ search_scope.scoping do
110
+ klass.send(*args)
111
+ end
112
+ end
113
+
114
+ # Returns an AR relation representing the scope of the search. The
115
+ # relation is either provided directly by, or defined by
116
+ # `find_options`.
117
+ def search_scope
118
+ if scope[:find_options].is_a?(ActiveRecord::Relation)
108
119
  scope[:find_options]
109
120
  else
110
- klass.send(:where, scope[:find_options] && scope[:find_options][:conditions] || {})
111
- end
112
- session_scope.scoping do
113
- klass.send(*args)
121
+ conditions = scope[:find_options] && scope[:find_options][:conditions] || {}
122
+ klass.send(:where, conditions)
114
123
  end
115
124
  end
116
125
  end
@@ -1,6 +1,7 @@
1
1
  module Authlogic
2
2
  module Session
3
- # Handles all parts of authentication that deal with sessions. Such as persisting a session and saving / destroy a session.
3
+ # Handles all parts of authentication that deal with sessions. Such as persisting a
4
+ # session and saving / destroy a session.
4
5
  module Session
5
6
  def self.included(klass)
6
7
  klass.class_eval do
@@ -9,7 +10,7 @@ module Authlogic
9
10
  persist :persist_by_session
10
11
  after_save :update_session
11
12
  after_destroy :update_session
12
- after_persisting :update_session, :unless => :single_access?
13
+ after_persisting :update_session, unless: :single_access?
13
14
  end
14
15
  end
15
16
 
@@ -33,19 +34,27 @@ module Authlogic
33
34
  def persist_by_session
34
35
  persistence_token, record_id = session_credentials
35
36
  if !persistence_token.nil?
36
- # Allow finding by persistence token, because when records are created the
37
- # session is maintained in a before_save, when there is no id. This is done
38
- # for performance reasons and to save on queries.
39
- record = record_id.nil? ?
40
- search_for_record("find_by_persistence_token", persistence_token.to_s) :
41
- search_for_record("find_by_#{klass.primary_key}", record_id.to_s)
42
- self.unauthorized_record = record if record && record.persistence_token == persistence_token
37
+ record = persist_by_session_search(persistence_token, record_id)
38
+ if record && record.persistence_token == persistence_token
39
+ self.unauthorized_record = record
40
+ end
43
41
  valid?
44
42
  else
45
43
  false
46
44
  end
47
45
  end
48
46
 
47
+ # Allow finding by persistence token, because when records are created
48
+ # the session is maintained in a before_save, when there is no id.
49
+ # This is done for performance reasons and to save on queries.
50
+ def persist_by_session_search(persistence_token, record_id)
51
+ if record_id.nil?
52
+ search_for_record("find_by_persistence_token", persistence_token.to_s)
53
+ else
54
+ search_for_record("find_by_#{klass.primary_key}", record_id.to_s)
55
+ end
56
+ end
57
+
49
58
  def session_credentials
50
59
  [
51
60
  controller.session[session_key],
@@ -59,7 +68,8 @@ module Authlogic
59
68
 
60
69
  def update_session
61
70
  controller.session[session_key] = record && record.persistence_token
62
- controller.session["#{session_key}_#{klass.primary_key}"] = record && record.send(record.class.primary_key)
71
+ compound_key = "#{session_key}_#{klass.primary_key}"
72
+ controller.session[compound_key] = record && record.send(record.class.primary_key)
63
73
  end
64
74
  end
65
75
  end
@@ -41,7 +41,7 @@ module Authlogic
41
41
  # they login and then leave the website, when do mark them as logged
42
42
  # out? I recommend just using this as a fun feature on your website or
43
43
  # reports, giving you a ballpark number of users logged in and active.
44
- # This is not meant to be a dead accurate representation of a users
44
+ # This is not meant to be a dead accurate representation of a user's
45
45
  # logged in state, since there is really no real way to do this with web
46
46
  # based apps. Think about a user that logs in and doesn't log out. There
47
47
  # is no action that tells you that the user isn't technically still
@@ -52,7 +52,7 @@ module Authlogic
52
52
  # this option to true and if your record returns true for stale? then
53
53
  # they will be required to log back in.
54
54
  #
55
- # Lastly, UserSession.find will still return a object is the session is
55
+ # Lastly, UserSession.find will still return an object if the session is
56
56
  # stale, but you will not get a record. This allows you to determine if
57
57
  # the user needs to log back in because their session went stale, or
58
58
  # because they just aren't logged in. Just call
@@ -15,7 +15,7 @@ module Authlogic
15
15
  def self.included(klass)
16
16
  klass.class_eval do
17
17
  attr_accessor :unauthorized_record
18
- validate :validate_by_unauthorized_record, :if => :authenticating_with_unauthorized_record?
18
+ validate :validate_by_unauthorized_record, if: :authenticating_with_unauthorized_record?
19
19
  end
20
20
  end
21
21
 
@@ -83,7 +83,7 @@ module Authlogic
83
83
  :base,
84
84
  I18n.t(
85
85
  'error_messages.no_authentication_details',
86
- :default => "You did not provide any details for authentication."
86
+ default: "You did not provide any details for authentication."
87
87
  )
88
88
  )
89
89
  end
@@ -50,7 +50,7 @@ module Authlogic
50
50
  # ben:
51
51
  # email: whatever@whatever.com
52
52
  # password_salt: <%= salt = Authlogic::Random.hex_token %>
53
- # crypted_password: <%= Authlogic::CryptoProviders::Sha512.encrypt("benrocks" + salt) %>
53
+ # crypted_password: <%= Authlogic::CryptoProviders::SCrypt.encrypt("benrocks" + salt) %>
54
54
  # persistence_token: <%= Authlogic::Random.hex_token %>
55
55
  # single_access_token: <%= Authlogic::Random.friendly_token %>
56
56
  # perishable_token: <%= Authlogic::Random.friendly_token %>
@@ -113,6 +113,67 @@ module Authlogic
113
113
  #
114
114
  # See how I am checking that Authlogic is interacting with the controller
115
115
  # properly? That's the idea here.
116
+ #
117
+ # === Testing with Rails 5
118
+ #
119
+ # Rails 5 has [deprecated classic controller tests](https://goo.gl/4zmt6y).
120
+ # Controller tests now inherit from `ActionDispatch::IntegrationTest` making
121
+ # them plain old integration tests now. You have two options for testing
122
+ # AuthLogic in Rails 5:
123
+ #
124
+ # * Add the `rails-controller-testing` gem to bring back the original
125
+ # controller testing usage
126
+ # * Go full steam ahead with integration testing and actually log a user in
127
+ # by submitting a form in the integration test.
128
+ #
129
+ # Naturally DHH recommends the second method and this is
130
+ # [what he does in his own tests](https://goo.gl/Ar6p0u). This is useful
131
+ # for testing not only AuthLogic itself (submitting login credentials to a
132
+ # UserSessionsController, for example) but any controller action that is
133
+ # behind a login wall. Add a helper method and use that before testing your
134
+ # actual controller action:
135
+ #
136
+ # # test/test_helper.rb
137
+ # def login(user)
138
+ # post user_sessions_url, :params => { :email => user.email, :password => 'password' }
139
+ # end
140
+ #
141
+ # # test/controllers/posts_controller_test.rb
142
+ # test "#create requires a user to be logged in
143
+ # post posts_url, :params => { :body => 'Lorem ipsum' }
144
+ #
145
+ # assert_redirected_to new_user_session_url
146
+ # end
147
+ #
148
+ # test "#create lets a logged in user create a new post" do
149
+ # login(users(:admin))
150
+ #
151
+ # assert_difference 'Posts.count' do
152
+ # post posts_url, :params => { :body => 'Lorem ipsum' }
153
+ # end
154
+ #
155
+ # assert_redirected_to posts_url
156
+ # end
157
+ #
158
+ # You still have access to the `session` helper in an integration test and so
159
+ # you can still test to see if a user is logged in. A couple of helper methods
160
+ # might look like:
161
+ #
162
+ # # test/test_helper.rb
163
+ # def assert_logged_in
164
+ # assert session[:user_credentials].present?
165
+ # end
166
+ #
167
+ # def assert_not_logged_in
168
+ # assert session[:user_credentials].blank?
169
+ # end
170
+ #
171
+ # # test/user_sessions_controller_test.rb
172
+ # test "#create logs in a user" do
173
+ # login(users(:admin))
174
+ #
175
+ # assert_logged_in
176
+ # end
116
177
  module TestCase
117
178
  # Activates authlogic so that you can use it in your tests. You should call
118
179
  # this method in your test's setup. Ex:
@@ -125,7 +186,9 @@ module Authlogic
125
186
  end
126
187
  end
127
188
 
128
- Authlogic::Session::Base.controller = (@request && Authlogic::TestCase::RailsRequestAdapter.new(@request)) || controller
189
+ Authlogic::Session::Base.controller = @request &&
190
+ Authlogic::TestCase::RailsRequestAdapter.new(@request) ||
191
+ controller
129
192
  end
130
193
 
131
194
  # The Authlogic::TestCase::MockController object passed to Authlogic to
@@ -1,7 +1,8 @@
1
1
  module Authlogic
2
2
  module TestCase
3
- # Basically acts like a controller but doesn't do anything. Authlogic can interact with this, do it's thing and then you
4
- # can look at the controller object to see if anything changed.
3
+ # Basically acts like a controller but doesn't do anything. Authlogic can interact
4
+ # with this, do it's thing and then you can look at the controller object to see if
5
+ # anything changed.
5
6
  class MockController < ControllerAdapters::AbstractAdapter
6
7
  attr_accessor :http_user, :http_password, :realm
7
8
  attr_writer :request_content_type
@@ -9,11 +10,11 @@ module Authlogic
9
10
  def initialize
10
11
  end
11
12
 
12
- def authenticate_with_http_basic(&block)
13
+ def authenticate_with_http_basic
13
14
  yield http_user, http_password
14
15
  end
15
16
 
16
- def authenticate_or_request_with_http_basic(realm = 'DefaultRealm', &block)
17
+ def authenticate_or_request_with_http_basic(realm = 'DefaultRealm')
17
18
  self.realm = realm
18
19
  @http_auth_requested = true
19
20
  yield http_user, http_password
@@ -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
11
 
9
- def delete(key, options = {})
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,7 +31,8 @@ module Authlogic
23
31
  end
24
32
 
25
33
  def [](val)
26
- if signed_message = @parent_jar[val]
34
+ signed_message = @parent_jar[val]
35
+ if signed_message
27
36
  payload, signature = signed_message.split('--')
28
37
  raise "Invalid signature" unless Digest::SHA1.hexdigest(payload) == signature
29
38
  payload
@@ -8,7 +8,11 @@ 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
@@ -1,7 +1,8 @@
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
@@ -0,0 +1,16 @@
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
+ # @api public
13
+ def self.gem_version
14
+ ::Gem::Version.new('4.0.0')
15
+ end
16
+ end
@@ -1,4 +1,3 @@
1
- # encoding: utf-8
2
1
  require 'test_helper'
3
2
 
4
3
  module ActsAsAuthenticTest
@@ -10,7 +9,7 @@ module ActsAsAuthenticTest
10
9
  "dakota.d'ux@gmail.com",
11
10
  "a&b@c.com",
12
11
  "someuser@somedomain.travelersinsurance"
13
- ]
12
+ ].freeze
14
13
 
15
14
  BAD_ASCII_EMAILS = [
16
15
  "",
@@ -19,13 +18,13 @@ module ActsAsAuthenticTest
19
18
  "backslash@g\\mail.com",
20
19
  "<script>alert(123);</script>\nnobody@example.com",
21
20
  "someuser@somedomain.isreallytoolongandimeanreallytoolong"
22
- ]
21
+ ].freeze
23
22
 
24
23
  # http://en.wikipedia.org/wiki/ISO/IEC_8859-1#Codepage_layout
25
24
  GOOD_ISO88591_EMAILS = [
26
25
  "töm.öm@dömain.fi", # https://github.com/binarylogic/authlogic/issues/176
27
26
  "Pelé@examplé.com", # http://en.wikipedia.org/wiki/Email_address#Internationalization_examples
28
- ]
27
+ ].freeze
29
28
 
30
29
  BAD_ISO88591_EMAILS = [
31
30
  "",
@@ -34,19 +33,19 @@ module ActsAsAuthenticTest
34
33
  "é[@example.com", # L bracket
35
34
  "question?mark@gmail.com", # question mark
36
35
  "back\\slash@gmail.com", # backslash
37
- ]
36
+ ].freeze
38
37
 
39
38
  GOOD_UTF8_EMAILS = [
40
- "δκιμή@παράδεγμα.δοκμή", # http://en.wikipedia.org/wiki/Email_address#Internationalization_examples
39
+ "δκιμή@παράδεγμα.δοκμή", # http://en.wikipedia.org/wiki/Email_address#Internationalization_examples
41
40
  "我本@屋企.香港", # http://en.wikipedia.org/wiki/Email_address#Internationalization_examples
42
41
  "甲斐@黒川.日買", # http://en.wikipedia.org/wiki/Email_address#Internationalization_examples
43
- "чебурша@ящик-с-пельнами.рф", # Contains dashes in domain head
44
- "企斐@黒川.みんな", # https://github.com/binarylogic/authlogic/issues/176#issuecomment-55829320
45
- ]
42
+ "чебурша@ящик-с-пельнами.рф", # Contains dashes in domain head
43
+ "企斐@黒川.みんな", # https://github.com/binarylogic/authlogic/issues/176#issuecomment-55829320
44
+ ].freeze
46
45
 
47
46
  BAD_UTF8_EMAILS = [
48
47
  "",
49
- ".みんな", # https://github.com/binarylogic/authlogic/issues/176#issuecomment-55829320
48
+ ".みんな", # https://github.com/binarylogic/authlogic/issues/176#issuecomment-55829320
50
49
  'δκιμή@παράδεγμα.δ', # short TLD
51
50
  "öm(@ava.fi", # L paren
52
51
  "é)@domain.com", # R paren
@@ -54,14 +53,14 @@ module ActsAsAuthenticTest
54
53
  "δ]@πράιγμα.δοκμή", # R bracket
55
54
  "我\.香港", # slash
56
55
  "甲;.日本", # semicolon
57
- "ч:@ящик-с-пельнами.рф", # colon
58
- "斐,.みんな", # comma
56
+ "ч:@ящик-с-пельнами.рф", # colon
57
+ "斐,.みんな", # comma
59
58
  "香<.香港", # less than
60
59
  "我>.香港", # greater than
61
- "我?本@屋企.香港", # question mark
62
- "чебурша@ьн\\ами.рф", # backslash
60
+ "我?本@屋企.香港", # question mark
61
+ "чебурша@ьн\\ами.рф", # backslash
63
62
  "user@domain.com%0A<script>alert('hello')</script>"
64
- ]
63
+ ].freeze
65
64
 
66
65
  def test_email_field_config
67
66
  assert_equal :email, User.email_field
@@ -84,22 +83,22 @@ module ActsAsAuthenticTest
84
83
  end
85
84
 
86
85
  def test_validates_length_of_email_field_options_config
87
- assert_equal({ :maximum => 100 }, User.validates_length_of_email_field_options)
88
- 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)
89
88
 
90
- User.validates_length_of_email_field_options = { :yes => "no" }
91
- assert_equal({ :yes => "no" }, User.validates_length_of_email_field_options)
92
- User.validates_length_of_email_field_options({ :within => 6..100 })
93
- 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)
94
93
  end
95
94
 
96
95
  def test_validates_format_of_email_field_options_config
97
96
  default = {
98
- :with => Authlogic::Regex.email,
99
- :message => proc do
97
+ with: Authlogic::Regex.email,
98
+ message: proc do
100
99
  I18n.t(
101
100
  'error_messages.email_invalid',
102
- :default => "should look like an email address."
101
+ default: "should look like an email address."
103
102
  )
104
103
  end
105
104
  }
@@ -117,17 +116,17 @@ module ActsAsAuthenticTest
117
116
  assert_equal default_message, message.call
118
117
  assert_equal default, options
119
118
 
120
- User.validates_format_of_email_field_options = { :yes => "no" }
121
- 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)
122
121
  User.validates_format_of_email_field_options default
123
122
  assert_equal default, User.validates_format_of_email_field_options
124
123
 
125
124
  with_email_nonascii = {
126
- :with => Authlogic::Regex.email_nonascii,
127
- :message => Proc.new do
125
+ with: Authlogic::Regex.email_nonascii,
126
+ message: Proc.new do
128
127
  I18n.t(
129
128
  'error_messages.email_invalid_international',
130
- :default => "should look like an international email address."
129
+ default: "should look like an international email address."
131
130
  )
132
131
  end
133
132
  }
@@ -158,14 +157,14 @@ module ActsAsAuthenticTest
158
157
 
159
158
  def test_validates_uniqueness_of_email_field_options_config
160
159
  default = {
161
- :case_sensitive => false,
162
- :scope => Employee.validations_scope,
163
- :if => "#{Employee.email_field}_changed?".to_sym
160
+ case_sensitive: false,
161
+ scope: Employee.validations_scope,
162
+ if: "#{Employee.email_field}_changed?".to_sym
164
163
  }
165
164
  assert_equal default, Employee.validates_uniqueness_of_email_field_options
166
165
 
167
- Employee.validates_uniqueness_of_email_field_options = { :yes => "no" }
168
- 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)
169
168
  Employee.validates_uniqueness_of_email_field_options default
170
169
  assert_equal default, Employee.validates_uniqueness_of_email_field_options
171
170
  end