correct the validator
This commit is contained in:
parent
91e0a77a60
commit
38c10a3dc2
|
@ -17,14 +17,20 @@ class TopicQuery
|
||||||
Integer === x && x >= 0
|
Integer === x && x >= 0
|
||||||
end
|
end
|
||||||
|
|
||||||
array_int = lambda do |x|
|
int = lambda do |x|
|
||||||
Array === x && x.length > 0 && x.all? { |i| Integer === i || i.match?(/^-?[0-9]+$/) }
|
Integer === x || (String === x && x.match?(/^-?[0-9]+$/))
|
||||||
|
end
|
||||||
|
|
||||||
|
array_int_or_int = lambda do |x|
|
||||||
|
int.call(x) || (
|
||||||
|
Array === x && x.length > 0 && x.all?(&int)
|
||||||
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
{
|
{
|
||||||
max_posts: zero_or_more,
|
max_posts: zero_or_more,
|
||||||
min_posts: zero_or_more,
|
min_posts: zero_or_more,
|
||||||
exclude_category_ids: array_int
|
exclude_category_ids: array_int_or_int
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -33,6 +33,9 @@ RSpec.describe ListController do
|
||||||
it "returns 200 for legit requests" do
|
it "returns 200 for legit requests" do
|
||||||
get "/latest.json?exclude_category_ids%5B%5D=69&exclude_category_ids%5B%5D=70&no_definitions=true&no_subcategories=false&page=1&_=1534296100767"
|
get "/latest.json?exclude_category_ids%5B%5D=69&exclude_category_ids%5B%5D=70&no_definitions=true&no_subcategories=false&page=1&_=1534296100767"
|
||||||
expect(response.status).to eq(200)
|
expect(response.status).to eq(200)
|
||||||
|
|
||||||
|
get "/latest.json?exclude_category_ids=-1"
|
||||||
|
expect(response.status).to eq(200)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "doesn't throw an error with page params as an array" do
|
it "doesn't throw an error with page params as an array" do
|
||||||
|
|
Loading…
Reference in New Issue