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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7a63f8c6fa440f31200326f8154cc5354a656f62c7c31e9e0080c4d63215970c
4
- data.tar.gz: '08183d70145bc652dcd5c686e2b154126bb07cd657a5d0b057b660e2486e9f91'
3
+ metadata.gz: fa2d51e94503ff4656ea0f9c90b45ea1616e7ffee979ca955f01b9e4704586a1
4
+ data.tar.gz: 7c27666b62f82f62c833ff502535eb666e75141196b1f59d49212680e7756ac5
5
5
  SHA512:
6
- metadata.gz: 782c4cf1f1e60d73cef7413654f36e745b3b6303c1f996330d548d8e8892917e0ff9bc8ceff5d2149230fe12f260c33cd15237e96635c33e4f947f9c0a10f530
7
- data.tar.gz: c3dbf979e54ffa77b364389a9805a6c4383ec64dda72611466a2b48222c91ba40a4ab76d21c7554595fbcf314a8da91908ceca5c4bbcec4bf0aaa064fbf89e71
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
@@ -228,8 +228,15 @@ module ActiveModel
228
228
  end
229
229
 
230
230
  message_key = key
231
- message_key = "numericality.must_be_a_number" if key == "numericality"
232
- unless VALIDATORS_WITHOUT_MAIN_KEYS.include?(key)
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"
@@ -1,4 +1,4 @@
1
1
  # -*- encoding : utf-8 -*-
2
2
  module ValidationHints
3
- VERSION = "8.1.19"
3
+ VERSION = "8.1.20"
4
4
  end
@@ -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
@@ -4,7 +4,7 @@ require "test_helper"
4
4
 
5
5
  class ValidationHintsTest < Minitest::Test
6
6
  def test_version
7
- assert_equal "8.1.4", ValidationHints::VERSION
7
+ assert_equal "8.1.20", ValidationHints::VERSION
8
8
  end
9
9
 
10
10
  def test_locale_path_exists
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: validation_hints
3
3
  version: !ruby/object:Gem::Version
4
- version: 8.1.19
4
+ version: 8.1.20
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ace Suares