spamtrap 0.3.3 → 0.3.5
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/lib/spamtrap/helper.rb +20 -1
- data/lib/spamtrap/version.rb +1 -1
- data/test/form_builder_mutation_test.rb +32 -0
- 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: 7fe29ab4e860e6ec50177f3726bee89e12d1e04ad26f1690937134e2fd3bb3ec
|
|
4
|
+
data.tar.gz: ccb09fadb403aa131c826422d774f9ec0d72929ca9d3f8f737a9ddb84795ecfd
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: '09de714c88709d90859cb25c8f129bb88efeba1a2c697519bca1aaa8df816894e3c442e37598c423fa8740832123af86c85b204ae5eec6eeb3115566a7fe74d4'
|
|
7
|
+
data.tar.gz: 65bda092b52a6bc5b0a58c61c5b08ad3e2f7723c1daf6418071582691eabfa0897998bf33bd7b473aae91708621cc9f0e368d1bf8e780bf14feb761c2a8f6f23
|
data/lib/spamtrap/helper.rb
CHANGED
|
@@ -43,7 +43,26 @@ module Spamtrap
|
|
|
43
43
|
|
|
44
44
|
super(encrypted_field, *args, opts, &blk)
|
|
45
45
|
when :label
|
|
46
|
-
#
|
|
46
|
+
# Preserve the human-readable label text using the real field name
|
|
47
|
+
# before substituting the encrypted form. Mirrors Rails' own
|
|
48
|
+
# resolution order:
|
|
49
|
+
# 1. explicit text argument — kept as-is
|
|
50
|
+
# 2. activerecord.attributes.Model.field (ActiveRecord models)
|
|
51
|
+
# 3. helpers.label.object_name.field (plain objects / form_with)
|
|
52
|
+
# 4. humanize fallback
|
|
53
|
+
# Discard any explicit nil that a subclass may have passed through
|
|
54
|
+
# (e.g. `super(method, nil, options)`) so it does not survive as a
|
|
55
|
+
# spurious positional argument in the final super call.
|
|
56
|
+
args.compact!
|
|
57
|
+
unless args.first.is_a?(String)
|
|
58
|
+
human_text =
|
|
59
|
+
if object.respond_to?(:to_model)
|
|
60
|
+
object.class.human_attribute_name(field.to_s, default: field.to_s.humanize)
|
|
61
|
+
else
|
|
62
|
+
I18n.t(field, scope: [:helpers, :label, object_name], default: field.to_s.humanize)
|
|
63
|
+
end
|
|
64
|
+
args.unshift(human_text)
|
|
65
|
+
end
|
|
47
66
|
super(encrypted_field, *args, opts, &blk)
|
|
48
67
|
else
|
|
49
68
|
opts[:value] = model_value unless opts.key?(:value)
|
data/lib/spamtrap/version.rb
CHANGED
|
@@ -133,6 +133,38 @@ class FormBuilderMutationTest < ActionView::TestCase
|
|
|
133
133
|
assert_match(/selected.*CA|CA.*selected/, html)
|
|
134
134
|
end
|
|
135
135
|
|
|
136
|
+
# --- label ---
|
|
137
|
+
|
|
138
|
+
def test_label_does_not_raise_when_mutate_is_true
|
|
139
|
+
msg = Message.new('Alice', 'alice@example.com', 'Hello')
|
|
140
|
+
f = build_form_builder(msg)
|
|
141
|
+
f.spamtrap(:trap, mutate: true)
|
|
142
|
+
|
|
143
|
+
assert_nothing_raised { f.label(:name) }
|
|
144
|
+
end
|
|
145
|
+
|
|
146
|
+
def test_label_with_explicit_nil_text_does_not_raise
|
|
147
|
+
# Regression: a subclass that calls super(method, nil, options) used to
|
|
148
|
+
# produce "wrong number of arguments (given 4, expected 1..3)" because the
|
|
149
|
+
# nil survived as a positional argument alongside the auto-generated text.
|
|
150
|
+
msg = Message.new('Alice', 'alice@example.com', 'Hello')
|
|
151
|
+
base = build_form_builder(msg)
|
|
152
|
+
base.spamtrap(:trap, mutate: true)
|
|
153
|
+
|
|
154
|
+
# Simulate what a subclass does: call label with nil text explicitly.
|
|
155
|
+
assert_nothing_raised { base.label(:name, nil, class: 'my-label') }
|
|
156
|
+
end
|
|
157
|
+
|
|
158
|
+
def test_label_with_explicit_nil_text_uses_humanized_fallback
|
|
159
|
+
msg = Message.new('Alice', 'alice@example.com', 'Hello')
|
|
160
|
+
base = build_form_builder(msg)
|
|
161
|
+
base.spamtrap(:trap, mutate: true)
|
|
162
|
+
|
|
163
|
+
html = base.label(:name, nil, class: 'my-label')
|
|
164
|
+
|
|
165
|
+
assert_includes html, 'Name'
|
|
166
|
+
end
|
|
167
|
+
|
|
136
168
|
private
|
|
137
169
|
|
|
138
170
|
# ActionView::TestCase helpers expect a #request method; provide a stub.
|