active_admin_filter_extensions 1.0.0 → 1.0.1
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:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 51bc6cafe8895502a79f648a96f6c7e4f28fbb9c3a985eac07c43aa7d86e320f
|
|
4
|
+
data.tar.gz: 37c3a1beef3da668ac558dc7364b076f8212d980f9efce5da8110213fac3aa22
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: a4fbb0cfa85464dbee996d124f7fa47120bd618e04a2fe645683b8a32593107921d0eda74ad39cbb8bb3898e23c4816ae9453c13b25e7eb52dfd31740def0535
|
|
7
|
+
data.tar.gz: d81c7d2722af7494ab5ff73255ea76818ed826d8196b9f04e9b5c94417ac1d29bbc24696311124b80394ab29826e26f58150a5a49f74235d18edb55b65b5a626
|
|
@@ -232,10 +232,29 @@ module ActiveAdminFilterExtensions
|
|
|
232
232
|
|
|
233
233
|
# The filter's own predicate dropdown submits _gt/_lt/_not_eq and friends beside the
|
|
234
234
|
# derived head key; a value policy guarding only the head leaves the same column one
|
|
235
|
-
# dropdown click from unpoliced. Siblings = request keys naming the same attribute
|
|
235
|
+
# dropdown click from unpoliced. Siblings = request keys naming the same attribute,
|
|
236
|
+
# minus the predicates answered by a boolean rather than by a value of the attribute's
|
|
237
|
+
# own type: `?q[customer_id_null]=true` carries "true", which `sanitize: :digits`
|
|
238
|
+
# empties and `validate: :integer` refuses - the reset would then drop a condition a
|
|
239
|
+
# drill-down link spelled out. A boolean predicate the filter declares itself stays
|
|
240
|
+
# policed: that one its author asked for.
|
|
236
241
|
def sibling_predicate_keys(q, keys)
|
|
237
242
|
bases = keys.map { |key| strip_ransack_predicate(key) }
|
|
238
|
-
|
|
243
|
+
declared = keys.map(&:to_s)
|
|
244
|
+
q.keys.select do |key|
|
|
245
|
+
next false unless bases.include?(strip_ransack_predicate(key))
|
|
246
|
+
|
|
247
|
+
declared.include?(key.to_s) || !boolean_predicate?(key)
|
|
248
|
+
end
|
|
249
|
+
end
|
|
250
|
+
|
|
251
|
+
def boolean_predicate?(name)
|
|
252
|
+
# Without Ransack there is nothing to ask - and nothing is stripped either, so a
|
|
253
|
+
# sibling can only be the declared key itself.
|
|
254
|
+
return false unless defined?(::Ransack::Predicate)
|
|
255
|
+
|
|
256
|
+
predicate = ::Ransack::Predicate.detect_from_string(name.to_s)
|
|
257
|
+
predicate && ::Ransack::Predicate.named(predicate)&.type == :boolean
|
|
239
258
|
end
|
|
240
259
|
|
|
241
260
|
def strip_ransack_predicate(name)
|
|
@@ -78,6 +78,19 @@ RSpec.describe "built-in numeric policies", type: :feature do
|
|
|
78
78
|
expect(page).to have_no_content("drop me")
|
|
79
79
|
end
|
|
80
80
|
|
|
81
|
+
it "leaves a boolean predicate of the same attribute to Ransack" do
|
|
82
|
+
# `?q[position_null]=true` is answered by "true", not by a value of the column's own
|
|
83
|
+
# type: the digits sanitizer would empty it and the integer validator refuse it, and the
|
|
84
|
+
# reset would drop a condition the admin's own drill-down link spelled out.
|
|
85
|
+
Post.create!(title: "no position", body: "no position body", status: "draft")
|
|
86
|
+
|
|
87
|
+
visit "/admin/integer_posts?q%5Bposition_null%5D=true"
|
|
88
|
+
|
|
89
|
+
expect(query_of(page.current_url)["q"]).to eq("position_null" => "true")
|
|
90
|
+
expect(page).to have_content("no position")
|
|
91
|
+
expect(page).to have_no_content("keep me")
|
|
92
|
+
end
|
|
93
|
+
|
|
81
94
|
it "sanitizes a sibling predicate too" do
|
|
82
95
|
visit "/admin/integer_posts?q%5Bposition_lt%5D=2%200a"
|
|
83
96
|
|