flash_validators 1.1.0 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (61) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +258 -35
  3. data/config/locales/en.yml +66 -42
  4. data/lib/flash_validators/matchers/ensure_valid_alpha_format_of.rb +10 -2
  5. data/lib/flash_validators/matchers/ensure_valid_alpha_numeric_format_of.rb +10 -2
  6. data/lib/flash_validators/matchers/ensure_valid_base64_format_of.rb +26 -0
  7. data/lib/flash_validators/matchers/ensure_valid_boolean_format_of.rb +10 -2
  8. data/lib/flash_validators/matchers/ensure_valid_credit_card_format_of.rb +10 -2
  9. data/lib/flash_validators/matchers/ensure_valid_currency_format_of.rb +10 -2
  10. data/lib/flash_validators/matchers/ensure_valid_cusip_format_of.rb +26 -0
  11. data/lib/flash_validators/matchers/ensure_valid_email_format_of.rb +10 -2
  12. data/lib/flash_validators/matchers/ensure_valid_equality_matcher_of.rb +12 -2
  13. data/lib/flash_validators/matchers/ensure_valid_gtin_format_of.rb +26 -0
  14. data/lib/flash_validators/matchers/ensure_valid_hex_format_of.rb +10 -2
  15. data/lib/flash_validators/matchers/ensure_valid_imei_format_of.rb +10 -2
  16. data/lib/flash_validators/matchers/ensure_valid_ip_format_of.rb +10 -2
  17. data/lib/flash_validators/matchers/ensure_valid_isbn_format_of.rb +10 -2
  18. data/lib/flash_validators/matchers/ensure_valid_isin_format_of.rb +26 -0
  19. data/lib/flash_validators/matchers/ensure_valid_latitude_format_of.rb +10 -2
  20. data/lib/flash_validators/matchers/ensure_valid_longitude_format_of.rb +10 -2
  21. data/lib/flash_validators/matchers/ensure_valid_mac_address_format_of.rb +10 -2
  22. data/lib/flash_validators/matchers/ensure_valid_name_format_of.rb +10 -2
  23. data/lib/flash_validators/matchers/ensure_valid_password_format_of.rb +10 -2
  24. data/lib/flash_validators/matchers/ensure_valid_phone_format_of.rb +10 -2
  25. data/lib/flash_validators/matchers/ensure_valid_sedol_format_of.rb +26 -0
  26. data/lib/flash_validators/matchers/ensure_valid_slug_format_of.rb +10 -2
  27. data/lib/flash_validators/matchers/ensure_valid_ssn_format_of.rb +10 -2
  28. data/lib/flash_validators/matchers/ensure_valid_url_format_of.rb +10 -2
  29. data/lib/flash_validators/matchers/ensure_valid_username_format_of.rb +10 -2
  30. data/lib/flash_validators/matchers/ensure_valid_uuid_format_of.rb +26 -0
  31. data/lib/flash_validators/validators/alpha_numeric_validator.rb +21 -7
  32. data/lib/flash_validators/validators/alpha_validator.rb +22 -10
  33. data/lib/flash_validators/validators/base64_validator.rb +9 -0
  34. data/lib/flash_validators/validators/credit_card_validator.rb +123 -15
  35. data/lib/flash_validators/validators/currency_validator.rb +13 -7
  36. data/lib/flash_validators/validators/cusip_validator.rb +33 -0
  37. data/lib/flash_validators/validators/email_validator.rb +7 -7
  38. data/lib/flash_validators/validators/equality_validator.rb +7 -7
  39. data/lib/flash_validators/validators/gtin_validator.rb +59 -0
  40. data/lib/flash_validators/validators/hex_validator.rb +1 -1
  41. data/lib/flash_validators/validators/imei_validator.rb +8 -8
  42. data/lib/flash_validators/validators/isbn_validator.rb +9 -16
  43. data/lib/flash_validators/validators/isin_validator.rb +38 -0
  44. data/lib/flash_validators/validators/mac_address_validator.rb +10 -10
  45. data/lib/flash_validators/validators/password_validator.rb +13 -7
  46. data/lib/flash_validators/validators/sedol_validator.rb +32 -0
  47. data/lib/flash_validators/validators/url_validator.rb +13 -13
  48. data/lib/flash_validators/validators/uuid_validator.rb +28 -0
  49. data/lib/flash_validators/version.rb +1 -1
  50. data/lib/flash_validators.rb +12 -0
  51. data/spec/lib/alpha_numeric_validator_spec.rb +31 -1
  52. data/spec/lib/alpha_validator_spec.rb +68 -6
  53. data/spec/lib/base64_validator_spec.rb +33 -0
  54. data/spec/lib/credit_card_validator_spec.rb +495 -125
  55. data/spec/lib/cusip_validator_spec.rb +27 -0
  56. data/spec/lib/gtin_validator_spec.rb +101 -0
  57. data/spec/lib/hex_validator_spec.rb +20 -0
  58. data/spec/lib/isin_validator_spec.rb +35 -0
  59. data/spec/lib/sedol_validator_spec.rb +31 -0
  60. data/spec/lib/uuid_validator_spec.rb +157 -0
  61. metadata +26 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 62a1fe02cdb774704575c71fd9e94dd70eb4ac61
4
- data.tar.gz: 77c9c4f93e1b1010e1e989d8b639a4a77d0a1602
3
+ metadata.gz: 4150ee9e67b137e4e05e7087f63bbd6b5957fe17
4
+ data.tar.gz: bf4b5c433dbee35418a093e7727ce88d441880e5
5
5
  SHA512:
6
- metadata.gz: 159e1bff68ddcec3ea18ba7dad44d6b0cf4b1a66e49ccb99aa7a0df57bc7642e508ba4a32578ddc491f75d470981eb4bb3a875fe8b77ec7767ee611ebc17247b
7
- data.tar.gz: e890f7b6401d9f551c2f3b1ee7c24183c9c4d064e54679bffd41366f8c98acb6616d2374b1dcdd93878f7338af1d5d4c82eae9751f9522baf6840ae8daaf44c0
6
+ metadata.gz: 2d9d77e2859702d00a11cf7c8f94aee316a87a55a87bb0159722f27a900db06068a20a6787b7efccdf20a934b88dc6dea52ff5193a7dd60d3d9c2f13e55c51be
7
+ data.tar.gz: d9951b4694622675d29881b428b06e74996f5d3b919ab0a8b2cef5c8c49bbc039c6dc911f58969cff1c66e5e75a40f12e24ac60dde34a73a4aee2a4906599252
data/README.md CHANGED
@@ -7,7 +7,7 @@
7
7
 
8
8
  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.
9
9
 
10
- Currently supported validators: alpha, alpha-numeric, boolean, credit card, currency, email, equality, hex, IMEI, IP, ISBN, latitude, longitude, mac address, name, password, phone, slug, ssn, url, and username.
10
+ Currently supported validators: alpha, alpha-numeric, Base64, boolean, credit card, currency, CUSIP, email, equality, GTIN, hex, IMEI, IP, ISBN, ISIN, latitude, longitude, MAC address, name, password, phone, SEDOL, slug, SSN, url, username, and UUID.
11
11
 
12
12
  Highly recommended validators:
13
13
  * **DateTime:** Validates Timeliness - https://github.com/adzap/validates_timeliness
@@ -58,18 +58,18 @@ class Book
58
58
  end
59
59
  ```
60
60
 
61
- Options: :strict, :lowercase, :uppercase
61
+ Options: :strict, case: [:lower, :upper]
62
62
 
63
63
  ```ruby
64
64
  validates :title, alpha: { strict: true }
65
- validates :title, alpha: { lowercase: true }
66
- validates :title, alpha: { uppsercase: true }
65
+ validates :title, alpha: { case: :lower }
66
+ validates :title, alpha: { case: :upper, strict: true }
67
67
  ```
68
68
 
69
69
  RSpec matcher is also available for your convenience:
70
70
 
71
71
  ```ruby
72
- describe Product do
72
+ describe Book do
73
73
  it { should ensure_valid_alpha_format_of(:title) }
74
74
  it { should_not ensure_valid_alpha_format_of(:name) }
75
75
  end
@@ -102,6 +102,7 @@ class Book
102
102
  end
103
103
  ```
104
104
 
105
+ Options: :strict
105
106
  Strict: requires not including spaces
106
107
 
107
108
  ```ruby
@@ -111,18 +112,54 @@ validates :title, alpha_numeric: { strict: true }
111
112
  RSpec matcher is also available for your convenience:
112
113
 
113
114
  ```ruby
114
- describe Product do
115
+ describe Book do
115
116
  it { should ensure_valid_alpha_numeric_format_of(:title) }
116
117
  it { should_not ensure_valid_alpha_numeric_format_of(:name) }
117
118
  end
118
119
  ```
119
120
 
121
+ ### Base64Validator
122
+
123
+ **Ex:** YW55IGNhcm5hbCBwbGVhcw==
124
+
125
+ **Rules:**
126
+ * Characters: 0-1 A-Z =
127
+
128
+ With an ActiveRecord model:
129
+
130
+ ```ruby
131
+ class Code < ActiveRecord::Base
132
+ attr_accessor :code, :name
133
+ validates :code, base64: true
134
+ end
135
+ ```
136
+
137
+ Or any ruby class:
138
+
139
+ ```ruby
140
+ class Code
141
+ include ActiveModel::Validations
142
+ attr_accessor :code, :name
143
+ validates :code, base64: true
144
+ end
145
+ ```
146
+
147
+ RSpec matcher is also available for your convenience:
148
+
149
+ ```ruby
150
+ describe Code do
151
+ it { should ensure_valid_base64_format_of(:code) }
152
+ it { should_not ensure_valid_base64_format_of(:name) }
153
+ end
154
+ ```
155
+
120
156
  ### BooleanValidator
121
157
 
122
158
  **Ex:** true or false or 1 or 0
123
159
 
124
160
  **Rules:**
125
- * Characters: 0-1 true or false
161
+ * Characters: 0-1
162
+ * Equality: true or false
126
163
 
127
164
  With an ActiveRecord model:
128
165
 
@@ -146,19 +183,20 @@ end
146
183
  RSpec matcher is also available for your convenience:
147
184
 
148
185
  ```ruby
149
- describe Product do
186
+ describe User do
150
187
  it { should ensure_valid_boolean_format_of(:active) }
151
188
  it { should_not ensure_valid_boolean_format_of(:name) }
152
189
  end
153
190
  ```
191
+
154
192
  ### CreditCardValidator
155
193
 
156
194
  **Ex:** 370000000000002
157
195
 
158
196
  **Rules:**
159
- * Characters: 0-9
197
+ * Characters: 0-9 .-
160
198
  * Must include: 0-9
161
- * Range for card digits: 15-16
199
+ * Range for card digits: 12-19
162
200
 
163
201
  With an ActiveRecord model:
164
202
 
@@ -179,15 +217,13 @@ class Invoice
179
217
  end
180
218
  ```
181
219
 
182
- Options: :american_express, :diners_club, :discover, :jbc, :master_card, :visa
220
+ Options: :strict, card: [:american_express (:amex), :diners_club, :discover, :jbc, :laser, :maestro, :mastercard, :solo, :unionpay, :visa]
221
+ Strict: requires not including spaces
183
222
 
184
223
  ```ruby
185
- validates :cc_number, currency: { american_express: true }
186
- validates :cc_number, currency: { diners_club: true }
187
- validates :cc_number, currency: { discover: true }
188
- validates :cc_number, currency: { jbc: true }
189
- validates :cc_number, currency: { master_card: true }
190
- validates :cc_number, currency: { visa: true }
224
+ validates :cc_number, credit_card: { card: :visa }
225
+ validates :cc_number, credit_card: { strict: true }
226
+ validates :cc_number, credit_card: { card: :discover, strict: true }
191
227
  ```
192
228
 
193
229
  RSpec matcher is also available for your convenience:
@@ -227,6 +263,7 @@ class Product
227
263
  end
228
264
  ```
229
265
 
266
+ Options: :strict
230
267
  Strict: requires leading number and exactly two decimals, 1.45
231
268
 
232
269
  ```ruby
@@ -242,6 +279,42 @@ describe Product do
242
279
  end
243
280
  ```
244
281
 
282
+ ### CusipValidator
283
+
284
+ **Ex:** 125509BG3
285
+
286
+ **Rules:**
287
+ * Characters: 0-1 A-Z
288
+ * Length: 1-9
289
+
290
+ With an ActiveRecord model:
291
+
292
+ ```ruby
293
+ class Bank < ActiveRecord::Base
294
+ attr_accessor :code, :name
295
+ validates :code, cusip: true
296
+ end
297
+ ```
298
+
299
+ Or any ruby class:
300
+
301
+ ```ruby
302
+ class Bank
303
+ include ActiveModel::Validations
304
+ attr_accessor :code, :name
305
+ validates :code, cusip: true
306
+ end
307
+ ```
308
+
309
+ RSpec matcher is also available for your convenience:
310
+
311
+ ```ruby
312
+ describe Bank do
313
+ it { should ensure_valid_cusip_format_of(:code) }
314
+ it { should_not ensure_cusip_base64_format_of(:name) }
315
+ end
316
+ ```
317
+
245
318
  ### EmailValidator
246
319
 
247
320
  **Ex:** user@example.com or user+123@example-site.com
@@ -271,7 +344,7 @@ class User
271
344
  end
272
345
  ```
273
346
 
274
- You can specify domains to which the email domain should belong in one of the folowing ways:
347
+ Options: :domains
275
348
 
276
349
  ```ruby
277
350
  validates :email, email: { domains: 'com' }
@@ -330,14 +403,59 @@ describe Auction do
330
403
  end
331
404
  ```
332
405
 
406
+ ### GtinValidator
407
+
408
+ **Ex:** 73513537 or 4 006381 33393 1
409
+
410
+ **Rules:**
411
+ * Length: 8, 12, 13, or 14
412
+ * Characters: 0-9
413
+
414
+ With an ActiveRecord model:
415
+
416
+ ```ruby
417
+ class Trade < ActiveRecord::Base
418
+ attr_accessor :code, :name
419
+ validates :code, gtin: true
420
+ end
421
+ ```
422
+
423
+ Or any ruby class:
424
+
425
+ ```ruby
426
+ class Trade
427
+ include ActiveModel::Validations
428
+ attr_accessor :code, :name
429
+ validates :code, gtin: true
430
+ end
431
+ ```
432
+
433
+ Options: :strict, format: [:ean_8, :gtin_8, :ucc_8, :gtin_12, :upc, :upc_a, :ean, :ean_13, :gtin_13, :ucc_13, :gtin_14, :ucc_14]
434
+ Strict: requires not including spaces
435
+
436
+ ```ruby
437
+ validates :code, gtin: { format: :ean_8 }
438
+ validates :code, gtin: { strict: true }
439
+ validates :code, gtin: { format: :ucc_13, strict: true }
440
+ ```
441
+
442
+ RSpec matcher is also available for your convenience:
443
+
444
+ ```ruby
445
+ describe Trade do
446
+ it { should ensure_valid_gtin_format_of(:code) }
447
+ it { should_not ensure_valid_gtin_format_of(:name) }
448
+ end
449
+ ```
450
+
333
451
  ### HexValidator
334
452
 
335
- **Ex:** #a9a9a9 or #999 or aaaaaa
453
+ **Ex:** #a9a9a9 or #999 or aaaaaa or AAA
336
454
 
337
455
  **Rules:**
338
456
  * Prefix (non-mandatory): #
339
457
  * Length: 3 or 6
340
- * Characters: a-f 0-9
458
+ * Characters: A-F a-f 0-9
341
459
 
342
460
  With an ActiveRecord model:
343
461
 
@@ -475,6 +593,43 @@ describe User do
475
593
  end
476
594
  ```
477
595
 
596
+ ### IsinValidator
597
+
598
+ **Ex:** US0378331005 or AU0000XVGZA3
599
+
600
+ **Rules:**
601
+ * Length: 12
602
+ * Characters: 0-9 A-Z
603
+ * Start: valid country code
604
+
605
+ With an ActiveRecord model:
606
+
607
+ ```ruby
608
+ class Trade < ActiveRecord::Base
609
+ attr_accessor :isin, :name
610
+ validates :isin, isin: true
611
+ end
612
+ ```
613
+
614
+ Or any ruby class:
615
+
616
+ ```ruby
617
+ class User
618
+ include ActiveModel::Validations
619
+ attr_accessor :isin, :name
620
+ validates :isin, isin: true
621
+ end
622
+ ```
623
+
624
+ RSpec matcher is also available for your convenience:
625
+
626
+ ```ruby
627
+ describe User do
628
+ it { should ensure_valid_isin_format_of(:isin) }
629
+ it { should_not ensure_valid_isin_format_of(:name) }
630
+ end
631
+ ```
632
+
478
633
  ### LatitudeValidator
479
634
 
480
635
  **Ex:** 78.213 or -34.985
@@ -651,7 +806,7 @@ class User
651
806
  validates :password, password: true
652
807
  end
653
808
  ```
654
-
809
+ Options: :strict
655
810
  Strict: requires length between 6 and 18, one number, lowercase, upcase letter
656
811
 
657
812
  ```ruby
@@ -702,6 +857,41 @@ describe User do
702
857
  end
703
858
  ```
704
859
 
860
+ ### SedolValidator
861
+
862
+ **Ex:** B0WNLY7
863
+
864
+ **Rules:**
865
+ * Characters: A-Z 0-9
866
+
867
+ With an ActiveRecord model:
868
+
869
+ ```ruby
870
+ class Trade < ActiveRecord::Base
871
+ attr_accessor :sedol, :name
872
+ validates :sedol, sedol: true
873
+ end
874
+ ```
875
+
876
+ Or any ruby class:
877
+
878
+ ```ruby
879
+ class Trade
880
+ include ActiveModel::Validations
881
+ attr_accessor :sedol, :name
882
+ validates :sedol, sedol: true
883
+ end
884
+ ```
885
+
886
+ RSpec matcher is also available for your convenience:
887
+
888
+ ```ruby
889
+ describe Trade do
890
+ it { should ensure_valid_sedol_format_of(:sedol) }
891
+ it { should_not ensure_valid_sedol_format_of(:name) }
892
+ end
893
+ ```
894
+
705
895
  ### SlugValidator
706
896
 
707
897
  **Ex:** slug1234 or slug-1234
@@ -800,27 +990,19 @@ class User
800
990
  end
801
991
  ```
802
992
 
803
- You can specify domains to which the URL domain should belong in one of the folowing ways:
993
+ Options: :domains, :root, :scheme
804
994
 
805
995
  ```ruby
996
+ validates :url, url: { scheme: :http }
997
+ validates :url, url: { scheme: [:http, 'https'] }
998
+ validates :url, url: { scheme: :http, root: true, domains: :com }
999
+ validates :url, url: { root: true }
1000
+ validates :url, url: { root: true, domains: :com }
806
1001
  validates :url, url: { domains: 'com' }
807
1002
  validates :url, url: { domains: :com }
808
1003
  validates :url, url: { domains: [:com, 'edu'] }
809
1004
  ```
810
1005
 
811
- You can specify if the URL should the site root:
812
-
813
- ```ruby
814
- validates :url, url: { root: true }
815
- ```
816
-
817
- You can specify the URL scheme:
818
-
819
- ```ruby
820
- validates :url, url: { scheme: :http }
821
- validates :url, url: { scheme: [:http, 'https'] }
822
- ```
823
-
824
1006
  RSpec matcher is also available for your convenience:
825
1007
 
826
1008
  ```ruby
@@ -866,6 +1048,47 @@ describe User do
866
1048
  end
867
1049
  ```
868
1050
 
1051
+ ### UuidValidator
1052
+
1053
+ **Ex:** 886313e1-3b8a-5372-9b90-0c9aee199e5d
1054
+
1055
+ **Rules:**
1056
+ * Characters: A-Z a-z 0-9 -
1057
+
1058
+ With an ActiveRecord model:
1059
+
1060
+ ```ruby
1061
+ class User < ActiveRecord::Base
1062
+ attr_accessor :uuid, :name
1063
+ validates :uuid, uuid: true
1064
+ end
1065
+ ```
1066
+
1067
+ Or any ruby class:
1068
+
1069
+ ```ruby
1070
+ class User
1071
+ include ActiveModel::Validations
1072
+ attr_accessor :uuid, :name
1073
+ validates :uuid, username: true
1074
+ end
1075
+ ```
1076
+
1077
+ Options: :version
1078
+
1079
+ ```ruby
1080
+ validates :uuid, uuid: { version: 3 }
1081
+ ```
1082
+
1083
+ RSpec matcher is also available for your convenience:
1084
+
1085
+ ```ruby
1086
+ describe User do
1087
+ it { should ensure_valid_uuid_format_of(:uuid) }
1088
+ it { should_not ensure_valid_uuid_format_of(:name) }
1089
+ end
1090
+ ```
1091
+
869
1092
  ## Contributing
870
1093
 
871
1094
  Your contribution is welcome.
@@ -3,87 +3,111 @@ en:
3
3
  messages:
4
4
  alpha: "is not a valid alpha characters"
5
5
  alpha_numeric: "is not a valid alpha-numeric characters"
6
+ base64: "is not a valid Base64 encode"
6
7
  boolean: "is not a valid boolean"
7
8
  credit_card: "is not a valid credit card"
8
9
  currency: "is not a valid currency"
10
+ cusip: "is not a valid CUSIP"
9
11
  email: "is not a valid email"
10
12
  equality: "is not %{operator} %{attr}"
13
+ gtin: "is not a valid GTIN"
11
14
  hex: "is not a valid hex color"
12
15
  imei: "is not a valid IMEI"
13
16
  ip: "is not a valid IP"
14
17
  isbn: "is not a valid ISBN"
18
+ isin: "is not a valid ISIN"
15
19
  longitude: "is not a valid latitude"
16
20
  longitude: "is not a valid longitude"
17
21
  mac_address: "is not a valid MAC address"
18
22
  name: "is not a valid name"
19
23
  password: "is not a valid password"
20
24
  phone: "is not a valid phone number"
25
+ sedol: "is not a valid SEDOL"
21
26
  slug: "is not a valid slug"
22
27
  ssn: "is not a valid social security number"
23
28
  url: "is not a valid URL"
24
29
  username: "is not a valid username"
30
+ uuid: "is not a valid UUID"
25
31
  flash_validators:
26
32
  matchers:
27
33
  ensure_valid_alpha_format_of:
28
- failure_message_for_should: "#{model} should ensure valid alpha format of attribute #{attr}"
29
- failure_message_for_should_not: "#{model} should not ensure valid alpha format of attribute #{attr}"
34
+ failure_message_for_should: "%{model} should ensure valid alpha format of attribute %{attr}"
35
+ failure_message_for_should_not: "%{model} should not ensure valid alpha format of attribute %{attr}"
30
36
  ensure_valid_alpha_numeric_format_of:
31
- failure_message_for_should: "#{model} should ensure valid alpha numeric format of attribute #{attr}"
32
- failure_message_for_should_not: "#{model} should not ensure valid alpha numeric format of attribute #{attr}"
37
+ failure_message_for_should: "%{model} should ensure valid alpha numeric format of attribute %{attr}"
38
+ failure_message_for_should_not: "%{model} should not ensure valid alpha numeric format of attribute %{attr}"
39
+ ensure_valid_base64_format_of:
40
+ failure_message_for_should: "%{model} should ensure valid Base64 encoded format of attribute %{attr}"
41
+ failure_message_for_should_not: "%{model} should not ensure valid Base64 encoded format of attribute %{attr}"
33
42
  ensure_valid_boolean_format_of:
34
- failure_message_for_should: "#{model} should ensure valid boolean format of attribute #{attr}"
35
- failure_message_for_should_not: "#{model} should not ensure valid boolean format of attribute #{attr}"
43
+ failure_message_for_should: "%{model} should ensure valid boolean format of attribute %{attr}"
44
+ failure_message_for_should_not: "%{model} should not ensure valid boolean format of attribute %{attr}"
36
45
  ensure_valid_credit_card_format_of:
37
- failure_message_for_should: "#{model} should ensure valid credit card format of attribute #{attr}"
38
- failure_message_for_should_not: "#{model} should not ensure valid credit card format of attribute #{attr}"
46
+ failure_message_for_should: "%{model} should ensure valid credit card format of attribute %{attr}"
47
+ failure_message_for_should_not: "%{model} should not ensure valid credit card format of attribute %{attr}"
39
48
  ensure_valid_currency_format_of:
40
- failure_message_for_should: "#{model} should ensure valid currency format of attribute #{attr}"
41
- failure_message_for_should_not: "#{model} should not ensure valid currency format of attribute #{attr}"
49
+ failure_message_for_should: "%{model} should ensure valid currency format of attribute %{attr}"
50
+ failure_message_for_should_not: "%{model} should not ensure valid currency format of attribute %{attr}"
51
+ ensure_valid_cusip_format_of:
52
+ failure_message_for_should: "%{model} should ensure valid CUSIP format of attribute %{attr}"
53
+ failure_message_for_should_not: "%{model} should not ensure valid CUSIP format of attribute %{attr}"
42
54
  ensure_valid_email_format_of:
43
- failure_message_for_should: "#{model} should ensure valid email format of attribute #{attr}"
44
- failure_message_for_should_not: "#{model} should not ensure valid email format of attribute #{attr}"
55
+ failure_message_for_should: "%{model} should ensure valid email format of attribute %{attr}"
56
+ failure_message_for_should_not: "%{model} should not ensure valid email format of attribute %{attr}"
45
57
  ensure_valid_equality_format_of:
46
- failure_message_for_should: "#{model} should ensure equality of #{operator} on attribute #{attr}"
47
- failure_message_for_should_not: "#{model} should not ensure equality of #{operator} on attribute #{attr}"
58
+ failure_message_for_should: "%{model} should ensure equality of %{operator} on attribute %{attr}"
59
+ failure_message_for_should_not: "%{model} should not ensure equality of %{operator} on attribute %{attr}"
60
+ ensure_valid_gtin_format_of:
61
+ failure_message_for_should: "%{model} should ensure valid GTIN format of attribute %{attr}"
62
+ failure_message_for_should_not: "%{model} should not ensure valid GTIN format of attribute %{attr}"
48
63
  ensure_valid_hex_format_of:
49
- failure_message_for_should: "#{model} should ensure valid hex format of attribute #{attr}"
50
- failure_message_for_should_not: "#{model} should not ensure valid hex format of attribute #{attr}"
64
+ failure_message_for_should: "%{model} should ensure valid hex format of attribute %{attr}"
65
+ failure_message_for_should_not: "%{model} should not ensure valid hex format of attribute %{attr}"
51
66
  ensure_valid_imei_format_of:
52
- failure_message_for_should: "#{model} should ensure valid IMEI address format of attribute #{attr}"
53
- failure_message_for_should_not: "#{model} should not ensure valid IMEI address format of attribute #{attr}"
67
+ failure_message_for_should: "%{model} should ensure valid IMEI address format of attribute %{attr}"
68
+ failure_message_for_should_not: "%{model} should not ensure valid IMEI address format of attribute %{attr}"
54
69
  ensure_valid_ip_format_of:
55
- failure_message_for_should: "#{model} should ensure valid IP address format of attribute #{attr}"
56
- failure_message_for_should_not: "#{model} should not ensure valid IP address format of attribute #{attr}"
70
+ failure_message_for_should: "%{model} should ensure valid IP address format of attribute %{attr}"
71
+ failure_message_for_should_not: "%{model} should not ensure valid IP address format of attribute %{attr}"
57
72
  ensure_valid_isbn_format_of:
58
- failure_message_for_should: "#{model} should ensure valid ISBN format of attribute #{attr}"
59
- failure_message_for_should_not: "#{model} should not ensure valid ISBN format of attribute #{attr}"
73
+ failure_message_for_should: "%{model} should ensure valid ISBN format of attribute %{attr}"
74
+ failure_message_for_should_not: "%{model} should not ensure valid ISBN format of attribute %{attr}"
75
+ ensure_valid_isin_format_of:
76
+ failure_message_for_should: "%{model} should ensure valid ISIN format of attribute %{attr}"
77
+ failure_message_for_should_not: "%{model} should not ensure valid ISIN format of attribute %{attr}"
60
78
  ensure_valid_latitude_format_of:
61
- failure_message_for_should: "#{model} should ensure valid latitude format of attribute #{attr}"
62
- failure_message_for_should_not: "#{model} should not ensure valid latitude format of attribute #{attr}"
79
+ failure_message_for_should: "%{model} should ensure valid latitude format of attribute %{attr}"
80
+ failure_message_for_should_not: "%{model} should not ensure valid latitude format of attribute %{attr}"
63
81
  ensure_valid_longitude_format_of:
64
- failure_message_for_should: "#{model} should ensure valid longitude format of attribute #{attr}"
65
- failure_message_for_should_not: "#{model} should not ensure valid longitude format of attribute #{attr}"
82
+ failure_message_for_should: "%{model} should ensure valid longitude format of attribute %{attr}"
83
+ failure_message_for_should_not: "%{model} should not ensure valid longitude format of attribute %{attr}"
66
84
  ensure_valid_mac_address_format_of:
67
- failure_message_for_should: "#{model} should ensure valid MAC address format of attribute #{attr}"
68
- failure_message_for_should_not: "#{model} should not ensure valid MAC address format of attribute #{attr}"
85
+ failure_message_for_should: "%{model} should ensure valid MAC address format of attribute %{attr}"
86
+ failure_message_for_should_not: "%{model} should not ensure valid MAC address format of attribute %{attr}"
69
87
  ensure_valid_name_format_of:
70
- failure_message_for_should: "#{model} should ensure valid name format of attribute #{attr}"
71
- failure_message_for_should_not: "#{model} should not ensure valid name format of attribute #{attr}"
88
+ failure_message_for_should: "%{model} should ensure valid name format of attribute %{attr}"
89
+ failure_message_for_should_not: "%{model} should not ensure valid name format of attribute %{attr}"
72
90
  ensure_valid_password_format_of:
73
- failure_message_for_should: "#{model} should ensure valid password format of attribute #{attr}"
74
- failure_message_for_should_not: "#{model} should not ensure valid password format of attribute #{attr}"
91
+ failure_message_for_should: "%{model} should ensure valid password format of attribute %{attr}"
92
+ failure_message_for_should_not: "%{model} should not ensure valid password format of attribute %{attr}"
75
93
  ensure_valid_phone_format_of:
76
- failure_message_for_should: "#{model} should ensure valid phone format of attribute #{attr}"
77
- failure_message_for_should_not: "#{model} should not ensure valid phone format of attribute #{attr}"
94
+ failure_message_for_should: "%{model} should ensure valid phone format of attribute %{attr}"
95
+ failure_message_for_should_not: "%{model} should not ensure valid phone format of attribute %{attr}"
96
+ ensure_valid_sedol_format_of:
97
+ failure_message_for_should: "%{model} should ensure valid SEDOL format of attribute %{attr}"
98
+ failure_message_for_should_not: "%{model} should not ensure valid SEDOL format of attribute %{attr}"
78
99
  ensure_valid_slug_format_of:
79
- failure_message_for_should: "#{model} should ensure valid slug format of attribute #{attr}"
80
- failure_message_for_should_not: "#{model} should not ensure valid slug format of attribute #{attr}"
100
+ failure_message_for_should: "%{model} should ensure valid slug format of attribute %{attr}"
101
+ failure_message_for_should_not: "%{model} should not ensure valid slug format of attribute %{attr}"
81
102
  ensure_valid_ssn_format_of:
82
- failure_message_for_should: "#{model} should ensure valid ssn format of attribute #{attr}"
83
- failure_message_for_should_not: "#{model} should not ensure valid ssn format of attribute #{attr}"
103
+ failure_message_for_should: "%{model} should ensure valid SSN format of attribute %{attr}"
104
+ failure_message_for_should_not: "%{model} should not ensure valid SSN format of attribute %{attr}"
84
105
  ensure_valid_url_format_of:
85
- failure_message_for_should: "#{model} should ensure valid URL format of attribute #{attr}"
86
- failure_message_for_should_not: "#{model} should not ensure valid URL format of attribute #{attr}"
106
+ failure_message_for_should: "%{model} should ensure valid URL format of attribute %{attr}"
107
+ failure_message_for_should_not: "%{model} should not ensure valid URL format of attribute %{attr}"
87
108
  ensure_valid_username_format_of:
88
- failure_message_for_should: "#{model} should ensure valid username format of attribute #{attr}"
89
- failure_message_for_should_not: "#{model} should not ensure valid username format of attribute #{attr}"
109
+ failure_message_for_should: "%{model} should ensure valid username format of attribute %{attr}"
110
+ failure_message_for_should_not: "%{model} should not ensure valid username format of attribute %{attr}"
111
+ ensure_valid_uuid_format_of:
112
+ failure_message_for_should: "%{model} should ensure valid UUID format of attribute %{attr}"
113
+ failure_message_for_should_not: "%{model} should not ensure valid UUID format of attribute %{attr}"
@@ -9,10 +9,18 @@ RSpec::Matchers.define :ensure_valid_alpha_format_of do |attribute|
9
9
  end
10
10
 
11
11
  failure_message do |model|
12
- I18n.t('flash_validators.matchers.ensure_valid_alpha_format_of.failure_message_for_should', model: model.class)
12
+ I18n.t(
13
+ 'flash_validators.matchers.ensure_valid_alpha_format_of.failure_message_for_should',
14
+ attr: attribute.inspect,
15
+ model: model.class.name
16
+ )
13
17
  end
14
18
 
15
19
  failure_message_when_negated do |model|
16
- I18n.t('flash_validators.matchers.ensure_valid_alpha_format_of.failure_message_for_should_not', model: model.class)
20
+ I18n.t(
21
+ 'flash_validators.matchers.ensure_valid_alpha_format_of.failure_message_for_should_not',
22
+ attr: attribute.inspect,
23
+ model: model.class.name
24
+ )
17
25
  end
18
26
  end
@@ -9,10 +9,18 @@ RSpec::Matchers.define :ensure_valid_alpha_numeric_format_of do |attribute|
9
9
  end
10
10
 
11
11
  failure_message do |model|
12
- I18n.t('flash_validators.matchers.ensure_valid_alpha_numeric_format_of.failure_message_for_should', model: model.class)
12
+ I18n.t(
13
+ 'flash_validators.matchers.ensure_valid_alpha_numeric_format_of.failure_message_for_should',
14
+ attr: attribute.inspect,
15
+ model: model.class.name
16
+ )
13
17
  end
14
18
 
15
19
  failure_message_when_negated do |model|
16
- I18n.t('flash_validators.matchers.ensure_valid_alpha_numeric_format_of.failure_message_for_should_not', model: model.class)
20
+ I18n.t(
21
+ 'flash_validators.matchers.ensure_valid_alpha_numeric_format_of.failure_message_for_should_not',
22
+ attr: attribute.inspect,
23
+ model: model.class.name
24
+ )
17
25
  end
18
26
  end
@@ -0,0 +1,26 @@
1
+ RSpec::Matchers.define :ensure_valid_base64_format_of do |attribute|
2
+ match do |model|
3
+ model.send("#{attribute}=", "1a.b2==")
4
+ model.valid?
5
+
6
+ if model.errors.has_key?(attribute)
7
+ model.errors[attribute].include?(I18n.t('errors.messages.base64'))
8
+ end
9
+ end
10
+
11
+ failure_message do |model|
12
+ I18n.t(
13
+ 'flash_validators.matchers.ensure_valid_base64_format_of.failure_message_for_should',
14
+ attr: attribute.inspect,
15
+ model: model.class.name
16
+ )
17
+ end
18
+
19
+ failure_message_when_negated do |model|
20
+ I18n.t(
21
+ 'flash_validators.matchers.ensure_valid_base64_format_of.failure_message_for_should_not',
22
+ attr: attribute.inspect,
23
+ model: model.class.name
24
+ )
25
+ end
26
+ end