Fix #5289: NoMethodError in /?search=.
This commit is contained in:
@@ -248,7 +248,7 @@ class ApplicationController < ActionController::Base
|
||||
# => /tags?search[name]=touhou
|
||||
def normalize_search
|
||||
return unless request.get? || request.head?
|
||||
params[:search] ||= ActionController::Parameters.new
|
||||
params[:search] = ActionController::Parameters.new unless params[:search].is_a?(ActionController::Parameters)
|
||||
|
||||
deep_reject_blank = lambda do |hash|
|
||||
hash.reject { |_k, v| v.blank? || (v.is_a?(Hash) && deep_reject_blank.call(v).blank?) }
|
||||
|
||||
@@ -342,6 +342,20 @@ class ApplicationControllerTest < ActionDispatch::IntegrationTest
|
||||
assert_equal([tags[0].id], response.parsed_body.pluck("id"))
|
||||
end
|
||||
|
||||
should "remove blank `search` params from the URL" do
|
||||
get tags_path(search: { name: "touhou", blah: "" }), as: :json
|
||||
|
||||
assert_redirected_to tags_path(search: { name: "touhou" })
|
||||
end
|
||||
|
||||
should "ignore invalid `search` params" do
|
||||
get tags_path(search: "foo"), as: :json
|
||||
assert_response :success
|
||||
|
||||
get tags_path("search[]": "foo"), as: :json
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
should "support the expiry parameter" do
|
||||
get posts_path, as: :json, params: { expiry: "1" }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user