format_validator 0.0.6 → 0.0.7

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: 946208875fae89009b6359bd3c77525900a2c405
4
- data.tar.gz: 0a12e9e05034c9f67193e26cc0fa0f5b133bf143
3
+ metadata.gz: 55067f76a196c8e4517988c74af4c738944ab994
4
+ data.tar.gz: df363d1b20ca7516e9cca81e7889518ae6358333
5
5
  SHA512:
6
- metadata.gz: 8fde01117b30e6c7a9a277f97fd85dc2bf67397d27dbaabf00cce036a186fb8904b3fadea9f9f378f7d20b29d859912d85bdac80315d2920f0dba098527a3188
7
- data.tar.gz: 194c101f8413e6f881c2175ffec6d773383472b6e143b2ea2af898ca06db02a1cd890ab337f0fe23b1d90dce02f03792502d72e7a2ec2124cc8615c5da6d6ad2
6
+ metadata.gz: dba0bfe8ed56ec22dcf9fa04e7b69a4849003df9d404a36c4e4008d4af1dd539dfaffd88b668ba55d8e7885ab7ce68d61e7bbda6e4f20e6cd34a58b48a30e8ca
7
+ data.tar.gz: c00e8ecdac7ec123b3f7c30ba199297540c4ae9818d7c5f333aa644f560d711ce2f5dd4755a277965b241e1c35664d8dd47ab304d36dbe3e74f558f5f49c7f5d
data/CHANGELOG CHANGED
@@ -26,3 +26,7 @@
26
26
  ## v0.0.6
27
27
 
28
28
  * Validate the company tax id
29
+
30
+ ## v0.0.7
31
+
32
+ * Validate the bank routing number
@@ -6,6 +6,7 @@ require 'format_validator/zip_code_format_validator'
6
6
  require 'format_validator/future_date_validator'
7
7
  require 'format_validator/ssn_format_validator'
8
8
  require 'format_validator/company_tax_id_format_validator'
9
+ require 'format_validator/bank_routing_number_format_validator'
9
10
 
10
11
  module FormatValidator
11
12
  I18n.load_path << File.expand_path('../locales/en.yml', __FILE__)
@@ -0,0 +1,11 @@
1
+ module ActiveModel
2
+ module Validations
3
+ class BankRoutingNumberFormatValidator < ActiveModel::EachValidator
4
+ def validate_each(object, attribute, value)
5
+ unless value.to_s.match /\A\d{9}\z/
6
+ object.errors[attribute] << (options[:message] || I18n.t('form.errors.bank_routing_number'))
7
+ end
8
+ end
9
+ end
10
+ end
11
+ end
@@ -1,3 +1,3 @@
1
1
  module FormatValidator
2
- VERSION = '0.0.6'
2
+ VERSION = '0.0.7'
3
3
  end
data/lib/locales/en.yml CHANGED
@@ -1,6 +1,7 @@
1
1
  en:
2
2
  form:
3
3
  errors:
4
+ bank_routing_number: is invalid
4
5
  date: must be in the future
5
6
  email: is invalid
6
7
  hostname: is invalid
@@ -0,0 +1,34 @@
1
+ require_relative '../spec_helper'
2
+
3
+ describe 'BankRoutingNumberFormatValidator' do
4
+ describe '#validate_each' do
5
+ let(:klass) do
6
+ Class.new do
7
+ include ActiveModel::Validations
8
+ attr_accessor :bank_routing_number
9
+ validates :bank_routing_number, bank_routing_number_format: true
10
+ end
11
+ end
12
+
13
+ subject { klass.new }
14
+
15
+ describe 'valid' do
16
+ it 'is valid when the number is 9 digits' do
17
+ subject.bank_routing_number = 123456789
18
+ subject.valid?.must_equal true
19
+ subject.errors.messages.must_be_empty
20
+ end
21
+ end
22
+
23
+ describe 'invalid' do
24
+ ['12345678', '1234567xx', '123 45 6789', '123', '1234567890'].each do |invalid_bank_routing_number|
25
+ it "adds error when the number is #{invalid_bank_routing_number}" do
26
+ subject.bank_routing_number = invalid_bank_routing_number
27
+ subject.valid?.must_equal false
28
+ subject.errors.messages.size.must_equal 1
29
+ subject.errors.messages[:bank_routing_number].must_equal ['is invalid']
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -23,9 +23,9 @@ describe 'CompanyTaxIdFormatValidator' do
23
23
  end
24
24
 
25
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
26
+ ['123-456789', '1234567xx', '123 45 6789', '123', '1234567890'].each do |invalid_tax_id|
27
+ it "should add error when tax id is #{invalid_tax_id}" do
28
+ subject.tax_id = invalid_tax_id
29
29
  subject.valid?.must_equal false
30
30
  subject.errors.messages.size.must_equal 1
31
31
  subject.errors.messages[:tax_id].must_equal ['is invalid']
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: format_validator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
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-04-03 00:00:00.000000000 Z
11
+ date: 2014-05-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel
@@ -68,6 +68,7 @@ files:
68
68
  - Rakefile
69
69
  - format_validator.gemspec
70
70
  - lib/format_validator.rb
71
+ - lib/format_validator/bank_routing_number_format_validator.rb
71
72
  - lib/format_validator/company_tax_id_format_validator.rb
72
73
  - lib/format_validator/email_format_validator.rb
73
74
  - lib/format_validator/future_date_validator.rb
@@ -77,6 +78,7 @@ files:
77
78
  - lib/format_validator/version.rb
78
79
  - lib/format_validator/zip_code_format_validator.rb
79
80
  - lib/locales/en.yml
81
+ - spec/format_validator/bank_routing_number_format_validator_spec.rb
80
82
  - spec/format_validator/company_tax_id_format_validator_spec.rb
81
83
  - spec/format_validator/email_format_validator_spec.rb
82
84
  - spec/format_validator/future_date_validator_spec.rb
@@ -111,6 +113,7 @@ specification_version: 4
111
113
  summary: format_validator is a gem that adds the missing format validators to Active
112
114
  Model
113
115
  test_files:
116
+ - spec/format_validator/bank_routing_number_format_validator_spec.rb
114
117
  - spec/format_validator/company_tax_id_format_validator_spec.rb
115
118
  - spec/format_validator/email_format_validator_spec.rb
116
119
  - spec/format_validator/future_date_validator_spec.rb