From 34337b0eb504247f20c6fc265100ca6610ecc791 Mon Sep 17 00:00:00 2001 From: evazion Date: Tue, 31 Mar 2020 21:06:49 -0500 Subject: [PATCH] popular posts: fix exception when given blank date param. Flexbooru calls this endpoint with a blank date param. --- app/controllers/explore/posts_controller.rb | 2 +- test/functional/explore/posts_controller_test.rb | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/app/controllers/explore/posts_controller.rb b/app/controllers/explore/posts_controller.rb index 89101f98d..a0939acb1 100644 --- a/app/controllers/explore/posts_controller.rb +++ b/app/controllers/explore/posts_controller.rb @@ -38,7 +38,7 @@ module Explore private def parse_date(params) - date = params[:date] ? Date.parse(params[:date]) : Time.zone.today + date = params[:date].present? ? Date.parse(params[:date]) : Time.zone.today scale = params[:scale].in?(["day", "week", "month"]) ? params[:scale] : "day" min_date = date.send("beginning_of_#{scale}") max_date = date.send("next_#{scale}").send("beginning_of_#{scale}") diff --git a/test/functional/explore/posts_controller_test.rb b/test/functional/explore/posts_controller_test.rb index b136904a1..171235f32 100644 --- a/test/functional/explore/posts_controller_test.rb +++ b/test/functional/explore/posts_controller_test.rb @@ -12,6 +12,11 @@ module Explore get popular_explore_posts_path assert_response :success end + + should "work with a blank date" do + get popular_explore_posts_path(date: "") + assert_response :success + end end context "#curated" do