ama_validators 0.0.11 → 0.0.12
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b7cd0ec1d63d3346d25bf45d17c5f737c7d60e32
|
4
|
+
data.tar.gz: dee42b51269ea2658cdfe587d825144ee2c928f0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a7afd829bd13299473396796be76a5d4d1dc33482704f6003d9efe1e5bbd2e4f998256df99485486629d0505ecc73f6f10da205fc54181a6d2bdff47201a9250
|
7
|
+
data.tar.gz: 5118c5f10713386b7ad75fac72d3835a62dd38c3acb02e202498e2f203ececc165215f84d96adb6b115e8968ed4510e081e19ed300a95d660f4f718a4d21ce67
|
@@ -0,0 +1,7 @@
|
|
1
|
+
class AlphanumericNameFormatValidator < ActiveModel::EachValidator
|
2
|
+
def validate_each(object, attribute, value)
|
3
|
+
unless value =~ /\A[\s\da-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
|
data/lib/ama_validators.rb
CHANGED
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'factories/profiles.rb'
|
2
|
+
|
3
|
+
describe AlphanumericNameFormatValidator do
|
4
|
+
|
5
|
+
let(:subject) { AlphanumericNameFormatValidator }
|
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è 1234567890 Ltd.]
|
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
|
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.
|
4
|
+
version: 0.0.12
|
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: 2016-05-
|
16
|
+
date: 2016-05-31 00:00:00.000000000 Z
|
17
17
|
dependencies:
|
18
18
|
- !ruby/object:Gem::Dependency
|
19
19
|
name: bundler
|
@@ -136,6 +136,7 @@ files:
|
|
136
136
|
- Rakefile
|
137
137
|
- ama_validators.gemspec
|
138
138
|
- lib/ama_validators.rb
|
139
|
+
- lib/ama_validators/alphanumeric_name_format_validator.rb
|
139
140
|
- lib/ama_validators/credit_card_format_validator.rb
|
140
141
|
- lib/ama_validators/email_format_validator.rb
|
141
142
|
- lib/ama_validators/membership_number_format_validator.rb
|
@@ -144,6 +145,7 @@ files:
|
|
144
145
|
- lib/ama_validators/postal_code_format_validator.rb
|
145
146
|
- lib/ama_validators/province_validator.rb
|
146
147
|
- lib/ama_validators/version.rb
|
148
|
+
- spec/alphanumeric_name_format_validator_spec.rb
|
147
149
|
- spec/credit_card_format_validator_spec.rb
|
148
150
|
- spec/email_format_validator_spec.rb
|
149
151
|
- spec/factories/profiles.rb
|
@@ -173,13 +175,14 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
173
175
|
version: '0'
|
174
176
|
requirements: []
|
175
177
|
rubyforge_project:
|
176
|
-
rubygems_version: 2.
|
178
|
+
rubygems_version: 2.4.5.1
|
177
179
|
signing_key:
|
178
180
|
specification_version: 4
|
179
181
|
summary: This gem will compile the following validators - Credit card - Email - Membership
|
180
182
|
number - Phone number - Postal code. With this gem there is no need for the validators
|
181
183
|
classes.
|
182
184
|
test_files:
|
185
|
+
- spec/alphanumeric_name_format_validator_spec.rb
|
183
186
|
- spec/credit_card_format_validator_spec.rb
|
184
187
|
- spec/email_format_validator_spec.rb
|
185
188
|
- spec/factories/profiles.rb
|