diff --git a/spec/integration/on_invalid_spec.rb b/spec/integration/on_invalid_spec.rb index 7f9460b..61f37be 100644 --- a/spec/integration/on_invalid_spec.rb +++ b/spec/integration/on_invalid_spec.rb @@ -94,12 +94,14 @@ def query_of(url) expect(page).to have_no_content("drop me") end - it "validates array elements emptied by the sanitizer and preserves the original input" do - visit "/admin/empty_digits_posts?q%5Bposition_eq%5D%5B%5D=abc" + it "validates array elements emptied by the sanitizer and keeps a checkbox input" do + visit "/admin/empty_digits_array_posts" + check "Not a number" + click_button "Filter" expect(page).to have_content("filter has an invalid value") - expect(query_of(page.current_url)["q"]).to eq("position_eq" => ["abc"]) - expect(page).to have_field("q[position_eq]", with: "0") + expect(query_of(page.current_url)["q"]).to eq("status_in" => ["abc"]) + expect(page).to have_checked_field("q[status_in][]", with: "abc") expect(page).to have_no_content("keep me") expect(page).to have_no_content("drop me") end diff --git a/spec/support/rails_template.rb b/spec/support/rails_template.rb index bf64ad8..01ffe01 100644 --- a/spec/support/rails_template.rb +++ b/spec/support/rails_template.rb @@ -517,6 +517,14 @@ def filter_defaults_apply? extensions: { sanitize: :digits, validate: :integer, on_invalid: :empty } end + ActiveAdmin.register Post, as: "EmptyDigitsArrayPost" do + # A genuine multi-value filter: unlike the scalar filter above, its check boxes submit + # q[status_in][] and can therefore render the preserved array back to the admin. + filter :status, as: :check_boxes, + collection: [["Not a number", "abc"], "draft", "published"], + extensions: { sanitize: :digits, validate: :integer, on_invalid: :empty } + end + ActiveAdmin.register Post, as: "RejectWindowPost" do # Value AND window policies on one :reject filter: the second violation must not answer # an already-answered request.