[ARVADOS] updated: 1.3.0-609-gce0caee0e

Git user git at public.curoverse.com
Fri Mar 29 17:54:49 UTC 2019


Summary of changes:
 services/api/app/models/collection.rb     | 14 ++++++++++++++
 services/api/test/unit/collection_test.rb | 32 +++++++++++++++++++++++++++++++
 2 files changed, 46 insertions(+)

       via  ce0caee0ecb9c8f6c6cbefc1a12a37560d0f7554 (commit)
      from  bd2ac2038b13b6ebe92b44cf722c8cf0fa15255b (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.


commit ce0caee0ecb9c8f6c6cbefc1a12a37560d0f7554
Author: Eric Biagiotti <ebiagiotti at veritasgenetics.com>
Date:   Fri Mar 29 13:54:28 2019 -0400

    14484: Adds tests for Collection model and makes file attributes readonly
    
    Arvados-DCO-1.1-Signed-off-by: Eric Biagiotti <ebiagiotti at veritasgenetics.com>

diff --git a/services/api/app/models/collection.rb b/services/api/app/models/collection.rb
index 73a8df11f..3dc64f6e0 100644
--- a/services/api/app/models/collection.rb
+++ b/services/api/app/models/collection.rb
@@ -29,6 +29,7 @@ class Collection < ArvadosModel
   validate :ensure_storage_classes_contain_non_empty_strings
   validate :versioning_metadata_updates, on: :update
   validate :past_versions_cannot_be_updated, on: :update
+  validate :file_count_and_size_cannot_be_changed
   before_save :set_file_names
   before_save :set_file_count_and_total_size
   around_update :manage_versioning
@@ -649,6 +650,19 @@ class Collection < ArvadosModel
     end
   end
 
+  def file_count_and_size_cannot_be_changed
+    valid = true
+    if file_count_changed?
+      errors.add(:file_count, "cannot be changed")
+      valid = false
+    end
+    if file_size_total_changed?
+      errors.add(:file_size_total, "cannot be changed")
+      valid = false
+    end
+    valid
+  end
+
   def versioning_metadata_updates
     valid = true
     if (current_version_uuid_was == uuid_was) && current_version_uuid_changed?
diff --git a/services/api/test/unit/collection_test.rb b/services/api/test/unit/collection_test.rb
index 9797ed63d..a0fa3cac9 100644
--- a/services/api/test/unit/collection_test.rb
+++ b/services/api/test/unit/collection_test.rb
@@ -61,6 +61,38 @@ class CollectionTest < ActiveSupport::TestCase
   end
 
   [
+    [". d41d8cd98f00b204e9800998ecf8427e 0:34:foo.txt\n", 1, 34],
+    [". d41d8cd98f00b204e9800998ecf8427e 0:34:foo.txt 0:30:foo.txt 0:30:foo1.txt 0:30:foo2.txt 0:30:foo3.txt 0:30:foo4.txt\n", 5, 184],
+    [". d41d8cd98f00b204e9800998ecf8427e 0:0:.\n", 0, 0]
+  ].each do |t|
+    test "file stats on create collection with #{t[0]}" do
+      act_as_system_user do
+        c = Collection.create(manifest_text: t[0])
+        assert_equal t[1], c.file_count
+        assert_equal t[2], c.file_size_total
+      end
+    end
+  end
+
+  test "file stats cannot be changed unless through manifest change" do
+    act_as_system_user do
+      c = Collection.create(manifest_text: ". d41d8cd98f00b204e9800998ecf8427e 0:34:foo.txt\n")
+      assert c.valid?
+      c.file_count = 6
+      c.file_size_total = 30
+      assert !c.valid?
+      c.reload
+      assert_equal 1, c.file_count
+      assert_equal 34, c.file_size_total
+      c.update(manifest_text: ". d41d8cd98f00b204e9800998ecf8427e 0:10:foo.txt 0:10:foo2.txt\n")
+      assert c.valid?
+      c.reload
+      assert_equal 2, c.file_count
+      assert_equal 20, c.file_size_total
+    end
+  end
+
+  [
     nil,
     "",
     ". d41d8cd98f00b204e9800998ecf8427e 0:0:foo.txt\n",

-----------------------------------------------------------------------


hooks/post-receive
-- 




More information about the arvados-commits mailing list