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.
- checksums.yaml +4 -4
- data/README.md +258 -35
- data/config/locales/en.yml +66 -42
- data/lib/flash_validators/matchers/ensure_valid_alpha_format_of.rb +10 -2
- data/lib/flash_validators/matchers/ensure_valid_alpha_numeric_format_of.rb +10 -2
- data/lib/flash_validators/matchers/ensure_valid_base64_format_of.rb +26 -0
- data/lib/flash_validators/matchers/ensure_valid_boolean_format_of.rb +10 -2
- data/lib/flash_validators/matchers/ensure_valid_credit_card_format_of.rb +10 -2
- data/lib/flash_validators/matchers/ensure_valid_currency_format_of.rb +10 -2
- data/lib/flash_validators/matchers/ensure_valid_cusip_format_of.rb +26 -0
- data/lib/flash_validators/matchers/ensure_valid_email_format_of.rb +10 -2
- data/lib/flash_validators/matchers/ensure_valid_equality_matcher_of.rb +12 -2
- data/lib/flash_validators/matchers/ensure_valid_gtin_format_of.rb +26 -0
- data/lib/flash_validators/matchers/ensure_valid_hex_format_of.rb +10 -2
- data/lib/flash_validators/matchers/ensure_valid_imei_format_of.rb +10 -2
- data/lib/flash_validators/matchers/ensure_valid_ip_format_of.rb +10 -2
- data/lib/flash_validators/matchers/ensure_valid_isbn_format_of.rb +10 -2
- data/lib/flash_validators/matchers/ensure_valid_isin_format_of.rb +26 -0
- data/lib/flash_validators/matchers/ensure_valid_latitude_format_of.rb +10 -2
- data/lib/flash_validators/matchers/ensure_valid_longitude_format_of.rb +10 -2
- data/lib/flash_validators/matchers/ensure_valid_mac_address_format_of.rb +10 -2
- data/lib/flash_validators/matchers/ensure_valid_name_format_of.rb +10 -2
- data/lib/flash_validators/matchers/ensure_valid_password_format_of.rb +10 -2
- data/lib/flash_validators/matchers/ensure_valid_phone_format_of.rb +10 -2
- data/lib/flash_validators/matchers/ensure_valid_sedol_format_of.rb +26 -0
- data/lib/flash_validators/matchers/ensure_valid_slug_format_of.rb +10 -2
- data/lib/flash_validators/matchers/ensure_valid_ssn_format_of.rb +10 -2
- data/lib/flash_validators/matchers/ensure_valid_url_format_of.rb +10 -2
- data/lib/flash_validators/matchers/ensure_valid_username_format_of.rb +10 -2
- data/lib/flash_validators/matchers/ensure_valid_uuid_format_of.rb +26 -0
- data/lib/flash_validators/validators/alpha_numeric_validator.rb +21 -7
- data/lib/flash_validators/validators/alpha_validator.rb +22 -10
- data/lib/flash_validators/validators/base64_validator.rb +9 -0
- data/lib/flash_validators/validators/credit_card_validator.rb +123 -15
- data/lib/flash_validators/validators/currency_validator.rb +13 -7
- data/lib/flash_validators/validators/cusip_validator.rb +33 -0
- data/lib/flash_validators/validators/email_validator.rb +7 -7
- data/lib/flash_validators/validators/equality_validator.rb +7 -7
- data/lib/flash_validators/validators/gtin_validator.rb +59 -0
- data/lib/flash_validators/validators/hex_validator.rb +1 -1
- data/lib/flash_validators/validators/imei_validator.rb +8 -8
- data/lib/flash_validators/validators/isbn_validator.rb +9 -16
- data/lib/flash_validators/validators/isin_validator.rb +38 -0
- data/lib/flash_validators/validators/mac_address_validator.rb +10 -10
- data/lib/flash_validators/validators/password_validator.rb +13 -7
- data/lib/flash_validators/validators/sedol_validator.rb +32 -0
- data/lib/flash_validators/validators/url_validator.rb +13 -13
- data/lib/flash_validators/validators/uuid_validator.rb +28 -0
- data/lib/flash_validators/version.rb +1 -1
- data/lib/flash_validators.rb +12 -0
- data/spec/lib/alpha_numeric_validator_spec.rb +31 -1
- data/spec/lib/alpha_validator_spec.rb +68 -6
- data/spec/lib/base64_validator_spec.rb +33 -0
- data/spec/lib/credit_card_validator_spec.rb +495 -125
- data/spec/lib/cusip_validator_spec.rb +27 -0
- data/spec/lib/gtin_validator_spec.rb +101 -0
- data/spec/lib/hex_validator_spec.rb +20 -0
- data/spec/lib/isin_validator_spec.rb +35 -0
- data/spec/lib/sedol_validator_spec.rb +31 -0
- data/spec/lib/uuid_validator_spec.rb +157 -0
- metadata +26 -2
@@ -9,10 +9,18 @@ RSpec::Matchers.define :ensure_valid_boolean_format_of do |attribute|
|
|
9
9
|
end
|
10
10
|
|
11
11
|
failure_message do |model|
|
12
|
-
I18n.t(
|
12
|
+
I18n.t(
|
13
|
+
'flash_validators.matchers.ensure_valid_boolean_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(
|
20
|
+
I18n.t(
|
21
|
+
'flash_validators.matchers.ensure_valid_boolean_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_credit_card_format_of do |attribute|
|
|
9
9
|
end
|
10
10
|
|
11
11
|
failure_message do |model|
|
12
|
-
I18n.t(
|
12
|
+
I18n.t(
|
13
|
+
'flash_validators.matchers.ensure_valid_credit_card_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(
|
20
|
+
I18n.t(
|
21
|
+
'flash_validators.matchers.ensure_valid_credit_card_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_currency_format_of do |attribute|
|
|
9
9
|
end
|
10
10
|
|
11
11
|
failure_message do |model|
|
12
|
-
I18n.t(
|
12
|
+
I18n.t(
|
13
|
+
'flash_validators.matchers.ensure_valid_currency_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(
|
20
|
+
I18n.t(
|
21
|
+
'flash_validators.matchers.ensure_valid_currency_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_cusip_format_of do |attribute|
|
2
|
+
match do |model|
|
3
|
+
model.send("#{attribute}=", "1234567890")
|
4
|
+
model.valid?
|
5
|
+
|
6
|
+
if model.errors.has_key?(attribute)
|
7
|
+
model.errors[attribute].include?(I18n.t('errors.messages.cusip'))
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
failure_message do |model|
|
12
|
+
I18n.t(
|
13
|
+
'flash_validators.matchers.ensure_valid_cusip_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_cusip_format_of.failure_message_for_should_not',
|
22
|
+
attr: attribute.inspect,
|
23
|
+
model: model.class.name
|
24
|
+
)
|
25
|
+
end
|
26
|
+
end
|
@@ -9,10 +9,18 @@ RSpec::Matchers.define :ensure_valid_email_format_of do |attribute|
|
|
9
9
|
end
|
10
10
|
|
11
11
|
failure_message do |model|
|
12
|
-
I18n.t(
|
12
|
+
I18n.t(
|
13
|
+
'flash_validators.matchers.ensure_valid_email_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(
|
20
|
+
I18n.t(
|
21
|
+
'flash_validators.matchers.ensure_valid_email_format_of.failure_message_for_should_not',
|
22
|
+
attr: attribute.inspect,
|
23
|
+
model: model.class.name
|
24
|
+
)
|
17
25
|
end
|
18
26
|
end
|
@@ -21,10 +21,20 @@ RSpec::Matchers.define :ensure_equality_of do |attribute|
|
|
21
21
|
end
|
22
22
|
|
23
23
|
failure_message do |model|
|
24
|
-
I18n.t(
|
24
|
+
I18n.t(
|
25
|
+
'flash_validators.matchers.ensure_valid_equality_format_of.failure_message_for_should',
|
26
|
+
attr: attribute.inspect,
|
27
|
+
model: model.class.name,
|
28
|
+
operator: "operator"
|
29
|
+
)
|
25
30
|
end
|
26
31
|
|
27
32
|
failure_message_when_negated do |model|
|
28
|
-
I18n.t(
|
33
|
+
I18n.t(
|
34
|
+
'flash_validators.matchers.ensure_valid_equality_format_of.failure_message_for_should_not',
|
35
|
+
attr: attribute.inspect,
|
36
|
+
model: model.class.name,
|
37
|
+
operator: "operator"
|
38
|
+
)
|
29
39
|
end
|
30
40
|
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
RSpec::Matchers.define :ensure_valid_gtin_format_of do |attribute|
|
2
|
+
match do |model|
|
3
|
+
model.send("#{attribute}=", "1234")
|
4
|
+
model.valid?
|
5
|
+
|
6
|
+
if model.errors.has_key?(attribute)
|
7
|
+
model.errors[attribute].include?(I18n.t('errors.messages.gtin'))
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
failure_message do |model|
|
12
|
+
I18n.t(
|
13
|
+
'flash_validators.matchers.ensure_valid_gtin_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_gtin_format_of.failure_message_for_should_not',
|
22
|
+
attr: attribute.inspect,
|
23
|
+
model: model.class.name
|
24
|
+
)
|
25
|
+
end
|
26
|
+
end
|
@@ -9,10 +9,18 @@ RSpec::Matchers.define :ensure_valid_hex_format_of do |attribute|
|
|
9
9
|
end
|
10
10
|
|
11
11
|
failure_message do |model|
|
12
|
-
I18n.t(
|
12
|
+
I18n.t(
|
13
|
+
'flash_validators.matchers.ensure_valid_hex_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(
|
20
|
+
I18n.t(
|
21
|
+
'flash_validators.matchers.ensure_valid_hex_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_imei_format_of do |attribute|
|
|
9
9
|
end
|
10
10
|
|
11
11
|
failure_message do |model|
|
12
|
-
I18n.t(
|
12
|
+
I18n.t(
|
13
|
+
'flash_validators.matchers.ensure_valid_imei_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(
|
20
|
+
I18n.t(
|
21
|
+
'flash_validators.matchers.ensure_valid_imei_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_ip_format_of do |attribute|
|
|
9
9
|
end
|
10
10
|
|
11
11
|
failure_message do |model|
|
12
|
-
I18n.t(
|
12
|
+
I18n.t(
|
13
|
+
'flash_validators.matchers.ensure_valid_ip_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(
|
20
|
+
I18n.t(
|
21
|
+
'flash_validators.matchers.ensure_valid_ip_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_isbn_format_of do |attribute|
|
|
9
9
|
end
|
10
10
|
|
11
11
|
failure_message do |model|
|
12
|
-
I18n.t(
|
12
|
+
I18n.t(
|
13
|
+
'flash_validators.matchers.ensure_valid_isbn_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(
|
20
|
+
I18n.t(
|
21
|
+
'flash_validators.matchers.ensure_valid_isbn_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_isin_format_of do |attribute|
|
2
|
+
match do |model|
|
3
|
+
model.send("#{attribute}=", "1234")
|
4
|
+
model.valid?
|
5
|
+
|
6
|
+
if model.errors.has_key?(attribute)
|
7
|
+
model.errors[attribute].include?(I18n.t('errors.messages.isin'))
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
failure_message do |model|
|
12
|
+
I18n.t(
|
13
|
+
'flash_validators.matchers.ensure_valid_isin_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_isin_format_of.failure_message_for_should_not',
|
22
|
+
attr: attribute.inspect,
|
23
|
+
model: model.class.name
|
24
|
+
)
|
25
|
+
end
|
26
|
+
end
|
@@ -9,10 +9,18 @@ RSpec::Matchers.define :ensure_valid_latitude_format_of do |attribute|
|
|
9
9
|
end
|
10
10
|
|
11
11
|
failure_message do |model|
|
12
|
-
I18n.t(
|
12
|
+
I18n.t(
|
13
|
+
'flash_validators.matchers.ensure_valid_latitude_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(
|
20
|
+
I18n.t(
|
21
|
+
'flash_validators.matchers.ensure_valid_latitude_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_longitude_format_of do |attribute|
|
|
9
9
|
end
|
10
10
|
|
11
11
|
failure_message do |model|
|
12
|
-
I18n.t(
|
12
|
+
I18n.t(
|
13
|
+
'flash_validators.matchers.ensure_valid_longitude_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(
|
20
|
+
I18n.t(
|
21
|
+
'flash_validators.matchers.ensure_valid_longitude_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_mac_address_format_of do |attribute|
|
|
9
9
|
end
|
10
10
|
|
11
11
|
failure_message do |model|
|
12
|
-
I18n.t(
|
12
|
+
I18n.t(
|
13
|
+
'flash_validators.matchers.ensure_valid_mac_address_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(
|
20
|
+
I18n.t(
|
21
|
+
'flash_validators.matchers.ensure_valid_mac_address_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_name_format_of do |attribute|
|
|
9
9
|
end
|
10
10
|
|
11
11
|
failure_message do |model|
|
12
|
-
I18n.t(
|
12
|
+
I18n.t(
|
13
|
+
'flash_validators.matchers.ensure_valid_name_format_of.failure_message_for_should',
|
14
|
+
attribute: attribute.inspect,
|
15
|
+
model: model.class.name
|
16
|
+
)
|
13
17
|
end
|
14
18
|
|
15
19
|
failure_message_when_negated do |model|
|
16
|
-
I18n.t(
|
20
|
+
I18n.t(
|
21
|
+
'flash_validators.matchers.ensure_valid_name_format_of.failure_message_for_should_not',
|
22
|
+
attribute: attribute.inspect,
|
23
|
+
model: model.class.name
|
24
|
+
)
|
17
25
|
end
|
18
26
|
end
|
@@ -9,10 +9,18 @@ RSpec::Matchers.define :ensure_valid_password_format_of do |attribute|
|
|
9
9
|
end
|
10
10
|
|
11
11
|
failure_message do |model|
|
12
|
-
I18n.t(
|
12
|
+
I18n.t(
|
13
|
+
'flash_validators.matchers.ensure_valid_password_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(
|
20
|
+
I18n.t(
|
21
|
+
'flash_validators.matchers.ensure_valid_password_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_phone_format_of do |attribute|
|
|
9
9
|
end
|
10
10
|
|
11
11
|
failure_message do |model|
|
12
|
-
I18n.t(
|
12
|
+
I18n.t(
|
13
|
+
'flash_validators.matchers.ensure_valid_phone_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(
|
20
|
+
I18n.t(
|
21
|
+
'flash_validators.matchers.ensure_valid_phone_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_sedol_format_of do |attribute|
|
2
|
+
match do |model|
|
3
|
+
model.send("#{attribute}=", "1234")
|
4
|
+
model.valid?
|
5
|
+
|
6
|
+
if model.errors.has_key?(attribute)
|
7
|
+
model.errors[attribute].include?(I18n.t('errors.messages.sedol'))
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
failure_message do |model|
|
12
|
+
I18n.t(
|
13
|
+
'flash_validators.matchers.ensure_valid_sedol_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_sedol_format_of.failure_message_for_should_not',
|
22
|
+
attr: attribute.inspect,
|
23
|
+
model: model.class.name
|
24
|
+
)
|
25
|
+
end
|
26
|
+
end
|
@@ -9,10 +9,18 @@ RSpec::Matchers.define :ensure_valid_slug_format_of do |attribute|
|
|
9
9
|
end
|
10
10
|
|
11
11
|
failure_message do |model|
|
12
|
-
I18n.t(
|
12
|
+
I18n.t(
|
13
|
+
'flash_validators.matchers.ensure_valid_slug_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(
|
20
|
+
I18n.t(
|
21
|
+
'flash_validators.matchers.ensure_valid_slug_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_ssn_format_of do |attribute|
|
|
9
9
|
end
|
10
10
|
|
11
11
|
failure_message do |model|
|
12
|
-
I18n.t(
|
12
|
+
I18n.t(
|
13
|
+
'flash_validators.matchers.ensure_valid_ssn_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(
|
20
|
+
I18n.t(
|
21
|
+
'flash_validators.matchers.ensure_valid_ssn_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_url_format_of do |attribute|
|
|
9
9
|
end
|
10
10
|
|
11
11
|
failure_message do |model|
|
12
|
-
I18n.t(
|
12
|
+
I18n.t(
|
13
|
+
'flash_validators.matchers.ensure_valid_url_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(
|
20
|
+
I18n.t(
|
21
|
+
'flash_validators.matchers.ensure_valid_url_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_username_format_of do |attribute|
|
|
9
9
|
end
|
10
10
|
|
11
11
|
failure_message do |model|
|
12
|
-
I18n.t(
|
12
|
+
I18n.t(
|
13
|
+
'flash_validators.matchers.ensure_valid_username_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(
|
20
|
+
I18n.t(
|
21
|
+
'flash_validators.matchers.ensure_valid_username_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_uuid_format_of do |attribute|
|
2
|
+
match do |model|
|
3
|
+
model.send("#{attribute}=", "1234uuid")
|
4
|
+
model.valid?
|
5
|
+
|
6
|
+
if model.errors.has_key?(attribute)
|
7
|
+
model.errors[attribute].include?(I18n.t('errors.messages.uuid'))
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
failure_message do |model|
|
12
|
+
I18n.t(
|
13
|
+
'flash_validators.matchers.ensure_valid_uuid_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_uuid_format_of.failure_message_for_should_not',
|
22
|
+
attr: attribute.inspect,
|
23
|
+
model: model.class.name
|
24
|
+
)
|
25
|
+
end
|
26
|
+
end
|
@@ -1,17 +1,31 @@
|
|
1
1
|
class AlphaNumericValidator < ActiveModel::EachValidator
|
2
2
|
|
3
3
|
def validate_each(record, attribute, value)
|
4
|
-
|
4
|
+
unless valid?(value, options)
|
5
|
+
record.errors[attribute] << (options[:message] || I18n.t('errors.messages.alpha_numeric'))
|
6
|
+
end
|
7
|
+
end
|
5
8
|
|
6
|
-
|
7
|
-
|
9
|
+
private
|
10
|
+
|
11
|
+
def valid_format?(value, options)
|
12
|
+
case options[:case]
|
13
|
+
when :lower
|
14
|
+
options[:strict] ? (value =~ /^[a-z0-9]+$/) : (value =~ /^[a-z0-9 ]+$/)
|
15
|
+
when :upper
|
16
|
+
options[:strict] ? (value =~ /^[A-Z0-9]+$/) : (value =~ /^[A-Z0-9 ]+$/)
|
8
17
|
else
|
9
|
-
|
18
|
+
options[:strict] ? (value =~ /^[A-Za-z0-9]+$/i) : (value =~ /^[A-Za-z0-9 ]+$/i)
|
10
19
|
end
|
20
|
+
end
|
11
21
|
|
12
|
-
|
13
|
-
|
14
|
-
|
22
|
+
def valid_length?(value)
|
23
|
+
value != ' '
|
24
|
+
end
|
25
|
+
|
26
|
+
def valid?(value, options)
|
27
|
+
valid_format?(value, options) &&
|
28
|
+
valid_length?(value)
|
15
29
|
end
|
16
30
|
|
17
31
|
end
|
@@ -1,19 +1,31 @@
|
|
1
1
|
class AlphaValidator < ActiveModel::EachValidator
|
2
2
|
|
3
3
|
def validate_each(record, attribute, value)
|
4
|
-
|
5
|
-
|
6
|
-
elsif options[:lowercase]
|
7
|
-
format = /^[a-z]+$/
|
8
|
-
elsif options[:uppercase]
|
9
|
-
format = /^[A-Z]+$/
|
10
|
-
else
|
11
|
-
format = /^[A-Za-z ]+$/i
|
4
|
+
unless valid?(value, options)
|
5
|
+
record.errors[attribute] << (options[:message] || I18n.t('errors.messages.alpha'))
|
12
6
|
end
|
7
|
+
end
|
13
8
|
|
14
|
-
|
15
|
-
|
9
|
+
private
|
10
|
+
|
11
|
+
def valid_format?(value, options)
|
12
|
+
case options[:case]
|
13
|
+
when :lower
|
14
|
+
options[:strict] ? (value =~ /^[a-z]+$/) : (value =~ /^[a-z ]+$/)
|
15
|
+
when :upper
|
16
|
+
options[:strict] ? (value =~ /^[A-Z]+$/) : (value =~ /^[A-Z ]+$/)
|
17
|
+
else
|
18
|
+
options[:strict] ? (value =~ /^[A-Za-z]+$/i) : (value =~ /^[A-Za-z ]+$/i)
|
16
19
|
end
|
17
20
|
end
|
18
21
|
|
22
|
+
def valid_length?(value)
|
23
|
+
value != ' '
|
24
|
+
end
|
25
|
+
|
26
|
+
def valid?(value, options)
|
27
|
+
valid_format?(value, options) &&
|
28
|
+
valid_length?(value)
|
29
|
+
end
|
30
|
+
|
19
31
|
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
class Base64Validator < ActiveModel::EachValidator
|
2
|
+
|
3
|
+
def validate_each(record, attribute, value)
|
4
|
+
unless value =~ /^(?:[A-Za-z0-9+$]{4})*(?:[A-Za-z0-9+$]{2}==|[A-Za-z0-9+$]{3}=|[A-Za-z0-9+$]{4})$/
|
5
|
+
record.errors[attribute] << (options[:message] || I18n.t('errors.messages.base64'))
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
end
|