diff --git a/lib/check_search.rb b/lib/check_search.rb index a2d77c1c35..eefe0d25fd 100644 --- a/lib/check_search.rb +++ b/lib/check_search.rb @@ -488,8 +488,8 @@ def file_filter def team_tasks_conditions conditions = [] - return conditions unless @options.has_key?('team_tasks') && @options['team_tasks'].class.name == 'Array' - @options['team_tasks'].delete_if{ |tt| tt['response'].blank? } + return conditions unless @options['team_tasks'].class.name == 'Array' + @options['team_tasks'].delete_if{ |tt| tt['response'].blank? || tt['id'].blank? } @options['team_tasks'].each do |tt| must_c = [] must_c << { term: { "task_responses.team_task_id": tt['id'] } } if tt.has_key?('id') diff --git a/test/models/saved_search_test.rb b/test/models/saved_search_test.rb index 4b74a28bbf..2980963db1 100644 --- a/test/models/saved_search_test.rb +++ b/test/models/saved_search_test.rb @@ -44,4 +44,11 @@ def setup ss = create_saved_search assert_equal 0, ss.items_count end + + test "should not crash if filter is invalid" do + ss = create_saved_search filters: { team_tasks: [{ id: '', task_type: 'single_choice', response: 'NO_VALUE' }] } + assert_nothing_raised do + assert_equal 0, ss.items_count + end + end end