4523: full-text search is not supported for individual columns and only 'any' is...
authorRadhika Chippada <radhika@curoverse.com>
Thu, 29 Jan 2015 18:13:16 +0000 (13:13 -0500)
committerRadhika Chippada <radhika@curoverse.com>
Thu, 29 Jan 2015 18:13:16 +0000 (13:13 -0500)
services/api/lib/record_filters.rb
services/api/test/integration/collections_api_test.rb
services/api/test/integration/groups_test.rb
services/api/test/unit/collection_test.rb

index 0156bb5bfcedf73e0b2400d5057dc3e29811c40a..b8cdef0b73b52dd0de1792437da1ff98bee28c9c 100644 (file)
@@ -34,9 +34,14 @@ module RecordFilters
       elsif !operator.is_a? String
         raise ArgumentError.new("Invalid operator '#{operator}' (#{operator.class}) in filter")
       end
+
       cond_out = []
 
       if operator == '@@' # full-text-search
+        if attrs_in != 'any'
+          raise ArgumentError.new("Full text search on individual columns is not supported")
+        end
+        attrs = [] #  skip the generic per-column operator loop below
         cond_out << model_class.full_text_tsvector+" @@ to_tsquery(?)"
         param_out << operand.split.each {|s| s.concat(':*')}.join(' & ')
       else
index b6cea740243123fb1552728c709d117738e37e75..983885d1adf4f80824b18463d47dc3a543067216 100644 (file)
@@ -165,6 +165,7 @@ class CollectionsApiTest < ActionDispatch::IntegrationTest
     }, auth(:active)
     assert_response :success
     assert_equal true, json_response['manifest_text'].include?('my_test_file.txt')
+    assert_includes json_response['manifest_text'], 'my_test_file.txt'
 
     created = json_response
 
@@ -179,8 +180,8 @@ class CollectionsApiTest < ActionDispatch::IntegrationTest
     }, auth(:active)
     assert_response :success
     assert_equal created['uuid'], json_response['uuid']
-    assert_equal true, json_response['manifest_text'].include?('my_updated_test_file.txt')
-    assert_equal false, json_response['manifest_text'].include?('my_test_file.txt')
+    assert_includes json_response['manifest_text'], 'my_updated_test_file.txt'
+    assert_not_includes json_response['manifest_text'], 'my_test_file.txt'
 
     # search using the new filename
     search_using_filter 'my_updated_test_file.txt', 1
@@ -196,10 +197,9 @@ class CollectionsApiTest < ActionDispatch::IntegrationTest
     response_items = json_response['items']
     assert_not_nil response_items
     if expected_items == 0
-      assert_equal 0, json_response['items_available']
-      assert_equal 0, response_items.size
+      assert_empty response_items
     else
-      assert_equal expected_items, response_items.size
+      refute_empty response_items
       first_item = response_items.first
       assert_not_nil first_item
     end
@@ -236,12 +236,19 @@ class CollectionsApiTest < ActionDispatch::IntegrationTest
     response_items = json_response['items']
     assert_not_nil response_items
     if expected_items == 0
-      assert_equal 0, json_response['items_available']
-      assert_equal 0, response_items.size
+      assert_empty response_items
     else
-      assert_equal expected_items, response_items.size, "Did not find results for #{search_filter}"
+      refute_empty response_items
       first_item = response_items.first
       assert_not_nil first_item
     end
   end
+
+  # search for the filename in the file_names column and expect error
+  test "full text search not supported for individual columns" do
+    get '/arvados/v1/collections', {
+      :filters => [['name', '@@', 'General']].to_json
+    }, auth(:active)
+    assert_response 422
+  end
 end
index f37b9860b52faa3a98008bad888ff4a11a8711fd..7ede5be7cc07e57d94fa8a5f20b8fcef6c50d2ea 100644 (file)
@@ -53,17 +53,22 @@ class GroupsTest < ActionDispatch::IntegrationTest
       }, auth(:active)
       assert_response :success
       if expect_results
-        assert_operator(0, :<, json_response['items'].count,
-                        "expected results but received 0")
+        refute_empty json_response['items']
         json_response['items'].each do |item|
           assert item['uuid']
           assert_equal groups(:aproject).uuid, item['owner_uuid']
         end
       else
-        assert_operator(0, :==, json_response['items'].count,
-                        "expected no results but received #{json_response['items'].length}")
+        assert_empty json_response['items']
       end
     end
   end
 
+  test "full text search is not supported for individual columns" do
+    get "/arvados/v1/groups/contents", {
+      :filters => [['name', '@@', 'Private']].to_json
+    }, auth(:active)
+    assert_response 422
+    end
+
 end
index 25ab6cd68496ceed0137078d1ea07ced04b81adf..89c9de3a54aad98210395d3e0e439b0c885e0405 100644 (file)
@@ -112,9 +112,9 @@ class CollectionTest < ActiveSupport::TestCase
       results = Collection.where("#{Collection.full_text_tsvector} @@ to_tsquery(?)",
                                  "#{search_filters}")
       if expect_results
-        assert_equal true, results.length>0, "No results found for '#{search_filter}'"
+        refute_empty results
       else
-        assert_equal 0, results.length, "Found #{results.length} results for '#{search_filter}'"
+        assert_empty results
       end
     end
   end