validation_hints 8.1.19 → 8.1.20
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/CHANGELOG.md +10 -0
- data/lib/active_model/hints.rb +9 -2
- data/lib/validation_hints/locale/en.yml +1 -0
- data/lib/validation_hints/version.rb +1 -1
- data/test/active_model/hints_test.rb +29 -0
- data/test/validation_hints_test.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: fa2d51e94503ff4656ea0f9c90b45ea1616e7ffee979ca955f01b9e4704586a1
|
|
4
|
+
data.tar.gz: 7c27666b62f82f62c833ff502535eb666e75141196b1f59d49212680e7756ac5
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: c2cad72f9115996ec3ea3e8a8a2f0cade7a6b5f1ae447d1a5da4984330263c3508d165ee94ab54d9807014bab62bb8e26e90d3ae524f992c069707dcc78d0a47
|
|
7
|
+
data.tar.gz: 0a56db43ba4abe2fa3545ca5e71e2afecb42a461549a4975e4b7f3566955a20a4d72e0ada001893b498c0afd34c543ac7e531c19843849de7c18bf7ec4a37832
|
data/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,16 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project are documented here.
|
|
4
4
|
|
|
5
|
+
## 8.1.20
|
|
6
|
+
|
|
7
|
+
### Fixed
|
|
8
|
+
|
|
9
|
+
- **A bare `validates :foo, numericality: true` now emits a `"must be a number"` hint — previously it emitted nothing.** `numericality` is listed in `VALIDATORS_WITHOUT_MAIN_KEYS`, so `Hints#messages_for_validator` computed the `numericality.must_be_a_number` base key but then skipped adding it under the `unless VALIDATORS_WITHOUT_MAIN_KEYS.include?(key)` guard. A bare `numericality: true` carries no option-specific keys (`only_integer`, ranges, `odd`/`even`, …), so the result was an **empty** hint list. The base `"must be a number"` message is now always emitted for `numericality`, with any option-specific messages appended after it. Existing option/range hints are unchanged except that they are now prefixed with `"must be a number"` (e.g. `only_integer` → `["must be a number", "must be an integer"]`; a `greater_than_or_equal_to`/`less_than_or_equal_to` range → `["must be a number", "must be greater than or equal to …", "must be less than or equal to …"]`).
|
|
10
|
+
|
|
11
|
+
### Added
|
|
12
|
+
|
|
13
|
+
- **`hints.messages.money` i18n key (`"must be a valid amount"`).** money-rails' `monetize` registers a `MoneyRails::ActiveModel::MoneyValidator` (validator key `money`) on the monetized attribute; without a mapping that produced no usable hint. The new key lets a money-validated attribute surface a meaningful label hint.
|
|
14
|
+
|
|
5
15
|
## 8.1.19
|
|
6
16
|
|
|
7
17
|
### Changed
|
data/lib/active_model/hints.rb
CHANGED
|
@@ -228,8 +228,15 @@ module ActiveModel
|
|
|
228
228
|
end
|
|
229
229
|
|
|
230
230
|
message_key = key
|
|
231
|
-
|
|
232
|
-
|
|
231
|
+
if key == "numericality"
|
|
232
|
+
# +numericality+ is listed in VALIDATORS_WITHOUT_MAIN_KEYS so the
|
|
233
|
+
# guard below would skip its base message — but a bare
|
|
234
|
+
# +numericality: true+ carries no option-specific keys, so it would
|
|
235
|
+
# then emit nothing at all. Always surface the "must be a number"
|
|
236
|
+
# base hint here; option keys (only_integer, ranges, odd/even, …)
|
|
237
|
+
# are appended by the options loop below.
|
|
238
|
+
result << generate_message(attribute, "numericality.must_be_a_number", options)
|
|
239
|
+
elsif !VALIDATORS_WITHOUT_MAIN_KEYS.include?(key)
|
|
233
240
|
result << generate_message(attribute, message_key, options)
|
|
234
241
|
end
|
|
235
242
|
|
|
@@ -26,6 +26,7 @@ en:
|
|
|
26
26
|
confirmation: "doesn't match confirmation"
|
|
27
27
|
acceptance: "must be accepted"
|
|
28
28
|
presence: "can't be blank"
|
|
29
|
+
money: "must be a valid amount"
|
|
29
30
|
length:
|
|
30
31
|
maximum: "must not be longer than %{count} characters"
|
|
31
32
|
minimum: "must not be shorter than %{count} characters"
|
|
@@ -34,10 +34,39 @@ class ActiveModelHintsTest < Minitest::Test
|
|
|
34
34
|
|
|
35
35
|
def test_numericality_option_hints
|
|
36
36
|
hints = @person.hints[:age]
|
|
37
|
+
assert_includes hints, "must be a number"
|
|
37
38
|
assert_includes hints, "must be an integer"
|
|
38
39
|
assert_includes hints, "must be greater than 19"
|
|
39
40
|
end
|
|
40
41
|
|
|
42
|
+
def test_bare_numericality_emits_must_be_a_number
|
|
43
|
+
model = Class.new(ActiveRecord::Base) do
|
|
44
|
+
self.table_name = "people"
|
|
45
|
+
validates :age, numericality: true
|
|
46
|
+
def self.name
|
|
47
|
+
"BareNumericalityModel"
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
assert_equal ["must be a number"], model.new.hints[:age]
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def test_numericality_range_options_keep_their_messages
|
|
55
|
+
model = Class.new(ActiveRecord::Base) do
|
|
56
|
+
self.table_name = "people"
|
|
57
|
+
validates :age, numericality: { greater_than_or_equal_to: -90, less_than_or_equal_to: 90 }
|
|
58
|
+
def self.name
|
|
59
|
+
"RangeNumericalityModel"
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
hints = model.new.hints[:age]
|
|
64
|
+
assert_equal "must be a number", hints.first,
|
|
65
|
+
"expected the base must-be-a-number hint to come first"
|
|
66
|
+
assert_includes hints, "must be greater than or equal to -90"
|
|
67
|
+
assert_includes hints, "must be less than or equal to 90"
|
|
68
|
+
end
|
|
69
|
+
|
|
41
70
|
def test_inclusion_hint_uses_list
|
|
42
71
|
hints = @person.hints[:status]
|
|
43
72
|
assert_equal 1, hints.size
|