flash_validators 1.1.0 → 3.0.0

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.
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
@@ -4,46 +4,58 @@ require 'rspec/matchers'
4
4
  require 'flash_validators/version'
5
5
  require 'flash_validators/validators/alpha_validator'
6
6
  require 'flash_validators/validators/alpha_numeric_validator'
7
+ require 'flash_validators/validators/base64_validator'
7
8
  require 'flash_validators/validators/boolean_validator'
8
9
  require 'flash_validators/validators/credit_card_validator'
9
10
  require 'flash_validators/validators/currency_validator'
11
+ require 'flash_validators/validators/cusip_validator'
10
12
  require 'flash_validators/validators/email_validator'
11
13
  require 'flash_validators/validators/equality_validator'
14
+ require 'flash_validators/validators/gtin_validator'
12
15
  require 'flash_validators/validators/hex_validator'
13
16
  require 'flash_validators/validators/imei_validator'
14
17
  require 'flash_validators/validators/ip_validator'
15
18
  require 'flash_validators/validators/isbn_validator'
19
+ require 'flash_validators/validators/isin_validator'
16
20
  require 'flash_validators/validators/latitude_validator'
17
21
  require 'flash_validators/validators/longitude_validator'
18
22
  require 'flash_validators/validators/mac_address_validator'
19
23
  require 'flash_validators/validators/name_validator'
20
24
  require 'flash_validators/validators/password_validator'
21
25
  require 'flash_validators/validators/phone_validator'
26
+ require 'flash_validators/validators/sedol_validator'
22
27
  require 'flash_validators/validators/slug_validator'
23
28
  require 'flash_validators/validators/ssn_validator'
24
29
  require 'flash_validators/validators/url_validator'
25
30
  require 'flash_validators/validators/username_validator'
31
+ require 'flash_validators/validators/uuid_validator'
26
32
 
27
33
  if defined?(RSpec)
28
34
  require 'flash_validators/matchers/ensure_valid_alpha_format_of'
29
35
  require 'flash_validators/matchers/ensure_valid_alpha_numeric_format_of'
36
+ require 'flash_validators/matchers/ensure_valid_base64_format_of'
30
37
  require 'flash_validators/matchers/ensure_valid_boolean_format_of'
31
38
  require 'flash_validators/matchers/ensure_valid_credit_card_format_of'
32
39
  require 'flash_validators/matchers/ensure_valid_currency_format_of'
40
+ require 'flash_validators/matchers/ensure_valid_cusip_format_of'
33
41
  require 'flash_validators/matchers/ensure_valid_email_format_of'
34
42
  require 'flash_validators/matchers/ensure_valid_equality_matcher_of'
43
+ require 'flash_validators/matchers/ensure_valid_gtin_format_of'
35
44
  require 'flash_validators/matchers/ensure_valid_hex_format_of'
36
45
  require 'flash_validators/matchers/ensure_valid_imei_format_of'
37
46
  require 'flash_validators/matchers/ensure_valid_ip_format_of'
38
47
  require 'flash_validators/matchers/ensure_valid_isbn_format_of'
48
+ require 'flash_validators/matchers/ensure_valid_isin_format_of'
39
49
  require 'flash_validators/matchers/ensure_valid_latitude_format_of'
40
50
  require 'flash_validators/matchers/ensure_valid_longitude_format_of'
41
51
  require 'flash_validators/matchers/ensure_valid_mac_address_format_of'
42
52
  require 'flash_validators/matchers/ensure_valid_name_format_of'
43
53
  require 'flash_validators/matchers/ensure_valid_password_format_of'
44
54
  require 'flash_validators/matchers/ensure_valid_phone_format_of'
55
+ require 'flash_validators/matchers/ensure_valid_sedol_format_of'
45
56
  require 'flash_validators/matchers/ensure_valid_slug_format_of'
46
57
  require 'flash_validators/matchers/ensure_valid_ssn_format_of'
47
58
  require 'flash_validators/matchers/ensure_valid_url_format_of'
48
59
  require 'flash_validators/matchers/ensure_valid_username_format_of'
60
+ require 'flash_validators/matchers/ensure_valid_uuid_format_of'
49
61
  end
@@ -13,13 +13,13 @@ describe AlphaNumericValidator do
13
13
 
14
14
  subject { klass.new }
15
15
 
16
- it { should allow_value(' ').for(:title) }
17
16
  it { should allow_value("Example").for(:title) }
18
17
  it { should allow_value("Example Title").for(:title) }
19
18
  it { should allow_value("Example1").for(:title) }
20
19
  it { should allow_value("Example 1").for(:title) }
21
20
 
22
21
  it { should_not allow_value('').for(:title) }
22
+ it { should_not allow_value(' ').for(:title) }
23
23
  it { should_not allow_value(nil).for(:title) }
24
24
  it { should_not allow_value("Ex-ample").for(:title) }
25
25
  it { should_not allow_value("Ex-ample1").for(:title) }
@@ -58,4 +58,34 @@ describe AlphaNumericValidator do
58
58
  it { should_not ensure_valid_alpha_numeric_format_of(:name) }
59
59
  end
60
60
 
61
+ context "with case: :lower option has a valid value" do
62
+ let(:klass) do
63
+ Class.new do
64
+ include ActiveModel::Validations
65
+ attr_accessor :title, :name
66
+ validates :title, alpha_numeric: { case: :lower }
67
+ end
68
+ end
69
+
70
+ subject { klass.new }
71
+
72
+ it { should allow_value("example1").for(:title) }
73
+ it { should allow_value("example title 1").for(:title) }
74
+
75
+ it { should_not allow_value('').for(:title) }
76
+ it { should_not allow_value(' ').for(:title) }
77
+ it { should_not allow_value(nil).for(:title) }
78
+ it { should_not allow_value("Example").for(:title) }
79
+ it { should_not allow_value("Example Title").for(:title) }
80
+ it { should_not allow_value("Example 1").for(:title) }
81
+ it { should_not allow_value("Example1").for(:title) }
82
+ it { should_not allow_value("Ex-ample").for(:title) }
83
+ it { should_not allow_value("Ex-ample1").for(:title) }
84
+ it { should_not allow_value("! \#$%\`|").for(:title) }
85
+ it { should_not allow_value("<>@[]\`|").for(:title) }
86
+
87
+ it { should ensure_valid_alpha_numeric_format_of(:title) }
88
+ it { should_not ensure_valid_alpha_numeric_format_of(:name) }
89
+ end
90
+
61
91
  end
@@ -13,15 +13,14 @@ describe AlphaValidator do
13
13
 
14
14
  subject { klass.new }
15
15
 
16
- it { should allow_value(' ').for(:title) }
17
16
  it { should allow_value("Example").for(:title) }
18
17
  it { should allow_value("Example Title").for(:title) }
19
18
 
20
19
  it { should_not allow_value('').for(:title) }
20
+ it { should_not allow_value(' ').for(:title) }
21
21
  it { should_not allow_value(nil).for(:title) }
22
22
  it { should_not allow_value("Example1").for(:title) }
23
23
  it { should_not allow_value("Example 1").for(:title) }
24
- it { should_not allow_value("Ex-ample").for(:title) }
25
24
  it { should_not allow_value("Ex-ample1").for(:title) }
26
25
  it { should_not allow_value("! \#$%\`|").for(:title) }
27
26
  it { should_not allow_value("<>@[]\`|").for(:title) }
@@ -58,12 +57,73 @@ describe AlphaValidator do
58
57
  it { should_not ensure_valid_alpha_format_of(:name) }
59
58
  end
60
59
 
61
- context "with :lowercase option has a valid value" do
60
+ context "with case: :lower option has a valid value" do
61
+ let(:klass) do
62
+ Class.new do
63
+ include ActiveModel::Validations
64
+ attr_accessor :title, :name
65
+ validates :title, alpha: { case: :lower }
66
+ end
67
+ end
68
+
69
+ subject { klass.new }
70
+
71
+ it { should allow_value("example").for(:title) }
72
+ it { should allow_value("example title").for(:title) }
73
+
74
+ it { should_not allow_value('').for(:title) }
75
+ it { should_not allow_value(' ').for(:title) }
76
+ it { should_not allow_value(nil).for(:title) }
77
+ it { should_not allow_value("Example").for(:title) }
78
+ it { should_not allow_value("Example Title").for(:title) }
79
+ it { should_not allow_value("Example 1").for(:title) }
80
+ it { should_not allow_value("Example1").for(:title) }
81
+ it { should_not allow_value("Ex-ample").for(:title) }
82
+ it { should_not allow_value("Ex-ample1").for(:title) }
83
+ it { should_not allow_value("! \#$%\`|").for(:title) }
84
+ it { should_not allow_value("<>@[]\`|").for(:title) }
85
+
86
+ it { should ensure_valid_alpha_format_of(:title) }
87
+ it { should_not ensure_valid_alpha_format_of(:name) }
88
+ end
89
+
90
+ context "with case: :upper option has a valid value" do
91
+ let(:klass) do
92
+ Class.new do
93
+ include ActiveModel::Validations
94
+ attr_accessor :title, :name
95
+ validates :title, alpha: { case: :upper }
96
+ end
97
+ end
98
+
99
+ subject { klass.new }
100
+
101
+ it { should allow_value("EXAMPLE").for(:title) }
102
+ it { should allow_value("EXAMPLE TITLE").for(:title) }
103
+
104
+ it { should_not allow_value('').for(:title) }
105
+ it { should_not allow_value(' ').for(:title) }
106
+ it { should_not allow_value(nil).for(:title) }
107
+ it { should_not allow_value("example").for(:title) }
108
+ it { should_not allow_value("Example").for(:title) }
109
+ it { should_not allow_value("Example Title").for(:title) }
110
+ it { should_not allow_value("Example 1").for(:title) }
111
+ it { should_not allow_value("Example1").for(:title) }
112
+ it { should_not allow_value("Ex-ample").for(:title) }
113
+ it { should_not allow_value("Ex-ample1").for(:title) }
114
+ it { should_not allow_value("! \#$%\`|").for(:title) }
115
+ it { should_not allow_value("<>@[]\`|").for(:title) }
116
+
117
+ it { should ensure_valid_alpha_format_of(:title) }
118
+ it { should_not ensure_valid_alpha_format_of(:name) }
119
+ end
120
+
121
+ context "with case: :lower and :strict option has a valid value" do
62
122
  let(:klass) do
63
123
  Class.new do
64
124
  include ActiveModel::Validations
65
125
  attr_accessor :title, :name
66
- validates :title, alpha: { lowercase: true }
126
+ validates :title, alpha: { case: :lower, strict: true }
67
127
  end
68
128
  end
69
129
 
@@ -80,6 +140,7 @@ describe AlphaValidator do
80
140
  it { should_not allow_value("Example1").for(:title) }
81
141
  it { should_not allow_value("Ex-ample").for(:title) }
82
142
  it { should_not allow_value("Ex-ample1").for(:title) }
143
+ it { should_not allow_value("example title").for(:title) }
83
144
  it { should_not allow_value("! \#$%\`|").for(:title) }
84
145
  it { should_not allow_value("<>@[]\`|").for(:title) }
85
146
 
@@ -87,12 +148,12 @@ describe AlphaValidator do
87
148
  it { should_not ensure_valid_alpha_format_of(:name) }
88
149
  end
89
150
 
90
- context "with :uppercase option has a valid value" do
151
+ context "with case: :upper and :strict option has a valid value" do
91
152
  let(:klass) do
92
153
  Class.new do
93
154
  include ActiveModel::Validations
94
155
  attr_accessor :title, :name
95
- validates :title, alpha: { uppercase: true }
156
+ validates :title, alpha: { case: :upper, strict: true }
96
157
  end
97
158
  end
98
159
 
@@ -110,6 +171,7 @@ describe AlphaValidator do
110
171
  it { should_not allow_value("Example1").for(:title) }
111
172
  it { should_not allow_value("Ex-ample").for(:title) }
112
173
  it { should_not allow_value("Ex-ample1").for(:title) }
174
+ it { should_not allow_value("EXAMPLE TITLE").for(:title) }
113
175
  it { should_not allow_value("! \#$%\`|").for(:title) }
114
176
  it { should_not allow_value("<>@[]\`|").for(:title) }
115
177
 
@@ -0,0 +1,33 @@
1
+ require 'spec_helper'
2
+
3
+ describe Base64Validator do
4
+
5
+ context "has a valid value" do
6
+ let(:klass) do
7
+ Class.new do
8
+ include ActiveModel::Validations
9
+ attr_accessor :code, :name
10
+ validates :code, base64: true
11
+ end
12
+ end
13
+
14
+ subject { klass.new }
15
+
16
+ it { should allow_value("YW55IGNhcm5hbCBwbGVhcw==").for(:code) }
17
+ it { should allow_value("YW55IGNhcm5hbCBwbGVhc3U=").for(:code) }
18
+ it { should allow_value("YW55IGNhcm5hbCBwbGVhc3Vy").for(:code) }
19
+ it { should allow_value("YW55IGNhcm5hbCBwbGVhc3VyZQ==").for(:code) }
20
+ it { should allow_value("YW55IGNhcm5hbCBwbGVhc3VyZS4=").for(:code) }
21
+
22
+ it { should_not allow_value('').for(:code) }
23
+ it { should_not allow_value(' ').for(:code) }
24
+ it { should_not allow_value(nil).for(:code) }
25
+ it { should_not allow_value("1a.b2").for(:code) }
26
+ it { should_not allow_value("1a b2").for(:code) }
27
+ it { should_not allow_value("1a.b2==").for(:code) }
28
+
29
+ it { should ensure_valid_base64_format_of(:code) }
30
+ it { should_not ensure_valid_base64_format_of(:name) }
31
+ end
32
+
33
+ end