more_validators 0.1.2 → 0.1.3

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.
data/CHANGELOG CHANGED
@@ -1,3 +1,6 @@
1
+ 0.1.3 - May 14th 2010
2
+ * added allow_blank => true as default behaviour for validators
3
+
1
4
  0.1.2 - May 13th 2010
2
5
  * new validators:
3
6
  ** validates_as_uf_br
data/README CHANGED
@@ -19,6 +19,11 @@ gem install more_validators
19
19
  Add to environment.rb initializer block:
20
20
  config.gem 'more_validators', :lib => 'validates_as_'
21
21
 
22
+ LatestVersion
23
+ --------------
24
+ Version: 0.1.3
25
+ --------------
26
+
22
27
  Usage:
23
28
  ======
24
29
  In your model file do something like:
@@ -26,22 +31,22 @@ In your model file do something like:
26
31
  class MyClass < ActiveRecord::Base
27
32
 
28
33
  # Email validation
29
- validates_as_email :email, :message => 'Invalid', :allow_nil => true
34
+ validates_as_email :email, :message => 'Invalid', :allow_nil => true, :allow_blank => true
30
35
 
31
36
  # Brazilian postal code validation
32
- validates_as_cep :cep, :message => 'Invalid', :allow_nil => true
37
+ validates_as_cep :cep, :message => 'Invalid', :allow_nil => true, :allow_blank => true
33
38
 
34
39
  # Brazilian phone number validation
35
- validates_as_phonenumber_br :phonenumber, :message => 'Invalid', :allow_nil => true
40
+ validates_as_phonenumber_br :phonenumber, :message => 'Invalid', :allow_nil => true, :allow_blank => true
36
41
 
37
42
  # CPF validation
38
- validates_as_cpf :cpf, :message => 'Invalid', :allow_nil => true
43
+ validates_as_cpf :cpf, :message => 'Invalid', :allow_nil => true, :allow_blank => true
39
44
 
40
45
  # CNPJ validation
41
- validates_as_cnpj :cnpj, :message => 'Invalid', :allow_nil => true
46
+ validates_as_cnpj :cnpj, :message => 'Invalid', :allow_nil => true, :allow_blank => true
42
47
 
43
48
  # Brazilian UF validation, both upcase and downcase are allowed by default
44
- validates_as_uf_br :uf, :message => 'Invalid', :allow_nil => true, :allow_up => true, :allow_down => true
49
+ validates_as_uf_br :uf, :allow_up => true, :allow_down => true
45
50
 
46
51
  end
47
52
 
@@ -5,7 +5,8 @@ module ActiveRecord
5
5
  configuration = {
6
6
  :message => I18n.translate('activerecord.errors.messages.invalid', :default => 'invalid' ),
7
7
  :with => /\A(\d{5})([-]{0,1})(\d{3})\Z/,
8
- :allow_nil => true }
8
+ :allow_nil => true,
9
+ :allow_blank => true }
9
10
  configuration.update(attr_names.pop) if attr_names.last.is_a?(Hash)
10
11
 
11
12
  validates_format_of attr_names, configuration
@@ -4,6 +4,7 @@ module CNPJ
4
4
  88888888888888 99999999999999)
5
5
 
6
6
  def self.valid?(cnpj)
7
+
7
8
  cnpj = cnpj.to_s
8
9
 
9
10
  # could be 13 or 14 digits or with mask 99.999.999/9999-99
@@ -57,7 +58,8 @@ module ActiveRecord
57
58
  def validates_as_cnpj(*attr_names)
58
59
  configuration = {
59
60
  :message => I18n.translate('activerecord.errors.messages.invalid', :default => 'invalid' ),
60
- :allow_nil => true }
61
+ :allow_nil => true,
62
+ :allow_blank => true }
61
63
  configuration.update(attr_names.pop) if attr_names.last.is_a?(Hash)
62
64
 
63
65
  validates_each attr_names, configuration do |record, attribute, value|
@@ -3,7 +3,7 @@ module CPF
3
3
  55555555555 66666666666 77777777777 88888888888 99999999999
4
4
  00000000000)
5
5
 
6
- def self.valid?(cpf)
6
+ def self.valid?(cpf)
7
7
  cpf = cpf.to_s
8
8
 
9
9
  # could be 10 or 11 digits or with mask 999.999.999-99
@@ -55,7 +55,8 @@ module ActiveRecord
55
55
  def validates_as_cpf(*attr_names)
56
56
  configuration = {
57
57
  :message => I18n.translate('activerecord.errors.messages.invalid', :default => 'invalid' ),
58
- :allow_nil => true }
58
+ :allow_nil => true,
59
+ :allow_blank => true }
59
60
  configuration.update(attr_names.pop) if attr_names.last.is_a?(Hash)
60
61
 
61
62
  validates_each attr_names, configuration do |record, attribute, value|
@@ -48,7 +48,8 @@ module ActiveRecord
48
48
  configuration = {
49
49
  :message => I18n.translate('activerecord.errors.messages.invalid', :default => 'invalid' ),
50
50
  :with => RFC822::EmailAddress,
51
- :allow_nil => true }
51
+ :allow_nil => true,
52
+ :allow_blank => true }
52
53
  configuration.update(attr_names.pop) if attr_names.last.is_a?(Hash)
53
54
 
54
55
  validates_format_of attr_names, configuration
@@ -5,7 +5,8 @@ module ActiveRecord
5
5
  configuration = {
6
6
  :message => I18n.translate('activerecord.errors.messages.invalid', :default => 'invalid' ),
7
7
  :with => /\A([1-9]{2})([- ]{0,1})(\d{3}|\d{4})([- ]{0,1})(\d{4})\Z/,
8
- :allow_nil => true }
8
+ :allow_nil => true,
9
+ :allow_blank => true }
9
10
  configuration.update(attr_names.pop) if attr_names.last.is_a?(Hash)
10
11
 
11
12
  validates_format_of attr_names, configuration
@@ -18,6 +18,7 @@ module ActiveRecord
18
18
  configuration = {
19
19
  :message => I18n.translate('activerecord.errors.messages.invalid', :default => 'invalid' ),
20
20
  :allow_nil => true,
21
+ :allow_blank => true,
21
22
  :allow_down => true,
22
23
  :allow_up => true }
23
24
  configuration.update(attr_names.pop) if attr_names.last.is_a?(Hash)
@@ -5,7 +5,8 @@ module ActiveRecord
5
5
  configuration = {
6
6
  :message => I18n.translate('activerecord.errors.messages.invalid', :default => 'invalid' ),
7
7
  :with => /\A(http|https)[:]\/{2}[^\/.]+([.][^\/.]+)+.*\Z/i,
8
- :allow_nil => true }
8
+ :allow_nil => true,
9
+ :allow_blank => true }
9
10
  configuration.update(attr_names.pop) if attr_names.last.is_a?(Hash)
10
11
 
11
12
  validates_format_of attr_names, configuration
@@ -38,6 +38,8 @@ class ValidatesAsCepTest < Test::Unit::TestCase
38
38
  '01234-000',
39
39
  '12345-678']
40
40
 
41
+ values.push('')
42
+
41
43
  values.each do |value|
42
44
  assert TestRecord.new(:cep => value).valid?, "#{value} should be legal."
43
45
  end
@@ -41,6 +41,8 @@ class ValidatesAsCNPJTest < Test::Unit::TestCase
41
41
  '28.261.861/0001-42',
42
42
  '28261861000142']
43
43
 
44
+ values.push('')
45
+
44
46
  values.each do |value|
45
47
  assert TestRecord.new(:cnpj => value).valid?, "#{value} should be legal."
46
48
  end
@@ -41,6 +41,8 @@ class ValidatesAsCpfTest < Test::Unit::TestCase
41
41
  values = [
42
42
  '227.566.442-42',
43
43
  '22756644242']
44
+
45
+ values.push('')
44
46
 
45
47
  values.each do |value|
46
48
  assert TestRecord.new(:cpf => value).valid?, "#{value} should be legal."
@@ -40,6 +40,9 @@ class ValidatesAsEmailTest < Test::Unit::TestCase
40
40
  'me@[187.223.45.119]',
41
41
  'someone@123.com',
42
42
  ]
43
+
44
+ addresses.push('')
45
+
43
46
  addresses.each do |address|
44
47
  assert TestRecord.new(:email => address).valid?, "#{address} should be legal."
45
48
  end
@@ -44,6 +44,8 @@ class ValidatesAsPhoneNumberBRTest < Test::Unit::TestCase
44
44
  '11-5555 5555',
45
45
  '11 555-5555']
46
46
 
47
+ values.push('')
48
+
47
49
  values.each do |value|
48
50
  assert TestRecord.new(:phonenumber_br => value).valid?, "#{value} should be legal."
49
51
  end
@@ -35,7 +35,9 @@ class ValidatesAsUFBRTest < Test::Unit::TestCase
35
35
  def test_legal_uf_br
36
36
  values = %w(ac al am ap ba ce df es go ma mg ms mt pa pb pe pi pr rj rn ro rr rs sc se sp to
37
37
  AC AL AM AP BA CE DF ES GO MA MG MS MT PA PB PE PI PR RJ RN RO RR RS SC SE SP TO)
38
-
38
+
39
+ values.push('')
40
+
39
41
  values.each do |value|
40
42
  assert TestRecord.new(:uf_br => value).valid?, "#{value} should be legal."
41
43
  end
@@ -40,6 +40,8 @@ class ValidatesAsWebsiteTest < Test::Unit::TestCase
40
40
  'https://test.com/',
41
41
  'http://www.test.com/test/test/test.html',
42
42
  'https://www.test.com/test/test/test.html?test=test']
43
+
44
+ values.push('')
43
45
 
44
46
  values.each do |value|
45
47
  assert TestRecord.new(:website => value).valid?, "#{value} should be legal."
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- - 2
9
- version: 0.1.2
8
+ - 3
9
+ version: 0.1.3
10
10
  platform: ruby
11
11
  authors:
12
12
  - Rafael Barbolo
@@ -17,7 +17,7 @@ autorequire:
17
17
  bindir: bin
18
18
  cert_chain: []
19
19
 
20
- date: 2010-05-13 00:00:00 -03:00
20
+ date: 2010-05-14 00:00:00 -03:00
21
21
  default_executable:
22
22
  dependencies: []
23
23