ama_validators 0.0.3 → 0.0.4

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: b489bd624f89d364f72259c065518a14e7e529cf
4
- data.tar.gz: 0d5db6097790f0d8a9ca9a39c0dc4b67916f6151
3
+ metadata.gz: 7f23e65bb1adaeeeb02df1e0bb11d43ecd908607
4
+ data.tar.gz: a89f702c90973a5a9132b1e4ca3d37b987a06882
5
5
  SHA512:
6
- metadata.gz: cf6a9dd7f796f03339d7d63d127958c12b5657c11dab18e6649e152da79b170f1ceca99a974187115844df2e1cd807b3f2d869d7ef630a3246fabd1662b299d3
7
- data.tar.gz: 55c095d322cb989b85ad22c57125f99b02ef2d1792dff1041178d549abde0520627ca848519fd95d15214b7d569014012e9e0dd20e16b00e7994c1e009142cf5
6
+ metadata.gz: fe8346c85ebbf628ce889a17f3fa07fe7f932503cef52e9ef6381bf3490e44722fe9d720e43d68b21ab6c6ae606119dc929fa01499cacd8ba6a3f77cfc75efe1
7
+ data.tar.gz: a877f357e65942f009294db4745c8ed80ca595b736cfd753809784de4bde687498d61d466d952bec7efab64e153ea7def70830364980b12429f7f01b18ec7bb3
data/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  [![Gem Version](https://badge.fury.io/rb/ama_validators.png)](http://badge.fury.io/rb/ama_validators)
4
4
  [![Code Climate](https://codeclimate.com/github/amaabca/ama_validators.png)](https://codeclimate.com/github/amaabca/ama_validators)
5
- [![Build Status](https://api.travis-ci.org/amaabca/ama_validators.png?branch=master)](https://travis-ci.org/amaabca/ama_validators)
5
+ [![Build Status](https://travis-ci.org/amaabca/ama_validators.png?branch=master)](https://travis-ci.org/amaabca/ama_validators)
6
6
  [![Coverage Status](https://coveralls.io/repos/amaabca/ama_validators/badge.png)](https://coveralls.io/r/amaabca/ama_validators)
7
7
  [![Dependency Status](https://gemnasium.com/amaabca/ama_validators.png)](https://gemnasium.com/amaabca/ama_validators)
8
8
 
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
10
10
  spec.email = ["ruben.a.estevez@gmail.com"]
11
11
  spec.description = "Compile the following validators: - Credit card - Email - Membership number - Phone number - Postal code"
12
12
  spec.summary = "This gem will compile the following validators - Credit card - Email - Membership number - Phone number - Postal code. With this gem there is no need for the validators classes."
13
- spec.homepage = ""
13
+ spec.homepage = "https://github.com/amaabca/ama_validators"
14
14
  spec.license = "MIT"
15
15
 
16
16
  spec.files = `git ls-files`.split($/)
@@ -1,6 +1,6 @@
1
1
  class EmailFormatValidator < ActiveModel::EachValidator
2
2
  def validate_each(object, attribute, value)
3
- unless value =~ /\A[^@\s]+@([^@\s\.]+\.)+[^@\s\.]+\z/
3
+ unless value =~ /\A[^`@\s]+@([^@`\s\.]+\.)+[^`@\s\.]+\z/
4
4
  object.errors[attribute] << (options[:message] || "enter a valid email address (e.g. name@example.com)")
5
5
  end
6
6
  end
@@ -1,6 +1,6 @@
1
1
  class PhoneNumberFormatValidator < ActiveModel::EachValidator
2
2
  def validate_each(object, attribute, value)
3
- unless value =~ /\A(1( |-)?)?(\(?[0-9]{3}\)?|[0-9]{3})( |-)?([0-9]{3}( |-)?[0-9]{4}|[a-zA-Z0-9]{7})\z/
3
+ unless value =~ /\A(\+?1( |-)?)?(\(?[0-9]{3}\)?|[0-9]{3})( |-)?([0-9]{3}( |-)?[0-9]{4})\z/
4
4
  object.errors[attribute] << (options[:message] || "enter a valid 10-digit number (e.g. 587-555-5555)")
5
5
  end
6
6
  end
@@ -1,7 +1,7 @@
1
1
  class PostalCodeFormatValidator < ActiveModel::EachValidator
2
2
  def validate_each(object, attribute, value)
3
- unless value =~ /\A(\d{5}((-|\s)\d{4})?)|([txTX]\d[abceghjklmnprtvxyzABCEGHJKLMNPRSTVWXYZ])\ {0,1}(\d[abceghjklmnprstvxyzABCEGHJKLMNPRSTVWXYZ]\d)\z/
4
- object.errors[attribute] << (options[:message] || "enter a valid AB or NT postal code (e.g. T2T 2T2)")
3
+ unless value =~ /\A(\d{5}((-|\s)\d{4})?)|([txTX]\d[abceghjklmnprstvwxyzABCEGHJKLMNPRSTVWXYZ])\ {0,1}(\d[abceghjklmnprstvwxyzABCEGHJKLMNPRSTVWXYZ]\d)\z/
4
+ object.errors[attribute] << (options[:message] || "enter a valid AB or NT postal code (e.g. T4C 1A5)")
5
5
  end
6
6
  end
7
7
  end
@@ -1,3 +1,3 @@
1
1
  module AmaValidators
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
@@ -7,20 +7,27 @@ describe CreditCardFormatValidator do
7
7
  let( :attribute ) { :credit_card }
8
8
  let (:object) { Profile.new }
9
9
 
10
+ invalid_credit_card_numbers = %w[9556494038121161 41128109359983 n396092084242542 535299462783972 1396092084242542]
11
+ valid_credit_card_numbers = %w[4556494038121161 4112810935509983 4556828677360012 5396092084242542 5180466231664941 5352994627083972]
12
+
10
13
 
11
14
  context 'Wrong credit card format' do
12
15
 
13
16
  context 'No message is sent on the options' do
14
17
  it 'it returns error message expecified on the validator' do
15
18
  n = subject.new( { attributes: attribute } )
16
- expect(n.validate_each(object, attribute, '9485582751367890')).to include('enter a valid credit card number (Visa or Mastercard)')
19
+ invalid_credit_card_numbers.each do |invalid_credit_card_number|
20
+ expect(n.validate_each(object, attribute, invalid_credit_card_number)).to include('enter a valid credit card number (Visa or Mastercard)')
21
+ end
17
22
  end
18
23
  end
19
24
 
20
25
  context 'Message is sent on the options' do
21
26
  it 'it returns error message expecified on the options' do
22
27
  n = subject.new( { message: 'Test error message', attributes: :postal_code } )
23
- expect(n.validate_each(object, attribute, '9485582751367890')).to include('Test error message')
28
+ invalid_credit_card_numbers.each do |invalid_credit_card_number|
29
+ expect(n.validate_each(object, attribute, invalid_credit_card_number)).to include('Test error message')
30
+ end
24
31
  end
25
32
  end
26
33
 
@@ -29,16 +36,20 @@ describe CreditCardFormatValidator do
29
36
  context 'Correct credit card format' do
30
37
 
31
38
  context 'No message is sent on the options' do
32
- it 'it do not return error message' do
39
+ it 'it does not return error message' do
33
40
  n = subject.new( { attributes: attribute } )
34
- expect(n.validate_each(object, attribute, '4716157014589654')).to equal(nil)
41
+ valid_credit_card_numbers.each do |valid_credit_card_number|
42
+ expect(n.validate_each(object, attribute, valid_credit_card_number)).to equal(nil)
43
+ end
35
44
  end
36
45
  end
37
46
 
38
47
  context 'Message is sent on the options' do
39
- it 'it do not return error message' do
48
+ it 'it does not return error message' do
40
49
  n = subject.new( { message: 'Test error message', attributes: attribute } )
41
- expect(n.validate_each(object, attribute, '5595361193388663')).to equal(nil)
50
+ valid_credit_card_numbers.each do |valid_credit_card_number|
51
+ expect(n.validate_each(object, attribute, valid_credit_card_number)).to equal(nil)
52
+ end
42
53
  end
43
54
  end
44
55
 
@@ -7,20 +7,27 @@ describe EmailFormatValidator do
7
7
  let( :attribute ) { :email }
8
8
  let (:object) { Profile.new }
9
9
 
10
+ invalid_addresses = %w[user@fail,com user_at.com user_fail.com user@ @fail.com ryan`1`@system88.com]
11
+ valid_addresses = %w[user@pass.com user_user@pass.com user.user@pass.com ryan+stage@systme88.com]
12
+
10
13
 
11
14
  context 'Wrong email format' do
12
15
 
13
16
  context 'No message is sent on the options' do
14
17
  it 'it returns error message expecified on the validator' do
15
18
  n = subject.new( { attributes: attribute } )
16
- expect(n.validate_each(object, attribute, 'fail@com')).to include('enter a valid email address (e.g. name@example.com)')
19
+ invalid_addresses.each do |invalid_address|
20
+ expect(n.validate_each(object, attribute, invalid_address)).to include('enter a valid email address (e.g. name@example.com)')
21
+ end
17
22
  end
18
23
  end
19
24
 
20
25
  context 'Message is sent on the options' do
21
26
  it 'it returns error message expecified on the options' do
22
27
  n = subject.new( { message: 'Test error message', attributes: :postal_code } )
23
- expect(n.validate_each(object, attribute, 'fail.com')).to include('Test error message')
28
+ invalid_addresses.each do |invalid_address|
29
+ expect(n.validate_each(object, attribute, invalid_address)).to include('Test error message')
30
+ end
24
31
  end
25
32
  end
26
33
 
@@ -29,16 +36,20 @@ describe EmailFormatValidator do
29
36
  context 'Correct email format' do
30
37
 
31
38
  context 'No message is sent on the options' do
32
- it 'it do not return error message' do
39
+ it 'it does not return error message' do
33
40
  n = subject.new( { attributes: attribute } )
34
- expect(n.validate_each(object, attribute, 'no_fail@mail.com')).to equal(nil)
41
+ valid_addresses.each do |valid_address|
42
+ expect(n.validate_each(object, attribute, valid_address)).to equal(nil)
43
+ end
35
44
  end
36
45
  end
37
46
 
38
47
  context 'Message is sent on the options' do
39
- it 'it do not return error message' do
48
+ it 'it does not return error message' do
40
49
  n = subject.new( { message: 'Test error message', attributes: attribute } )
41
- expect(n.validate_each(object, attribute, 'no_fail@mail.com')).to equal(nil)
50
+ valid_addresses.each do |valid_address|
51
+ expect(n.validate_each(object, attribute, valid_address)).to equal(nil)
52
+ end
42
53
  end
43
54
  end
44
55
 
@@ -7,20 +7,27 @@ describe MembershipNumberFormatValidator do
7
7
  let( :attribute ) { :membership_number }
8
8
  let (:object) { Profile.new }
9
9
 
10
+ invalid_membership_numbers = %w[waffles 1234560022820001 620272089641001 62027217054490012 1202722030577003 6202822030577003]
11
+ valid_membership_numbers = %w[6202720022820001 6202720896410004 6202721705449001 6202722030577003]
12
+
10
13
 
11
14
  context 'Wrong membership number format' do
12
15
 
13
16
  context 'No message is sent on the options' do
14
17
  it 'it returns error message expecified on the validator' do
15
18
  n = subject.new( { attributes: attribute } )
16
- expect(n.validate_each(object, attribute, '6202721111')).to include('must be a valid membership number')
19
+ invalid_membership_numbers.each do |invalid_membership_number|
20
+ expect(n.validate_each(object, attribute, invalid_membership_number)).to include('must be a valid membership number')
21
+ end
17
22
  end
18
23
  end
19
24
 
20
25
  context 'Message is sent on the options' do
21
26
  it 'it returns error message expecified on the options' do
22
27
  n = subject.new( { message: 'Test error message', attributes: :postal_code } )
23
- expect(n.validate_each(object, attribute, '6202721111')).to include('Test error message')
28
+ invalid_membership_numbers.each do |invalid_membership_number|
29
+ expect(n.validate_each(object, attribute, invalid_membership_number)).to include('Test error message')
30
+ end
24
31
  end
25
32
  end
26
33
 
@@ -29,16 +36,20 @@ describe MembershipNumberFormatValidator do
29
36
  context 'Correct membership number format' do
30
37
 
31
38
  context 'No message is sent on the options' do
32
- it 'it do not return error message' do
39
+ it 'it does not return error message' do
33
40
  n = subject.new( { attributes: attribute } )
34
- expect(n.validate_each(object, attribute, '6202720022820001')).to equal(nil)
41
+ valid_membership_numbers.each do |valid_membership_number|
42
+ expect(n.validate_each(object, attribute, valid_membership_number)).to equal(nil)
43
+ end
35
44
  end
36
45
  end
37
46
 
38
47
  context 'Message is sent on the options' do
39
- it 'it do not return error message' do
48
+ it 'it does not return error message' do
40
49
  n = subject.new( { message: 'Test error message', attributes: attribute } )
41
- expect(n.validate_each(object, attribute, '6202720022820001')).to equal(nil)
50
+ valid_membership_numbers.each do |valid_membership_number|
51
+ expect(n.validate_each(object, attribute, valid_membership_number)).to equal(nil)
52
+ end
42
53
  end
43
54
  end
44
55
 
@@ -7,20 +7,26 @@ describe PhoneNumberFormatValidator do
7
7
  let( :attribute ) { :phone_number }
8
8
  let (:object) { Profile.new }
9
9
 
10
+ invalid_phone_numbers = %w[123 780123456 1234456 666 mynumber 780myphone]
11
+ valid_phone_numbers = %w[587-555-5555 5875555555 1234567890 17809172969 (780)9172969 7809172969 +17809172969 +1(780)9172969]
10
12
 
11
13
  context 'Wrong phone number format' do
12
14
 
13
15
  context 'No message is sent on the options' do
14
16
  it 'it returns error message expecified on the validator' do
15
17
  n = subject.new( { attributes: attribute } )
16
- expect(n.validate_each(object, attribute, '777 777')).to include('enter a valid 10-digit number (e.g. 587-555-5555)')
18
+ invalid_phone_numbers.each do |invalid_phone_number|
19
+ expect(n.validate_each(object, attribute, invalid_phone_number)).to include('enter a valid 10-digit number (e.g. 587-555-5555)')
20
+ end
17
21
  end
18
22
  end
19
23
 
20
24
  context 'Message is sent on the options' do
21
25
  it 'it returns error message expecified on the options' do
22
26
  n = subject.new( { message: 'Test error message', attributes: attribute } )
23
- expect(n.validate_each(object, attribute, '777 777')).to include('Test error message')
27
+ invalid_phone_numbers.each do |invalid_phone_number|
28
+ expect(n.validate_each(object, attribute, invalid_phone_number)).to include('Test error message')
29
+ end
24
30
  end
25
31
  end
26
32
 
@@ -29,16 +35,20 @@ describe PhoneNumberFormatValidator do
29
35
  context 'Correct phone number format' do
30
36
 
31
37
  context 'No message is sent on the options' do
32
- it 'it do not return error message' do
38
+ it 'it does not return error message' do
33
39
  n = subject.new( { attributes: attribute } )
34
- expect(n.validate_each(object, attribute, '777 123 4567')).to equal(nil)
40
+ valid_phone_numbers.each do |valid_phone_number|
41
+ expect(n.validate_each(object, attribute, valid_phone_number)).to equal(nil)
42
+ end
35
43
  end
36
44
  end
37
45
 
38
46
  context 'Message is sent on the options' do
39
- it 'it do not return error message' do
47
+ it 'it does not return error message' do
40
48
  n = subject.new( { message: 'Test error message', attributes: attribute } )
41
- expect(n.validate_each(object, attribute, '777 123 4567')).to equal(nil)
49
+ valid_phone_numbers.each do |valid_phone_number|
50
+ expect(n.validate_each(object, attribute, valid_phone_number)).to equal(nil)
51
+ end
42
52
  end
43
53
  end
44
54
 
@@ -7,20 +7,26 @@ describe PostalCodeFormatValidator do
7
7
  let( :attribute ) { :postal_code }
8
8
  let (:object) { Profile.new }
9
9
 
10
+ invalid_postal_codes = %w[2w2e3e b4hk6j t556v7 x2ceee t3x6sv T5j5M/]
11
+ valid_postal_codes = %w[T5w4g5 T5W4G5 X4H3J9 t6J4M5 x3B5X8]
10
12
 
11
13
  context 'Wrong postal code format' do
12
14
 
13
15
  context 'No message is sent on the options' do
14
16
  it 'it returns error message expecified on the validator' do
15
17
  n = subject.new( { attributes: attribute } )
16
- expect(n.validate_each(object, attribute, 'TTJ4M5')).to include('enter a valid AB or NT postal code (e.g. T2T 2T2)')
18
+ invalid_postal_codes.each do |invalid_postal_code|
19
+ expect(n.validate_each(object, attribute, invalid_postal_code)).to include('enter a valid AB or NT postal code (e.g. T4C 1A5)')
20
+ end
17
21
  end
18
22
  end
19
23
 
20
24
  context 'Message is sent on the options' do
21
25
  it 'it returns error message expecified on the options' do
22
26
  n = subject.new( { message: 'Test error message', attributes: attribute } )
23
- expect(n.validate_each(object, attribute, 'G7J4M5')).to include('Test error message')
27
+ invalid_postal_codes.each do |invalid_postal_code|
28
+ expect(n.validate_each(object, attribute, invalid_postal_code)).to include('Test error message')
29
+ end
24
30
  end
25
31
  end
26
32
 
@@ -29,16 +35,20 @@ describe PostalCodeFormatValidator do
29
35
  context 'Correct postal code format' do
30
36
 
31
37
  context 'No message is sent on the options' do
32
- it 'it do not return error message' do
38
+ it 'it does not return error message' do
33
39
  n = subject.new( { attributes: attribute } )
34
- expect(n.validate_each(object, attribute, 'T6J4M5')).to equal(nil)
40
+ valid_postal_codes.each do |valid_postal_code|
41
+ expect(n.validate_each(object, attribute, valid_postal_code)).to equal(nil)
42
+ end
35
43
  end
36
44
  end
37
45
 
38
46
  context 'Message is sent on the options' do
39
- it 'it do not return error message' do
47
+ it 'it does not return error message' do
40
48
  n = subject.new( { message: 'Test error message', attributes: attribute } )
41
- expect(n.validate_each(object, attribute, 'T6J4M5')).to equal(nil)
49
+ valid_postal_codes.each do |valid_postal_code|
50
+ expect(n.validate_each(object, attribute, valid_postal_code)).to equal(nil)
51
+ end
42
52
  end
43
53
  end
44
54
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ama_validators
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ruben Estevez
@@ -167,7 +167,7 @@ files:
167
167
  - spec/phone_number_format_validator_spec.rb
168
168
  - spec/postal_code_format_validator_spec.rb
169
169
  - spec/spec_helper.rb
170
- homepage: ''
170
+ homepage: https://github.com/amaabca/ama_validators
171
171
  licenses:
172
172
  - MIT
173
173
  metadata: {}