Support parsing array in #param_to_integer_list

Co-authored-by: Akshay Birajdar <akshay.birajdar@coupa.com>
This commit is contained in:
Akshay Birajdar 2021-11-03 21:26:33 +05:30 committed by Robin Ward
parent cfabdb72bc
commit 6b5e8be25a
2 changed files with 10 additions and 1 deletions

View File

@ -928,8 +928,11 @@ class ApplicationController < ActionController::Base
# returns an array of integers given a param key
# returns nil if key is not found
def param_to_integer_list(key, delimiter = ',')
if params[key]
case params[key]
when String
params[key].split(delimiter).map(&:to_i)
when Array
params[key].map(&:to_i)
end
end

View File

@ -55,6 +55,12 @@ RSpec.describe ListController do
get "/latest?search="
expect(response.status).to eq(200)
get "/latest.json?topic_ids%5B%5D=14583&topic_ids%5B%5D=14584"
expect(response.status).to eq(200)
get "/latest.json?topic_ids=14583%2C14584"
expect(response.status).to eq(200)
end
(Discourse.anonymous_filters - [:categories]).each do |filter|