Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions spec/integration/on_invalid_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions spec/support/rails_template.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Loading