From 937ab3f21327ded989781dab6204c031834c6686 Mon Sep 17 00:00:00 2001 From: Gerhard Schlager Date: Thu, 16 Aug 2018 10:36:02 +0200 Subject: [PATCH] FIX: Validation of min_posts and max_posts didn't work --- lib/topic_query.rb | 8 ++++---- spec/requests/list_controller_spec.rb | 6 ++++++ 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/lib/topic_query.rb b/lib/topic_query.rb index 5592a29bb79..c01d7c8567e 100644 --- a/lib/topic_query.rb +++ b/lib/topic_query.rb @@ -13,14 +13,14 @@ class TopicQuery def self.validators @validators ||= begin - zero_or_more = lambda do |x| - Integer === x && x >= 0 - end - int = lambda do |x| Integer === x || (String === x && x.match?(/^-?[0-9]+$/)) end + zero_or_more = lambda do |x| + int.call(x) && x.to_i >= 0 + end + array_int_or_int = lambda do |x| int.call(x) || ( Array === x && x.length > 0 && x.all?(&int) diff --git a/spec/requests/list_controller_spec.rb b/spec/requests/list_controller_spec.rb index e9c863d82f4..3ea4170486f 100644 --- a/spec/requests/list_controller_spec.rb +++ b/spec/requests/list_controller_spec.rb @@ -36,6 +36,12 @@ RSpec.describe ListController do get "/latest.json?exclude_category_ids=-1" expect(response.status).to eq(200) + + get "/latest.json?max_posts=12" + expect(response.status).to eq(200) + + get "/latest.json?min_posts=0" + expect(response.status).to eq(200) end it "doesn't throw an error with page params as an array" do