validators 2.4.0 → 2.4.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 73b3e57e7ba767a4a7a43ca74e054e2c7980ca0b
4
- data.tar.gz: 636a5f838f51bf383aa90bb5699264ef61bf5dac
3
+ metadata.gz: a52bd8c6c0154e31767455e8a2e1037c6e6a8c2e
4
+ data.tar.gz: 22b34fe94029f994f37a2d8165ec377567d16c3b
5
5
  SHA512:
6
- metadata.gz: 600a78867d4426086a580a22c2916716518c31b511ff4b9e8a81d77c6d50bf5d8d234732a294c84e20b13b6c6e09ddd9d64f43f64cfdec8bc26bd7744e1f7d8f
7
- data.tar.gz: ceb262312fc3d3742622bb006f423ec938683f04406ec7e05fc6d5388e225e673551d22f92d438bcd49025e0ea1b4600140dca55e97bff8dc1c16b0f66b495e2
6
+ metadata.gz: 2468097e60de4e9296bbe3271ce78390f303b73252a5982e32e2af084fe34b9d49b63f2b0dacc19e6a5edd33870456efeb8730a1e3bed48ef30bdaa86646f7b1
7
+ data.tar.gz: 1213ca2a3b9472dbf599d005de080dc62b158ec416e09a18bd46855063120541116d24ffa3d9abacf22f07715821527e8e2683c358f149a832808ced8d2c1a1f
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- validators (2.4.0)
4
+ validators (2.4.1)
5
5
 
6
6
  GEM
7
7
  remote: http://rubygems.org/
@@ -2,6 +2,9 @@ module ActiveModel
2
2
  module Validations
3
3
  class CnpjValidator < EachValidator
4
4
  def validate_each(record, attribute, value)
5
+ return if value.blank? && options[:allow_blank]
6
+ return if value.nil? && options[:allow_nil]
7
+
5
8
  record.errors.add(attribute, :invalid_cnpj,
6
9
  message: options[:message],
7
10
  value: value
@@ -2,6 +2,9 @@ module ActiveModel
2
2
  module Validations
3
3
  class CpfValidator < EachValidator
4
4
  def validate_each(record, attribute, value)
5
+ return if value.blank? && options[:allow_blank]
6
+ return if value.nil? && options[:allow_nil]
7
+
5
8
  record.errors.add(attribute, :invalid_cpf,
6
9
  message: options[:message],
7
10
  value: value
@@ -6,6 +6,9 @@ module ActiveModel
6
6
  end
7
7
 
8
8
  def validate_each(record, attribute, value)
9
+ return if value.blank? && options[:allow_blank]
10
+ return if value.nil? && options[:allow_nil]
11
+
9
12
  unless date?(value)
10
13
  record.errors.add(attribute, :invalid_date,
11
14
  :message => options[:message], :value => value
@@ -2,6 +2,9 @@ module ActiveModel
2
2
  module Validations
3
3
  class EmailValidator < EachValidator
4
4
  def validate_each(record, attribute, value)
5
+ return if value.blank? && options[:allow_blank]
6
+ return if value.nil? && options[:allow_nil]
7
+
5
8
  if value.to_s !~ Validators::EMAIL_FORMAT
6
9
  record.errors.add(
7
10
  attribute, :invalid_email,
@@ -3,6 +3,8 @@ module ActiveModel
3
3
  class HostnameValidator < EachValidator
4
4
  # Rules taken from http://www.zytrax.com/books/dns/apa/names.html
5
5
  def validate_each(record, attribute, value)
6
+ return if value.blank? && options[:allow_blank]
7
+ return if value.nil? && options[:allow_nil]
6
8
  return if valid_hostname?(value.to_s)
7
9
 
8
10
  record.errors.add(attribute, :invalid_hostname,
@@ -15,6 +17,7 @@ module ActiveModel
15
17
  host = host.to_s
16
18
  uri = URI(host)
17
19
 
20
+ host.present? &&
18
21
  uri.host.nil? &&
19
22
  uri.scheme.nil? &&
20
23
  uri.fragment.nil? &&
@@ -2,6 +2,9 @@ module ActiveModel
2
2
  module Validations
3
3
  class SshPrivateKeyValidator < EachValidator
4
4
  def validate_each(record, attribute, value)
5
+ return if value.blank? && options[:allow_blank]
6
+ return if value.nil? && options[:allow_nil]
7
+
5
8
  sshkey = SSHKey.new(value.to_s)
6
9
  validate_type(record, attribute, sshkey)
7
10
  validate_bits(record, attribute, sshkey)
@@ -2,6 +2,9 @@ module ActiveModel
2
2
  module Validations
3
3
  class SshPublicKeyValidator < EachValidator
4
4
  def validate_each(record, attribute, value)
5
+ return if value.blank? && options[:allow_blank]
6
+ return if value.nil? && options[:allow_nil]
7
+
5
8
  record.errors.add(attribute, :invalid_ssh_public_key,
6
9
  message: options[:message],
7
10
  value: value
@@ -8,6 +8,8 @@ module ActiveModel
8
8
  end
9
9
 
10
10
  def validate_each(record, attribute, value)
11
+ return if value.blank? && options[:allow_blank]
12
+ return if value.nil? && options[:allow_nil]
11
13
  return if url?(value.to_s)
12
14
 
13
15
  record.errors.add(attribute, :invalid_url,
@@ -2,7 +2,7 @@ module Validators
2
2
  module Version
3
3
  MAJOR = 2
4
4
  MINOR = 4
5
- PATCH = 0
5
+ PATCH = 1
6
6
  STRING = "#{MAJOR}.#{MINOR}.#{PATCH}"
7
7
  end
8
8
  end
@@ -34,5 +34,15 @@ describe ".validates_hostname_format_of" do
34
34
  expect(server).not_to be_valid
35
35
  end
36
36
  end
37
+
38
+ it 'rejects nil hostname' do
39
+ server = ServerWithoutTLD.new(nil)
40
+ expect(server).not_to be_valid
41
+ end
42
+
43
+ it 'rejects blank hostname' do
44
+ server = ServerWithoutTLD.new('')
45
+ expect(server).not_to be_valid
46
+ end
37
47
  end
38
48
  end
@@ -51,5 +51,15 @@ describe ".validates_url_format_of" do
51
51
  expect(user).not_to be_valid
52
52
  expect(user.errors[:url]).to eq(["não parece ser uma URL válida"])
53
53
  end
54
+
55
+ it "rejects nil urls" do
56
+ user = User.new(url: nil)
57
+ expect(user).not_to be_valid
58
+ end
59
+
60
+ it "rejects blank urls" do
61
+ user = User.new(url: '')
62
+ expect(user).not_to be_valid
63
+ end
54
64
  end
55
65
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: validators
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.4.0
4
+ version: 2.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nando Vieira