ama_validators 0.0.5 → 0.0.6

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: 5a838e0200871822f6a9d4ac306d958be9c305ba
4
- data.tar.gz: eb93a5b69be19ee09416b9125839b23fd2027317
3
+ metadata.gz: 64029a3e49c71deed296020736920b6907e0d572
4
+ data.tar.gz: 894448afc757c3165d1634f0011fa2974d05fb4a
5
5
  SHA512:
6
- metadata.gz: 77581258db711ad2ac1d8c73b737dd3b46a867c2107ce4d1a245265c50893e935cd4c90b5a6b3a8f6fbf9e4db58cb844a2e4f00293ef4736d21f114035c54409
7
- data.tar.gz: d13222d9ec07157e3eb48fa2e492a12739d571c220fae0ba496b78e872011e6a4a3b02077026f25b340273e2e3888066dfa7370f60a2dd3f120415019cb2e260
6
+ metadata.gz: a9b49b334d61fc0f831328317cb21212020b2520be6e5bd5ecd5d276aa8b13cd2fa9d44945e792b0b33da363ab19ea83f205779a81d41941403773fc87e0d537
7
+ data.tar.gz: 6ffae19b0cfa27123b2ed6e6a851caa2f1abb460cdcaaffea0b56325b1dca29bbd3a8da2a0ac2127461241b095fcb7b22b719b1df80f962dee67d9ac1f3d72f4
data/.gitignore CHANGED
@@ -15,3 +15,5 @@ spec/reports
15
15
  test/tmp
16
16
  test/version_tmp
17
17
  tmp
18
+ .idea
19
+ vendor/bundle
data/.travis.yml CHANGED
@@ -1,3 +1,3 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 1.9.3
3
+ - 2.0.0
@@ -0,0 +1,7 @@
1
+ class NameFormatValidator < ActiveModel::EachValidator
2
+ def validate_each(object, attribute, value)
3
+ unless value =~ /\A[\sa-zA-ZÀàÂâÄäÈèÉéÊêËëÎîÏïÔôŒœÙùÛûÜüŸÿÇç,.'-]+\z/
4
+ object.errors[attribute] << (options[:message] || "We're sorry your name cannot contain any special characters")
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,24 @@
1
+ # Use this with
2
+ # validates :your_province_field, province: { country: :your_country_field }
3
+
4
+ class ProvinceValidator < ActiveModel::EachValidator
5
+ def validate_each(object, attribute, value)
6
+ provinces = PROV_STATE[object.send(options[:country])]
7
+ if !provinces.try(:include?, value)
8
+ object.errors[attribute] << (options[:message] || 'Province/State is in selected country.')
9
+ end
10
+ end
11
+
12
+ PROV_STATE = {
13
+ canada: ['Alberta', 'British Columbia', 'Manitoba', 'New Brunswick', 'Newfoundland', 'Nova Scotia',
14
+ 'Northwest Territories', 'Nunavut', 'Ontario', 'Prince Edward Island', 'Saskatchewan',
15
+ 'Quebec', 'Yukon'],
16
+ usa: ['Alabama', 'Alaska', 'Arizona', 'Arkansas', 'California', 'Colorado', 'Connecticut', 'Delaware',
17
+ 'Florida', 'Georgia', 'Hawaii', 'Idaho', 'Illinois', 'Indiana', 'Iowa', 'Kansas', 'Kentucky',
18
+ 'Louisiana', 'Maine', 'Maryland', 'Massachusetts', 'Michigan', 'Minnesota', 'Mississippi',
19
+ 'Missouri', 'Montana', 'Nebraska', 'Nevada', 'New Hampshire', 'New Jersey', 'New Mexico',
20
+ 'New York', 'North Carolina', 'North Dakota', 'Ohio', 'Oklahoma', 'Oregon', 'Pennsylvania',
21
+ 'Rhode Island', 'South Carolina', 'South Dakota', 'Tennessee', 'Texas', 'Utah', 'Vermont',
22
+ 'Virginia', 'Washington', 'Washington, D.C', 'West Virginia', 'Wisconsin', 'Wyoming']
23
+ }
24
+ end
@@ -1,3 +1,3 @@
1
1
  module AmaValidators
2
- VERSION = "0.0.5"
2
+ VERSION = "0.0.6"
3
3
  end
@@ -7,5 +7,7 @@ module AmaValidators
7
7
  require 'ama_validators/credit_card_format_validator'
8
8
  require 'ama_validators/membership_number_format_validator'
9
9
  require 'ama_validators/phone_number_format_validator'
10
+ require 'ama_validators/province_validator'
11
+ require 'ama_validators/name_format_validator'
10
12
 
11
13
  end
@@ -0,0 +1,51 @@
1
+ require 'factories/profiles.rb'
2
+
3
+ describe NameFormatValidator do
4
+
5
+ let(:subject) { NameFormatValidator }
6
+ let (:object) { Profile.new }
7
+
8
+ invalid_names = %w[A%^dam G∫ Ra©©øøl œ∑´®††a †††¬∆µ ©ƒ∂ßåΩ ≈ç√∫µ@]
9
+ valid_names = %w[George Jerry Elaine Kramer Jean-François Noël étè]
10
+
11
+ context 'Wrong name format' do
12
+ context 'No message is sent on the options' do
13
+ it 'it returns error message expecified on the validator' do
14
+ n = subject.new( { attributes: :first_name } )
15
+ invalid_names.each do |invalid_name|
16
+ expect(n.validate_each(object, :first_name, invalid_name)).to include("We're sorry your name cannot contain any special characters")
17
+ end
18
+ end
19
+ end
20
+
21
+ context 'Message is sent on the options' do
22
+ it 'it returns error message expecified on the options' do
23
+ n = subject.new( { message: 'Test error message', attributes: :first_name } )
24
+ invalid_names.each do |invalid_name|
25
+ expect(n.validate_each(object, :first_name, invalid_name)).to include('Test error message')
26
+ end
27
+ end
28
+ end
29
+ end
30
+
31
+ context 'Correct name format' do
32
+
33
+ context 'No message is sent on the options' do
34
+ it 'it does not return error message' do
35
+ n = subject.new( { attributes: :first_name } )
36
+ valid_names.each do |valid_name|
37
+ expect(n.validate_each(object, :first_name, valid_name)).to equal(nil)
38
+ end
39
+ end
40
+ end
41
+
42
+ context 'Message is sent on the options' do
43
+ it 'it does not return error message' do
44
+ n = subject.new( { message: 'Test error message', attributes: :first_name } )
45
+ valid_names.each do |valid_name|
46
+ expect(n.validate_each(object, :first_name, valid_name)).to equal(nil)
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,52 @@
1
+ require 'spec_helper'
2
+
3
+ describe ProvinceValidator do
4
+ class Validatable
5
+ include ActiveModel::Validations
6
+ include ActiveModel::Model
7
+ attr_accessor :country, :province
8
+
9
+ validates :province, province: { country: :country }
10
+ end
11
+
12
+ subject { Validatable.new({ country: country, province: province }) }
13
+
14
+ context 'province is in selected country' do
15
+ let(:country) { :canada }
16
+ let(:province) { 'Alberta' }
17
+
18
+ it 'is valid' do
19
+ expect(subject).to be_valid
20
+ end
21
+ end
22
+
23
+ context 'province is not in selected country' do
24
+ let(:country) { :canada }
25
+ let(:province) { 'Alabama' }
26
+
27
+ it 'is not valid' do
28
+ expect(subject).to_not be_valid
29
+ expect(subject.errors[:province]).to_not be_empty
30
+ end
31
+ end
32
+
33
+ context 'province is blank' do
34
+ let(:country) { :canada }
35
+ let(:province) { '' }
36
+
37
+ it 'is not valid' do
38
+ expect(subject).to_not be_valid
39
+ expect(subject.errors[:province]).to_not be_empty
40
+ end
41
+ end
42
+
43
+ context 'province is nil' do
44
+ let(:country) { :canada }
45
+ let(:province) { nil }
46
+
47
+ it 'is not valid' do
48
+ expect(subject).to_not be_valid
49
+ expect(subject.errors[:province]).to_not be_empty
50
+ end
51
+ end
52
+ end
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.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael van den Beuken
@@ -13,7 +13,7 @@ authors:
13
13
  autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
- date: 2014-09-30 00:00:00.000000000 Z
16
+ date: 2015-10-22 00:00:00.000000000 Z
17
17
  dependencies:
18
18
  - !ruby/object:Gem::Dependency
19
19
  name: bundler
@@ -139,15 +139,19 @@ files:
139
139
  - lib/ama_validators/credit_card_format_validator.rb
140
140
  - lib/ama_validators/email_format_validator.rb
141
141
  - lib/ama_validators/membership_number_format_validator.rb
142
+ - lib/ama_validators/name_format_validator.rb
142
143
  - lib/ama_validators/phone_number_format_validator.rb
143
144
  - lib/ama_validators/postal_code_format_validator.rb
145
+ - lib/ama_validators/province_validator.rb
144
146
  - lib/ama_validators/version.rb
145
147
  - spec/credit_card_format_validator_spec.rb
146
148
  - spec/email_format_validator_spec.rb
147
149
  - spec/factories/profiles.rb
148
150
  - spec/membership_number_format_validator_spec.rb
151
+ - spec/name_format_validator_spec.rb
149
152
  - spec/phone_number_format_validator_spec.rb
150
153
  - spec/postal_code_format_validator_spec.rb
154
+ - spec/province_validator_spec.rb
151
155
  - spec/spec_helper.rb
152
156
  homepage: https://github.com/amaabca/ama_validators
153
157
  licenses:
@@ -169,7 +173,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
169
173
  version: '0'
170
174
  requirements: []
171
175
  rubyforge_project:
172
- rubygems_version: 2.4.1
176
+ rubygems_version: 2.4.5
173
177
  signing_key:
174
178
  specification_version: 4
175
179
  summary: This gem will compile the following validators - Credit card - Email - Membership
@@ -180,6 +184,8 @@ test_files:
180
184
  - spec/email_format_validator_spec.rb
181
185
  - spec/factories/profiles.rb
182
186
  - spec/membership_number_format_validator_spec.rb
187
+ - spec/name_format_validator_spec.rb
183
188
  - spec/phone_number_format_validator_spec.rb
184
189
  - spec/postal_code_format_validator_spec.rb
190
+ - spec/province_validator_spec.rb
185
191
  - spec/spec_helper.rb