validators 2.7.0 → 2.8.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 (36) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +9 -9
  3. data/bin/sync-disposable-hostnames +6 -6
  4. data/bin/sync-tld +4 -4
  5. data/data/disposable.json +8272 -2
  6. data/data/tld.json +0 -1
  7. data/lib/validators/constants.rb +1 -0
  8. data/lib/validators/hostname.rb +1 -1
  9. data/lib/validators/validates_cnpj_format_of.rb +2 -1
  10. data/lib/validators/validates_cpf_format_of.rb +2 -1
  11. data/lib/validators/validates_datetime.rb +29 -18
  12. data/lib/validators/validates_email_format_of.rb +19 -13
  13. data/lib/validators/validates_ip_address.rb +13 -9
  14. data/lib/validators/validates_ownership_of.rb +11 -9
  15. data/lib/validators/validates_ssh_private_key.rb +15 -7
  16. data/lib/validators/validates_ssh_public_key.rb +5 -2
  17. data/lib/validators/validates_url_format_of.rb +5 -3
  18. data/lib/validators/version.rb +2 -2
  19. data/test/schema.rb +1 -1
  20. data/test/support/emails.rb +37 -27
  21. data/test/support/models.rb +1 -1
  22. data/test/support/urls.rb +28 -28
  23. data/test/validators/validates_datetime/after_option_test.rb +5 -5
  24. data/test/validators/validates_datetime/before_option_test.rb +2 -2
  25. data/test/validators/validates_datetime/defaults_test.rb +1 -1
  26. data/test/validators/validates_email_format_of_test.rb +11 -11
  27. data/test/validators/validates_ip_address/ipv4_test.rb +2 -2
  28. data/test/validators/validates_ip_address/ipv6_test.rb +2 -2
  29. data/test/validators/validates_ip_address_test.rb +2 -2
  30. data/test/validators/validates_ownership_of_test.rb +5 -5
  31. data/test/validators/validates_ssh_private_key/dsa_test.rb +2 -2
  32. data/test/validators/validates_ssh_private_key/rsa_test.rb +1 -1
  33. data/test/validators/validates_url_format_of/with_tld_validation_test.rb +1 -1
  34. data/test/validators/validates_url_format_of/without_tld_validation_test.rb +7 -7
  35. data/validators.gemspec +2 -2
  36. metadata +4 -4
data/data/tld.json CHANGED
@@ -165,7 +165,6 @@
165
165
  "boo",
166
166
  "book",
167
167
  "booking",
168
- "boots",
169
168
  "bosch",
170
169
  "bostik",
171
170
  "boston",
@@ -1,5 +1,6 @@
1
1
  module Validators
2
2
  EMAIL_FORMAT = /\A[a-z0-9]+([-._][a-z0-9]+)*(\+[^@]+)?@[a-z0-9]+([.-][a-z0-9]+)*\.[a-z]{2,}\z/i
3
+ MICROSOFT_EMAIL_FORMAT = /\A[\w][\w\d._-]*[\w\d_-]+(\+[\w\d]+)?@(hotmail|outlook).com\z/i
3
4
 
4
5
  # Source: https://github.com/henrik/validates_url_format_of
5
6
  IPv4_PART = /\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5]/ # 0-255
@@ -18,7 +18,7 @@ module Validators
18
18
  end
19
19
 
20
20
  def self.valid_label?(label)
21
- !label.start_with?('-') &&
21
+ !label.start_with?("-") &&
22
22
  !label.match(/\A\d+\z/) &&
23
23
  label.match(/\A[a-z0-9-]{1,63}\z/i)
24
24
  end
@@ -4,11 +4,12 @@ module ActiveModel
4
4
  def validate_each(record, attribute, value)
5
5
  return if value.blank? && options[:allow_blank]
6
6
  return if value.nil? && options[:allow_nil]
7
+ return if CNPJ.valid?(value)
7
8
 
8
9
  record.errors.add(attribute, :invalid_cnpj,
9
10
  message: options[:message],
10
11
  value: value
11
- ) unless CNPJ.valid?(value)
12
+ )
12
13
  end
13
14
  end
14
15
 
@@ -4,11 +4,12 @@ module ActiveModel
4
4
  def validate_each(record, attribute, value)
5
5
  return if value.blank? && options[:allow_blank]
6
6
  return if value.nil? && options[:allow_nil]
7
+ return if CPF.valid?(value)
7
8
 
8
9
  record.errors.add(attribute, :invalid_cpf,
9
10
  message: options[:message],
10
11
  value: value
11
- ) unless CPF.valid?(value)
12
+ )
12
13
  end
13
14
  end
14
15
 
@@ -10,8 +10,11 @@ module ActiveModel
10
10
  return if value.nil? && options[:allow_nil]
11
11
 
12
12
  unless date?(value)
13
- record.errors.add(attribute, :invalid_date,
14
- :message => options[:message], :value => value
13
+ record.errors.add(
14
+ attribute,
15
+ :invalid_date,
16
+ message: options[:message],
17
+ value: value
15
18
  )
16
19
  end
17
20
 
@@ -50,11 +53,15 @@ module ActiveModel
50
53
 
51
54
  date, value = date_for(record, value, options[:after])
52
55
 
53
- record.errors.add(attribute, :invalid_date_after, {
54
- :message => options[:after_message],
55
- :value => value,
56
- :date => (date?(date) ? I18n.l(date) : date.inspect)
57
- }) unless value.present? && date.present? && (value && date && value > date)
56
+ return if value.present? && date.present? && (value && date && value > date)
57
+
58
+ record.errors.add(
59
+ attribute,
60
+ :invalid_date_after,
61
+ message: options[:after_message],
62
+ value: value,
63
+ date: (date?(date) ? I18n.l(date) : date.inspect)
64
+ )
58
65
  end
59
66
 
60
67
  def validate_before_option(record, attribute, value)
@@ -62,11 +69,15 @@ module ActiveModel
62
69
 
63
70
  date, value = date_for(record, value, options[:before])
64
71
 
65
- record.errors.add(attribute, :invalid_date_before, {
66
- :message => options[:before_message],
67
- :value => value,
68
- :date => I18n.l(date)
69
- }) unless value.present? && date.present? && (value && date && value < date)
72
+ return if value.present? && date.present? && (value && date && value < date)
73
+
74
+ record.errors.add(
75
+ attribute,
76
+ :invalid_date_before,
77
+ message: options[:before_message],
78
+ value: value,
79
+ date: I18n.l(date)
80
+ )
70
81
  end
71
82
  end
72
83
 
@@ -79,12 +90,12 @@ module ActiveModel
79
90
  #
80
91
  # Other usages:
81
92
  #
82
- # validates_datetime :starts_at, :after => 2.years.ago
83
- # validates_datetime :starts_at, :before => 2.years.ago
84
- # validates_datetime :starts_at, :before => :today
85
- # validates_datetime :starts_at, :before => :now
86
- # validates_datetime :starts_at, :before => :ends_at
87
- # validates_datetime :ends_at, :after => :starts_at
93
+ # validates_datetime :starts_at, after: 2.years.ago
94
+ # validates_datetime :starts_at, before: 2.years.ago
95
+ # validates_datetime :starts_at, before: :today
96
+ # validates_datetime :starts_at, before: :now
97
+ # validates_datetime :starts_at, before: :ends_at
98
+ # validates_datetime :ends_at, after: :starts_at
88
99
  #
89
100
  def validates_datetime(*attr_names)
90
101
  validates_with DatetimeValidator, _merge_attributes(attr_names)
@@ -1,6 +1,8 @@
1
1
  module ActiveModel
2
2
  module Validations
3
3
  class EmailValidator < EachValidator
4
+ AT_SIGN = "@".freeze
5
+
4
6
  def validate_each(record, attribute, value)
5
7
  allow_disposable = options.fetch(:disposable, false)
6
8
  check_tld = options.fetch(:tld, false)
@@ -14,18 +16,19 @@ module ActiveModel
14
16
  end
15
17
 
16
18
  def validate_email_format(record, attribute, value, options)
17
- if value.to_s !~ Validators::EMAIL_FORMAT
18
- record.errors.add(
19
- attribute,
20
- :invalid_email,
21
- message: options[:message],
22
- value: value
23
- )
24
- end
19
+ return if value.to_s =~ Validators::EMAIL_FORMAT
20
+ return if value.to_s =~ Validators::MICROSOFT_EMAIL_FORMAT
21
+
22
+ record.errors.add(
23
+ attribute,
24
+ :invalid_email,
25
+ message: options[:message],
26
+ value: value
27
+ )
25
28
  end
26
29
 
27
30
  def validate_tld(record, attribute, value, options)
28
- host = value.to_s.split("@").last
31
+ host = value.to_s.split(AT_SIGN).last
29
32
  return if Validators::TLD.host_with_valid_tld?(host)
30
33
 
31
34
  record.errors.add(
@@ -37,12 +40,15 @@ module ActiveModel
37
40
  end
38
41
 
39
42
  def validate_disposable_email(record, attribute, value, options)
40
- hostname = value.to_s.split("@").last.to_s.downcase
43
+ hostname = value.to_s.split(AT_SIGN).last.to_s.downcase
44
+
45
+ return unless Validators::DisposableHostnames.all.include?(hostname)
41
46
 
42
47
  record.errors.add(
43
- attribute, :disposable_email,
44
- :value => value
45
- ) if Validators::DisposableHostnames.all.include?(hostname)
48
+ attribute,
49
+ :disposable_email,
50
+ value: value
51
+ )
46
52
  end
47
53
  end
48
54
 
@@ -19,16 +19,20 @@ module ActiveModel
19
19
  scope = :invalid_ip_address
20
20
  end
21
21
 
22
- unless valid
23
- record.errors.add(
24
- attribute, scope,
25
- :message => options[:message], :value => value
26
- )
27
- end
22
+ return if valid
23
+
24
+ record.errors.add(
25
+ attribute, scope,
26
+ message: options[:message],
27
+ value: value
28
+ )
28
29
  end
29
30
 
30
31
  def check_validity!
31
- raise ArgumentError, ":only accepts a symbol that can be either :v6 or :v4" if options.key?(:only) && ![:v4, :v6].include?(options[:only])
32
+ return unless options.key?(:only)
33
+ return if [:v4, :v6].include?(options[:only])
34
+
35
+ raise ArgumentError, ":only accepts a symbol that can be either :v6 or :v4"
32
36
  end
33
37
  end
34
38
 
@@ -36,8 +40,8 @@ module ActiveModel
36
40
  # Validates whether or not the specified URL is valid.
37
41
  #
38
42
  # validates_ip_address :ip #=> accepts both v4 and v6
39
- # validates_ip_address :ip, :only => :v4
40
- # validates_ip_address :ip, :only => :v6
43
+ # validates_ip_address :ip, only: :v4
44
+ # validates_ip_address :ip, only: :v6
41
45
  #
42
46
  def validates_ip_address(*attr_names)
43
47
  validates_with IpAddressValidator, _merge_attributes(attr_names)
@@ -5,12 +5,14 @@ module ActiveModel
5
5
  owner = record.send(options[:with])
6
6
  actual_owner = value ? value.send(options[:with]) : nil
7
7
 
8
- if value && owner != actual_owner
9
- record.errors.add(
10
- attribute, :invalid_owner,
11
- :message => options[:message]
12
- )
13
- end
8
+ return unless value
9
+ return if owner == actual_owner
10
+
11
+ record.errors.add(
12
+ attribute,
13
+ :invalid_owner,
14
+ message: options[:message]
15
+ )
14
16
  end
15
17
 
16
18
  def check_validity!
@@ -26,7 +28,7 @@ module ActiveModel
26
28
  # belongs_to :user
27
29
  # belongs_to :category
28
30
  #
29
- # validates_ownership_of :category, :with => :user
31
+ # validates_ownership_of :category, with: :user
30
32
  # end
31
33
  #
32
34
  # user = User.find(1)
@@ -35,11 +37,11 @@ module ActiveModel
35
37
  # user_category = user.categories.first
36
38
  # another_user_category = another_user.categories.first
37
39
  #
38
- # task = user.tasks.create(:category => user_category)
40
+ # task = user.tasks.create(category: user_category)
39
41
  # task.valid?
40
42
  # #=> true
41
43
  #
42
- # task = user.tasks.create(:category => another_user_category)
44
+ # task = user.tasks.create(category: another_user_category)
43
45
  # task.valid?
44
46
  # #=> false
45
47
  #
@@ -9,7 +9,9 @@ module ActiveModel
9
9
  validate_type(record, attribute, sshkey)
10
10
  validate_bits(record, attribute, sshkey)
11
11
  rescue OpenSSL::PKey::DSAError, OpenSSL::PKey::RSAError
12
- record.errors.add(attribute, :invalid_ssh_private_key,
12
+ record.errors.add(
13
+ attribute,
14
+ :invalid_ssh_private_key,
13
15
  message: options[:message],
14
16
  value: value
15
17
  )
@@ -20,23 +22,29 @@ module ActiveModel
20
22
  def validate_type(record, attribute, sshkey)
21
23
  return unless options[:type]
22
24
 
23
- valid = [options[:type]]
24
- .flatten.compact.map(&:to_s).include?(sshkey.type)
25
+ valid = [options[:type]].flatten.compact.map(&:to_s).include?(sshkey.type)
25
26
 
26
- record.errors.add(attribute, :invalid_ssh_private_key_type,
27
+ return if valid
28
+
29
+ record.errors.add(
30
+ attribute,
31
+ :invalid_ssh_private_key_type,
27
32
  message: options[:message],
28
33
  value: (%w[rsa dsa] - [sshkey.type])[0].upcase
29
- ) unless valid
34
+ )
30
35
  end
31
36
 
32
37
  def validate_bits(record, attribute, sshkey)
33
38
  return unless options[:bits]
39
+ return if sshkey.bits >= options[:bits].to_i
34
40
 
35
- record.errors.add(attribute, :invalid_ssh_private_key_bits,
41
+ record.errors.add(
42
+ attribute,
43
+ :invalid_ssh_private_key_bits,
36
44
  message: options[:message],
37
45
  value: sshkey.bits,
38
46
  required: options[:bits]
39
- ) unless sshkey.bits >= options[:bits].to_i
47
+ )
40
48
  end
41
49
  end
42
50
 
@@ -4,11 +4,14 @@ module ActiveModel
4
4
  def validate_each(record, attribute, value)
5
5
  return if value.blank? && options[:allow_blank]
6
6
  return if value.nil? && options[:allow_nil]
7
+ return if SSHKey.valid_ssh_public_key?(value)
7
8
 
8
- record.errors.add(attribute, :invalid_ssh_public_key,
9
+ record.errors.add(
10
+ attribute,
11
+ :invalid_ssh_public_key,
9
12
  message: options[:message],
10
13
  value: value
11
- ) unless SSHKey.valid_ssh_public_key?(value)
14
+ )
12
15
  end
13
16
  end
14
17
 
@@ -6,9 +6,11 @@ module ActiveModel
6
6
  return if value.nil? && options[:allow_nil]
7
7
  return if url?(value.to_s)
8
8
 
9
- record.errors.add(attribute, :invalid_url,
10
- :message => options[:message],
11
- :value => value
9
+ record.errors.add(
10
+ attribute,
11
+ :invalid_url,
12
+ message: options[:message],
13
+ value: value
12
14
  )
13
15
  end
14
16
 
@@ -1,8 +1,8 @@
1
1
  module Validators
2
2
  module Version
3
3
  MAJOR = 2
4
- MINOR = 7
4
+ MINOR = 8
5
5
  PATCH = 0
6
- STRING = "#{MAJOR}.#{MINOR}.#{PATCH}"
6
+ STRING = "#{MAJOR}.#{MINOR}.#{PATCH}".freeze
7
7
  end
8
8
  end
data/test/schema.rb CHANGED
@@ -1,4 +1,4 @@
1
- ActiveRecord::Schema.define(:version => 0) do
1
+ ActiveRecord::Schema.define(version: 0) do
2
2
  create_table :users do |t|
3
3
  t.string :email, :corporate_email, :url
4
4
  t.datetime :registered_at, :starts_at, :ends_at
@@ -1,40 +1,50 @@
1
1
  INVALID_EMAILS = [
2
- 'invalid@example-com',
2
+ "invalid@example-com",
3
3
  # period can not start local part
4
- '.invalid@example.com',
4
+ ".invalid@example.com",
5
5
  # period can not end local part
6
- 'invalid.@example.com',
6
+ "invalid.@example.com",
7
7
  # period can not appear twice consecutively in local part
8
- 'invali..d@example.com',
8
+ "invali..d@example.com",
9
9
  # should not allow underscores in domain names
10
- 'invalid@ex_mple.com',
11
- 'invalid@example.com.',
12
- 'invalid@example.com_',
13
- 'invalid@example.com-',
14
- 'invalid-example.com',
15
- 'invalid@example.b#r.com',
16
- 'invalid@example.c',
17
- 'invali d@example.com',
18
- 'invalidexample.com',
19
- 'invalid@example.',
10
+ "invalid@ex_mple.com",
11
+ "invalid@example.com.",
12
+ "invalid@example.com_",
13
+ "invalid@example.com-",
14
+ "invalid-example.com",
15
+ "invalid@example.b#r.com",
16
+ "invalid@example.c",
17
+ "invali d@example.com",
18
+ "invalidexample.com",
19
+ "invalid@example.",
20
20
  # from http://tools.ietf.org/html/rfc3696, page 5
21
21
  # corrected in http://www.rfc-editor.org/errata_search.php?rfc=3696
22
22
  'Fred\ Bloggs_@example.com',
23
23
  'Abc\@def+@example.com',
24
- 'Joe.\\Blow@example.com'
24
+ 'Joe.\\Blow@example.com',
25
+ 'invalid.@hotmail.com',
26
+ 'invalid.@outlook.com',
25
27
  ]
26
28
 
27
29
  VALID_EMAILS = [
28
- 'valid@somedomain.com',
29
- 'Valid@test.somedomain.com',
30
- 'valid+valid123@test.somedomain.com',
31
- 'valid_valid123@test.somedomain.com',
32
- 'valid-valid+123@test.somedomain.co.uk',
33
- 'valid-valid+1.23@test.somedomain.com.au',
34
- 'valid@somedomain.co.uk',
35
- 'v@somedomain.com',
36
- 'valid@somedomain.ca',
37
- 'valid123.456@somedomain.org',
38
- 'valid@somedomain.mobi',
39
- 'valid@somedomain.info',
30
+ "valid@somedomain.com",
31
+ "Valid@test.somedomain.com",
32
+ "valid+valid123@test.somedomain.com",
33
+ "valid_valid123@test.somedomain.com",
34
+ "valid-valid+123@test.somedomain.co.uk",
35
+ "valid-valid+1.23@test.somedomain.com.au",
36
+ "valid@somedomain.co.uk",
37
+ "v@somedomain.com",
38
+ "valid@somedomain.ca",
39
+ "valid123.456@somedomain.org",
40
+ "valid@somedomain.mobi",
41
+ "valid@somedomain.info",
42
+ "valid-@hotmail.com",
43
+ "valid-@outlook.com",
44
+ "valid_@hotmail.com",
45
+ "valid_@outlook.com",
46
+ "valid_-_-_-_-_-_@hotmail.com",
47
+ "valid_-_-_-_-_-_@outlook.com",
48
+ "sub_total-5+8@hotmail.com",
49
+ "sub_total-5+8@outlook.com",
40
50
  ]
@@ -28,7 +28,7 @@ class UserWithTLD
28
28
  validates_url_format_of :url, tld: true
29
29
 
30
30
  def self.name
31
- 'User'
31
+ "User"
32
32
  end
33
33
 
34
34
  def initialize(url)
data/test/support/urls.rb CHANGED
@@ -1,29 +1,29 @@
1
1
  # encoding: utf-8
2
2
  VALID_URLS = [
3
- 'http://example.com',
4
- 'http://example.com/',
5
- 'http://www.example.com/',
6
- 'http://sub.domain.example.com/',
7
- 'http://bbc.co.uk',
8
- 'http://example.com?foo',
9
- 'http://example.com?url=http://example.com',
10
- 'http://example.com:8000',
11
- 'http://www.sub.example.com/page.html?foo=bar&baz=%23#anchor',
12
- 'http://user:pass@example.com',
13
- 'http://user:@example.com',
14
- 'http://example.com/~user',
15
- 'http://example.museum',
16
- 'http://1.0.255.249',
17
- 'http://1.2.3.4:80',
18
- 'HttP://example.com',
19
- 'https://example.com',
20
- # 'http://räksmörgås.nu', # IDN
21
- 'http://xn--rksmrgs-5wao1o.nu', # Punycode
22
- 'http://www.xn--rksmrgs-5wao1o.nu',
23
- 'http://foo.bar.xn--rksmrgs-5wao1o.nu',
24
- 'http://example.xy', # Only valid TLD
25
- 'http://example.com.', # Explicit TLD root period
26
- 'http://example.com./foo'
3
+ "http://example.com",
4
+ "http://example.com/",
5
+ "http://www.example.com/",
6
+ "http://sub.domain.example.com/",
7
+ "http://bbc.co.uk",
8
+ "http://example.com?foo",
9
+ "http://example.com?url=http://example.com",
10
+ "http://example.com:8000",
11
+ "http://www.sub.example.com/page.html?foo=bar&baz=%23#anchor",
12
+ "http://user:pass@example.com",
13
+ "http://user:@example.com",
14
+ "http://example.com/~user",
15
+ "http://example.museum",
16
+ "http://1.0.255.249",
17
+ "http://1.2.3.4:80",
18
+ "HttP://example.com",
19
+ "https://example.com",
20
+ # "http://räksmörgås.nu", # IDN
21
+ "http://xn--rksmrgs-5wao1o.nu", # Punycode
22
+ "http://www.xn--rksmrgs-5wao1o.nu",
23
+ "http://foo.bar.xn--rksmrgs-5wao1o.nu",
24
+ "http://example.xy", # Only valid TLD
25
+ "http://example.com.", # Explicit TLD root period
26
+ "http://example.com./foo"
27
27
  ]
28
28
 
29
29
  INVALID_URLS = [
@@ -31,13 +31,13 @@ INVALID_URLS = [
31
31
  "www.example.com",
32
32
  "http://ex ample.com",
33
33
  "http://example.com/foo bar",
34
- 'http://256.0.0.1',
35
- 'http://u:u:u@example.com',
36
- 'http://r?ksmorgas.com',
34
+ "http://256.0.0.1",
35
+ "http://u:u:u@example.com",
36
+ "http://r?ksmorgas.com",
37
37
 
38
38
  # These can all be valid local URLs, but should not be considered valid
39
39
  # for public consumption.
40
40
  "http://example",
41
41
  "http://example.c",
42
- 'http://example.toolongtld'
42
+ "http://example.toolongtld"
43
43
  ]
@@ -5,7 +5,7 @@ class ValidatesDatetimeAfterOptionTest < Minitest::Test
5
5
 
6
6
  test "rejects when date is set to before :after option" do
7
7
  future_date = 1.week.from_now
8
- User.validates_datetime :registered_at, :after => future_date
8
+ User.validates_datetime :registered_at, after: future_date
9
9
  user.registered_at = Time.now
10
10
 
11
11
  refute user.valid?
@@ -13,14 +13,14 @@ class ValidatesDatetimeAfterOptionTest < Minitest::Test
13
13
  end
14
14
 
15
15
  test "accepts when date is set accordingly to the :after option" do
16
- User.validates_datetime :registered_at, :after => 1.week.from_now
16
+ User.validates_datetime :registered_at, after: 1.week.from_now
17
17
  user.registered_at = 2.weeks.from_now
18
18
 
19
19
  assert user.valid?
20
20
  end
21
21
 
22
22
  test "validates using today as date" do
23
- User.validates_datetime :registered_at, :after => :today
23
+ User.validates_datetime :registered_at, after: :today
24
24
 
25
25
  user.registered_at = Time.now
26
26
  refute user.valid?
@@ -36,7 +36,7 @@ class ValidatesDatetimeAfterOptionTest < Minitest::Test
36
36
  end
37
37
 
38
38
  test "validates using now as date" do
39
- User.validates_datetime :registered_at, :after => :now
39
+ User.validates_datetime :registered_at, after: :now
40
40
 
41
41
  user.registered_at = Time.now
42
42
  refute user.valid?
@@ -53,7 +53,7 @@ class ValidatesDatetimeAfterOptionTest < Minitest::Test
53
53
 
54
54
  test "validates using method as date" do
55
55
  User.validates_datetime :starts_at
56
- User.validates_datetime :ends_at, :after => :starts_at, :if => :starts_at?
56
+ User.validates_datetime :ends_at, after: :starts_at, if: :starts_at?
57
57
 
58
58
  user.starts_at = nil
59
59
  user.ends_at = Time.now
@@ -7,7 +7,7 @@ class ValidatesDatetimeBeforeOptionTest < Minitest::Test
7
7
  week_ago = 1.week.ago
8
8
  now = Time.now
9
9
 
10
- User.validates_datetime :registered_at, :before => week_ago
10
+ User.validates_datetime :registered_at, before: week_ago
11
11
  user.registered_at = now
12
12
 
13
13
  refute user.valid?
@@ -15,7 +15,7 @@ class ValidatesDatetimeBeforeOptionTest < Minitest::Test
15
15
  end
16
16
 
17
17
  test "accepts when date is set accordingly to the :before option" do
18
- User.validates_datetime :registered_at, :before => 1.week.ago
18
+ User.validates_datetime :registered_at, before: 1.week.ago
19
19
  user.registered_at = 2.weeks.ago
20
20
 
21
21
  assert user.valid?
@@ -5,7 +5,7 @@ class ValidatesDatetimeDefaultsTest < Minitest::Test
5
5
 
6
6
  setup do
7
7
  User.validates_datetime :registered_at
8
- User.validates :birthday, :datetime => true
8
+ User.validates :birthday, datetime: true
9
9
  end
10
10
 
11
11
  VALID_DATES.each do |date|