flash_validators 0.0.1 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (36) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +2 -3
  3. data/README.md +483 -232
  4. data/config/locales/en.yml +12 -0
  5. data/lib/flash_validators.rb +6 -0
  6. data/lib/flash_validators/matchers/ensure_valid_alpha_format_of.rb +18 -0
  7. data/lib/flash_validators/matchers/ensure_valid_alpha_numeric_format_of.rb +18 -0
  8. data/lib/flash_validators/matchers/ensure_valid_boolean_format_of.rb +2 -4
  9. data/lib/flash_validators/matchers/ensure_valid_credit_card_format_of.rb +18 -0
  10. data/lib/flash_validators/matchers/ensure_valid_currency_format_of.rb +2 -4
  11. data/lib/flash_validators/matchers/ensure_valid_email_format_of.rb +2 -4
  12. data/lib/flash_validators/matchers/ensure_valid_equality_matcher_of.rb +2 -4
  13. data/lib/flash_validators/matchers/ensure_valid_hex_format_of.rb +2 -4
  14. data/lib/flash_validators/matchers/ensure_valid_imei_format_of.rb +2 -4
  15. data/lib/flash_validators/matchers/ensure_valid_ip_format_of.rb +2 -4
  16. data/lib/flash_validators/matchers/ensure_valid_latitude_format_of.rb +2 -4
  17. data/lib/flash_validators/matchers/ensure_valid_longitude_format_of.rb +2 -4
  18. data/lib/flash_validators/matchers/ensure_valid_mac_address_format_of.rb +2 -4
  19. data/lib/flash_validators/matchers/ensure_valid_name_format_of.rb +2 -4
  20. data/lib/flash_validators/matchers/ensure_valid_password_format_of.rb +2 -4
  21. data/lib/flash_validators/matchers/ensure_valid_phone_format_of.rb +2 -4
  22. data/lib/flash_validators/matchers/ensure_valid_slug_format_of.rb +2 -4
  23. data/lib/flash_validators/matchers/ensure_valid_ssn_format_of.rb +2 -4
  24. data/lib/flash_validators/matchers/ensure_valid_url_format_of.rb +2 -4
  25. data/lib/flash_validators/matchers/ensure_valid_username_format_of.rb +2 -4
  26. data/lib/flash_validators/validators/alpha_numeric_validator.rb +17 -0
  27. data/lib/flash_validators/validators/alpha_validator.rb +19 -0
  28. data/lib/flash_validators/validators/credit_card_validator.rb +25 -0
  29. data/lib/flash_validators/validators/password_validator.rb +9 -1
  30. data/lib/flash_validators/version.rb +2 -2
  31. data/spec/lib/alpha_numeric_validator_spec.rb +61 -0
  32. data/spec/lib/alpha_validator_spec.rb +120 -0
  33. data/spec/lib/credit_card_validator_spec.rb +316 -0
  34. data/spec/lib/currency_validator_spec.rb +1 -1
  35. data/spec/lib/password_validator_spec.rb +42 -0
  36. metadata +15 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d819664070dae5bc9091a3eebb5d63967faf32d4
4
- data.tar.gz: 5b26cc91037a93c2b3f74d9b2444e73b6b60d71a
3
+ metadata.gz: b467f38532ba8c73ce3756b5f63b4990b545b06a
4
+ data.tar.gz: 5c2b50e04ea7e771b4a98cc2b783320fccad5f74
5
5
  SHA512:
6
- metadata.gz: 86ea4ff678d74c4488271ad78703ac653300d90b3c005455270cac338a4e5379ade7bd129d1adfe5abdad7f1b9198b3330a4b8400a021f4bb45646d71d9f0036
7
- data.tar.gz: cf5fc12b6ecac763ac7968874d913c8fbd3d894d92242aba24783a89b0bbfec767fa4bb693b23fd5919de691342c5e5050dbfbf749d3688ab6613d8cbc9d5887
6
+ metadata.gz: 16fd40d55f1dc9e8a420ce88a7e4225608946894dccf85b665d50ed284382b46215c1892ce39ded908a31699ca4c71eca356444d6583c82c15505c0247b0ccbf
7
+ data.tar.gz: 5f1099472b2a4b7c651143b8bc643cbbc18bc961846f68c2b45fd107a9be832bf2c256b6581aefbc67ee71bd336551f691a618d7684027357de3b455a6df1400
data/.travis.yml CHANGED
@@ -1,3 +1,5 @@
1
+ before_install:
2
+ - sudo apt-get install libxml2-dev
1
3
  cache: bundler
2
4
  language: ruby
3
5
  notifications:
@@ -7,8 +9,5 @@ notifications:
7
9
  on_failure: change
8
10
  on_success: never
9
11
  rvm:
10
- - '2.1.0'
11
- - '2.0.0'
12
- - '1.9.3'
13
12
  - ruby-head
14
13
  script: 'bundle exec rake'
data/README.md CHANGED
@@ -6,7 +6,7 @@
6
6
 
7
7
  Flash Validators is a collection of custom validators that are often required in Rails applications plus shoulda-style RSpec matchers to test the validation rules.
8
8
 
9
- Currently supported validators: boolean, currency, email, equality, hex, IMEI, IP, latitude, longitude, mac address, name, password, phone, slug, ssn, url, and username.
9
+ Currently supported validators: alpha, alpha-numeric, boolean, credit card, currency, email, equality, hex, IMEI, IP, latitude, longitude, mac address, name, password, phone, slug, ssn, url, and username.
10
10
 
11
11
  Highly recommended validators:
12
12
  * **DateTime:** Validates Timeliness - https://github.com/adzap/validates_timeliness
@@ -30,6 +30,92 @@ Or install it yourself as:
30
30
 
31
31
  ## Usage
32
32
 
33
+ ### AlphaValidator
34
+
35
+ **Ex:** Example or Example Title
36
+
37
+ **Rules:**
38
+ * Characters: A-Z a-z
39
+ * Must include: A-Z a-z
40
+
41
+ With an ActiveRecord model:
42
+
43
+ ```ruby
44
+ class Book < ActiveRecord::Base
45
+ attr_accessor :title, :name
46
+ validates :title, alpha: true
47
+ end
48
+ ```
49
+
50
+ Or any ruby class:
51
+
52
+ ```ruby
53
+ class Book
54
+ include ActiveModel::Validations
55
+ attr_accessor :title, :name
56
+ validates :title, alpha: true
57
+ end
58
+ ```
59
+
60
+ Options: :strict, :lowercase, :uppercase
61
+
62
+ ```ruby
63
+ validates :title, alpha: { strict: true }
64
+ validates :title, alpha: { lowercase: true }
65
+ validates :title, alpha: { uppsercase: true }
66
+ ```
67
+
68
+ RSpec matcher is also available for your convenience:
69
+
70
+ ```ruby
71
+ describe Product do
72
+ it { should ensure_valid_alpha_format_of(:title) }
73
+ it { should_not ensure_valid_alpha_format_of(:name) }
74
+ end
75
+ ```
76
+
77
+ ### AlphaNumericValidator
78
+
79
+ **Ex:** Example1 or Example Title 1
80
+
81
+ **Rules:**
82
+ * Characters: A-Z a-z 0-9
83
+ * Must include: A-Z a-z 0-9
84
+
85
+ With an ActiveRecord model:
86
+
87
+ ```ruby
88
+ class Book < ActiveRecord::Base
89
+ attr_accessor :title, :name
90
+ validates :title, alpha_numeric: true
91
+ end
92
+ ```
93
+
94
+ Or any ruby class:
95
+
96
+ ```ruby
97
+ class Book
98
+ include ActiveModel::Validations
99
+ attr_accessor :title, :name
100
+ validates :title, alpha_numeric: true
101
+ end
102
+ ```
103
+
104
+ Strict: requires not including spaces
105
+
106
+ ```ruby
107
+ validates :title, alpha_numeric: { strict: true }
108
+ ```
109
+
110
+ RSpec matcher is also available for your convenience:
111
+
112
+ ```ruby
113
+ describe Product do
114
+ it { should ensure_valid_alpha_numeric_format_of(:title) }
115
+ it { should_not ensure_valid_alpha_numeric_format_of(:name) }
116
+ end
117
+ ```
118
+
33
119
  ### BooleanValidator
34
120
 
35
121
  **Ex:** true or false or 1 or 0
@@ -39,25 +125,78 @@ Or install it yourself as:
39
125
 
40
126
  With an ActiveRecord model:
41
127
 
42
- class User < ActiveRecord::Base
43
- attr_accessor :active, :name
44
- validates :active, boolean: true
45
- end
128
+ ```ruby
129
+ class User < ActiveRecord::Base
130
+ attr_accessor :active, :name
131
+ validates :active, boolean: true
132
+ end
133
+ ```
134
+
135
+ Or any ruby class:
136
+
137
+ ```ruby
138
+ class User
139
+ include ActiveModel::Validations
140
+ attr_accessor :active, :name
141
+ validates :active, boolean: true
142
+ end
143
+ ```
144
+
145
+ RSpec matcher is also available for your convenience:
146
+
147
+ ```ruby
148
+ describe Product do
149
+ it { should ensure_valid_boolean_format_of(:active) }
150
+ it { should_not ensure_valid_boolean_format_of(:name) }
151
+ end
152
+ ```
153
+ ### CreditCardValidator
154
+
155
+ **Ex:** 370000000000002
156
+
157
+ **Rules:**
158
+ * Characters: 0-9
159
+ * Must include: 0-9
160
+ * Range for card digits: 15-16
161
+
162
+ With an ActiveRecord model:
163
+
164
+ ```ruby
165
+ class Invoice < ActiveRecord::Base
166
+ attr_accessor :cc_number, :name
167
+ validates :cc_number, credit_card: true
168
+ end
169
+ ```
46
170
 
47
171
  Or any ruby class:
48
172
 
49
- class User
50
- include ActiveModel::Validations
51
- attr_accessor :active, :name
52
- validates :active, boolean: true
53
- end
173
+ ```ruby
174
+ class Invoice
175
+ include ActiveModel::Validations
176
+ attr_accessor :cc_number, :name
177
+ validates :cc_number, credit_card: true
178
+ end
179
+ ```
180
+
181
+ Options: :american_express, :diners_club, :discover, :jbc, :master_card, :visa
182
+
183
+ ```ruby
184
+ validates :cc_number, currency: { american_express: true }
185
+ validates :cc_number, currency: { diners_club: true }
186
+ validates :cc_number, currency: { discover: true }
187
+ validates :cc_number, currency: { jbc: true }
188
+ validates :cc_number, currency: { master_card: true }
189
+ validates :cc_number, currency: { visa: true }
190
+ ```
54
191
 
55
192
  RSpec matcher is also available for your convenience:
56
193
 
57
- describe Product do
58
- it { should ensure_valid_boolean_format_of(:active) }
59
- it { should_not ensure_valid_boolean_format_of(:name) }
60
- end
194
+ ```ruby
195
+ describe Invoice do
196
+ it { should ensure_valid_credit_card_format_of(:cc_number) }
197
+ it { should_not ensure_valid_credit_card_format_of(:name) }
198
+ end
199
+ ```
61
200
 
62
201
  ### CurrencyValidator
63
202
 
@@ -70,29 +209,37 @@ RSpec matcher is also available for your convenience:
70
209
 
71
210
  With an ActiveRecord model:
72
211
 
73
- class Product < ActiveRecord::Base
74
- attr_accessor :price, :name
75
- validates :price, currency: true
76
- end
212
+ ```ruby
213
+ class Product < ActiveRecord::Base
214
+ attr_accessor :price, :name
215
+ validates :price, currency: true
216
+ end
217
+ ```
77
218
 
78
219
  Or any ruby class:
79
220
 
80
- class Product
81
- include ActiveModel::Validations
82
- attr_accessor :price, :name
83
- validates :price, currency: true
84
- end
221
+ ```ruby
222
+ class Product
223
+ include ActiveModel::Validations
224
+ attr_accessor :price, :name
225
+ validates :price, currency: true
226
+ end
227
+ ```
85
228
 
86
229
  Strict: requires leading number and exactly two decimals, 1.45
87
230
 
88
- validates :price, currency: { strict: true }
231
+ ```ruby
232
+ validates :price, currency: { strict: true }
233
+ ```
89
234
 
90
235
  RSpec matcher is also available for your convenience:
91
236
 
92
- describe Product do
93
- it { should ensure_valid_currency_format_of(:price) }
94
- it { should_not ensure_valid_currency_format_of(:name) }
95
- end
237
+ ```ruby
238
+ describe Product do
239
+ it { should ensure_valid_currency_format_of(:price) }
240
+ it { should_not ensure_valid_currency_format_of(:name) }
241
+ end
242
+ ```
96
243
 
97
244
  ### EmailValidator
98
245
 
@@ -106,31 +253,39 @@ RSpec matcher is also available for your convenience:
106
253
 
107
254
  With an ActiveRecord model:
108
255
 
109
- class User < ActiveRecord::Base
110
- attr_accessor :email, :name
111
- validates :email, email: true
112
- end
256
+ ```ruby
257
+ class User < ActiveRecord::Base
258
+ attr_accessor :email, :name
259
+ validates :email, email: true
260
+ end
261
+ ```
113
262
 
114
263
  Or any ruby class:
115
264
 
116
- class User
117
- include ActiveModel::Validations
118
- attr_accessor :email, :name
119
- validates :email, email: true
120
- end
265
+ ```ruby
266
+ class User
267
+ include ActiveModel::Validations
268
+ attr_accessor :email, :name
269
+ validates :email, email: true
270
+ end
271
+ ```
121
272
 
122
273
  You can specify domains to which the email domain should belong in one of the folowing ways:
123
274
 
124
- validates :email, email: { domains: 'com' }
125
- validates :email, email: { domains: :com }
126
- validates :email, email: { domains: [:com, 'edu'] }
275
+ ```ruby
276
+ validates :email, email: { domains: 'com' }
277
+ validates :email, email: { domains: :com }
278
+ validates :email, email: { domains: [:com, 'edu'] }
279
+ ```
127
280
 
128
281
  RSpec matcher is also available for your convenience:
129
282
 
130
- describe User do
131
- it { should ensure_valid_email_format_of(:email) }
132
- it { should_not ensure_valid_email_format_of(:name) }
133
- end
283
+ ```ruby
284
+ describe User do
285
+ it { should ensure_valid_email_format_of(:email) }
286
+ it { should_not ensure_valid_email_format_of(:name) }
287
+ end
288
+ ```
134
289
 
135
290
  ### EqualityValidator
136
291
 
@@ -148,25 +303,31 @@ RSpec matcher is also available for your convenience:
148
303
 
149
304
  With an ActiveRecord model:
150
305
 
151
- class Auction < ActiveRecord::Base
152
- attr_accessor :bid, :price, :product
153
- validates :bid, equality: { operator: :greater_than_or_equal_to, to: :price }
154
- end
306
+ ```ruby
307
+ class Auction < ActiveRecord::Base
308
+ attr_accessor :bid, :price, :product
309
+ validates :bid, equality: { operator: :greater_than_or_equal_to, to: :price }
310
+ end
311
+ ```
155
312
 
156
313
  Or any ruby class:
157
314
 
158
- class Auction
159
- include ActiveModel::Validations
160
- attr_accessor :bid, :price, :product
161
- validates :bid, equality: { operator: :greater_than_or_equal_to, to: :price }
162
- end
315
+ ```ruby
316
+ class Auction
317
+ include ActiveModel::Validations
318
+ attr_accessor :bid, :price, :product
319
+ validates :bid, equality: { operator: :greater_than_or_equal_to, to: :price }
320
+ end
321
+ ```
163
322
 
164
323
  RSpec matcher is also available for your convenience:
165
324
 
166
- describe Auction do
167
- it { should ensure_equality_of(:bid).to(:price) }
168
- it { should_not ensure_equality_of(:bid).to(:product) }
169
- end
325
+ ```ruby
326
+ describe Auction do
327
+ it { should ensure_equality_of(:bid).to(:price) }
328
+ it { should_not ensure_equality_of(:bid).to(:product) }
329
+ end
330
+ ```
170
331
 
171
332
  ### HexValidator
172
333
 
@@ -179,25 +340,31 @@ RSpec matcher is also available for your convenience:
179
340
 
180
341
  With an ActiveRecord model:
181
342
 
182
- class Profile < ActiveRecord::Base
183
- attr_accessor :color, :trim
184
- validates :color, hex: true
185
- end
343
+ ```ruby
344
+ class Profile < ActiveRecord::Base
345
+ attr_accessor :color, :trim
346
+ validates :color, hex: true
347
+ end
348
+ ```
186
349
 
187
350
  Or any ruby class:
188
351
 
189
- class Profile
190
- include ActiveModel::Validations
191
- attr_accessor :color, :trim
192
- validates :color, hex: true
193
- end
352
+ ```ruby
353
+ class Profile
354
+ include ActiveModel::Validations
355
+ attr_accessor :color, :trim
356
+ validates :color, hex: true
357
+ end
358
+ ```
194
359
 
195
360
  RSpec matcher is also available for your convenience:
196
361
 
197
- describe Color do
198
- it { should ensure_valid_hex_format_of(:color) }
199
- it { should_not ensure_valid_hex_format_of(:trim) }
200
- end
362
+ ```ruby
363
+ describe Color do
364
+ it { should ensure_valid_hex_format_of(:color) }
365
+ it { should_not ensure_valid_hex_format_of(:trim) }
366
+ end
367
+ ```
201
368
 
202
369
  ### ImeiValidator
203
370
 
@@ -209,25 +376,31 @@ RSpec matcher is also available for your convenience:
209
376
 
210
377
  With an ActiveRecord model:
211
378
 
212
- class User < ActiveRecord::Base
213
- attr_accessor :imei, :name
214
- validates :imei, imei: true
215
- end
379
+ ```ruby
380
+ class User < ActiveRecord::Base
381
+ attr_accessor :imei, :name
382
+ validates :imei, imei: true
383
+ end
384
+ ```
216
385
 
217
386
  Or any ruby class:
218
387
 
219
- class User
220
- include ActiveModel::Validations
221
- attr_accessor :imei, :name
222
- validates :imei, imei: true
223
- end
388
+ ```ruby
389
+ class User
390
+ include ActiveModel::Validations
391
+ attr_accessor :imei, :name
392
+ validates :imei, imei: true
393
+ end
394
+ ```
224
395
 
225
396
  RSpec matcher is also available for your convenience:
226
397
 
227
- describe User do
228
- it { should ensure_valid_imei_format_of(:imei) }
229
- it { should_not ensure_valid_imei_format_of(:name) }
230
- end
398
+ ```ruby
399
+ describe User do
400
+ it { should ensure_valid_imei_format_of(:imei) }
401
+ it { should_not ensure_valid_imei_format_of(:name) }
402
+ end
403
+ ```
231
404
 
232
405
  ### IpValidator
233
406
 
@@ -239,25 +412,31 @@ RSpec matcher is also available for your convenience:
239
412
 
240
413
  With an ActiveRecord model:
241
414
 
242
- class User < ActiveRecord::Base
243
- attr_accessor :ip, :name
244
- validates :ip, ip: true
245
- end
415
+ ```ruby
416
+ class User < ActiveRecord::Base
417
+ attr_accessor :ip, :name
418
+ validates :ip, ip: true
419
+ end
420
+ ```
246
421
 
247
422
  Or any ruby class:
248
423
 
249
- class User
250
- include ActiveModel::Validations
251
- attr_accessor :ip, :name
252
- validates :ip, ip: true
253
- end
424
+ ```ruby
425
+ class User
426
+ include ActiveModel::Validations
427
+ attr_accessor :ip, :name
428
+ validates :ip, ip: true
429
+ end
430
+ ```
254
431
 
255
432
  RSpec matcher is also available for your convenience:
256
433
 
257
- describe User do
258
- it { should ensure_valid_ip_format_of(:ip) }
259
- it { should_not ensure_valid_ip_format_of(:name) }
260
- end
434
+ ```ruby
435
+ describe User do
436
+ it { should ensure_valid_ip_format_of(:ip) }
437
+ it { should_not ensure_valid_ip_format_of(:name) }
438
+ end
439
+ ```
261
440
 
262
441
  ### LatitudeValidator
263
442
 
@@ -269,25 +448,31 @@ RSpec matcher is also available for your convenience:
269
448
 
270
449
  With an ActiveRecord model:
271
450
 
272
- class Location < ActiveRecord::Base
273
- attr_accessor :lat, :name
274
- validates :lat, latitude: true
275
- end
451
+ ```ruby
452
+ class Location < ActiveRecord::Base
453
+ attr_accessor :lat, :name
454
+ validates :lat, latitude: true
455
+ end
456
+ ```
276
457
 
277
458
  Or any ruby class:
278
459
 
279
- class Location
280
- include ActiveModel::Validations
281
- attr_accessor :lat, :name
282
- validates :lat, latitude: true
283
- end
460
+ ```ruby
461
+ class Location
462
+ include ActiveModel::Validations
463
+ attr_accessor :lat, :name
464
+ validates :lat, latitude: true
465
+ end
466
+ ```
284
467
 
285
468
  RSpec matcher is also available for your convenience:
286
469
 
287
- describe Location do
288
- it { should ensure_valid_latitude_format_of(:lat) }
289
- it { should_not ensure_valid_latitude_format_of(:name) }
290
- end
470
+ ```ruby
471
+ describe Location do
472
+ it { should ensure_valid_latitude_format_of(:lat) }
473
+ it { should_not ensure_valid_latitude_format_of(:name) }
474
+ end
475
+ ```
291
476
 
292
477
  ### LongitudeValidator
293
478
 
@@ -299,25 +484,31 @@ RSpec matcher is also available for your convenience:
299
484
 
300
485
  With an ActiveRecord model:
301
486
 
302
- class Location < ActiveRecord::Base
303
- attr_accessor :lon, :name
304
- validates :lon, longitude: true
305
- end
487
+ ```ruby
488
+ class Location < ActiveRecord::Base
489
+ attr_accessor :lon, :name
490
+ validates :lon, longitude: true
491
+ end
492
+ ```
306
493
 
307
494
  Or any ruby class:
308
495
 
309
- class Location
310
- include ActiveModel::Validations
311
- attr_accessor :lon, :name
312
- validates :lon, longitude: true
313
- end
496
+ ```ruby
497
+ class Location
498
+ include ActiveModel::Validations
499
+ attr_accessor :lon, :name
500
+ validates :lon, longitude: true
501
+ end
502
+ ```
314
503
 
315
504
  RSpec matcher is also available for your convenience:
316
505
 
317
- describe Location do
318
- it { should ensure_valid_longitude_format_of(:lon) }
319
- it { should_not ensure_valid_longitude_format_of(:name) }
320
- end
506
+ ```ruby
507
+ describe Location do
508
+ it { should ensure_valid_longitude_format_of(:lon) }
509
+ it { should_not ensure_valid_longitude_format_of(:name) }
510
+ end
511
+ ```
321
512
 
322
513
  ### MacAddressValidator
323
514
 
@@ -334,25 +525,31 @@ RSpec matcher is also available for your convenience:
334
525
 
335
526
  With an ActiveRecord model:
336
527
 
337
- class Device < ActiveRecord::Base
338
- attr_accessor :mac, :name
339
- validates :mac, mac_address: true
340
- end
528
+ ```ruby
529
+ class Device < ActiveRecord::Base
530
+ attr_accessor :mac, :name
531
+ validates :mac, mac_address: true
532
+ end
533
+ ```
341
534
 
342
535
  Or any ruby class:
343
536
 
344
- class Device
345
- include ActiveModel::Validations
346
- attr_accessor :mac, :name
347
- validates :mac, mac_address: true
348
- end
537
+ ```ruby
538
+ class Device
539
+ include ActiveModel::Validations
540
+ attr_accessor :mac, :name
541
+ validates :mac, mac_address: true
542
+ end
543
+ ```
349
544
 
350
545
  RSpec matcher is also available for your convenience:
351
546
 
352
- describe Device do
353
- it { should ensure_valid_mac_address_format_of }
354
- it { should_not ensure_valid_mac_address_format_of(:name) }
355
- end
547
+ ```ruby
548
+ describe Device do
549
+ it { should ensure_valid_mac_address_format_of }
550
+ it { should_not ensure_valid_mac_address_format_of(:name) }
551
+ end
552
+ ```
356
553
 
357
554
  ### NameValidator
358
555
 
@@ -365,25 +562,31 @@ RSpec matcher is also available for your convenience:
365
562
 
366
563
  With an ActiveRecord model:
367
564
 
368
- class User < ActiveRecord::Base
369
- attr_accessor :name, :email
370
- validates :name, name: true
371
- end
565
+ ```ruby
566
+ class User < ActiveRecord::Base
567
+ attr_accessor :name, :email
568
+ validates :name, name: true
569
+ end
570
+ ```
372
571
 
373
572
  Or any ruby class:
374
573
 
375
- class User
376
- include ActiveModel::Validations
377
- attr_accessor :name, :email
378
- validates :name, name: true
379
- end
574
+ ```ruby
575
+ class User
576
+ include ActiveModel::Validations
577
+ attr_accessor :name, :email
578
+ validates :name, name: true
579
+ end
580
+ ```
380
581
 
381
582
  RSpec matcher is also available for your convenience:
382
583
 
383
- describe User do
384
- it { should ensure_valid_name_format_of(:name) }
385
- it { should_not ensure_valid_name_format_of(:email) }
386
- end
584
+ ```ruby
585
+ describe User do
586
+ it { should ensure_valid_name_format_of(:name) }
587
+ it { should_not ensure_valid_name_format_of(:email) }
588
+ end
589
+ ```
387
590
 
388
591
  ### PasswordValidator
389
592
 
@@ -395,25 +598,37 @@ RSpec matcher is also available for your convenience:
395
598
 
396
599
  With an ActiveRecord model:
397
600
 
398
- class User < ActiveRecord::Base
399
- attr_accessor :password, :name
400
- validates :password, password: true
401
- end
601
+ ```ruby
602
+ class User < ActiveRecord::Base
603
+ attr_accessor :password, :name
604
+ validates :password, password: true
605
+ end
606
+ ```
402
607
 
403
608
  Or any ruby class:
404
609
 
405
- class User
406
- include ActiveModel::Validations
407
- attr_accessor :password, :name
408
- validates :password, name: true
409
- end
610
+ ```ruby
611
+ class User
612
+ include ActiveModel::Validations
613
+ attr_accessor :password, :name
614
+ validates :password, name: true
615
+ end
616
+ ```
617
+
618
+ Strict: requires length between 6 and 18, one number, lowercase, upcase letter
619
+
620
+ ```ruby
621
+ validates :password, password: { strict: true }
622
+ ```
410
623
 
411
624
  RSpec matcher is also available for your convenience:
412
625
 
413
- describe User do
414
- it { should ensure_valid_password_format_of(:password) }
415
- it { should_not ensure_valid_password_format_of(:name) }
416
- end
626
+ ```ruby
627
+ describe User do
628
+ it { should ensure_valid_password_format_of(:password) }
629
+ it { should_not ensure_valid_password_format_of(:name) }
630
+ end
631
+ ```
417
632
 
418
633
  ### PhoneValidator
419
634
 
@@ -424,25 +639,31 @@ RSpec matcher is also available for your convenience:
424
639
 
425
640
  With an ActiveRecord model:
426
641
 
427
- class User < ActiveRecord::Base
428
- attr_accessor :phone, :name
429
- validates :phone, phone: true
430
- end
642
+ ```ruby
643
+ class User < ActiveRecord::Base
644
+ attr_accessor :phone, :name
645
+ validates :phone, phone: true
646
+ end
647
+ ```
431
648
 
432
649
  Or any ruby class:
433
650
 
434
- class User
435
- include ActiveModel::Validations
436
- attr_accessor :phone, :name
437
- validates :phone, phone: true
438
- end
651
+ ```ruby
652
+ class User
653
+ include ActiveModel::Validations
654
+ attr_accessor :phone, :name
655
+ validates :phone, phone: true
656
+ end
657
+ ```
439
658
 
440
659
  RSpec matcher is also available for your convenience:
441
660
 
442
- describe User do
443
- it { should ensure_valid_phone_format_of(:phone) }
444
- it { should_not ensure_valid_phone_format_of(:name) }
445
- end
661
+ ```ruby
662
+ describe User do
663
+ it { should ensure_valid_phone_format_of(:phone) }
664
+ it { should_not ensure_valid_phone_format_of(:name) }
665
+ end
666
+ ```
446
667
 
447
668
  ### SlugValidator
448
669
 
@@ -453,25 +674,31 @@ RSpec matcher is also available for your convenience:
453
674
 
454
675
  With an ActiveRecord model:
455
676
 
456
- class User < ActiveRecord::Base
457
- attr_accessor :slug, :name
458
- validates :slug, slug: true
459
- end
677
+ ```ruby
678
+ class User < ActiveRecord::Base
679
+ attr_accessor :slug, :name
680
+ validates :slug, slug: true
681
+ end
682
+ ```
460
683
 
461
684
  Or any ruby class:
462
685
 
463
- class User
464
- include ActiveModel::Validations
465
- attr_accessor :slug, :name
466
- validates :slug, slug: true
467
- end
686
+ ```ruby
687
+ class User
688
+ include ActiveModel::Validations
689
+ attr_accessor :slug, :name
690
+ validates :slug, slug: true
691
+ end
692
+ ```
468
693
 
469
694
  RSpec matcher is also available for your convenience:
470
695
 
471
- describe User do
472
- it { should ensure_valid_slug_format_of(:slug) }
473
- it { should_not ensure_valid_slug_format_of(:name) }
474
- end
696
+ ```ruby
697
+ describe User do
698
+ it { should ensure_valid_slug_format_of(:slug) }
699
+ it { should_not ensure_valid_slug_format_of(:name) }
700
+ end
701
+ ```
475
702
 
476
703
  ### SsnValidator
477
704
 
@@ -482,25 +709,31 @@ RSpec matcher is also available for your convenience:
482
709
 
483
710
  With an ActiveRecord model:
484
711
 
485
- class User < ActiveRecord::Base
486
- attr_accessor :ssn, :name
487
- validates :ssn, ssn: true
488
- end
712
+ ```ruby
713
+ class User < ActiveRecord::Base
714
+ attr_accessor :ssn, :name
715
+ validates :ssn, ssn: true
716
+ end
717
+ ```
489
718
 
490
719
  Or any ruby class:
491
720
 
492
- class User
493
- include ActiveModel::Validations
494
- attr_accessor :ssn, :name
495
- validates :ssn, ssn: true
496
- end
721
+ ```ruby
722
+ class User
723
+ include ActiveModel::Validations
724
+ attr_accessor :ssn, :name
725
+ validates :ssn, ssn: true
726
+ end
727
+ ```
497
728
 
498
729
  RSpec matcher is also available for your convenience:
499
730
 
500
- describe User do
501
- it { should ensure_valid_ssn_format_of(:ssn) }
502
- it { should_not ensure_valid_ssn_format_of(:name) }
503
- end
731
+ ```ruby
732
+ describe User do
733
+ it { should ensure_valid_ssn_format_of(:ssn) }
734
+ it { should_not ensure_valid_ssn_format_of(:name) }
735
+ end
736
+ ```
504
737
 
505
738
  ### UrlValidator
506
739
 
@@ -513,40 +746,52 @@ RSpec matcher is also available for your convenience:
513
746
 
514
747
  With an ActiveRecord model:
515
748
 
516
- class User < ActiveRecord::Base
517
- attr_accessor :url, :name
518
- validates :url, url: true
519
- end
749
+ ```ruby
750
+ class User < ActiveRecord::Base
751
+ attr_accessor :url, :name
752
+ validates :url, url: true
753
+ end
754
+ ```
520
755
 
521
756
  Or any ruby class:
522
757
 
523
- class User
524
- include ActiveModel::Validations
525
- attr_accessor :url, :name
526
- validates :url, url: true
527
- end
758
+ ```ruby
759
+ class User
760
+ include ActiveModel::Validations
761
+ attr_accessor :url, :name
762
+ validates :url, url: true
763
+ end
764
+ ```
528
765
 
529
766
  You can specify domains to which the URL domain should belong in one of the folowing ways:
530
767
 
531
- validates :url, url: { domains: 'com' }
532
- validates :url, url: { domains: :com }
533
- validates :url, url: { domains: [:com, 'edu'] }
768
+ ```ruby
769
+ validates :url, url: { domains: 'com' }
770
+ validates :url, url: { domains: :com }
771
+ validates :url, url: { domains: [:com, 'edu'] }
772
+ ```
534
773
 
535
774
  You can specify if the URL should the site root:
536
775
 
537
- validates :url, url: { root: true }
776
+ ```ruby
777
+ validates :url, url: { root: true }
778
+ ```
538
779
 
539
780
  You can specify the URL scheme:
540
781
 
541
- validates :url, url: { scheme: :http }
542
- validates :url, url: { scheme: [:http, 'https'] }
782
+ ```ruby
783
+ validates :url, url: { scheme: :http }
784
+ validates :url, url: { scheme: [:http, 'https'] }
785
+ ```
543
786
 
544
787
  RSpec matcher is also available for your convenience:
545
788
 
546
- describe User do
547
- it { should ensure_valid_url_format_of(:url) }
548
- it { should_not ensure_valid_url_format_of(:name) }
549
- end
789
+ ```ruby
790
+ describe User do
791
+ it { should ensure_valid_url_format_of(:url) }
792
+ it { should_not ensure_valid_url_format_of(:name) }
793
+ end
794
+ ```
550
795
 
551
796
  ### UsernameValidator
552
797
 
@@ -558,25 +803,31 @@ RSpec matcher is also available for your convenience:
558
803
 
559
804
  With an ActiveRecord model:
560
805
 
561
- class User < ActiveRecord::Base
562
- attr_accessor :username, :name
563
- validates :username, username: true
564
- end
806
+ ```ruby
807
+ class User < ActiveRecord::Base
808
+ attr_accessor :username, :name
809
+ validates :username, username: true
810
+ end
811
+ ```
565
812
 
566
813
  Or any ruby class:
567
814
 
568
- class User
569
- include ActiveModel::Validations
570
- attr_accessor :username, :name
571
- validates :username, username: true
572
- end
815
+ ```ruby
816
+ class User
817
+ include ActiveModel::Validations
818
+ attr_accessor :username, :name
819
+ validates :username, username: true
820
+ end
821
+ ```
573
822
 
574
823
  RSpec matcher is also available for your convenience:
575
824
 
576
- describe User do
577
- it { should ensure_valid_username_format_of(:username) }
578
- it { should_not ensure_valid_username_format_of(:name) }
579
- end
825
+ ```ruby
826
+ describe User do
827
+ it { should ensure_valid_username_format_of(:username) }
828
+ it { should_not ensure_valid_username_format_of(:name) }
829
+ end
830
+ ```
580
831
 
581
832
  ## Contributing
582
833