Merge remote-tracking branch 'origin/master' into 14484-collection-record-update
[arvados.git] / services / api / test / unit / collection_test.rb
index 8538b35b35c7ba20738144b166326ee7257e4df9..8deedee0186ea5bbd87ba6d219d7ef4d47f66314 100644 (file)
@@ -76,25 +76,34 @@ class CollectionTest < ActiveSupport::TestCase
 
   test "file stats cannot be changed unless through manifest change" do
     act_as_system_user do
-      # Changing file stats via an update should fail validation
+      # Direct changes to file stats should be ignored
       c = Collection.create(manifest_text: ". d41d8cd98f00b204e9800998ecf8427e 0:34:foo.txt\n")
       c.file_count = 6
       c.file_size_total = 30
-      assert !c.valid?
-      c.reload
+      assert c.valid?
       assert_equal 1, c.file_count
       assert_equal 34, c.file_size_total
 
-      # Changing the file stats via manifest change validates
-      c = Collection.create(manifest_text: ". d41d8cd98f00b204e9800998ecf8427e 0:34:foo.txt 0:34:foo2.txt\n")
-      c.reload
+      # File stats specified on create should be ignored and overwritten
+      c = Collection.create(manifest_text: ". d41d8cd98f00b204e9800998ecf8427e 0:34:foo.txt\n", file_count: 10, file_size_total: 10)
+      assert c.valid?
+      assert_equal 1, c.file_count
+      assert_equal 34, c.file_size_total
+
+      # Updating the manifest should change file stats
+      c.update_attributes(manifest_text: ". d41d8cd98f00b204e9800998ecf8427e 0:34:foo.txt 0:34:foo2.txt\n")
       assert c.valid?
       assert_equal 2, c.file_count
       assert_equal 68, c.file_size_total
 
-      # Changing file stats at create, will silently overwrite
-      c = Collection.create(manifest_text: ". d41d8cd98f00b204e9800998ecf8427e 0:34:foo.txt\n", file_count: 10, file_size_total: 10)
-      c.reload
+      # Updating file stats and the manifest should use manifest values
+      c.update_attributes(manifest_text: ". d41d8cd98f00b204e9800998ecf8427e 0:34:foo.txt\n", file_count:10, file_size_total: 10)
+      assert c.valid?
+      assert_equal 1, c.file_count
+      assert_equal 34, c.file_size_total
+
+      # Updating just the file stats should be ignored
+      c.update_attributes(file_count: 10, file_size_total: 10)
       assert c.valid?
       assert_equal 1, c.file_count
       assert_equal 34, c.file_size_total