closes #5186
[arvados.git] / services / api / test / unit / collection_test.rb
index 07831149906354a9ae4692350bbaec4ef9e32fd5..08f46fddccced0974db6cf12f51f04827f862734 100644 (file)
@@ -92,28 +92,49 @@ class CollectionTest < ActiveSupport::TestCase
 
     [
       ['foo', true],
-      ['foo bar', true],
-      ['foox barx', false],                   # no match for either
-      ['foo barx', true],
-      ['file4', true],                        # whole string match
+      ['foo bar', false],                     # no collection matching both
+      ['foo&bar', false],                     # no collection matching both
+      ['foo|bar', true],                      # works only no spaces between the words
+      ['Gnu public', true],                   # both prefixes found, though not consecutively
+      ['Gnu&public', true],                   # both prefixes found, though not consecutively
+      ['file4', true],                        # prefix match
       ['file4.txt', true],                    # whole string match
-      ['filex', false],                       # looks for the whole string and fails
+      ['filex', false],                       # no such prefix
+      ['subdir', true],                       # prefix matches
       ['subdir2', true],
       ['subdir2/', true],
       ['subdir2/subdir3', true],
       ['subdir2/subdir3/subdir4', true],
-      ['subdir', true],                       # prefix matches
-      ['no-such-file', false],                # looks for whole string and fails
-      ['no such file', true],                 # matches "file"
+      ['subdir2 file4', true],                # look for both prefixes
+      ['subdir4', false],                     # not a prefix match
     ].each do |search_filter, expect_results|
-      search_filters = search_filter.split.each {|s| s.concat(':*')}
-      results = Collection.where("to_tsvector('english', file_names) @@ to_tsquery(?)",
-                                 "#{search_filters.join('|')}")
+      search_filters = search_filter.split.each {|s| s.concat(':*')}.join('&')
+      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
+
+  [0, 2, 4, nil].each do |ask|
+    test "replication_desired reports #{ask or 2} if redundancy is #{ask}" do
+      act_as_user users(:active) do
+        c = collections(:collection_owned_by_active)
+        c.update_attributes redundancy: ask
+        assert_equal (ask or 2), c.replication_desired
       end
     end
   end
+
+  test "create collection with properties" do
+    act_as_system_user do
+      c = Collection.create(manifest_text: ". acbd18db4cc2f85cedef654fccc4a4d8+3 0:3:foo\n",
+                            properties: {'property_1' => 'value_1'})
+      assert c.valid?
+      assert_equal 'value_1', c.properties['property_1']
+    end
+  end
 end