Make integer attributes searchable, add test cases.
authorTom Clegg <tom@curoverse.com>
Fri, 14 Mar 2014 14:31:03 +0000 (10:31 -0400)
committerTom Clegg <tom@curoverse.com>
Fri, 14 Mar 2014 14:31:03 +0000 (10:31 -0400)
services/api/app/controllers/application_controller.rb
services/api/app/models/arvados_model.rb
services/api/test/functional/arvados/v1/jobs_controller_test.rb
services/api/test/functional/arvados/v1/keep_disks_controller_test.rb

index 2d37dc18cdeb8732e3cc78181048102c43d9ffbf..a47bfb57a572217a30dca8effe49b332ceee7f2e 100644 (file)
@@ -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
index 84bdf957632d2c35999d1d247a2abcf342fd207d..8e37898648c9721765bafee733c0229c7bd5b11e 100644 (file)
@@ -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
index 91f867a15cda4c934e9ce86ec42a1c76b0932bf6..f68cbc2dd2467281872adf45cea3bc72a53f6432 100644 (file)
@@ -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, {
index 3ccfa055e705dd03ff80dc694d798db24fe76efc..385710e060c94796cdcecfa634ae1631870b73ab 100644 (file)
@@ -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