omg_validator 0.0.8 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (67) hide show
  1. data/.yardoc/checksums +14 -17
  2. data/.yardoc/object_types +0 -0
  3. data/.yardoc/objects/root.dat +0 -0
  4. data/.yardoc/proxy_types +0 -0
  5. data/README.markdown +2 -7
  6. data/README.rdoc +2 -7
  7. data/doc/OmgValidator.html +31 -26
  8. data/doc/OmgValidator/Validators.html +30 -24
  9. data/doc/OmgValidator/Validators/AlphaDashValidator.html +57 -39
  10. data/doc/OmgValidator/Validators/{DecimalValidator.html → AlphaNumericDashValidator.html} +62 -43
  11. data/doc/OmgValidator/Validators/AlphaNumericValidator.html +55 -37
  12. data/doc/OmgValidator/Validators/AlphaValidator.html +55 -37
  13. data/doc/OmgValidator/Validators/EmailValidator.html +55 -37
  14. data/doc/OmgValidator/Validators/IpAddressValidator.html +55 -37
  15. data/doc/OmgValidator/Validators/PhoneNumberValidator.html +56 -38
  16. data/doc/OmgValidator/Validators/PostalCodeValidator.html +55 -37
  17. data/doc/OmgValidator/Validators/PostalOrZipCodeValidator.html +55 -37
  18. data/doc/OmgValidator/Validators/StrongPasswordValidator.html +56 -38
  19. data/doc/OmgValidator/Validators/UrlValidator.html +56 -40
  20. data/doc/OmgValidator/Validators/ZipCodeValidator.html +55 -36
  21. data/doc/_index.html +41 -74
  22. data/doc/class_list.html +12 -6
  23. data/doc/css/full_list.css +4 -2
  24. data/doc/css/style.css +50 -44
  25. data/doc/file.README.html +32 -28
  26. data/doc/file_list.html +12 -6
  27. data/doc/frames.html +20 -5
  28. data/doc/index.html +32 -28
  29. data/doc/js/app.js +52 -43
  30. data/doc/js/full_list.js +9 -9
  31. data/doc/js/jquery.js +4 -16
  32. data/doc/method_list.html +25 -43
  33. data/doc/top-level-namespace.html +25 -18
  34. data/lib/omg_validator.rb +1 -4
  35. data/lib/omg_validator/validators/alpha_dash_validator.rb +10 -6
  36. data/lib/omg_validator/validators/alpha_numeric_dash_validator.rb +25 -0
  37. data/lib/omg_validator/validators/alpha_numeric_validator.rb +8 -4
  38. data/lib/omg_validator/validators/alpha_validator.rb +7 -3
  39. data/lib/omg_validator/validators/email_validator.rb +7 -3
  40. data/lib/omg_validator/validators/ip_address_validator.rb +7 -3
  41. data/lib/omg_validator/validators/phone_number_validator.rb +7 -3
  42. data/lib/omg_validator/validators/postal_code_validator.rb +7 -3
  43. data/lib/omg_validator/validators/postal_or_zip_code_validator.rb +7 -3
  44. data/lib/omg_validator/validators/strong_password_validator.rb +7 -3
  45. data/lib/omg_validator/validators/url_validator.rb +7 -3
  46. data/lib/omg_validator/validators/zip_code_validator.rb +7 -3
  47. data/lib/omg_validator/version.rb +1 -1
  48. data/omg_validator-0.0.7.gem +0 -0
  49. data/omg_validator-0.0.8.gem +0 -0
  50. data/test/alpha_dash_validator_test.rb +26 -0
  51. data/test/alpha_numeric_dash_validator_test.rb +26 -0
  52. data/test/alpha_numeric_validator_test.rb +26 -0
  53. data/test/alpha_validator_test.rb +26 -0
  54. data/test/dummy/app/models/thing.rb +4 -10
  55. data/test/email_validator_test.rb +26 -0
  56. data/test/ip_address_validator_test.rb +26 -0
  57. data/test/support/things.rb +18 -263
  58. data/test/support/things.yml +109 -0
  59. metadata +23 -20
  60. data/doc/OmgValidator/Validators/DateValidator.html +0 -207
  61. data/doc/OmgValidator/Validators/IntegerValidator.html +0 -209
  62. data/doc/OmgValidator/Validators/NumericValidator.html +0 -208
  63. data/lib/omg_validator/validators/date_validator.rb +0 -19
  64. data/lib/omg_validator/validators/decimal_validator.rb +0 -21
  65. data/lib/omg_validator/validators/integer_validator.rb +0 -21
  66. data/lib/omg_validator/validators/numeric_validator.rb +0 -21
  67. data/test/omg_validator_test.rb +0 -247
@@ -0,0 +1,26 @@
1
+ require 'test_helper'
2
+
3
+ class AlphaValidatorTest < ActiveSupport::TestCase
4
+ def setup
5
+ @thing = Thing.new
6
+ @things = Things.new
7
+ end
8
+
9
+ def teardown
10
+ @thing = nil
11
+ end
12
+
13
+ test 'Thing should be valid if the alpha attribute contains only alpha characters.' do
14
+ @things.alpha['valid'].each do |string|
15
+ @thing.alpha = string.to_s
16
+ assert @thing.valid?, string.to_s << ' - ' << @thing.errors.full_messages.join('\n')
17
+ end
18
+ end
19
+
20
+ test 'Thing should be invalid if the alpha attribute contains non-alpha characters.' do
21
+ @things.alpha['invalid'].each do |string|
22
+ @thing.alpha = string.to_s
23
+ assert !@thing.valid?, string.to_s << ' - ' << @thing.errors.full_messages.join('\n')
24
+ end
25
+ end
26
+ end
@@ -3,40 +3,34 @@ require 'active_model'
3
3
  class Thing
4
4
  include ActiveModel::Validations
5
5
 
6
- attr_accessor :alpha, :alpha_numeric, :alpha_dash, :zip_code, :postal_or_zip_code, :postal_code,
7
- :decimal, :integer, :numeric, :email, :ip_address, :url, :phone, :password, :date
6
+ attr_accessor :alpha, :alpha_numeric, :alpha_numeric_dash, :alpha_dash, :zip_code, :postal_or_zip_code, :postal_code,
7
+ :email, :ip_address, :url, :phone, :password
8
8
 
9
9
  validates :alpha, alpha: true
10
10
  validates :alpha_numeric, alpha_numeric: true
11
+ validates :alpha_numeric_dash, alpha_numeric_dash: true
11
12
  validates :alpha_dash, alpha_dash: true
12
13
  validates :zip_code, zip_code: true
13
14
  validates :postal_or_zip_code, postal_or_zip_code: true
14
15
  validates :postal_code, postal_code: true
15
- validates :decimal, decimal: true
16
- validates :integer, integer: true
17
- validates :numeric, numeric: true
18
16
  validates :email, email: true
19
17
  validates :ip_address, ip_address: true
20
18
  validates :url, url: true
21
19
  validates :phone, phone_number: true
22
20
  validates :password, strong_password: true
23
- validates :date, date: true
24
21
 
25
22
  def initialize(options = {})
26
23
  @alpha = nil
27
24
  @alpha_numeric = nil
25
+ @alpha_numeric_dash = nil
28
26
  @alpha_dash = nil
29
27
  @zip_code = nil
30
28
  @postal_or_zip_code = nil
31
29
  @postal_code = nil
32
- @decimal = nil
33
- @integer = nil
34
- @numeric = nil
35
30
  @email = nil
36
31
  @ip_address = nil
37
32
  @url = nil
38
33
  @phone = nil
39
34
  @password = nil
40
- @date = nil
41
35
  end
42
36
  end
@@ -0,0 +1,26 @@
1
+ require 'test_helper'
2
+
3
+ class EmailValidatorTest < ActiveSupport::TestCase
4
+ def setup
5
+ @thing = Thing.new
6
+ @things = Things.new
7
+ end
8
+
9
+ def teardown
10
+ @thing = nil
11
+ end
12
+
13
+ test 'Thing should be valid if email attribute is a valid email address.' do
14
+ @things.email['valid'].each do |string|
15
+ @thing.email = string.to_s
16
+ assert @thing.valid?, string.to_s << ' - ' << @thing.errors.full_messages.join('\n')
17
+ end
18
+ end
19
+
20
+ test 'Thing should invalid if email attribute is not a valid email address.' do
21
+ @things.email['invalid'].each do |string|
22
+ @thing.email = string.to_s
23
+ assert !@thing.valid?, string.to_s << ' - ' << @thing.errors.full_messages.join('\n')
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,26 @@
1
+ require 'test_helper'
2
+
3
+ class IpAddressValidatorTest < ActiveSupport::TestCase
4
+ def setup
5
+ @thing = Thing.new
6
+ @things = Things.new
7
+ end
8
+
9
+ def teardown
10
+ @thing = nil
11
+ end
12
+
13
+ test 'Thing should be valid if the ip address attribute is a valid ip address.' do
14
+ @things.ip_address['valid'].each do |string|
15
+ @thing.ip_address = string.to_s
16
+ assert @thing.valid?, string.to_s << ' - ' << @thing.errors.full_messages.join('\n')
17
+ end
18
+ end
19
+
20
+ test 'Thing should be invalid if the ip address attribute is a valid ip address.' do
21
+ @things.ip_address['invalid'].each do |string|
22
+ @thing.ip_address = string.to_s
23
+ assert !@thing.valid?, string.to_s << ' - ' << @thing.errors.full_messages.join('\n')
24
+ end
25
+ end
26
+ end
@@ -1,280 +1,35 @@
1
- class Things
2
- def self.alphas
3
- {
4
- valid: [
5
- "a",
6
- "aZ",
7
- "AZ",
8
- "az",
9
- "",
10
- nil
11
- ],
12
- invalid: [
13
- "0",
14
- "9",
15
- "a z",
16
- "A_z",
17
- "A-Z",
18
- "a0z"
19
- ]
20
- }
21
- end
22
-
23
- def self.alpha_dashes
24
- {
25
- valid: [
26
- "azqy",
27
- "az-qy",
28
- "AZ-qy",
29
- "01-qy",
30
- "01_qy",
31
- "01001",
32
- "-----",
33
- "",
34
- nil
35
- ],
36
- invalid: [
37
- "#",
38
- " ",
39
- "az qy",
40
- "az#qy",
41
- "01 qy",
42
- "01#qy"
43
- ]
44
- }
45
- end
1
+ require 'yaml'
46
2
 
47
- def self.alpha_numerics
48
- {
49
- valid: [
50
- "azqy",
51
- "az99",
52
- "AZqy",
53
- "AZQY",
54
- "AZ99",
55
- "0099",
56
- "",
57
- nil
58
- ],
59
- invalid: [
60
- "a qy",
61
- "a-qy",
62
- "a_qy",
63
- "a#qy",
64
- "A9-y",
65
- "9 99"
66
- ]
67
- }
68
- end
69
-
70
- def self.postal_codes
71
- {
72
- valid: [
73
- "L2J 4T5",
74
- "l2j 4t5",
75
- "l2j4t5",
76
- "",
77
- nil
78
- ],
79
- invalid: [
80
- "L2%4T5",
81
- "LL2J 4T5",
82
- "L2J45T",
83
- "L2j 45T"
84
- ]
85
- }
86
- end
87
-
88
- def self.zip_codes
89
- {
90
- valid: [
91
- "90210",
92
- "20037-8001",
93
- "",
94
- nil
95
- ],
96
- invalid: [
97
- "9021",
98
- "902100",
99
- "9O210",
100
- "200037-801",
101
- "2000378001"
102
- ]
103
- }
104
- end
105
-
106
- def self.dates
107
- {
108
- valid: [
109
- "2012-04-23",
110
- "04-05-2012",
111
- "April 4 2012",
112
- "Wednesday May 10, 2010",
113
- "",
114
- nil
115
- ],
116
- invalid: [
117
- "210-09-09",
118
- "2012-13-05",
119
- "Maypril 5, 2012",
120
- "23223232",
121
- ]
122
- }
123
- end
124
-
125
- def self.decimals
126
- {
127
- valid: [
128
- "10.00",
129
- "23.23",
130
- "1.23",
131
- "100.00",
132
- "",
133
- nil
134
- ],
135
- invalid: [
136
- "20..00",
137
- "210.02.22",
138
- "9O210",
139
- "237-841",
140
- ]
141
- }
3
+ class Things
4
+ def initialize
5
+ @config = YAML.load_file("#{File.dirname(__FILE__)}/things.yml")
142
6
  end
143
7
 
144
- def self.emails
145
- {
146
- valid: [
147
- "user@domain.com",
148
- "my_user@domain.on.ca",
149
- "mail@hoemail.net",
150
- "",
151
- nil
152
- ],
153
- invalid: [
154
- "@asd.com",
155
- "mail@you@rock.com",
156
- "myemailaddress.com",
157
- "myemailaddress",
158
- "amasd@asd.com.a.",
159
- ]
160
- }
8
+ def alpha
9
+ @config['alpha']
161
10
  end
162
11
 
163
- def self.integers
164
- {
165
- valid: [
166
- "10",
167
- "23",
168
- "154",
169
- "134256",
170
- "",
171
- nil
172
- ],
173
- invalid: [
174
- "20..00",
175
- "210.02.22",
176
- "9O2.10",
177
- "237-841",
178
- ]
179
- }
12
+ def alpha_dash
13
+ @config['alpha_dash']
180
14
  end
181
15
 
182
- def self.ip_addresses
183
- {
184
- valid: [
185
- "120.20.123.123",
186
- "255.255.255.0",
187
- "127.0.0.1",
188
- "100.1.123.254",
189
- "",
190
- nil
191
- ],
192
- invalid: [
193
- "2.0.0.0.0",
194
- "123-123-23-",
195
- "123 23 23 24",
196
- "41.34.52",
197
- ]
198
- }
16
+ def alpha_numeric
17
+ @config['alpha_numeric']
199
18
  end
200
19
 
201
- def self.numeric
202
- {
203
- valid: [
204
- "10",
205
- "23.23",
206
- "1.23",
207
- "100.00",
208
- "",
209
- nil
210
- ],
211
- invalid: [
212
- "20..00",
213
- "210.02.22",
214
- "9O210",
215
- "237-841",
216
- ]
217
- }
20
+ def alpha_numeric_dash
21
+ @config['alpha_numeric_dash']
218
22
  end
219
23
 
220
- def self.phone_numbers
221
- {
222
- valid: [
223
- "123-123-1240",
224
- "123-123-0123",
225
- "1905-232-2323",
226
- "1-905-232-2323",
227
- "",
228
- nil
229
- ],
230
- invalid: [
231
- "1323-23-123",
232
- "213-2323-122",
233
- "923210",
234
- "905-232-23239",
235
- "123-123-23233",
236
- ]
237
- }
24
+ def email
25
+ @config['email']
238
26
  end
239
27
 
240
- def self.strong_passwords
241
- {
242
- valid: [
243
- "ASdj3j3jsS",
244
- "8#adCje30",
245
- "To34zNbsr30",
246
- "pwd#fdJa9",
247
- "",
248
- nil
249
- ],
250
- invalid: [
251
- "password",
252
- "Testing",
253
- "password23",
254
- "3434ksdlfk3",
255
- "1afs3l3",
256
- ]
257
- }
28
+ def integer
29
+ @config['integer']
258
30
  end
259
31
 
260
- def self.urls
261
- {
262
- valid: [
263
- "http://www.example.com",
264
- "www.example.com",
265
- "example.com",
266
- "http://www.example.com",
267
- "sub.example.com",
268
- "",
269
- nil
270
- ],
271
- invalid: [
272
- "@asd.com",
273
- "domain.c",
274
- "mydomain",
275
- "domain..asd.",
276
- "amasd@asd.com.a",
277
- ]
278
- }
32
+ def ip_address
33
+ @config['ip_address']
279
34
  end
280
35
  end
@@ -0,0 +1,109 @@
1
+ alpha:
2
+ valid:
3
+ - a
4
+ - Z
5
+ - abcdefghijklmnopqrstuvwxyz
6
+ - ABCDEFGHIJKLMNOPQRSTUVWXYZ
7
+ invalid:
8
+ - hello world
9
+ - hello_world
10
+ - hello-world
11
+ - $
12
+ - 1
13
+ - 1234567890
14
+ - ----------
15
+ - __________
16
+ - hell0_wor1d
17
+
18
+ alpha_dash:
19
+ valid:
20
+ - a
21
+ - abcdefghijklmnopqrstuvwxyz
22
+ - helloWorld
23
+ - hello-world
24
+ - hello_world
25
+ - -----------
26
+ - ___________
27
+ invalid:
28
+ - $
29
+ - 1
30
+ - 1234567890
31
+ - hell0Wor1d
32
+ - hello world
33
+
34
+ alpha_numeric:
35
+ valid:
36
+ - a
37
+ - abcdefghijklmnopqrstuvwxyz
38
+ - helloWorld
39
+ - helloWor1d
40
+ - 1
41
+ - 1234567890
42
+ invalid:
43
+ - $
44
+ - hello-world
45
+ - hello_world
46
+ - hello world
47
+
48
+ alpha_numeric_dash:
49
+ valid:
50
+ - a
51
+ - abcdefghijklmnopqrstuvwxyz
52
+ - helloWorld
53
+ - helloWor1d
54
+ - hello-world
55
+ - hello_wor1d
56
+ - 1
57
+ - 1234567890
58
+ invalid:
59
+ - $
60
+ - hello world
61
+
62
+ email:
63
+ valid:
64
+ - 'j@abc.com'
65
+ - 'john@abc.ca'
66
+ - 'john.appleseed@abc.co.uk'
67
+ - 'j123@appleseed.de'
68
+ invalid:
69
+ - '@abc.com'
70
+ - 'john@abc'
71
+ - 'abc.com'
72
+ - 'john.appleseed'
73
+ - 'john@appleseed@abc.com'
74
+
75
+ integer:
76
+ valid:
77
+ - 0
78
+ - 1
79
+ - -1
80
+ - 1001
81
+ - 100,000,000
82
+ invalid:
83
+ - 0.999
84
+ - .0009
85
+ - abcdefghijklmnopqrstuvwxyz
86
+ - $
87
+ - --------
88
+ - ________
89
+
90
+ ip_address:
91
+ valid:
92
+ - 0.0.0.0
93
+ - 1.1.1.1
94
+ - 11.11.11.11
95
+ - 111.111.111.111
96
+ - 11.111.11.111
97
+ - 9.99.255.9
98
+ invalid:
99
+ - 0
100
+ - 0.0
101
+ - 0.0.0
102
+ - 000.000.000
103
+ - 101.101.101
104
+ - 9.99.999.9
105
+ - abcdefghijklmnopqrstuvwxyz
106
+ - $
107
+ - $$$.xyz.012.123
108
+ - 0.0.0.0.0
109
+ - 0.0.0.0.0.0