From b17fdc57fe5762e4f32a0cb1a93e6372ade42df9 Mon Sep 17 00:00:00 2001 From: yuenmichelle1 Date: Thu, 10 Oct 2024 14:48:10 -0500 Subject: [PATCH] Bug fix, allow allowable periods to be case insensitive --- app/controllers/application_controller.rb | 3 ++- .../user_classification_count_controller_spec.rb | 1 + spec/support/query_params_validator.rb | 6 ++++++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 3e52214..2f13f43 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -78,7 +78,8 @@ def validate_date(date_param) end def validate_period - raise ValidationError, 'Invalid bucket option. Valid options for period is day, week, month, or year' unless SelectableWithTimeBucket::TIME_BUCKET_OPTIONS.keys.include? params[:period].downcase.to_sym + params[:period] = params[:period].downcase + raise ValidationError, 'Invalid bucket option. Valid options for period is day, week, month, or year' unless SelectableWithTimeBucket::TIME_BUCKET_OPTIONS.keys.include? params[:period].to_sym end def valid_date_range diff --git a/spec/controllers/user_classification_count_controller_spec.rb b/spec/controllers/user_classification_count_controller_spec.rb index 1d7b57b..0f3aa54 100644 --- a/spec/controllers/user_classification_count_controller_spec.rb +++ b/spec/controllers/user_classification_count_controller_spec.rb @@ -92,6 +92,7 @@ end context 'param validations' do + before(:each) { authenticate!(is_panoptes_admin: true) } it_behaves_like 'ensure valid query params', :query, id: 1 it 'ensures you cannot query by workflow and project_contributions' do diff --git a/spec/support/query_params_validator.rb b/spec/support/query_params_validator.rb index ff2015d..0bf8a2e 100644 --- a/spec/support/query_params_validator.rb +++ b/spec/support/query_params_validator.rb @@ -18,6 +18,12 @@ expect(response.body).to include('Invalid bucket option. Valid options for period is day, week, month, or year') end + it 'allows period param to be case-insensitive' do + params[:period] = 'MONTH' + get query, params: params + expect(response.status).to eq(200) + end + it 'ensures that we do not query by both workflow and project' do params[:workflow_id] = 1 params[:project_id] = 2