A platform for community discussion. Free, open, simple.
DEV: Return 400 instead of 500 for invalid top period (#13828)
Blake Erickson6ac3f1f7b593
diff --git a/app/controllers/list_controller.rb b/app/controllers/list_controller.rbindex b0d3f6bd100..1fc891ea767 100644--- a/app/controllers/list_controller.rb+++ b/app/controllers/list_controller.rb@@ -259,6 +259,7 @@ class ListController < ApplicationControlleroptions ||= {}period = params[:period]period ||= ListController.best_period_for(current_user.try(:previous_visit_at), options[:category])+ TopTopic.validate_period(period)public_send("top_#{period}", options)enddiff --git a/spec/requests/list_controller_spec.rb b/spec/requests/list_controller_spec.rbindex e84888a00a8..9bd7c6f8596 100644--- a/spec/requests/list_controller_spec.rb+++ b/spec/requests/list_controller_spec.rb@@ -424,6 +424,23 @@ RSpec.describe ListController doendend+ describe 'Top' do+ it 'renders top' do+ get "/top"+ expect(response.status).to eq(200)+ end++ it 'renders top with a period' do+ get "/top?period=weekly"+ expect(response.status).to eq(200)+ end++ it 'errors for invalid periods on top' do+ get "/top?period=decadely"+ expect(response.status).to eq(400)+ end+ end+describe 'category' docontext 'in a category' dolet(:category) { Fabricate(:category_with_definition) }