From 1dec6cc7093bcc565bed2baba17c8a892b7e2633 Mon Sep 17 00:00:00 2001 From: Tom Clegg Date: Fri, 14 Mar 2014 10:31:03 -0400 Subject: [PATCH] Make integer attributes searchable, add test cases. --- .../app/controllers/application_controller.rb | 6 ++- services/api/app/models/arvados_model.rb | 2 +- .../arvados/v1/jobs_controller_test.rb | 49 +++++++++++++++++++ .../arvados/v1/keep_disks_controller_test.rb | 28 +++++++++++ 4 files changed, 82 insertions(+), 3 deletions(-) diff --git a/services/api/app/controllers/application_controller.rb b/services/api/app/controllers/application_controller.rb index 2d37dc18cd..a47bfb57a5 100644 --- a/services/api/app/controllers/application_controller.rb +++ b/services/api/app/controllers/application_controller.rb @@ -153,8 +153,10 @@ class ApplicationController < ActionController::Base when '=', '<', '<=', '>', '>=', 'like' if operand.is_a? String cond_out << "#{table_name}.#{attr} #{operator} ?" - if operator.match(/[<=>]/) and - model_class.attribute_column(attr).type == :datetime + if (# any operator that operates on value rather than + # representation: + operator.match(/[<=>]/) and + model_class.attribute_column(attr).type == :datetime) operand = Time.parse operand end param_out << operand diff --git a/services/api/app/models/arvados_model.rb b/services/api/app/models/arvados_model.rb index 84bdf95763..8e37898648 100644 --- a/services/api/app/models/arvados_model.rb +++ b/services/api/app/models/arvados_model.rb @@ -40,7 +40,7 @@ class ArvadosModel < ActiveRecord::Base def self.searchable_columns self.columns.collect do |col| - if [:string, :text, :datetime].index(col.type) && col.name != 'owner_uuid' + if [:string, :text, :datetime, :integer].index(col.type) && col.name != 'owner_uuid' col.name end end.compact diff --git a/services/api/test/functional/arvados/v1/jobs_controller_test.rb b/services/api/test/functional/arvados/v1/jobs_controller_test.rb index 91f867a15c..f68cbc2dd2 100644 --- a/services/api/test/functional/arvados/v1/jobs_controller_test.rb +++ b/services/api/test/functional/arvados/v1/jobs_controller_test.rb @@ -170,6 +170,55 @@ class Arvados::V1::JobsControllerTest < ActionController::TestCase 'zzzzz-8i9sb-pshmckwoma9plh7'] end + test "search jobs by started_at with < query" do + authorize_with :active + get :index, { + filters: [['started_at', '<', Time.now.to_s]] + } + assert_response :success + found = assigns(:objects).collect(&:uuid) + assert_equal true, !!found.index('zzzzz-8i9sb-pshmckwoma9plh7') + end + + test "search jobs by started_at with > query" do + authorize_with :active + get :index, { + filters: [['started_at', '>', Time.now.to_s]] + } + assert_response :success + assert_equal 0, assigns(:objects).count + end + + test "search jobs by started_at with >= query on metric date" do + authorize_with :active + get :index, { + filters: [['started_at', '>=', '2014-01-01']] + } + assert_response :success + found = assigns(:objects).collect(&:uuid) + assert_equal true, !!found.index('zzzzz-8i9sb-pshmckwoma9plh7') + end + + test "search jobs by started_at with >= query on metric date and time" do + authorize_with :active + get :index, { + filters: [['started_at', '>=', '2014-01-01 01:23:45']] + } + assert_response :success + found = assigns(:objects).collect(&:uuid) + assert_equal true, !!found.index('zzzzz-8i9sb-pshmckwoma9plh7') + end + + test "search jobs with 'any' operator" do + authorize_with :active + get :index, { + where: { any: ['contains', 'pshmckw'] } + } + assert_response :success + found = assigns(:objects).collect(&:uuid) + assert_equal true, !!found.index('zzzzz-8i9sb-pshmckwoma9plh7') + end + test "search jobs by nonexistent column with < query" do authorize_with :active get :index, { diff --git a/services/api/test/functional/arvados/v1/keep_disks_controller_test.rb b/services/api/test/functional/arvados/v1/keep_disks_controller_test.rb index 3ccfa055e7..385710e060 100644 --- a/services/api/test/functional/arvados/v1/keep_disks_controller_test.rb +++ b/services/api/test/functional/arvados/v1/keep_disks_controller_test.rb @@ -94,4 +94,32 @@ class Arvados::V1::KeepDisksControllerTest < ActionController::TestCase end end + test "search keep_disks by service_port with >= query" do + authorize_with :active + get :index, { + filters: [['service_port', '>=', 25107]] + } + assert_response :success + assert_equal true, assigns(:objects).any? + end + + test "search keep_disks by service_port with < query" do + authorize_with :active + get :index, { + filters: [['service_port', '<', 25107]] + } + assert_response :success + assert_equal false, assigns(:objects).any? + end + + test "search keep_disks with 'any' operator" do + authorize_with :active + get :index, { + where: { any: ['contains', 'o2t1q5w'] } + } + assert_response :success + found = assigns(:objects).collect(&:uuid) + assert_equal true, !!found.index('zzzzz-penuu-5w2o2t1q5wy7fhn') + end + end -- 2.30.2