active_validation 3.0.0 → 4.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/.DS_Store +0 -0
- data/.fasterer.yml +19 -0
- data/.reek +36 -0
- data/.rubocop.yml +54 -0
- data/Gemfile +1 -1
- data/Rakefile +1 -1
- data/active_validation.gemspec +21 -18
- data/bin/console +4 -4
- data/bin/rake +6 -7
- data/config/locales/en.yml +83 -83
- data/lib/.DS_Store +0 -0
- data/lib/active_validation.rb +12 -83
- data/lib/active_validation/.DS_Store +0 -0
- data/lib/active_validation/railtie.rb +19 -0
- data/lib/active_validation/validators/alpha_numeric_validator.rb +11 -10
- data/lib/active_validation/validators/alpha_validator.rb +11 -10
- data/lib/active_validation/validators/base64_validator.rb +2 -1
- data/lib/active_validation/validators/boolean_validator.rb +4 -6
- data/lib/active_validation/validators/coordinate_validator.rb +8 -5
- data/lib/active_validation/validators/credit_card_validator.rb +35 -36
- data/lib/active_validation/validators/currency_validator.rb +3 -2
- data/lib/active_validation/validators/cusip_validator.rb +9 -6
- data/lib/active_validation/validators/email_validator.rb +4 -3
- data/lib/active_validation/validators/equality_validator.rb +14 -13
- data/lib/active_validation/validators/hex_validator.rb +2 -1
- data/lib/active_validation/validators/imei_validator.rb +7 -6
- data/lib/active_validation/validators/ip_validator.rb +4 -1
- data/lib/active_validation/validators/isbn_validator.rb +5 -4
- data/lib/active_validation/validators/isin_validator.rb +12 -9
- data/lib/active_validation/validators/mac_address_validator.rb +7 -3
- data/lib/active_validation/validators/name_validator.rb +3 -2
- data/lib/active_validation/validators/password_validator.rb +7 -2
- data/lib/active_validation/validators/phone_validator.rb +3 -2
- data/lib/active_validation/validators/sedol_validator.rb +4 -3
- data/lib/active_validation/validators/slug_validator.rb +2 -1
- data/lib/active_validation/validators/ssn_validator.rb +2 -1
- data/lib/active_validation/validators/tracking_number_validator.rb +73 -68
- data/lib/active_validation/validators/type_validator.rb +3 -2
- data/lib/active_validation/validators/url_validator.rb +12 -11
- data/lib/active_validation/validators/username_validator.rb +2 -1
- data/lib/active_validation/validators/uuid_validator.rb +12 -11
- data/lib/active_validation/version.rb +1 -1
- metadata +51 -29
- data/lib/active_validation/matchers/ensure_valid_alpha_format_of.rb +0 -26
- data/lib/active_validation/matchers/ensure_valid_alpha_numeric_format_of.rb +0 -26
- data/lib/active_validation/matchers/ensure_valid_base64_format_of.rb +0 -26
- data/lib/active_validation/matchers/ensure_valid_boolean_format_of.rb +0 -26
- data/lib/active_validation/matchers/ensure_valid_coordinate_format_of.rb +0 -26
- data/lib/active_validation/matchers/ensure_valid_credit_card_format_of.rb +0 -26
- data/lib/active_validation/matchers/ensure_valid_currency_format_of.rb +0 -26
- data/lib/active_validation/matchers/ensure_valid_cusip_format_of.rb +0 -26
- data/lib/active_validation/matchers/ensure_valid_email_format_of.rb +0 -26
- data/lib/active_validation/matchers/ensure_valid_equality_matcher_of.rb +0 -40
- data/lib/active_validation/matchers/ensure_valid_hex_format_of.rb +0 -26
- data/lib/active_validation/matchers/ensure_valid_imei_format_of.rb +0 -26
- data/lib/active_validation/matchers/ensure_valid_ip_format_of.rb +0 -26
- data/lib/active_validation/matchers/ensure_valid_isbn_format_of.rb +0 -26
- data/lib/active_validation/matchers/ensure_valid_isin_format_of.rb +0 -26
- data/lib/active_validation/matchers/ensure_valid_mac_address_format_of.rb +0 -26
- data/lib/active_validation/matchers/ensure_valid_name_format_of.rb +0 -26
- data/lib/active_validation/matchers/ensure_valid_password_format_of.rb +0 -26
- data/lib/active_validation/matchers/ensure_valid_phone_format_of.rb +0 -26
- data/lib/active_validation/matchers/ensure_valid_sedol_format_of.rb +0 -26
- data/lib/active_validation/matchers/ensure_valid_slug_format_of.rb +0 -26
- data/lib/active_validation/matchers/ensure_valid_ssn_format_of.rb +0 -26
- data/lib/active_validation/matchers/ensure_valid_tracking_number_format_of.rb +0 -26
- data/lib/active_validation/matchers/ensure_valid_type_format_of.rb +0 -26
- data/lib/active_validation/matchers/ensure_valid_url_format_of.rb +0 -26
- data/lib/active_validation/matchers/ensure_valid_username_format_of.rb +0 -26
- data/lib/active_validation/matchers/ensure_valid_uuid_format_of.rb +0 -26
@@ -6,14 +6,15 @@ class TypeValidator < ActiveModel::EachValidator
|
|
6
6
|
|
7
7
|
def validate_each(record, attribute, value)
|
8
8
|
unless valid?(value, options)
|
9
|
-
record.errors[attribute] <<
|
9
|
+
record.errors[attribute] <<
|
10
|
+
(options[:message] || I18n.t('active_validation.errors.messages.type'))
|
10
11
|
end
|
11
12
|
end
|
12
13
|
|
13
14
|
private
|
14
15
|
|
15
16
|
def valid?(value, options)
|
16
|
-
klass = options
|
17
|
+
klass = options[:with]
|
17
18
|
|
18
19
|
if klass == Boolean
|
19
20
|
value.is_a?(TrueClass) || value.is_a?(FalseClass)
|
@@ -1,20 +1,21 @@
|
|
1
|
-
require
|
1
|
+
require 'uri'
|
2
2
|
class UrlValidator < ActiveModel::EachValidator
|
3
3
|
|
4
4
|
def validate_each(record, attribute, value)
|
5
5
|
uri = URI.parse(value.to_s)
|
6
6
|
raise URI::InvalidURIError unless valid?(uri, options)
|
7
7
|
rescue URI::InvalidURIError
|
8
|
-
record.errors[attribute] <<
|
8
|
+
record.errors[attribute] <<
|
9
|
+
(options[:message] || I18n.t('active_validation.errors.messages.url'))
|
9
10
|
end
|
10
11
|
|
11
12
|
private
|
12
13
|
|
13
|
-
DEFAULT_SCHEMES = [:http, :https]
|
14
|
+
DEFAULT_SCHEMES = [:http, :https].freeze
|
14
15
|
|
15
16
|
def valid_domain?(value, options)
|
16
17
|
value_downcased = value.host.to_s.downcase
|
17
|
-
options.empty? || options.any? { |
|
18
|
+
options.empty? || options.any? { |dom| value_downcased.end_with?(".#{dom.downcase}") }
|
18
19
|
end
|
19
20
|
|
20
21
|
def valid_length?(value)
|
@@ -23,23 +24,23 @@ class UrlValidator < ActiveModel::EachValidator
|
|
23
24
|
|
24
25
|
def valid_scheme?(value, options)
|
25
26
|
value_downcased = value.scheme.to_s.downcase
|
26
|
-
options.empty? || options.any? { |
|
27
|
+
options.empty? || options.any? { |sch| value_downcased == sch.to_s.downcase }
|
27
28
|
end
|
28
29
|
|
29
30
|
def valid_root?(value)
|
30
|
-
[
|
31
|
+
['/', ''].include?(value.path) && value.query.blank? && value.fragment.blank?
|
31
32
|
end
|
32
33
|
|
33
34
|
def valid_uri?(value)
|
34
|
-
value.
|
35
|
+
value.is_a?(URI::Generic)
|
35
36
|
end
|
36
37
|
|
37
38
|
def valid?(value, options)
|
38
39
|
valid_length?(value) &&
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
40
|
+
valid_uri?(value) &&
|
41
|
+
valid_domain?(value, [*(options[:domain])]) &&
|
42
|
+
valid_scheme?(value, [*(options[:scheme] || UrlValidator::DEFAULT_SCHEMES)]) &&
|
43
|
+
(options[:root] ? valid_root?(value) : true)
|
43
44
|
end
|
44
45
|
|
45
46
|
end
|
@@ -2,7 +2,8 @@ class UsernameValidator < ActiveModel::EachValidator
|
|
2
2
|
|
3
3
|
def validate_each(record, attribute, value)
|
4
4
|
unless valid?(value.to_s)
|
5
|
-
record.errors[attribute] <<
|
5
|
+
record.errors[attribute] <<
|
6
|
+
(options[:message] || I18n.t('active_validation.errors.messages.username'))
|
6
7
|
end
|
7
8
|
end
|
8
9
|
|
@@ -2,23 +2,24 @@ class UuidValidator < ActiveModel::EachValidator
|
|
2
2
|
|
3
3
|
def validate_each(record, attribute, value)
|
4
4
|
unless valid?(value.to_s, options)
|
5
|
-
record.errors[attribute] <<
|
5
|
+
record.errors[attribute] <<
|
6
|
+
(options[:message] || I18n.t('active_validation.errors.messages.uuid'))
|
6
7
|
end
|
7
8
|
end
|
8
9
|
|
9
10
|
private
|
10
11
|
|
11
12
|
def valid_format?(value, options)
|
12
|
-
value =~ case options
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
13
|
+
value =~ case options[:version]
|
14
|
+
when 3
|
15
|
+
/^[0-9A-F]{8}-[0-9A-F]{4}-3[0-9A-F]{3}-[0-9A-F]{4}-[0-9A-F]{12}$/i
|
16
|
+
when 4
|
17
|
+
/^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i
|
18
|
+
when 5
|
19
|
+
/^[0-9A-F]{8}-[0-9A-F]{4}-5[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i
|
20
|
+
else
|
21
|
+
/^[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}$/i
|
22
|
+
end
|
22
23
|
end
|
23
24
|
|
24
25
|
def valid_length?(value)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_validation
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 4.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Juan Gomez
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-09-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel
|
@@ -108,6 +108,48 @@ dependencies:
|
|
108
108
|
- - ">="
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: fasterer
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: reek
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ">="
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: rubocop
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - ">="
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '0'
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - ">="
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '0'
|
111
153
|
description: Validate commonly used attributes easily with ActiveValidation.
|
112
154
|
email:
|
113
155
|
- j.gomez@drexed.com
|
@@ -115,9 +157,13 @@ executables: []
|
|
115
157
|
extensions: []
|
116
158
|
extra_rdoc_files: []
|
117
159
|
files:
|
160
|
+
- ".DS_Store"
|
118
161
|
- ".coveralls.yml"
|
162
|
+
- ".fasterer.yml"
|
119
163
|
- ".gitignore"
|
164
|
+
- ".reek"
|
120
165
|
- ".rspec"
|
166
|
+
- ".rubocop.yml"
|
121
167
|
- ".travis.yml"
|
122
168
|
- CODE_OF_CONDUCT.md
|
123
169
|
- Gemfile
|
@@ -129,34 +175,10 @@ files:
|
|
129
175
|
- bin/rake
|
130
176
|
- bin/setup
|
131
177
|
- config/locales/en.yml
|
178
|
+
- lib/.DS_Store
|
132
179
|
- lib/active_validation.rb
|
133
|
-
- lib/active_validation
|
134
|
-
- lib/active_validation/
|
135
|
-
- lib/active_validation/matchers/ensure_valid_base64_format_of.rb
|
136
|
-
- lib/active_validation/matchers/ensure_valid_boolean_format_of.rb
|
137
|
-
- lib/active_validation/matchers/ensure_valid_coordinate_format_of.rb
|
138
|
-
- lib/active_validation/matchers/ensure_valid_credit_card_format_of.rb
|
139
|
-
- lib/active_validation/matchers/ensure_valid_currency_format_of.rb
|
140
|
-
- lib/active_validation/matchers/ensure_valid_cusip_format_of.rb
|
141
|
-
- lib/active_validation/matchers/ensure_valid_email_format_of.rb
|
142
|
-
- lib/active_validation/matchers/ensure_valid_equality_matcher_of.rb
|
143
|
-
- lib/active_validation/matchers/ensure_valid_hex_format_of.rb
|
144
|
-
- lib/active_validation/matchers/ensure_valid_imei_format_of.rb
|
145
|
-
- lib/active_validation/matchers/ensure_valid_ip_format_of.rb
|
146
|
-
- lib/active_validation/matchers/ensure_valid_isbn_format_of.rb
|
147
|
-
- lib/active_validation/matchers/ensure_valid_isin_format_of.rb
|
148
|
-
- lib/active_validation/matchers/ensure_valid_mac_address_format_of.rb
|
149
|
-
- lib/active_validation/matchers/ensure_valid_name_format_of.rb
|
150
|
-
- lib/active_validation/matchers/ensure_valid_password_format_of.rb
|
151
|
-
- lib/active_validation/matchers/ensure_valid_phone_format_of.rb
|
152
|
-
- lib/active_validation/matchers/ensure_valid_sedol_format_of.rb
|
153
|
-
- lib/active_validation/matchers/ensure_valid_slug_format_of.rb
|
154
|
-
- lib/active_validation/matchers/ensure_valid_ssn_format_of.rb
|
155
|
-
- lib/active_validation/matchers/ensure_valid_tracking_number_format_of.rb
|
156
|
-
- lib/active_validation/matchers/ensure_valid_type_format_of.rb
|
157
|
-
- lib/active_validation/matchers/ensure_valid_url_format_of.rb
|
158
|
-
- lib/active_validation/matchers/ensure_valid_username_format_of.rb
|
159
|
-
- lib/active_validation/matchers/ensure_valid_uuid_format_of.rb
|
180
|
+
- lib/active_validation/.DS_Store
|
181
|
+
- lib/active_validation/railtie.rb
|
160
182
|
- lib/active_validation/validators/alpha_numeric_validator.rb
|
161
183
|
- lib/active_validation/validators/alpha_validator.rb
|
162
184
|
- lib/active_validation/validators/base64_validator.rb
|
@@ -1,26 +0,0 @@
|
|
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.errors.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.errors.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
|
@@ -1,26 +0,0 @@
|
|
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.errors.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.errors.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
|
@@ -1,26 +0,0 @@
|
|
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.errors.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.errors.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
|
@@ -1,26 +0,0 @@
|
|
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.errors.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.errors.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
|
@@ -1,26 +0,0 @@
|
|
1
|
-
RSpec::Matchers.define :ensure_valid_coordinate_format_of do |attribute|
|
2
|
-
match do |model|
|
3
|
-
model.send("#{attribute}=", [91, 181])
|
4
|
-
model.valid?
|
5
|
-
|
6
|
-
if model.errors.has_key?(attribute)
|
7
|
-
model.errors[attribute].include?(I18n.t("active_validation.errors.messages.coordinate.coordinate"))
|
8
|
-
end
|
9
|
-
end
|
10
|
-
|
11
|
-
failure_message do |model|
|
12
|
-
I18n.t(
|
13
|
-
"active_validation.errors.matchers.ensure_valid_coordinate_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_coordinate_format_of.failure_message_for_should_not",
|
22
|
-
attr: attribute.inspect,
|
23
|
-
model: model.class.name
|
24
|
-
)
|
25
|
-
end
|
26
|
-
end
|
@@ -1,26 +0,0 @@
|
|
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.errors.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.errors.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
|
@@ -1,26 +0,0 @@
|
|
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.errors.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.errors.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
|
@@ -1,26 +0,0 @@
|
|
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.errors.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.errors.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
|