format_validator 0.0.5 → 0.0.6

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 85766a3287dd11e546adc7d1422e7351cc2abff2
4
- data.tar.gz: d0f70f024444a0baca1efc91848277aa6b7acbd1
3
+ metadata.gz: 946208875fae89009b6359bd3c77525900a2c405
4
+ data.tar.gz: 0a12e9e05034c9f67193e26cc0fa0f5b133bf143
5
5
  SHA512:
6
- metadata.gz: 47de56e8c03ef94eedccb0224206de5f04ba966bd2aab49b2b60d73d6e45ec9be5da6bb553b817d22762cc98b3c2eb567dd247c63df435ee5e908a203d9cfded
7
- data.tar.gz: a710d6418ec8d4a03e46972832e999de93b17ba8b62f550850ada005fee093ef53d607005a7bd8dba92538fbffc47dbcaba84f872f7a257c72358db717044a4e
6
+ metadata.gz: 8fde01117b30e6c7a9a277f97fd85dc2bf67397d27dbaabf00cce036a186fb8904b3fadea9f9f378f7d20b29d859912d85bdac80315d2920f0dba098527a3188
7
+ data.tar.gz: 194c101f8413e6f881c2175ffec6d773383472b6e143b2ea2af898ca06db02a1cd890ab337f0fe23b1d90dce02f03792502d72e7a2ec2124cc8615c5da6d6ad2
data/CHANGELOG CHANGED
@@ -22,3 +22,7 @@
22
22
  * Add validations for zip code short format
23
23
  * Validate SSN
24
24
  * Change regex to be treated as string
25
+
26
+ ## v0.0.6
27
+
28
+ * Validate the company tax id
data/README.md CHANGED
@@ -22,6 +22,7 @@ validates :zip_code, zip_code_format: true
22
22
  validates :zip_code, zip_code_short_format: true
23
23
  validates :expiration_date, future_date: true
24
24
  validates :ssn, ssn_format: true
25
+ validates :tax_id, company_tax_id_format: true
25
26
  ```
26
27
 
27
28
  ## Contributing
@@ -0,0 +1,11 @@
1
+ module ActiveModel
2
+ module Validations
3
+ class CompanyTaxIdFormatValidator < ActiveModel::EachValidator
4
+ def validate_each(object, attribute, value)
5
+ unless value =~ /\A\d{2}-?\d{7}\z/
6
+ object.errors[attribute] << (options[:message] || I18n.t('form.errors.ssn'))
7
+ end
8
+ end
9
+ end
10
+ end
11
+ end
@@ -1,3 +1,3 @@
1
1
  module FormatValidator
2
- VERSION = '0.0.5'
2
+ VERSION = '0.0.6'
3
3
  end
@@ -5,6 +5,7 @@ require 'format_validator/hostname_format_validator'
5
5
  require 'format_validator/zip_code_format_validator'
6
6
  require 'format_validator/future_date_validator'
7
7
  require 'format_validator/ssn_format_validator'
8
+ require 'format_validator/company_tax_id_format_validator'
8
9
 
9
10
  module FormatValidator
10
11
  I18n.load_path << File.expand_path('../locales/en.yml', __FILE__)
@@ -0,0 +1,36 @@
1
+ require_relative '../spec_helper'
2
+
3
+ describe 'CompanyTaxIdFormatValidator' do
4
+ describe '#validate_each' do
5
+ let(:klass) do
6
+ Class.new do
7
+ include ActiveModel::Validations
8
+ attr_accessor :tax_id
9
+ validates :tax_id, company_tax_id_format: true
10
+ end
11
+ end
12
+
13
+ subject { klass.new }
14
+
15
+ describe 'valid' do
16
+ ['123456789', '12-3456789'].each do |number|
17
+ it "should not add any error when the tax id is #{number}" do
18
+ subject.tax_id = number
19
+ subject.valid?.must_equal true
20
+ subject.errors.messages.must_be_empty
21
+ end
22
+ end
23
+ end
24
+
25
+ describe 'invalid' do
26
+ ['123-456789', '1234567xx', '123 45 6789', '123', '1234567890'].each do |invalid_ssn|
27
+ it "should add error when ssn is #{invalid_ssn}" do
28
+ subject.tax_id = invalid_ssn
29
+ subject.valid?.must_equal false
30
+ subject.errors.messages.size.must_equal 1
31
+ subject.errors.messages[:tax_id].must_equal ['is invalid']
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
metadata CHANGED
@@ -1,55 +1,55 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: format_validator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jamal El Milahi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-03-18 00:00:00.000000000 Z
11
+ date: 2014-04-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - '>='
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '0'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - '>='
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ~>
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
33
  version: '1.3'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ~>
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '1.3'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rake
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - '>='
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - '>='
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  description: Active Model's missing format validators
@@ -59,8 +59,8 @@ executables: []
59
59
  extensions: []
60
60
  extra_rdoc_files: []
61
61
  files:
62
- - .gitignore
63
- - .travis.yml
62
+ - ".gitignore"
63
+ - ".travis.yml"
64
64
  - CHANGELOG
65
65
  - Gemfile
66
66
  - LICENSE.txt
@@ -68,6 +68,7 @@ files:
68
68
  - Rakefile
69
69
  - format_validator.gemspec
70
70
  - lib/format_validator.rb
71
+ - lib/format_validator/company_tax_id_format_validator.rb
71
72
  - lib/format_validator/email_format_validator.rb
72
73
  - lib/format_validator/future_date_validator.rb
73
74
  - lib/format_validator/hostname_format_validator.rb
@@ -76,6 +77,7 @@ files:
76
77
  - lib/format_validator/version.rb
77
78
  - lib/format_validator/zip_code_format_validator.rb
78
79
  - lib/locales/en.yml
80
+ - spec/format_validator/company_tax_id_format_validator_spec.rb
79
81
  - spec/format_validator/email_format_validator_spec.rb
80
82
  - spec/format_validator/future_date_validator_spec.rb
81
83
  - spec/format_validator/hostname_format_validator_spec.rb
@@ -93,22 +95,23 @@ require_paths:
93
95
  - lib
94
96
  required_ruby_version: !ruby/object:Gem::Requirement
95
97
  requirements:
96
- - - '>='
98
+ - - ">="
97
99
  - !ruby/object:Gem::Version
98
100
  version: '0'
99
101
  required_rubygems_version: !ruby/object:Gem::Requirement
100
102
  requirements:
101
- - - '>='
103
+ - - ">="
102
104
  - !ruby/object:Gem::Version
103
105
  version: '0'
104
106
  requirements: []
105
107
  rubyforge_project:
106
- rubygems_version: 2.0.3
108
+ rubygems_version: 2.2.2
107
109
  signing_key:
108
110
  specification_version: 4
109
111
  summary: format_validator is a gem that adds the missing format validators to Active
110
112
  Model
111
113
  test_files:
114
+ - spec/format_validator/company_tax_id_format_validator_spec.rb
112
115
  - spec/format_validator/email_format_validator_spec.rb
113
116
  - spec/format_validator/future_date_validator_spec.rb
114
117
  - spec/format_validator/hostname_format_validator_spec.rb