authlogic 3.5.0 → 3.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (58) hide show
  1. checksums.yaml +4 -4
  2. data/.github/ISSUE_TEMPLATE.md +13 -0
  3. data/.rubocop_todo.yml +1 -37
  4. data/.travis.yml +11 -6
  5. data/CHANGELOG.md +19 -0
  6. data/CONTRIBUTING.md +13 -2
  7. data/README.md +2 -3
  8. data/authlogic.gemspec +5 -5
  9. data/lib/authlogic/acts_as_authentic/base.rb +4 -2
  10. data/lib/authlogic/acts_as_authentic/email.rb +8 -3
  11. data/lib/authlogic/acts_as_authentic/logged_in_status.rb +21 -3
  12. data/lib/authlogic/acts_as_authentic/login.rb +44 -25
  13. data/lib/authlogic/acts_as_authentic/password.rb +28 -12
  14. data/lib/authlogic/acts_as_authentic/perishable_token.rb +21 -12
  15. data/lib/authlogic/acts_as_authentic/restful_authentication.rb +16 -9
  16. data/lib/authlogic/acts_as_authentic/session_maintenance.rb +5 -3
  17. data/lib/authlogic/authenticates_many/association.rb +7 -4
  18. data/lib/authlogic/controller_adapters/rack_adapter.rb +6 -2
  19. data/lib/authlogic/controller_adapters/rails_adapter.rb +11 -8
  20. data/lib/authlogic/crypto_providers/bcrypt.rb +4 -1
  21. data/lib/authlogic/crypto_providers/sha512.rb +15 -10
  22. data/lib/authlogic/session/activation.rb +19 -10
  23. data/lib/authlogic/session/cookies.rb +3 -1
  24. data/lib/authlogic/session/id.rb +13 -7
  25. data/lib/authlogic/session/magic_columns.rb +19 -10
  26. data/lib/authlogic/session/magic_states.rb +7 -1
  27. data/lib/authlogic/session/password.rb +48 -34
  28. data/lib/authlogic/session/perishable_token.rb +7 -3
  29. data/lib/authlogic/session/validation.rb +13 -11
  30. data/lib/authlogic/test_case.rb +52 -32
  31. data/test/acts_as_authentic_test/email_test.rb +33 -29
  32. data/test/acts_as_authentic_test/logged_in_status_test.rb +2 -2
  33. data/test/acts_as_authentic_test/login_test.rb +50 -37
  34. data/test/acts_as_authentic_test/magic_columns_test.rb +8 -8
  35. data/test/acts_as_authentic_test/password_test.rb +14 -14
  36. data/test/acts_as_authentic_test/perishable_token_test.rb +5 -5
  37. data/test/acts_as_authentic_test/persistence_token_test.rb +4 -4
  38. data/test/acts_as_authentic_test/restful_authentication_test.rb +6 -6
  39. data/test/acts_as_authentic_test/session_maintenance_test.rb +15 -10
  40. data/test/acts_as_authentic_test/single_access_test.rb +6 -6
  41. data/test/authenticates_many_test.rb +1 -1
  42. data/test/gemfiles/Gemfile.rails-5.1.x +6 -0
  43. data/test/session_test/activation_test.rb +1 -1
  44. data/test/session_test/active_record_trickery_test.rb +3 -3
  45. data/test/session_test/brute_force_protection_test.rb +19 -14
  46. data/test/session_test/cookies_test.rb +21 -12
  47. data/test/session_test/existence_test.rb +15 -10
  48. data/test/session_test/http_auth_test.rb +2 -2
  49. data/test/session_test/magic_columns_test.rb +7 -4
  50. data/test/session_test/magic_states_test.rb +7 -9
  51. data/test/session_test/params_test.rb +6 -6
  52. data/test/session_test/password_test.rb +2 -2
  53. data/test/session_test/perishability_test.rb +1 -1
  54. data/test/session_test/persistence_test.rb +2 -2
  55. data/test/session_test/timeout_test.rb +7 -5
  56. data/test/session_test/validation_test.rb +1 -1
  57. data/test/test_helper.rb +10 -2
  58. metadata +10 -7
@@ -1,7 +1,9 @@
1
1
  module Authlogic
2
2
  module Session
3
- # Maintains the perishable token, which is helpful for confirming records or authorizing records to reset their password. All that this
4
- # module does is reset it after a session have been saved, just keep it changing. The more it changes, the tighter the security.
3
+ # Maintains the perishable token, which is helpful for confirming records or
4
+ # authorizing records to reset their password. All that this module does is
5
+ # reset it after a session have been saved, just keep it changing. The more
6
+ # it changes, the tighter the security.
5
7
  #
6
8
  # See Authlogic::ActsAsAuthentic::PerishableToken for more information.
7
9
  module PerishableToken
@@ -12,7 +14,9 @@ module Authlogic
12
14
  private
13
15
 
14
16
  def reset_perishable_token!
15
- record.reset_perishable_token if record.respond_to?(:reset_perishable_token) && !record.disable_perishable_token_maintenance?
17
+ if record.respond_to?(:reset_perishable_token) && !record.disable_perishable_token_maintenance?
18
+ record.reset_perishable_token
19
+ end
16
20
  end
17
21
  end
18
22
  end
@@ -2,7 +2,8 @@ module Authlogic
2
2
  module Session
3
3
  # Responsible for session validation
4
4
  module Validation
5
- # The errors in Authlogic work JUST LIKE ActiveRecord. In fact, it uses the exact same ActiveRecord errors class. Use it the same way:
5
+ # The errors in Authlogic work JUST LIKE ActiveRecord. In fact, it uses
6
+ # the exact same ActiveRecord errors class. Use it the same way:
6
7
  #
7
8
  # class UserSession
8
9
  # validate :check_if_awesome
@@ -22,9 +23,10 @@ module Authlogic
22
23
  end
23
24
  end
24
25
 
25
- # You should use this as a place holder for any records that you find during validation. The main reason for this is to
26
- # allow other modules to use it if needed. Take the failed_login_count feature, it needs this in order to increase
27
- # the failed login count.
26
+ # You should use this as a place holder for any records that you find
27
+ # during validation. The main reason for this is to allow other modules to
28
+ # use it if needed. Take the failed_login_count feature, it needs this in
29
+ # order to increase the failed login count.
28
30
  def attempted_record
29
31
  @attempted_record
30
32
  end
@@ -34,8 +36,8 @@ module Authlogic
34
36
  @attempted_record = value
35
37
  end
36
38
 
37
- # The errors in Authlogic work JUST LIKE ActiveRecord. In fact, it uses the exact same ActiveRecord errors class.
38
- # Use it the same way:
39
+ # The errors in Authlogic work JUST LIKE ActiveRecord. In fact, it uses
40
+ # the exact same ActiveRecord errors class. Use it the same way:
39
41
  #
40
42
  # === Example
41
43
  #
@@ -52,9 +54,9 @@ module Authlogic
52
54
  @errors ||= Errors.new(self)
53
55
  end
54
56
 
55
- # Determines if the information you provided for authentication is valid or not. If there is
56
- # a problem with the information provided errors will be added to the errors object and this
57
- # method will return false.
57
+ # Determines if the information you provided for authentication is valid
58
+ # or not. If there is a problem with the information provided errors will
59
+ # be added to the errors object and this method will return false.
58
60
  def valid?
59
61
  errors.clear
60
62
  self.attempted_record = nil
@@ -64,13 +66,13 @@ module Authlogic
64
66
  validate
65
67
  ensure_authentication_attempted
66
68
 
67
- if errors.size == 0
69
+ if errors.empty?
68
70
  new_session? ? after_validation_on_create : after_validation_on_update
69
71
  after_validation
70
72
  end
71
73
 
72
74
  save_record(attempted_record)
73
- errors.size == 0
75
+ errors.empty?
74
76
  end
75
77
 
76
78
  private
@@ -5,8 +5,9 @@ require File.dirname(__FILE__) + "/test_case/mock_logger"
5
5
  require File.dirname(__FILE__) + "/test_case/mock_request"
6
6
 
7
7
  module Authlogic
8
- # This module is a collection of methods and classes that help you easily test Authlogic. In fact,
9
- # I use these same tools to test the internals of Authlogic.
8
+ # This module is a collection of methods and classes that help you easily test
9
+ # Authlogic. In fact, I use these same tools to test the internals of
10
+ # Authlogic.
10
11
  #
11
12
  # === The quick and dirty
12
13
  #
@@ -18,26 +19,33 @@ module Authlogic
18
19
  #
19
20
  # === Setting up
20
21
  #
21
- # Authlogic comes with some simple testing tools. To get these, you need to first require Authlogic's TestCase. If
22
- # you are doing this in a rails app, you would require this file at the top of your test_helper.rb file:
22
+ # Authlogic comes with some simple testing tools. To get these, you need to
23
+ # first require Authlogic's TestCase. If you are doing this in a rails app,
24
+ # you would require this file at the top of your test_helper.rb file:
23
25
  #
24
26
  # require "authlogic/test_case"
25
27
  #
26
- # If you are using Test::Unit::TestCase, the standard testing library that comes with ruby, then you can skip this next part.
27
- # If you are not, you need to include the Authlogic::TestCase into your testing suite as follows:
28
+ # If you are using Test::Unit::TestCase, the standard testing library that
29
+ # comes with ruby, then you can skip this next part. If you are not, you need
30
+ # to include the Authlogic::TestCase into your testing suite as follows:
28
31
  #
29
32
  # include Authlogic::TestCase
30
33
  #
31
- # Now that everything is ready to go, let's move onto actually testing. Here is the basic idea behind testing:
34
+ # Now that everything is ready to go, let's move onto actually testing. Here
35
+ # is the basic idea behind testing:
32
36
  #
33
- # Authlogic requires a "connection" to your controller to activate it. In the same manner that ActiveRecord requires a connection to
34
- # your database. It can't do anything until it gets connected. That being said, Authlogic will raise an
35
- # Authlogic::Session::Activation::NotActivatedError any time you try to instantiate an object without a "connection".
36
- # So before you do anything with Authlogic, you need to activate / connect Authlogic. Let's walk through how to do this in tests:
37
+ # Authlogic requires a "connection" to your controller to activate it. In the
38
+ # same manner that ActiveRecord requires a connection to your database. It
39
+ # can't do anything until it gets connected. That being said, Authlogic will
40
+ # raise an Authlogic::Session::Activation::NotActivatedError any time you try
41
+ # to instantiate an object without a "connection". So before you do anything
42
+ # with Authlogic, you need to activate / connect Authlogic. Let's walk through
43
+ # how to do this in tests:
37
44
  #
38
45
  # === Fixtures / Factories
39
46
  #
40
- # Creating users via fixtures / factories is easy. Here's an example of a fixture:
47
+ # Creating users via fixtures / factories is easy. Here's an example of a
48
+ # fixture:
41
49
  #
42
50
  # ben:
43
51
  # email: whatever@whatever.com
@@ -47,43 +55,52 @@ module Authlogic
47
55
  # single_access_token: <%= Authlogic::Random.friendly_token %>
48
56
  # perishable_token: <%= Authlogic::Random.friendly_token %>
49
57
  #
50
- # Notice the crypted_password value. Just supplement that with whatever crypto provider you are using, if you are not using the default.
58
+ # Notice the crypted_password value. Just supplement that with whatever crypto
59
+ # provider you are using, if you are not using the default.
51
60
  #
52
61
  # === Functional tests
53
62
  #
54
- # Activating Authlogic isn't a problem here, because making a request will activate Authlogic for you. The problem is
55
- # logging users in so they can access restricted areas. Solving this is simple, just do this:
63
+ # Activating Authlogic isn't a problem here, because making a request will
64
+ # activate Authlogic for you. The problem is logging users in so they can
65
+ # access restricted areas. Solving this is simple, just do this:
56
66
  #
57
67
  # setup :activate_authlogic
58
68
  #
59
- # For those of you unfamiliar with TestUnit, the setup method basically just executes a method before any test is ran.
60
- # It is essentially "setting up" your tests.
69
+ # For those of you unfamiliar with TestUnit, the setup method basically just
70
+ # executes a method before any test is ran. It is essentially "setting up"
71
+ # your tests.
61
72
  #
62
73
  # Once you have done this, just log users in like usual:
63
74
  #
64
75
  # UserSession.create(users(:whomever))
65
76
  # # access my restricted area here
66
77
  #
67
- # Do this before you make your request and it will act as if that user is logged in.
78
+ # Do this before you make your request and it will act as if that user is
79
+ # logged in.
68
80
  #
69
81
  # === Integration tests
70
82
  #
71
- # Again, just like functional tests, you don't have to do anything. As soon as you make a request, Authlogic will be
72
- # connected. If you want to activate Authlogic before making a request follow the same steps described in the
83
+ # Again, just like functional tests, you don't have to do anything. As soon as
84
+ # you make a request, Authlogic will be connected. If you want to activate
85
+ # Authlogic before making a request follow the same steps described in the
73
86
  # "functional tests" section above. It works in the same manner.
74
87
  #
75
88
  # === Unit tests
76
89
  #
77
- # The only time you need to do any trickiness here is if you want to test Authlogic models. Maybe you added some custom
78
- # code or methods in your Authlogic models. Maybe you are writing a plugin or a library that extends Authlogic.
90
+ # The only time you need to do any trickiness here is if you want to test
91
+ # Authlogic models. Maybe you added some custom code or methods in your
92
+ # Authlogic models. Maybe you are writing a plugin or a library that extends
93
+ # Authlogic.
79
94
  #
80
- # That being said, in this environment there is no controller. So you need to use a "mock" controller. Something
81
- # that looks like a controller, acts like a controller, but isn't a "real" controller. You are essentially connecting
82
- # Authlogic to your "mock" controller, then you can test off of the mock controller to make sure everything is functioning
83
- # properly.
95
+ # That being said, in this environment there is no controller. So you need to
96
+ # use a "mock" controller. Something that looks like a controller, acts like a
97
+ # controller, but isn't a "real" controller. You are essentially connecting
98
+ # Authlogic to your "mock" controller, then you can test off of the mock
99
+ # controller to make sure everything is functioning properly.
84
100
  #
85
- # I use a mock controller to test Authlogic myself. It's part of the Authlogic library that you can easily use. It's as simple
86
- # as functional and integration tests. Just do the following:
101
+ # I use a mock controller to test Authlogic myself. It's part of the Authlogic
102
+ # library that you can easily use. It's as simple as functional and
103
+ # integration tests. Just do the following:
87
104
  #
88
105
  # setup :activate_authlogic
89
106
  #
@@ -94,9 +111,11 @@ module Authlogic
94
111
  # assert UserSession.create(ben)
95
112
  # assert_equal controller.session["user_credentials"], ben.persistence_token
96
113
  #
97
- # See how I am checking that Authlogic is interacting with the controller properly? That's the idea here.
114
+ # See how I am checking that Authlogic is interacting with the controller
115
+ # properly? That's the idea here.
98
116
  module TestCase
99
- # Activates authlogic so that you can use it in your tests. You should call this method in your test's setup. Ex:
117
+ # Activates authlogic so that you can use it in your tests. You should call
118
+ # this method in your test's setup. Ex:
100
119
  #
101
120
  # setup :activate_authlogic
102
121
  def activate_authlogic
@@ -109,8 +128,9 @@ module Authlogic
109
128
  Authlogic::Session::Base.controller = (@request && Authlogic::TestCase::RailsRequestAdapter.new(@request)) || controller
110
129
  end
111
130
 
112
- # The Authlogic::TestCase::MockController object passed to Authlogic to activate it. You can access this in your test.
113
- # See the module description for an example.
131
+ # The Authlogic::TestCase::MockController object passed to Authlogic to
132
+ # activate it. You can access this in your test. See the module description
133
+ # for an example.
114
134
  def controller
115
135
  @controller ||= Authlogic::TestCase::MockController.new
116
136
  end
@@ -8,7 +8,7 @@ module ActsAsAuthenticTest
8
8
  "damien+test1...etc..@mydomain.com",
9
9
  "dakota.dux+1@gmail.com",
10
10
  "dakota.d'ux@gmail.com",
11
- "a&b@c.com",
11
+ "a&b@c.com"
12
12
  ]
13
13
 
14
14
  BAD_ASCII_EMAILS = [
@@ -16,7 +16,7 @@ module ActsAsAuthenticTest
16
16
  "aaaaaaaaaaaaa",
17
17
  "question?mark@gmail.com",
18
18
  "backslash@g\\mail.com",
19
- "<script>alert(123);</script>\nnobody@example.com",
19
+ "<script>alert(123);</script>\nnobody@example.com"
20
20
  ]
21
21
 
22
22
  # http://en.wikipedia.org/wiki/ISO/IEC_8859-1#Codepage_layout
@@ -58,7 +58,7 @@ module ActsAsAuthenticTest
58
58
  "我>.香港", # greater than
59
59
  "我?本@屋企.香港", # question mark
60
60
  "чебурша@ьн\\ами.рф", # backslash
61
- "user@domain.com%0A<script>alert('hello')</script>",
61
+ "user@domain.com%0A<script>alert('hello')</script>"
62
62
  ]
63
63
 
64
64
  def test_email_field_config
@@ -76,7 +76,7 @@ module ActsAsAuthenticTest
76
76
  assert Employee.validate_email_field
77
77
 
78
78
  User.validate_email_field = false
79
- assert !User.validate_email_field
79
+ refute User.validate_email_field
80
80
  User.validate_email_field true
81
81
  assert User.validate_email_field
82
82
  end
@@ -94,25 +94,25 @@ module ActsAsAuthenticTest
94
94
  def test_validates_format_of_email_field_options_config
95
95
  default = {
96
96
  :with => Authlogic::Regex.email,
97
- :message => Proc.new do
97
+ :message => proc do
98
98
  I18n.t(
99
99
  'error_messages.email_invalid',
100
100
  :default => "should look like an email address."
101
101
  )
102
102
  end
103
103
  }
104
- dmessage = default.delete(:message).call
104
+ default_message = default.delete(:message).call
105
105
 
106
106
  options = User.validates_format_of_email_field_options
107
107
  message = options.delete(:message)
108
- assert message.kind_of?(Proc)
109
- assert_equal dmessage, message.call
108
+ assert message.is_a?(Proc)
109
+ assert_equal default_message, message.call
110
110
  assert_equal default, options
111
111
 
112
112
  options = Employee.validates_format_of_email_field_options
113
113
  message = options.delete(:message)
114
- assert message.kind_of?(Proc)
115
- assert_equal dmessage, message.call
114
+ assert message.is_a?(Proc)
115
+ assert_equal default_message, message.call
116
116
  assert_equal default, options
117
117
 
118
118
  User.validates_format_of_email_field_options = { :yes => "no" }
@@ -155,7 +155,11 @@ module ActsAsAuthenticTest
155
155
  end
156
156
 
157
157
  def test_validates_uniqueness_of_email_field_options_config
158
- default = { :case_sensitive => false, :scope => Employee.validations_scope, :if => "#{Employee.email_field}_changed?".to_sym }
158
+ default = {
159
+ :case_sensitive => false,
160
+ :scope => Employee.validations_scope,
161
+ :if => "#{Employee.email_field}_changed?".to_sym
162
+ }
159
163
  assert_equal default, Employee.validates_uniqueness_of_email_field_options
160
164
 
161
165
  Employee.validates_uniqueness_of_email_field_options = { :yes => "no" }
@@ -167,43 +171,43 @@ module ActsAsAuthenticTest
167
171
  def test_validates_length_of_email_field
168
172
  u = User.new
169
173
  u.email = "a@a.a"
170
- assert !u.valid?
171
- assert u.errors[:email].size > 0
174
+ refute u.valid?
175
+ refute u.errors[:email].empty?
172
176
 
173
177
  u.email = "a@a.com"
174
- assert !u.valid?
175
- assert u.errors[:email].size == 0
178
+ refute u.valid?
179
+ assert u.errors[:email].empty?
176
180
  end
177
181
 
178
182
  def test_validates_format_of_email_field
179
183
  u = User.new
180
184
  u.email = "aaaaaaaaaaaaa"
181
185
  u.valid?
182
- assert u.errors[:email].size > 0
186
+ refute u.errors[:email].empty?
183
187
 
184
188
  u.email = "a@a.com"
185
189
  u.valid?
186
- assert u.errors[:email].size == 0
190
+ assert u.errors[:email].empty?
187
191
 
188
192
  u.email = "damien+test1...etc..@mydomain.com"
189
193
  u.valid?
190
- assert u.errors[:email].size == 0
194
+ assert u.errors[:email].empty?
191
195
 
192
196
  u.email = "dakota.dux+1@gmail.com"
193
197
  u.valid?
194
- assert u.errors[:email].size == 0
198
+ assert u.errors[:email].empty?
195
199
 
196
200
  u.email = "dakota.d'ux@gmail.com"
197
201
  u.valid?
198
- assert u.errors[:email].size == 0
202
+ assert u.errors[:email].empty?
199
203
 
200
204
  u.email = "<script>alert(123);</script>\nnobody@example.com"
201
- assert !u.valid?
202
- assert u.errors[:email].size > 0
205
+ refute u.valid?
206
+ refute u.errors[:email].empty?
203
207
 
204
208
  u.email = "a&b@c.com"
205
209
  u.valid?
206
- assert u.errors[:email].size == 0
210
+ assert u.errors[:email].empty?
207
211
  end
208
212
 
209
213
  def test_validates_format_of_nonascii_email_field
@@ -219,16 +223,16 @@ module ActsAsAuthenticTest
219
223
  def test_validates_uniqueness_of_email_field
220
224
  u = User.new
221
225
  u.email = "bjohnson@binarylogic.com"
222
- assert !u.valid?
223
- assert u.errors[:email].size > 0
226
+ refute u.valid?
227
+ refute u.errors[:email].empty?
224
228
 
225
229
  u.email = "BJOHNSON@binarylogic.com"
226
- assert !u.valid?
227
- assert u.errors[:email].size > 0
230
+ refute u.valid?
231
+ refute u.errors[:email].empty?
228
232
 
229
233
  u.email = "a@a.com"
230
- assert !u.valid?
231
- assert u.errors[:email].size == 0
234
+ refute u.valid?
235
+ assert u.errors[:email].empty?
232
236
  end
233
237
  end
234
238
  end
@@ -52,11 +52,11 @@ module ActsAsAuthenticTest
52
52
 
53
53
  def test_logged_in_logged_out
54
54
  u = User.first
55
- assert !u.logged_in?
55
+ refute u.logged_in?
56
56
  assert u.logged_out?
57
57
  u.last_request_at = Time.now
58
58
  assert u.logged_in?
59
- assert !u.logged_out?
59
+ refute u.logged_out?
60
60
  end
61
61
  end
62
62
  end
@@ -17,7 +17,7 @@ module ActsAsAuthenticTest
17
17
  assert Employee.validate_login_field
18
18
 
19
19
  User.validate_login_field = false
20
- assert !User.validate_login_field
20
+ refute User.validate_login_field
21
21
  User.validate_login_field true
22
22
  assert User.validate_login_field
23
23
  end
@@ -35,13 +35,26 @@ module ActsAsAuthenticTest
35
35
  def test_validates_format_of_login_field_options_config
36
36
  default = {
37
37
  :with => /\A[a-zA-Z0-9_][a-zA-Z0-9\.+\-_@ ]+\z/,
38
- :message => I18n.t(
39
- 'error_messages.login_invalid',
40
- :default => "should use only letters, numbers, spaces, and .-_@+ please."
41
- )
38
+ :message => proc do
39
+ I18n.t(
40
+ 'error_messages.login_invalid',
41
+ :default => "should use only letters, numbers, spaces, and .-_@+ please."
42
+ )
43
+ end
42
44
  }
43
- assert_equal default, User.validates_format_of_login_field_options
44
- assert_equal default, Employee.validates_format_of_login_field_options
45
+ default_message = default.delete(:message).call
46
+
47
+ options = User.validates_format_of_login_field_options
48
+ message = options.delete(:message)
49
+ assert message.is_a?(Proc)
50
+ assert_equal default_message, message.call
51
+ assert_equal default, options
52
+
53
+ options = Employee.validates_format_of_login_field_options
54
+ message = options.delete(:message)
55
+ assert message.is_a?(Proc)
56
+ assert_equal default_message, message.call
57
+ assert_equal default, options
45
58
 
46
59
  User.validates_format_of_login_field_options = { :yes => "no" }
47
60
  assert_equal({ :yes => "no" }, User.validates_format_of_login_field_options)
@@ -62,70 +75,70 @@ module ActsAsAuthenticTest
62
75
  def test_validates_length_of_login_field
63
76
  u = User.new
64
77
  u.login = "a"
65
- assert !u.valid?
66
- assert u.errors[:login].size > 0
78
+ refute u.valid?
79
+ refute u.errors[:login].empty?
67
80
 
68
81
  u.login = "aaaaaaaaaa"
69
- assert !u.valid?
70
- assert u.errors[:login].size == 0
82
+ refute u.valid?
83
+ assert u.errors[:login].empty?
71
84
  end
72
85
 
73
86
  def test_validates_format_of_login_field
74
87
  u = User.new
75
88
  u.login = "fdsf@^&*"
76
- assert !u.valid?
77
- assert u.errors[:login].size > 0
89
+ refute u.valid?
90
+ refute u.errors[:login].empty?
78
91
 
79
92
  u.login = "fdsfdsfdsfdsfs"
80
- assert !u.valid?
81
- assert u.errors[:login].size == 0
93
+ refute u.valid?
94
+ assert u.errors[:login].empty?
82
95
 
83
96
  u.login = "dakota.dux+1@gmail.com"
84
- assert !u.valid?
85
- assert u.errors[:login].size == 0
97
+ refute u.valid?
98
+ assert u.errors[:login].empty?
86
99
 
87
100
  u.login = "marks .-_@+"
88
- assert !u.valid?
89
- assert u.errors[:login].size == 0
101
+ refute u.valid?
102
+ assert u.errors[:login].empty?
90
103
 
91
104
  u.login = " space"
92
- assert !u.valid?
93
- assert u.errors[:login].size > 0
105
+ refute u.valid?
106
+ refute u.errors[:login].empty?
94
107
 
95
108
  u.login = ".dot"
96
- assert !u.valid?
97
- assert u.errors[:login].size > 0
109
+ refute u.valid?
110
+ refute u.errors[:login].empty?
98
111
 
99
112
  u.login = "-hyphen"
100
- assert !u.valid?
101
- assert u.errors[:login].size > 0
113
+ refute u.valid?
114
+ refute u.errors[:login].empty?
102
115
 
103
116
  u.login = "_underscore"
104
- assert !u.valid?
105
- assert u.errors[:login].size == 0
117
+ refute u.valid?
118
+ assert u.errors[:login].empty?
106
119
 
107
120
  u.login = "@atmark"
108
- assert !u.valid?
109
- assert u.errors[:login].size > 0
121
+ refute u.valid?
122
+ refute u.errors[:login].empty?
110
123
 
111
124
  u.login = "+plus"
112
- assert !u.valid?
113
- assert u.errors[:login].size > 0
125
+ refute u.valid?
126
+ refute u.errors[:login].empty?
114
127
  end
115
128
 
116
129
  def test_validates_uniqueness_of_login_field
117
130
  u = User.new
118
131
  u.login = "bjohnson"
119
- assert !u.valid?
120
- assert u.errors[:login].size > 0
132
+ refute u.valid?
133
+ refute u.errors[:login].empty?
121
134
 
122
135
  u.login = "BJOHNSON"
123
- assert !u.valid?
124
- assert u.errors[:login].size > 0
136
+ refute u.valid?
137
+ refute u.errors[:login].empty?
125
138
 
126
139
  u.login = "fdsfdsf"
127
- assert !u.valid?
128
- assert u.errors[:login].size == 0
140
+ refute u.valid?
141
+ assert u.errors[:login].empty?
129
142
  end
130
143
 
131
144
  def test_find_by_smart_case_login_field