active_validation 1.1.0 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (58) hide show
  1. checksums.yaml +4 -4
  2. data/Rakefile +3 -1
  3. data/active_validation.gemspec +1 -0
  4. data/config/locales/en.yml +4 -0
  5. data/lib/active_validation/matchers/ensure_valid_alpha_format_of.rb +2 -2
  6. data/lib/active_validation/matchers/ensure_valid_alpha_numeric_format_of.rb +2 -2
  7. data/lib/active_validation/matchers/ensure_valid_base64_format_of.rb +2 -2
  8. data/lib/active_validation/matchers/ensure_valid_boolean_format_of.rb +2 -2
  9. data/lib/active_validation/matchers/ensure_valid_coordinate_format_of.rb +2 -2
  10. data/lib/active_validation/matchers/ensure_valid_credit_card_format_of.rb +2 -2
  11. data/lib/active_validation/matchers/ensure_valid_currency_format_of.rb +2 -2
  12. data/lib/active_validation/matchers/ensure_valid_cusip_format_of.rb +2 -2
  13. data/lib/active_validation/matchers/ensure_valid_email_format_of.rb +2 -2
  14. data/lib/active_validation/matchers/ensure_valid_equality_matcher_of.rb +2 -2
  15. data/lib/active_validation/matchers/ensure_valid_hex_format_of.rb +2 -2
  16. data/lib/active_validation/matchers/ensure_valid_imei_format_of.rb +2 -2
  17. data/lib/active_validation/matchers/ensure_valid_ip_format_of.rb +2 -2
  18. data/lib/active_validation/matchers/ensure_valid_isbn_format_of.rb +2 -2
  19. data/lib/active_validation/matchers/ensure_valid_isin_format_of.rb +2 -2
  20. data/lib/active_validation/matchers/ensure_valid_mac_address_format_of.rb +2 -2
  21. data/lib/active_validation/matchers/ensure_valid_name_format_of.rb +2 -2
  22. data/lib/active_validation/matchers/ensure_valid_password_format_of.rb +2 -2
  23. data/lib/active_validation/matchers/ensure_valid_phone_format_of.rb +2 -2
  24. data/lib/active_validation/matchers/ensure_valid_sedol_format_of.rb +2 -2
  25. data/lib/active_validation/matchers/ensure_valid_slug_format_of.rb +2 -2
  26. data/lib/active_validation/matchers/ensure_valid_ssn_format_of.rb +2 -2
  27. data/lib/active_validation/matchers/ensure_valid_tracking_number_format_of.rb +26 -0
  28. data/lib/active_validation/matchers/ensure_valid_url_format_of.rb +2 -2
  29. data/lib/active_validation/matchers/ensure_valid_username_format_of.rb +2 -2
  30. data/lib/active_validation/matchers/ensure_valid_uuid_format_of.rb +2 -2
  31. data/lib/active_validation/validators/alpha_numeric_validator.rb +10 -7
  32. data/lib/active_validation/validators/alpha_validator.rb +10 -8
  33. data/lib/active_validation/validators/base64_validator.rb +16 -1
  34. data/lib/active_validation/validators/coordinate_validator.rb +12 -3
  35. data/lib/active_validation/validators/credit_card_validator.rb +10 -10
  36. data/lib/active_validation/validators/currency_validator.rb +7 -6
  37. data/lib/active_validation/validators/cusip_validator.rb +11 -9
  38. data/lib/active_validation/validators/email_validator.rb +11 -7
  39. data/lib/active_validation/validators/equality_validator.rb +14 -7
  40. data/lib/active_validation/validators/hex_validator.rb +16 -1
  41. data/lib/active_validation/validators/imei_validator.rb +14 -12
  42. data/lib/active_validation/validators/ip_validator.rb +16 -1
  43. data/lib/active_validation/validators/isbn_validator.rb +8 -4
  44. data/lib/active_validation/validators/isin_validator.rb +16 -14
  45. data/lib/active_validation/validators/mac_address_validator.rb +21 -7
  46. data/lib/active_validation/validators/name_validator.rb +16 -1
  47. data/lib/active_validation/validators/password_validator.rb +7 -6
  48. data/lib/active_validation/validators/phone_validator.rb +16 -1
  49. data/lib/active_validation/validators/sedol_validator.rb +15 -10
  50. data/lib/active_validation/validators/slug_validator.rb +16 -1
  51. data/lib/active_validation/validators/ssn_validator.rb +16 -1
  52. data/lib/active_validation/validators/tracking_number_validator.rb +235 -0
  53. data/lib/active_validation/validators/url_validator.rb +11 -2
  54. data/lib/active_validation/validators/username_validator.rb +16 -1
  55. data/lib/active_validation/validators/uuid_validator.rb +11 -6
  56. data/lib/active_validation/version.rb +1 -1
  57. data/lib/active_validation.rb +5 -6
  58. metadata +18 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b5ccff82b8b3a8db274c0bbc81e53cd8bb8d13b8
4
- data.tar.gz: dad2de52f03c0c04804e5c9f38c4628223edce97
3
+ metadata.gz: 30fc4f9a1e1513760c6a6e89377de0ec0fad9986
4
+ data.tar.gz: 5c53383b55cbe7500f0665375035599b759ae9f8
5
5
  SHA512:
6
- metadata.gz: 671b0fd59813c7fee27ef9c77a54beeba2e828162b06a94666eecd54f7f4036e31f820aef3ee59031e4c35ea6db2dd174b1596cf22f35084e49179060e8fc78d
7
- data.tar.gz: 28b97dc6717a429579c7d24a4e50e461001eabf94abf9418f074171cf294509a23a145294e07563ec99a1c3790579d2bb5b23db22592e291f2bb72b5fb0cceab
6
+ metadata.gz: 899cd1d1afea9f43a373f483d8ebb18bb12191e4f85f903332529f29ed0f57602d2754ff48b6a9f3604b0bd16aa2cb7b2aa2a1b5dbce4325851a8e64908fbff0
7
+ data.tar.gz: 5aac70ad5078bdecd33492af3c9bb1cb4a82e0496bfe757fbe10c660a72e57a9db2b7f4bea14609c872cfa99df6e06867019b687f5d03b0b30bba624a82ec82c
data/Rakefile CHANGED
@@ -1 +1,3 @@
1
- require "bundler/gem_tasks"
1
+ require "bundler/gem_tasks"
2
+
3
+ task default: :spec
@@ -21,6 +21,7 @@ Gem::Specification.new do |spec|
21
21
 
22
22
  spec.add_runtime_dependency "activemodel"
23
23
  spec.add_runtime_dependency "activesupport"
24
+ spec.add_runtime_dependency "active_object"
24
25
 
25
26
  spec.add_development_dependency "bundler"
26
27
  spec.add_development_dependency "coveralls"
@@ -27,6 +27,7 @@ en:
27
27
  sedol: "is not a valid SEDOL"
28
28
  slug: "is not a valid slug"
29
29
  ssn: "is not a valid social security number"
30
+ tracking_number: "is not a valid tracking number"
30
31
  url: "is not a valid URL"
31
32
  username: "is not a valid username"
32
33
  uuid: "is not a valid UUID"
@@ -97,6 +98,9 @@ en:
97
98
  ensure_valid_ssn_format_of:
98
99
  failure_message_for_should: "%{model} should ensure valid SSN format of attribute %{attr}"
99
100
  failure_message_for_should_not: "%{model} should not ensure valid SSN format of attribute %{attr}"
101
+ ensure_valid_tracking_number_format_of:
102
+ failure_message_for_should: "%{model} should ensure valid tracking number format of attribute %{attr}"
103
+ failure_message_for_should_not: "%{model} should not ensure valid tracking number format of attribute %{attr}"
100
104
  ensure_valid_url_format_of:
101
105
  failure_message_for_should: "%{model} should ensure valid URL format of attribute %{attr}"
102
106
  failure_message_for_should_not: "%{model} should not ensure valid URL format of attribute %{attr}"
@@ -10,7 +10,7 @@ RSpec::Matchers.define :ensure_valid_alpha_format_of do |attribute|
10
10
 
11
11
  failure_message do |model|
12
12
  I18n.t(
13
- 'active_validation.matchers.ensure_valid_alpha_format_of.failure_message_for_should',
13
+ 'active_validation.errors.matchers.ensure_valid_alpha_format_of.failure_message_for_should',
14
14
  attr: attribute.inspect,
15
15
  model: model.class.name
16
16
  )
@@ -18,7 +18,7 @@ RSpec::Matchers.define :ensure_valid_alpha_format_of do |attribute|
18
18
 
19
19
  failure_message_when_negated do |model|
20
20
  I18n.t(
21
- 'active_validation.matchers.ensure_valid_alpha_format_of.failure_message_for_should_not',
21
+ 'active_validation.errors.matchers.ensure_valid_alpha_format_of.failure_message_for_should_not',
22
22
  attr: attribute.inspect,
23
23
  model: model.class.name
24
24
  )
@@ -10,7 +10,7 @@ RSpec::Matchers.define :ensure_valid_alpha_numeric_format_of do |attribute|
10
10
 
11
11
  failure_message do |model|
12
12
  I18n.t(
13
- 'active_validation.matchers.ensure_valid_alpha_numeric_format_of.failure_message_for_should',
13
+ 'active_validation.errors.matchers.ensure_valid_alpha_numeric_format_of.failure_message_for_should',
14
14
  attr: attribute.inspect,
15
15
  model: model.class.name
16
16
  )
@@ -18,7 +18,7 @@ RSpec::Matchers.define :ensure_valid_alpha_numeric_format_of do |attribute|
18
18
 
19
19
  failure_message_when_negated do |model|
20
20
  I18n.t(
21
- 'active_validation.matchers.ensure_valid_alpha_numeric_format_of.failure_message_for_should_not',
21
+ 'active_validation.errors.matchers.ensure_valid_alpha_numeric_format_of.failure_message_for_should_not',
22
22
  attr: attribute.inspect,
23
23
  model: model.class.name
24
24
  )
@@ -10,7 +10,7 @@ RSpec::Matchers.define :ensure_valid_base64_format_of do |attribute|
10
10
 
11
11
  failure_message do |model|
12
12
  I18n.t(
13
- 'active_validation.matchers.ensure_valid_base64_format_of.failure_message_for_should',
13
+ 'active_validation.errors.matchers.ensure_valid_base64_format_of.failure_message_for_should',
14
14
  attr: attribute.inspect,
15
15
  model: model.class.name
16
16
  )
@@ -18,7 +18,7 @@ RSpec::Matchers.define :ensure_valid_base64_format_of do |attribute|
18
18
 
19
19
  failure_message_when_negated do |model|
20
20
  I18n.t(
21
- 'active_validation.matchers.ensure_valid_base64_format_of.failure_message_for_should_not',
21
+ 'active_validation.errors.matchers.ensure_valid_base64_format_of.failure_message_for_should_not',
22
22
  attr: attribute.inspect,
23
23
  model: model.class.name
24
24
  )
@@ -10,7 +10,7 @@ RSpec::Matchers.define :ensure_valid_boolean_format_of do |attribute|
10
10
 
11
11
  failure_message do |model|
12
12
  I18n.t(
13
- 'active_validation.matchers.ensure_valid_boolean_format_of.failure_message_for_should',
13
+ 'active_validation.errors.matchers.ensure_valid_boolean_format_of.failure_message_for_should',
14
14
  attr: attribute.inspect,
15
15
  model: model.class.name
16
16
  )
@@ -18,7 +18,7 @@ RSpec::Matchers.define :ensure_valid_boolean_format_of do |attribute|
18
18
 
19
19
  failure_message_when_negated do |model|
20
20
  I18n.t(
21
- 'active_validation.matchers.ensure_valid_boolean_format_of.failure_message_for_should_not',
21
+ 'active_validation.errors.matchers.ensure_valid_boolean_format_of.failure_message_for_should_not',
22
22
  attr: attribute.inspect,
23
23
  model: model.class.name
24
24
  )
@@ -10,7 +10,7 @@ RSpec::Matchers.define :ensure_valid_coordinate_format_of do |attribute|
10
10
 
11
11
  failure_message do |model|
12
12
  I18n.t(
13
- 'active_validation.matchers.ensure_valid_coordinate_format_of.failure_message_for_should',
13
+ 'active_validation.errors.matchers.ensure_valid_coordinate_format_of.failure_message_for_should',
14
14
  attr: attribute.inspect,
15
15
  model: model.class.name
16
16
  )
@@ -18,7 +18,7 @@ RSpec::Matchers.define :ensure_valid_coordinate_format_of do |attribute|
18
18
 
19
19
  failure_message_when_negated do |model|
20
20
  I18n.t(
21
- 'active_validation.matchers.ensure_valid_coordinate_format_of.failure_message_for_should_not',
21
+ 'active_validation.errors.matchers.ensure_valid_coordinate_format_of.failure_message_for_should_not',
22
22
  attr: attribute.inspect,
23
23
  model: model.class.name
24
24
  )
@@ -10,7 +10,7 @@ RSpec::Matchers.define :ensure_valid_credit_card_format_of do |attribute|
10
10
 
11
11
  failure_message do |model|
12
12
  I18n.t(
13
- 'active_validation.matchers.ensure_valid_credit_card_format_of.failure_message_for_should',
13
+ 'active_validation.errors.matchers.ensure_valid_credit_card_format_of.failure_message_for_should',
14
14
  attr: attribute.inspect,
15
15
  model: model.class.name
16
16
  )
@@ -18,7 +18,7 @@ RSpec::Matchers.define :ensure_valid_credit_card_format_of do |attribute|
18
18
 
19
19
  failure_message_when_negated do |model|
20
20
  I18n.t(
21
- 'active_validation.matchers.ensure_valid_credit_card_format_of.failure_message_for_should_not',
21
+ 'active_validation.errors.matchers.ensure_valid_credit_card_format_of.failure_message_for_should_not',
22
22
  attr: attribute.inspect,
23
23
  model: model.class.name
24
24
  )
@@ -10,7 +10,7 @@ RSpec::Matchers.define :ensure_valid_currency_format_of do |attribute|
10
10
 
11
11
  failure_message do |model|
12
12
  I18n.t(
13
- 'active_validation.matchers.ensure_valid_currency_format_of.failure_message_for_should',
13
+ 'active_validation.errors.matchers.ensure_valid_currency_format_of.failure_message_for_should',
14
14
  attr: attribute.inspect,
15
15
  model: model.class.name
16
16
  )
@@ -18,7 +18,7 @@ RSpec::Matchers.define :ensure_valid_currency_format_of do |attribute|
18
18
 
19
19
  failure_message_when_negated do |model|
20
20
  I18n.t(
21
- 'active_validation.matchers.ensure_valid_currency_format_of.failure_message_for_should_not',
21
+ 'active_validation.errors.matchers.ensure_valid_currency_format_of.failure_message_for_should_not',
22
22
  attr: attribute.inspect,
23
23
  model: model.class.name
24
24
  )
@@ -10,7 +10,7 @@ RSpec::Matchers.define :ensure_valid_cusip_format_of do |attribute|
10
10
 
11
11
  failure_message do |model|
12
12
  I18n.t(
13
- 'active_validation.matchers.ensure_valid_cusip_format_of.failure_message_for_should',
13
+ 'active_validation.errors.matchers.ensure_valid_cusip_format_of.failure_message_for_should',
14
14
  attr: attribute.inspect,
15
15
  model: model.class.name
16
16
  )
@@ -18,7 +18,7 @@ RSpec::Matchers.define :ensure_valid_cusip_format_of do |attribute|
18
18
 
19
19
  failure_message_when_negated do |model|
20
20
  I18n.t(
21
- 'active_validation.matchers.ensure_valid_cusip_format_of.failure_message_for_should_not',
21
+ 'active_validation.errors.matchers.ensure_valid_cusip_format_of.failure_message_for_should_not',
22
22
  attr: attribute.inspect,
23
23
  model: model.class.name
24
24
  )
@@ -10,7 +10,7 @@ RSpec::Matchers.define :ensure_valid_email_format_of do |attribute|
10
10
 
11
11
  failure_message do |model|
12
12
  I18n.t(
13
- 'active_validation.matchers.ensure_valid_email_format_of.failure_message_for_should',
13
+ 'active_validation.errors.matchers.ensure_valid_email_format_of.failure_message_for_should',
14
14
  attr: attribute.inspect,
15
15
  model: model.class.name
16
16
  )
@@ -18,7 +18,7 @@ RSpec::Matchers.define :ensure_valid_email_format_of do |attribute|
18
18
 
19
19
  failure_message_when_negated do |model|
20
20
  I18n.t(
21
- 'active_validation.matchers.ensure_valid_email_format_of.failure_message_for_should_not',
21
+ 'active_validation.errors.matchers.ensure_valid_email_format_of.failure_message_for_should_not',
22
22
  attr: attribute.inspect,
23
23
  model: model.class.name
24
24
  )
@@ -22,7 +22,7 @@ RSpec::Matchers.define :ensure_equality_of do |attribute|
22
22
 
23
23
  failure_message do |model|
24
24
  I18n.t(
25
- 'active_validation.matchers.ensure_valid_equality_format_of.failure_message_for_should',
25
+ 'active_validation.errors.matchers.ensure_valid_equality_format_of.failure_message_for_should',
26
26
  attr: attribute.inspect,
27
27
  model: model.class.name,
28
28
  operator: "operator"
@@ -31,7 +31,7 @@ RSpec::Matchers.define :ensure_equality_of do |attribute|
31
31
 
32
32
  failure_message_when_negated do |model|
33
33
  I18n.t(
34
- 'active_validation.matchers.ensure_valid_equality_format_of.failure_message_for_should_not',
34
+ 'active_validation.errors.matchers.ensure_valid_equality_format_of.failure_message_for_should_not',
35
35
  attr: attribute.inspect,
36
36
  model: model.class.name,
37
37
  operator: "operator"
@@ -10,7 +10,7 @@ RSpec::Matchers.define :ensure_valid_hex_format_of do |attribute|
10
10
 
11
11
  failure_message do |model|
12
12
  I18n.t(
13
- 'active_validation.matchers.ensure_valid_hex_format_of.failure_message_for_should',
13
+ 'active_validation.errors.matchers.ensure_valid_hex_format_of.failure_message_for_should',
14
14
  attr: attribute.inspect,
15
15
  model: model.class.name
16
16
  )
@@ -18,7 +18,7 @@ RSpec::Matchers.define :ensure_valid_hex_format_of do |attribute|
18
18
 
19
19
  failure_message_when_negated do |model|
20
20
  I18n.t(
21
- 'active_validation.matchers.ensure_valid_hex_format_of.failure_message_for_should_not',
21
+ 'active_validation.errors.matchers.ensure_valid_hex_format_of.failure_message_for_should_not',
22
22
  attr: attribute.inspect,
23
23
  model: model.class.name
24
24
  )
@@ -10,7 +10,7 @@ RSpec::Matchers.define :ensure_valid_imei_format_of do |attribute|
10
10
 
11
11
  failure_message do |model|
12
12
  I18n.t(
13
- 'active_validation.matchers.ensure_valid_imei_format_of.failure_message_for_should',
13
+ 'active_validation.errors.matchers.ensure_valid_imei_format_of.failure_message_for_should',
14
14
  attr: attribute.inspect,
15
15
  model: model.class.name
16
16
  )
@@ -18,7 +18,7 @@ RSpec::Matchers.define :ensure_valid_imei_format_of do |attribute|
18
18
 
19
19
  failure_message_when_negated do |model|
20
20
  I18n.t(
21
- 'active_validation.matchers.ensure_valid_imei_format_of.failure_message_for_should_not',
21
+ 'active_validation.errors.matchers.ensure_valid_imei_format_of.failure_message_for_should_not',
22
22
  attr: attribute.inspect,
23
23
  model: model.class.name
24
24
  )
@@ -10,7 +10,7 @@ RSpec::Matchers.define :ensure_valid_ip_format_of do |attribute|
10
10
 
11
11
  failure_message do |model|
12
12
  I18n.t(
13
- 'active_validation.matchers.ensure_valid_ip_format_of.failure_message_for_should',
13
+ 'active_validation.errors.matchers.ensure_valid_ip_format_of.failure_message_for_should',
14
14
  attr: attribute.inspect,
15
15
  model: model.class.name
16
16
  )
@@ -18,7 +18,7 @@ RSpec::Matchers.define :ensure_valid_ip_format_of do |attribute|
18
18
 
19
19
  failure_message_when_negated do |model|
20
20
  I18n.t(
21
- 'active_validation.matchers.ensure_valid_ip_format_of.failure_message_for_should_not',
21
+ 'active_validation.errors.matchers.ensure_valid_ip_format_of.failure_message_for_should_not',
22
22
  attr: attribute.inspect,
23
23
  model: model.class.name
24
24
  )
@@ -10,7 +10,7 @@ RSpec::Matchers.define :ensure_valid_isbn_format_of do |attribute|
10
10
 
11
11
  failure_message do |model|
12
12
  I18n.t(
13
- 'active_validation.matchers.ensure_valid_isbn_format_of.failure_message_for_should',
13
+ 'active_validation.errors.matchers.ensure_valid_isbn_format_of.failure_message_for_should',
14
14
  attr: attribute.inspect,
15
15
  model: model.class.name
16
16
  )
@@ -18,7 +18,7 @@ RSpec::Matchers.define :ensure_valid_isbn_format_of do |attribute|
18
18
 
19
19
  failure_message_when_negated do |model|
20
20
  I18n.t(
21
- 'active_validation.matchers.ensure_valid_isbn_format_of.failure_message_for_should_not',
21
+ 'active_validation.errors.matchers.ensure_valid_isbn_format_of.failure_message_for_should_not',
22
22
  attr: attribute.inspect,
23
23
  model: model.class.name
24
24
  )
@@ -10,7 +10,7 @@ RSpec::Matchers.define :ensure_valid_isin_format_of do |attribute|
10
10
 
11
11
  failure_message do |model|
12
12
  I18n.t(
13
- 'active_validation.matchers.ensure_valid_isin_format_of.failure_message_for_should',
13
+ 'active_validation.errors.matchers.ensure_valid_isin_format_of.failure_message_for_should',
14
14
  attr: attribute.inspect,
15
15
  model: model.class.name
16
16
  )
@@ -18,7 +18,7 @@ RSpec::Matchers.define :ensure_valid_isin_format_of do |attribute|
18
18
 
19
19
  failure_message_when_negated do |model|
20
20
  I18n.t(
21
- 'active_validation.matchers.ensure_valid_isin_format_of.failure_message_for_should_not',
21
+ 'active_validation.errors.matchers.ensure_valid_isin_format_of.failure_message_for_should_not',
22
22
  attr: attribute.inspect,
23
23
  model: model.class.name
24
24
  )
@@ -10,7 +10,7 @@ RSpec::Matchers.define :ensure_valid_mac_address_format_of do |attribute|
10
10
 
11
11
  failure_message do |model|
12
12
  I18n.t(
13
- 'active_validation.matchers.ensure_valid_mac_address_format_of.failure_message_for_should',
13
+ 'active_validation.errors.matchers.ensure_valid_mac_address_format_of.failure_message_for_should',
14
14
  attr: attribute.inspect,
15
15
  model: model.class.name
16
16
  )
@@ -18,7 +18,7 @@ RSpec::Matchers.define :ensure_valid_mac_address_format_of do |attribute|
18
18
 
19
19
  failure_message_when_negated do |model|
20
20
  I18n.t(
21
- 'active_validation.matchers.ensure_valid_mac_address_format_of.failure_message_for_should_not',
21
+ 'active_validation.errors.matchers.ensure_valid_mac_address_format_of.failure_message_for_should_not',
22
22
  attr: attribute.inspect,
23
23
  model: model.class.name
24
24
  )
@@ -10,7 +10,7 @@ RSpec::Matchers.define :ensure_valid_name_format_of do |attribute|
10
10
 
11
11
  failure_message do |model|
12
12
  I18n.t(
13
- 'active_validation.matchers.ensure_valid_name_format_of.failure_message_for_should',
13
+ 'active_validation.errors.matchers.ensure_valid_name_format_of.failure_message_for_should',
14
14
  attribute: attribute.inspect,
15
15
  model: model.class.name
16
16
  )
@@ -18,7 +18,7 @@ RSpec::Matchers.define :ensure_valid_name_format_of do |attribute|
18
18
 
19
19
  failure_message_when_negated do |model|
20
20
  I18n.t(
21
- 'active_validation.matchers.ensure_valid_name_format_of.failure_message_for_should_not',
21
+ 'active_validation.errors.matchers.ensure_valid_name_format_of.failure_message_for_should_not',
22
22
  attribute: attribute.inspect,
23
23
  model: model.class.name
24
24
  )
@@ -10,7 +10,7 @@ RSpec::Matchers.define :ensure_valid_password_format_of do |attribute|
10
10
 
11
11
  failure_message do |model|
12
12
  I18n.t(
13
- 'active_validation.matchers.ensure_valid_password_format_of.failure_message_for_should',
13
+ 'active_validation.errors.matchers.ensure_valid_password_format_of.failure_message_for_should',
14
14
  attr: attribute.inspect,
15
15
  model: model.class.name
16
16
  )
@@ -18,7 +18,7 @@ RSpec::Matchers.define :ensure_valid_password_format_of do |attribute|
18
18
 
19
19
  failure_message_when_negated do |model|
20
20
  I18n.t(
21
- 'active_validation.matchers.ensure_valid_password_format_of.failure_message_for_should_not',
21
+ 'active_validation.errors.matchers.ensure_valid_password_format_of.failure_message_for_should_not',
22
22
  attr: attribute.inspect,
23
23
  model: model.class.name
24
24
  )
@@ -10,7 +10,7 @@ RSpec::Matchers.define :ensure_valid_phone_format_of do |attribute|
10
10
 
11
11
  failure_message do |model|
12
12
  I18n.t(
13
- 'active_validation.matchers.ensure_valid_phone_format_of.failure_message_for_should',
13
+ 'active_validation.errors.matchers.ensure_valid_phone_format_of.failure_message_for_should',
14
14
  attr: attribute.inspect,
15
15
  model: model.class.name
16
16
  )
@@ -18,7 +18,7 @@ RSpec::Matchers.define :ensure_valid_phone_format_of do |attribute|
18
18
 
19
19
  failure_message_when_negated do |model|
20
20
  I18n.t(
21
- 'active_validation.matchers.ensure_valid_phone_format_of.failure_message_for_should_not',
21
+ 'active_validation.errors.matchers.ensure_valid_phone_format_of.failure_message_for_should_not',
22
22
  attr: attribute.inspect,
23
23
  model: model.class.name
24
24
  )
@@ -10,7 +10,7 @@ RSpec::Matchers.define :ensure_valid_sedol_format_of do |attribute|
10
10
 
11
11
  failure_message do |model|
12
12
  I18n.t(
13
- 'active_validation.matchers.ensure_valid_sedol_format_of.failure_message_for_should',
13
+ 'active_validation.errors.matchers.ensure_valid_sedol_format_of.failure_message_for_should',
14
14
  attr: attribute.inspect,
15
15
  model: model.class.name
16
16
  )
@@ -18,7 +18,7 @@ RSpec::Matchers.define :ensure_valid_sedol_format_of do |attribute|
18
18
 
19
19
  failure_message_when_negated do |model|
20
20
  I18n.t(
21
- 'active_validation.matchers.ensure_valid_sedol_format_of.failure_message_for_should_not',
21
+ 'active_validation.errors.matchers.ensure_valid_sedol_format_of.failure_message_for_should_not',
22
22
  attr: attribute.inspect,
23
23
  model: model.class.name
24
24
  )
@@ -10,7 +10,7 @@ RSpec::Matchers.define :ensure_valid_slug_format_of do |attribute|
10
10
 
11
11
  failure_message do |model|
12
12
  I18n.t(
13
- 'active_validation.matchers.ensure_valid_slug_format_of.failure_message_for_should',
13
+ 'active_validation.errors.matchers.ensure_valid_slug_format_of.failure_message_for_should',
14
14
  attr: attribute.inspect,
15
15
  model: model.class.name
16
16
  )
@@ -18,7 +18,7 @@ RSpec::Matchers.define :ensure_valid_slug_format_of do |attribute|
18
18
 
19
19
  failure_message_when_negated do |model|
20
20
  I18n.t(
21
- 'active_validation.matchers.ensure_valid_slug_format_of.failure_message_for_should_not',
21
+ 'active_validation.errors.matchers.ensure_valid_slug_format_of.failure_message_for_should_not',
22
22
  attr: attribute.inspect,
23
23
  model: model.class.name
24
24
  )
@@ -10,7 +10,7 @@ RSpec::Matchers.define :ensure_valid_ssn_format_of do |attribute|
10
10
 
11
11
  failure_message do |model|
12
12
  I18n.t(
13
- 'active_validation.matchers.ensure_valid_ssn_format_of.failure_message_for_should',
13
+ 'active_validation.errors.matchers.ensure_valid_ssn_format_of.failure_message_for_should',
14
14
  attr: attribute.inspect,
15
15
  model: model.class.name
16
16
  )
@@ -18,7 +18,7 @@ RSpec::Matchers.define :ensure_valid_ssn_format_of do |attribute|
18
18
 
19
19
  failure_message_when_negated do |model|
20
20
  I18n.t(
21
- 'active_validation.matchers.ensure_valid_ssn_format_of.failure_message_for_should_not',
21
+ 'active_validation.errors.matchers.ensure_valid_ssn_format_of.failure_message_for_should_not',
22
22
  attr: attribute.inspect,
23
23
  model: model.class.name
24
24
  )
@@ -0,0 +1,26 @@
1
+ RSpec::Matchers.define :ensure_valid_tracking_number_format_of do |attribute|
2
+ match do |model|
3
+ model.send("#{attribute}=", "3318810026")
4
+ model.valid?
5
+
6
+ if model.errors.has_key?(attribute)
7
+ model.errors[attribute].include?(I18n.t('active_validation.errors.messages.tracking_number'))
8
+ end
9
+ end
10
+
11
+ failure_message do |model|
12
+ I18n.t(
13
+ 'active_validation.errors.matchers.ensure_valid_tracking_number_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
+ 'active_validation.errors.matchers.ensure_valid_tracking_number_format_of.failure_message_for_should_not',
22
+ attr: attribute.inspect,
23
+ model: model.class.name
24
+ )
25
+ end
26
+ end
@@ -10,7 +10,7 @@ RSpec::Matchers.define :ensure_valid_url_format_of do |attribute|
10
10
 
11
11
  failure_message do |model|
12
12
  I18n.t(
13
- 'active_validation.matchers.ensure_valid_url_format_of.failure_message_for_should',
13
+ 'active_validation.errors.matchers.ensure_valid_url_format_of.failure_message_for_should',
14
14
  attr: attribute.inspect,
15
15
  model: model.class.name
16
16
  )
@@ -18,7 +18,7 @@ RSpec::Matchers.define :ensure_valid_url_format_of do |attribute|
18
18
 
19
19
  failure_message_when_negated do |model|
20
20
  I18n.t(
21
- 'active_validation.matchers.ensure_valid_url_format_of.failure_message_for_should_not',
21
+ 'active_validation.errors.matchers.ensure_valid_url_format_of.failure_message_for_should_not',
22
22
  attr: attribute.inspect,
23
23
  model: model.class.name
24
24
  )
@@ -10,7 +10,7 @@ RSpec::Matchers.define :ensure_valid_username_format_of do |attribute|
10
10
 
11
11
  failure_message do |model|
12
12
  I18n.t(
13
- 'active_validation.matchers.ensure_valid_username_format_of.failure_message_for_should',
13
+ 'active_validation.errors.matchers.ensure_valid_username_format_of.failure_message_for_should',
14
14
  attr: attribute.inspect,
15
15
  model: model.class.name
16
16
  )
@@ -18,7 +18,7 @@ RSpec::Matchers.define :ensure_valid_username_format_of do |attribute|
18
18
 
19
19
  failure_message_when_negated do |model|
20
20
  I18n.t(
21
- 'active_validation.matchers.ensure_valid_username_format_of.failure_message_for_should_not',
21
+ 'active_validation.errors.matchers.ensure_valid_username_format_of.failure_message_for_should_not',
22
22
  attr: attribute.inspect,
23
23
  model: model.class.name
24
24
  )
@@ -10,7 +10,7 @@ RSpec::Matchers.define :ensure_valid_uuid_format_of do |attribute|
10
10
 
11
11
  failure_message do |model|
12
12
  I18n.t(
13
- 'active_validation.matchers.ensure_valid_uuid_format_of.failure_message_for_should',
13
+ 'active_validation.errors.matchers.ensure_valid_uuid_format_of.failure_message_for_should',
14
14
  attr: attribute.inspect,
15
15
  model: model.class.name
16
16
  )
@@ -18,7 +18,7 @@ RSpec::Matchers.define :ensure_valid_uuid_format_of do |attribute|
18
18
 
19
19
  failure_message_when_negated do |model|
20
20
  I18n.t(
21
- 'active_validation.matchers.ensure_valid_uuid_format_of.failure_message_for_should_not',
21
+ 'active_validation.errors.matchers.ensure_valid_uuid_format_of.failure_message_for_should_not',
22
22
  attr: attribute.inspect,
23
23
  model: model.class.name
24
24
  )
@@ -1,7 +1,7 @@
1
1
  class AlphaNumericValidator < ActiveModel::EachValidator
2
2
 
3
3
  def validate_each(record, attribute, value)
4
- unless valid?(value, options)
4
+ unless valid?(value.to_s, options)
5
5
  record.errors[attribute] << (options[:message] || I18n.t('active_validation.errors.messages.alpha_numeric'))
6
6
  end
7
7
  end
@@ -9,22 +9,25 @@ class AlphaNumericValidator < ActiveModel::EachValidator
9
9
  private
10
10
 
11
11
  def valid_format?(value, options)
12
- case options[:case]
12
+ strict = options.fetch(:strict, false)
13
+
14
+ value =~ case options[:case]
13
15
  when :lower
14
- options[:strict] ? (value =~ /^[a-z0-9]+$/) : (value =~ /^[a-z0-9 ]+$/)
16
+ strict ? /^[a-z0-9]+$/ : /^[a-z0-9 ]+$/
15
17
  when :upper
16
- options[:strict] ? (value =~ /^[A-Z0-9]+$/) : (value =~ /^[A-Z0-9 ]+$/)
18
+ strict ? /^[A-Z0-9]+$/ : /^[A-Z0-9 ]+$/
17
19
  else
18
- options[:strict] ? (value =~ /^[A-Za-z0-9]+$/i) : (value =~ /^[A-Za-z0-9 ]+$/i)
20
+ strict ? /^[A-Za-z0-9]+$/i : /^[A-Za-z0-9 ]+$/i
19
21
  end
20
22
  end
21
23
 
22
24
  def valid_length?(value)
23
- value != ' '
25
+ value.present?
24
26
  end
25
27
 
26
28
  def valid?(value, options)
27
- valid_format?(value, options) && valid_length?(value)
29
+ valid_length?(value) &&
30
+ valid_format?(value, options)
28
31
  end
29
32
 
30
33
  end
@@ -1,7 +1,7 @@
1
1
  class AlphaValidator < ActiveModel::EachValidator
2
2
 
3
3
  def validate_each(record, attribute, value)
4
- unless valid?(value, options)
4
+ unless valid?(value.to_s, options)
5
5
  record.errors[attribute] << (options[:message] || I18n.t('active_validation.errors.messages.alpha'))
6
6
  end
7
7
  end
@@ -9,23 +9,25 @@ class AlphaValidator < ActiveModel::EachValidator
9
9
  private
10
10
 
11
11
  def valid_format?(value, options)
12
- case options[:case]
12
+ strict = options.fetch(:strict, false)
13
+
14
+ value =~ case options[:case]
13
15
  when :lower
14
- options[:strict] ? (value =~ /^[a-z]+$/) : (value =~ /^[a-z ]+$/)
16
+ strict ? /^[a-z]+$/ : /^[a-z ]+$/
15
17
  when :upper
16
- options[:strict] ? (value =~ /^[A-Z]+$/) : (value =~ /^[A-Z ]+$/)
18
+ strict ? /^[A-Z]+$/ : /^[A-Z ]+$/
17
19
  else
18
- options[:strict] ? (value =~ /^[A-Za-z]+$/i) : (value =~ /^[A-Za-z ]+$/i)
20
+ strict ? /^[A-Za-z]+$/i : /^[A-Za-z ]+$/i
19
21
  end
20
22
  end
21
23
 
22
24
  def valid_length?(value)
23
- value != ' '
25
+ value.present?
24
26
  end
25
27
 
26
28
  def valid?(value, options)
27
- valid_format?(value, options) &&
28
- valid_length?(value)
29
+ valid_length?(value) &&
30
+ valid_format?(value, options)
29
31
  end
30
32
 
31
33
  end