active_validation 1.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 (93) hide show
  1. checksums.yaml +7 -0
  2. data/.coveralls.yml +1 -0
  3. data/.gitignore +14 -0
  4. data/.rspec +4 -0
  5. data/.travis.yml +13 -0
  6. data/Gemfile +4 -0
  7. data/LICENSE.txt +22 -0
  8. data/README.md +1099 -0
  9. data/Rakefile +1 -0
  10. data/active_validation.gemspec +29 -0
  11. data/config/locales/en.yml +109 -0
  12. data/lib/active_validation/matchers/ensure_valid_alpha_format_of.rb +26 -0
  13. data/lib/active_validation/matchers/ensure_valid_alpha_numeric_format_of.rb +26 -0
  14. data/lib/active_validation/matchers/ensure_valid_base64_format_of.rb +26 -0
  15. data/lib/active_validation/matchers/ensure_valid_boolean_format_of.rb +26 -0
  16. data/lib/active_validation/matchers/ensure_valid_credit_card_format_of.rb +26 -0
  17. data/lib/active_validation/matchers/ensure_valid_currency_format_of.rb +26 -0
  18. data/lib/active_validation/matchers/ensure_valid_cusip_format_of.rb +26 -0
  19. data/lib/active_validation/matchers/ensure_valid_email_format_of.rb +26 -0
  20. data/lib/active_validation/matchers/ensure_valid_equality_matcher_of.rb +40 -0
  21. data/lib/active_validation/matchers/ensure_valid_hex_format_of.rb +26 -0
  22. data/lib/active_validation/matchers/ensure_valid_imei_format_of.rb +26 -0
  23. data/lib/active_validation/matchers/ensure_valid_ip_format_of.rb +26 -0
  24. data/lib/active_validation/matchers/ensure_valid_isbn_format_of.rb +26 -0
  25. data/lib/active_validation/matchers/ensure_valid_isin_format_of.rb +26 -0
  26. data/lib/active_validation/matchers/ensure_valid_latitude_format_of.rb +26 -0
  27. data/lib/active_validation/matchers/ensure_valid_longitude_format_of.rb +26 -0
  28. data/lib/active_validation/matchers/ensure_valid_mac_address_format_of.rb +26 -0
  29. data/lib/active_validation/matchers/ensure_valid_name_format_of.rb +26 -0
  30. data/lib/active_validation/matchers/ensure_valid_password_format_of.rb +26 -0
  31. data/lib/active_validation/matchers/ensure_valid_phone_format_of.rb +26 -0
  32. data/lib/active_validation/matchers/ensure_valid_sedol_format_of.rb +26 -0
  33. data/lib/active_validation/matchers/ensure_valid_slug_format_of.rb +26 -0
  34. data/lib/active_validation/matchers/ensure_valid_ssn_format_of.rb +26 -0
  35. data/lib/active_validation/matchers/ensure_valid_url_format_of.rb +26 -0
  36. data/lib/active_validation/matchers/ensure_valid_username_format_of.rb +26 -0
  37. data/lib/active_validation/matchers/ensure_valid_uuid_format_of.rb +26 -0
  38. data/lib/active_validation/validators/alpha_numeric_validator.rb +30 -0
  39. data/lib/active_validation/validators/alpha_validator.rb +31 -0
  40. data/lib/active_validation/validators/base64_validator.rb +9 -0
  41. data/lib/active_validation/validators/boolean_validator.rb +9 -0
  42. data/lib/active_validation/validators/credit_card_validator.rb +133 -0
  43. data/lib/active_validation/validators/currency_validator.rb +23 -0
  44. data/lib/active_validation/validators/cusip_validator.rb +33 -0
  45. data/lib/active_validation/validators/email_validator.rb +25 -0
  46. data/lib/active_validation/validators/equality_validator.rb +27 -0
  47. data/lib/active_validation/validators/hex_validator.rb +9 -0
  48. data/lib/active_validation/validators/imei_validator.rb +37 -0
  49. data/lib/active_validation/validators/ip_validator.rb +9 -0
  50. data/lib/active_validation/validators/isbn_validator.rb +24 -0
  51. data/lib/active_validation/validators/isin_validator.rb +38 -0
  52. data/lib/active_validation/validators/latitude_validator.rb +9 -0
  53. data/lib/active_validation/validators/longitude_validator.rb +9 -0
  54. data/lib/active_validation/validators/mac_address_validator.rb +24 -0
  55. data/lib/active_validation/validators/name_validator.rb +9 -0
  56. data/lib/active_validation/validators/password_validator.rb +23 -0
  57. data/lib/active_validation/validators/phone_validator.rb +9 -0
  58. data/lib/active_validation/validators/sedol_validator.rb +32 -0
  59. data/lib/active_validation/validators/slug_validator.rb +9 -0
  60. data/lib/active_validation/validators/ssn_validator.rb +9 -0
  61. data/lib/active_validation/validators/url_validator.rb +36 -0
  62. data/lib/active_validation/validators/username_validator.rb +9 -0
  63. data/lib/active_validation/validators/uuid_validator.rb +28 -0
  64. data/lib/active_validation/version.rb +3 -0
  65. data/lib/active_validation.rb +91 -0
  66. data/spec/lib/alpha_numeric_validator_spec.rb +91 -0
  67. data/spec/lib/alpha_validator_spec.rb +182 -0
  68. data/spec/lib/base64_validator_spec.rb +33 -0
  69. data/spec/lib/boolean_validator_spec.rb +35 -0
  70. data/spec/lib/credit_card_validator_spec.rb +686 -0
  71. data/spec/lib/currency_validator_spec.rb +63 -0
  72. data/spec/lib/cusip_validator_spec.rb +27 -0
  73. data/spec/lib/email_validator_spec.rb +109 -0
  74. data/spec/lib/equality_validator_spec.rb +334 -0
  75. data/spec/lib/hex_validator_spec.rb +73 -0
  76. data/spec/lib/imei_validator_spec.rb +41 -0
  77. data/spec/lib/ip_validator_spec.rb +33 -0
  78. data/spec/lib/isbn_validator_spec.rb +41 -0
  79. data/spec/lib/isin_validator_spec.rb +35 -0
  80. data/spec/lib/latitude_validator_spec.rb +31 -0
  81. data/spec/lib/longitude_validator_spec.rb +31 -0
  82. data/spec/lib/mac_address_validator_spec.rb +54 -0
  83. data/spec/lib/name_validator_spec.rb +39 -0
  84. data/spec/lib/password_validator_spec.rb +85 -0
  85. data/spec/lib/phone_validator_spec.rb +42 -0
  86. data/spec/lib/sedol_validator_spec.rb +31 -0
  87. data/spec/lib/slug_validator_spec.rb +41 -0
  88. data/spec/lib/ssn_validator_spec.rb +36 -0
  89. data/spec/lib/url_validator_spec.rb +106 -0
  90. data/spec/lib/username_validator_spec.rb +37 -0
  91. data/spec/lib/uuid_validator_spec.rb +157 -0
  92. data/spec/spec_helper.rb +12 -0
  93. metadata +260 -0
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,29 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'active_validation/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "active_validation"
8
+ spec.version = ActiveValidation::VERSION
9
+ spec.authors = ["Juan Gomez"]
10
+ spec.email = ["j.gomez@drexed.com"]
11
+ spec.summary = %q{Gem for commonly used validators.}
12
+ spec.description = %q{Validate commonly used attributes easily with ActiveValidation.}
13
+ spec.homepage = "https://github.com/drexed/active_validation"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_runtime_dependency "activemodel"
22
+ spec.add_runtime_dependency "activesupport"
23
+
24
+ spec.add_development_dependency "bundler"
25
+ spec.add_development_dependency "coveralls"
26
+ spec.add_development_dependency "rake"
27
+ spec.add_development_dependency "rspec"
28
+ spec.add_development_dependency "shoulda-matchers"
29
+ end
@@ -0,0 +1,109 @@
1
+ en:
2
+ active_validation:
3
+ errors:
4
+ messages:
5
+ alpha: "is not a valid alpha characters"
6
+ alpha_numeric: "is not a valid alpha-numeric characters"
7
+ base64: "is not a valid Base64 encode"
8
+ boolean: "is not a valid boolean"
9
+ credit_card: "is not a valid credit card"
10
+ currency: "is not a valid currency"
11
+ cusip: "is not a valid CUSIP"
12
+ email: "is not a valid email"
13
+ equality: "is not %{operator} %{attr}"
14
+ hex: "is not a valid hex color"
15
+ imei: "is not a valid IMEI"
16
+ ip: "is not a valid IP"
17
+ isbn: "is not a valid ISBN"
18
+ isin: "is not a valid ISIN"
19
+ longitude: "is not a valid latitude"
20
+ longitude: "is not a valid longitude"
21
+ mac_address: "is not a valid MAC address"
22
+ name: "is not a valid name"
23
+ password: "is not a valid password"
24
+ phone: "is not a valid phone number"
25
+ sedol: "is not a valid SEDOL"
26
+ slug: "is not a valid slug"
27
+ ssn: "is not a valid social security number"
28
+ url: "is not a valid URL"
29
+ username: "is not a valid username"
30
+ uuid: "is not a valid UUID"
31
+ matchers:
32
+ ensure_valid_alpha_format_of:
33
+ failure_message_for_should: "%{model} should ensure valid alpha format of attribute %{attr}"
34
+ failure_message_for_should_not: "%{model} should not ensure valid alpha format of attribute %{attr}"
35
+ ensure_valid_alpha_numeric_format_of:
36
+ failure_message_for_should: "%{model} should ensure valid alpha numeric format of attribute %{attr}"
37
+ failure_message_for_should_not: "%{model} should not ensure valid alpha numeric format of attribute %{attr}"
38
+ ensure_valid_base64_format_of:
39
+ failure_message_for_should: "%{model} should ensure valid Base64 encoded format of attribute %{attr}"
40
+ failure_message_for_should_not: "%{model} should not ensure valid Base64 encoded format of attribute %{attr}"
41
+ ensure_valid_boolean_format_of:
42
+ failure_message_for_should: "%{model} should ensure valid boolean format of attribute %{attr}"
43
+ failure_message_for_should_not: "%{model} should not ensure valid boolean format of attribute %{attr}"
44
+ ensure_valid_credit_card_format_of:
45
+ failure_message_for_should: "%{model} should ensure valid credit card format of attribute %{attr}"
46
+ failure_message_for_should_not: "%{model} should not ensure valid credit card format of attribute %{attr}"
47
+ ensure_valid_currency_format_of:
48
+ failure_message_for_should: "%{model} should ensure valid currency format of attribute %{attr}"
49
+ failure_message_for_should_not: "%{model} should not ensure valid currency format of attribute %{attr}"
50
+ ensure_valid_cusip_format_of:
51
+ failure_message_for_should: "%{model} should ensure valid CUSIP format of attribute %{attr}"
52
+ failure_message_for_should_not: "%{model} should not ensure valid CUSIP format of attribute %{attr}"
53
+ ensure_valid_email_format_of:
54
+ failure_message_for_should: "%{model} should ensure valid email format of attribute %{attr}"
55
+ failure_message_for_should_not: "%{model} should not ensure valid email format of attribute %{attr}"
56
+ ensure_valid_equality_format_of:
57
+ failure_message_for_should: "%{model} should ensure equality of %{operator} on attribute %{attr}"
58
+ failure_message_for_should_not: "%{model} should not ensure equality of %{operator} on attribute %{attr}"
59
+ ensure_valid_hex_format_of:
60
+ failure_message_for_should: "%{model} should ensure valid hex format of attribute %{attr}"
61
+ failure_message_for_should_not: "%{model} should not ensure valid hex format of attribute %{attr}"
62
+ ensure_valid_imei_format_of:
63
+ failure_message_for_should: "%{model} should ensure valid IMEI address format of attribute %{attr}"
64
+ failure_message_for_should_not: "%{model} should not ensure valid IMEI address format of attribute %{attr}"
65
+ ensure_valid_ip_format_of:
66
+ failure_message_for_should: "%{model} should ensure valid IP address format of attribute %{attr}"
67
+ failure_message_for_should_not: "%{model} should not ensure valid IP address format of attribute %{attr}"
68
+ ensure_valid_isbn_format_of:
69
+ failure_message_for_should: "%{model} should ensure valid ISBN format of attribute %{attr}"
70
+ failure_message_for_should_not: "%{model} should not ensure valid ISBN format of attribute %{attr}"
71
+ ensure_valid_isin_format_of:
72
+ failure_message_for_should: "%{model} should ensure valid ISIN format of attribute %{attr}"
73
+ failure_message_for_should_not: "%{model} should not ensure valid ISIN format of attribute %{attr}"
74
+ ensure_valid_latitude_format_of:
75
+ failure_message_for_should: "%{model} should ensure valid latitude format of attribute %{attr}"
76
+ failure_message_for_should_not: "%{model} should not ensure valid latitude format of attribute %{attr}"
77
+ ensure_valid_longitude_format_of:
78
+ failure_message_for_should: "%{model} should ensure valid longitude format of attribute %{attr}"
79
+ failure_message_for_should_not: "%{model} should not ensure valid longitude format of attribute %{attr}"
80
+ ensure_valid_mac_address_format_of:
81
+ failure_message_for_should: "%{model} should ensure valid MAC address format of attribute %{attr}"
82
+ failure_message_for_should_not: "%{model} should not ensure valid MAC address format of attribute %{attr}"
83
+ ensure_valid_name_format_of:
84
+ failure_message_for_should: "%{model} should ensure valid name format of attribute %{attr}"
85
+ failure_message_for_should_not: "%{model} should not ensure valid name format of attribute %{attr}"
86
+ ensure_valid_password_format_of:
87
+ failure_message_for_should: "%{model} should ensure valid password format of attribute %{attr}"
88
+ failure_message_for_should_not: "%{model} should not ensure valid password format of attribute %{attr}"
89
+ ensure_valid_phone_format_of:
90
+ failure_message_for_should: "%{model} should ensure valid phone format of attribute %{attr}"
91
+ failure_message_for_should_not: "%{model} should not ensure valid phone format of attribute %{attr}"
92
+ ensure_valid_sedol_format_of:
93
+ failure_message_for_should: "%{model} should ensure valid SEDOL format of attribute %{attr}"
94
+ failure_message_for_should_not: "%{model} should not ensure valid SEDOL format of attribute %{attr}"
95
+ ensure_valid_slug_format_of:
96
+ failure_message_for_should: "%{model} should ensure valid slug format of attribute %{attr}"
97
+ failure_message_for_should_not: "%{model} should not ensure valid slug format of attribute %{attr}"
98
+ ensure_valid_ssn_format_of:
99
+ failure_message_for_should: "%{model} should ensure valid SSN format of attribute %{attr}"
100
+ failure_message_for_should_not: "%{model} should not ensure valid SSN format of attribute %{attr}"
101
+ ensure_valid_url_format_of:
102
+ failure_message_for_should: "%{model} should ensure valid URL format of attribute %{attr}"
103
+ failure_message_for_should_not: "%{model} should not ensure valid URL format of attribute %{attr}"
104
+ ensure_valid_username_format_of:
105
+ failure_message_for_should: "%{model} should ensure valid username format of attribute %{attr}"
106
+ failure_message_for_should_not: "%{model} should not ensure valid username format of attribute %{attr}"
107
+ ensure_valid_uuid_format_of:
108
+ failure_message_for_should: "%{model} should ensure valid UUID format of attribute %{attr}"
109
+ failure_message_for_should_not: "%{model} should not ensure valid UUID format of attribute %{attr}"
@@ -0,0 +1,26 @@
1
+ RSpec::Matchers.define :ensure_valid_alpha_format_of do |attribute|
2
+ match do |model|
3
+ model.send("#{attribute}=", "$1234.56")
4
+ model.valid?
5
+
6
+ if model.errors.has_key?(attribute)
7
+ model.errors[attribute].include?(I18n.t('active_validation.errors.messages.alpha'))
8
+ end
9
+ end
10
+
11
+ failure_message do |model|
12
+ I18n.t(
13
+ 'active_validation.matchers.ensure_valid_alpha_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.matchers.ensure_valid_alpha_format_of.failure_message_for_should_not',
22
+ attr: attribute.inspect,
23
+ model: model.class.name
24
+ )
25
+ end
26
+ end
@@ -0,0 +1,26 @@
1
+ RSpec::Matchers.define :ensure_valid_alpha_numeric_format_of do |attribute|
2
+ match do |model|
3
+ model.send("#{attribute}=", "$1234.56")
4
+ model.valid?
5
+
6
+ if model.errors.has_key?(attribute)
7
+ model.errors[attribute].include?(I18n.t('active_validation.errors.messages.alpha_numeric'))
8
+ end
9
+ end
10
+
11
+ failure_message do |model|
12
+ I18n.t(
13
+ 'active_validation.matchers.ensure_valid_alpha_numeric_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.matchers.ensure_valid_alpha_numeric_format_of.failure_message_for_should_not',
22
+ attr: attribute.inspect,
23
+ model: model.class.name
24
+ )
25
+ end
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('active_validation.errors.messages.base64'))
8
+ end
9
+ end
10
+
11
+ failure_message do |model|
12
+ I18n.t(
13
+ 'active_validation.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
+ 'active_validation.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
@@ -0,0 +1,26 @@
1
+ RSpec::Matchers.define :ensure_valid_boolean_format_of do |attribute|
2
+ match do |model|
3
+ model.send("#{attribute}=", nil)
4
+ model.valid?
5
+
6
+ if model.errors.has_key?(attribute)
7
+ model.errors[attribute].include?(I18n.t('active_validation.errors.messages.boolean'))
8
+ end
9
+ end
10
+
11
+ failure_message do |model|
12
+ I18n.t(
13
+ 'active_validation.matchers.ensure_valid_boolean_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.matchers.ensure_valid_boolean_format_of.failure_message_for_should_not',
22
+ attr: attribute.inspect,
23
+ model: model.class.name
24
+ )
25
+ end
26
+ end
@@ -0,0 +1,26 @@
1
+ RSpec::Matchers.define :ensure_valid_credit_card_format_of do |attribute|
2
+ match do |model|
3
+ model.send("#{attribute}=", "9999")
4
+ model.valid?
5
+
6
+ if model.errors.has_key?(attribute)
7
+ model.errors[attribute].include?(I18n.t('active_validation.errors.messages.credit_card'))
8
+ end
9
+ end
10
+
11
+ failure_message do |model|
12
+ I18n.t(
13
+ 'active_validation.matchers.ensure_valid_credit_card_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.matchers.ensure_valid_credit_card_format_of.failure_message_for_should_not',
22
+ attr: attribute.inspect,
23
+ model: model.class.name
24
+ )
25
+ end
26
+ end
@@ -0,0 +1,26 @@
1
+ RSpec::Matchers.define :ensure_valid_currency_format_of do |attribute|
2
+ match do |model|
3
+ model.send("#{attribute}=", "$1234.56")
4
+ model.valid?
5
+
6
+ if model.errors.has_key?(attribute)
7
+ model.errors[attribute].include?(I18n.t('active_validation.errors.messages.currency'))
8
+ end
9
+ end
10
+
11
+ failure_message do |model|
12
+ I18n.t(
13
+ 'active_validation.matchers.ensure_valid_currency_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.matchers.ensure_valid_currency_format_of.failure_message_for_should_not',
22
+ attr: attribute.inspect,
23
+ model: model.class.name
24
+ )
25
+ end
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('active_validation.errors.messages.cusip'))
8
+ end
9
+ end
10
+
11
+ failure_message do |model|
12
+ I18n.t(
13
+ 'active_validation.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
+ 'active_validation.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
@@ -0,0 +1,26 @@
1
+ RSpec::Matchers.define :ensure_valid_email_format_of do |attribute|
2
+ match do |model|
3
+ model.send("#{attribute}=", "invalid@email_address")
4
+ model.valid?
5
+
6
+ if model.errors.has_key?(attribute)
7
+ model.errors[attribute].include?(I18n.t('active_validation.errors.messages.email'))
8
+ end
9
+ end
10
+
11
+ failure_message do |model|
12
+ I18n.t(
13
+ 'active_validation.matchers.ensure_valid_email_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.matchers.ensure_valid_email_format_of.failure_message_for_should_not',
22
+ attr: attribute.inspect,
23
+ model: model.class.name
24
+ )
25
+ end
26
+ end
@@ -0,0 +1,40 @@
1
+ RSpec::Matchers.define :ensure_equality_of do |attribute|
2
+ chain :to do |to|
3
+ @to = to
4
+ end
5
+
6
+ chain :operator do |operator|
7
+ @operator = operator
8
+ end
9
+
10
+ match do |model|
11
+ raise Exception if @to.nil? || @operator.nil?
12
+
13
+ value = model.send(attribute)
14
+ model.send("#{@to}=", value)
15
+ model.send("#{@operator}=", value)
16
+ model.valid?
17
+
18
+ if model.errors.has_key?(attribute)
19
+ model.errors[attribute].include?(I18n.t('active_validation.errors.messages.equality', attr: @to, operator: @operator))
20
+ end
21
+ end
22
+
23
+ failure_message do |model|
24
+ I18n.t(
25
+ 'active_validation.matchers.ensure_valid_equality_format_of.failure_message_for_should',
26
+ attr: attribute.inspect,
27
+ model: model.class.name,
28
+ operator: "operator"
29
+ )
30
+ end
31
+
32
+ failure_message_when_negated do |model|
33
+ I18n.t(
34
+ 'active_validation.matchers.ensure_valid_equality_format_of.failure_message_for_should_not',
35
+ attr: attribute.inspect,
36
+ model: model.class.name,
37
+ operator: "operator"
38
+ )
39
+ end
40
+ end
@@ -0,0 +1,26 @@
1
+ RSpec::Matchers.define :ensure_valid_hex_format_of do |attribute|
2
+ match do |model|
3
+ model.send("#{attribute}=", "#9999999")
4
+ model.valid?
5
+
6
+ if model.errors.has_key?(attribute)
7
+ model.errors[attribute].include?(I18n.t('active_validation.errors.messages.hex'))
8
+ end
9
+ end
10
+
11
+ failure_message do |model|
12
+ I18n.t(
13
+ 'active_validation.matchers.ensure_valid_hex_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.matchers.ensure_valid_hex_format_of.failure_message_for_should_not',
22
+ attr: attribute.inspect,
23
+ model: model.class.name
24
+ )
25
+ end
26
+ end
@@ -0,0 +1,26 @@
1
+ RSpec::Matchers.define :ensure_valid_imei_format_of do |attribute|
2
+ match do |model|
3
+ model.send("#{attribute}=", "invalid.imei")
4
+ model.valid?
5
+
6
+ if model.errors.has_key?(attribute)
7
+ model.errors[attribute].include?(I18n.t('active_validation.errors.messages.imei'))
8
+ end
9
+ end
10
+
11
+ failure_message do |model|
12
+ I18n.t(
13
+ 'active_validation.matchers.ensure_valid_imei_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.matchers.ensure_valid_imei_format_of.failure_message_for_should_not',
22
+ attr: attribute.inspect,
23
+ model: model.class.name
24
+ )
25
+ end
26
+ end
@@ -0,0 +1,26 @@
1
+ RSpec::Matchers.define :ensure_valid_ip_format_of do |attribute|
2
+ match do |model|
3
+ model.send("#{attribute}=", ".")
4
+ model.valid?
5
+
6
+ if model.errors.has_key?(attribute)
7
+ model.errors[attribute].include?(I18n.t('active_validation.errors.messages.ip'))
8
+ end
9
+ end
10
+
11
+ failure_message do |model|
12
+ I18n.t(
13
+ 'active_validation.matchers.ensure_valid_ip_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.matchers.ensure_valid_ip_format_of.failure_message_for_should_not',
22
+ attr: attribute.inspect,
23
+ model: model.class.name
24
+ )
25
+ end
26
+ end
@@ -0,0 +1,26 @@
1
+ RSpec::Matchers.define :ensure_valid_isbn_format_of do |attribute|
2
+ match do |model|
3
+ model.send("#{attribute}=", "12345")
4
+ model.valid?
5
+
6
+ if model.errors.has_key?(attribute)
7
+ model.errors[attribute].include?(I18n.t('active_validation.errors.messages.isbn'))
8
+ end
9
+ end
10
+
11
+ failure_message do |model|
12
+ I18n.t(
13
+ 'active_validation.matchers.ensure_valid_isbn_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.matchers.ensure_valid_isbn_format_of.failure_message_for_should_not',
22
+ attr: attribute.inspect,
23
+ model: model.class.name
24
+ )
25
+ end
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('active_validation.errors.messages.isin'))
8
+ end
9
+ end
10
+
11
+ failure_message do |model|
12
+ I18n.t(
13
+ 'active_validation.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
+ 'active_validation.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
@@ -0,0 +1,26 @@
1
+ RSpec::Matchers.define :ensure_valid_latitude_format_of do |attribute|
2
+ match do |model|
3
+ model.send("#{attribute}=", 91)
4
+ model.valid?
5
+
6
+ if model.errors.has_key?(attribute)
7
+ model.errors[attribute].include?(I18n.t('active_validation.errors.messages.latitude'))
8
+ end
9
+ end
10
+
11
+ failure_message do |model|
12
+ I18n.t(
13
+ 'active_validation.matchers.ensure_valid_latitude_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.matchers.ensure_valid_latitude_format_of.failure_message_for_should_not',
22
+ attr: attribute.inspect,
23
+ model: model.class.name
24
+ )
25
+ end
26
+ end
@@ -0,0 +1,26 @@
1
+ RSpec::Matchers.define :ensure_valid_longitude_format_of do |attribute|
2
+ match do |model|
3
+ model.send("#{attribute}=", 181)
4
+ model.valid?
5
+
6
+ if model.errors.has_key?(attribute)
7
+ model.errors[attribute].include?(I18n.t('active_validation.errors.messages.longitude'))
8
+ end
9
+ end
10
+
11
+ failure_message do |model|
12
+ I18n.t(
13
+ 'active_validation.matchers.ensure_valid_longitude_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.matchers.ensure_valid_longitude_format_of.failure_message_for_should_not',
22
+ attr: attribute.inspect,
23
+ model: model.class.name
24
+ )
25
+ end
26
+ end
@@ -0,0 +1,26 @@
1
+ RSpec::Matchers.define :ensure_valid_mac_address_format_of do |attribute|
2
+ match do |model|
3
+ model.send("#{attribute}=", "invalid.mac.address")
4
+ model.valid?
5
+
6
+ if model.errors.has_key?(attribute)
7
+ model.errors[attribute].include?(I18n.t('active_validation.errors.messages.mac_address'))
8
+ end
9
+ end
10
+
11
+ failure_message do |model|
12
+ I18n.t(
13
+ 'active_validation.matchers.ensure_valid_mac_address_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.matchers.ensure_valid_mac_address_format_of.failure_message_for_should_not',
22
+ attr: attribute.inspect,
23
+ model: model.class.name
24
+ )
25
+ end
26
+ end
@@ -0,0 +1,26 @@
1
+ RSpec::Matchers.define :ensure_valid_name_format_of do |attribute|
2
+ match do |model|
3
+ model.send("#{attribute}=", "Jame$ Ear1 Jones")
4
+ model.valid?
5
+
6
+ if model.errors.has_key?(attribute)
7
+ model.errors[attribute].include?(I18n.t('active_validation.errors.messages.name'))
8
+ end
9
+ end
10
+
11
+ failure_message do |model|
12
+ I18n.t(
13
+ 'active_validation.matchers.ensure_valid_name_format_of.failure_message_for_should',
14
+ attribute: attribute.inspect,
15
+ model: model.class.name
16
+ )
17
+ end
18
+
19
+ failure_message_when_negated do |model|
20
+ I18n.t(
21
+ 'active_validation.matchers.ensure_valid_name_format_of.failure_message_for_should_not',
22
+ attribute: attribute.inspect,
23
+ model: model.class.name
24
+ )
25
+ end
26
+ end